All those busily working on my problem (ie. Smartys ) can ignore the above post. I've solved it...but will post again once I run into some more difficulty (which I'm sure will be in no time at all).
Thanks,
You are not logged in. Please login or register.
PunBB Forums → Posts by lostcoin
Pages 1
All those busily working on my problem (ie. Smartys ) can ignore the above post. I've solved it...but will post again once I run into some more difficulty (which I'm sure will be in no time at all).
Thanks,
Hi folks, I'm hoping someone can help me understand arrays created from checkboxes in a form.
I'd like to have a user submit a form which has some checkboxes...and then have the checkboxes be pre-populated based on what the user selected (and allow the user to make changes etc. the next time it's loaded)
So, let's suppose I have some code like the following (where eventually I'll set a variable coding for "checked" to be in the form corresponding to values stored in the array $option):
$option=$_POST['option'];
echo "Value stored in \$option[red] is: ".$option[red];
echo "Value stored in \$option[blue] is: ".$option[blue];
echo "Value stored in \$option[yellow] is: ".$option[yellow];
<form action="thispage.php" method="post">
Option(s):
<ul><li><input type="checkbox" name=option[red] value="red" >Red </input>
<li><input type="checkbox" name=option[blue] value="blue">Blue </input>
<li><input type="checkbox" name=option[yellow] value="yellow">Yellow </input>
</ul>
<input type="submit" value="Submit">
</form>
What is the correct syntax to have the posted array stored in a new array? (like "red" stored in option[red] if it was selected etc.) I can't seem to implement anything correctly that I've searched and found so far.
Anyway, I know the above code is likely way off the mark but any help is greatly appreciated.
Thanks Smartys, I ended up putting it in an entirely different filename altogether and that seems to be working okay.
Thanks for your help! It is very much appreciated.
Hi folks, I know this is not punbb related but I'm *really* hoping that someone can help me.
I have the following to allow users to download certain files that were uploaded to a database. However, when the user clicks on the link, the file is inserted with all the header information from the current page and is thus currupt upon download. I know I can't "clear the current headers" before the download but what do I do here to make this work properly? Any help is greatly appreciated.
<?php
define('PUN_ROOT', '../');
include '../include/common.php';
global $pun_user;
require_once "../../../header.php";
?>
<div id="heading"><h1>File Download</h1></div><div id="main">
<?php
if ($pun_user['is_guest']) {
echo "<p><b>You must be logged in to view this page.</b><br />";
echo "<p>Please <a href=\"../login.php\">login</a> or <a href=\"../register.php\">register</a>.<br />";
echo "<p>Once registered, you can download files here.</p>";
}
else {
echo "<span class=\"login_text\">Logged in as: ".pun_htmlspecialchars($pun_user['username'])." :: <a href=\"../login.php?action=out&id=".$pun_user['id']."&location_out=".$_SERVER['PHP_SELF']."\">Logout</a></span></p><hr /><p>";
// download the file if it's clicked on
if(isset($_GET['id']))
{
include '../../dbconfig.php';
$id = $_GET['id'];
$query = "SELECT username, filename, type, size, content FROM upload WHERE id = '$id'";
$result = mysql_query($query) or die('Error, query failed');
list($db_username, $name, $type, $size, $content) = mysql_fetch_array($result);
if ($db_username != $pun_user['username']) {
echo "<br /><br /><FONT color=\"red\"><b>You do not have authorization to download that file.</b></font><br />";
} else {
header("Content-Disposition: attachment; filename=$name");
header("Content-length: $size");
header("Content-type: $type");
echo $content;
exit;
}
}
?>
<html>
<head>
<title>Download File</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body>
<?
include '../../dbconfig.php';
$user = $pun_user['username'];
$query = "SELECT id, filename FROM upload WHERE username = '$user'";
$result = mysql_query($query) or die('Error, query failed'.mysql_error());
if(mysql_num_rows($result) == 0)
{
echo "<p><b>No files found for your account.</b>";
}
// if there are files to download, list them here
else
{ echo "<p><b>Available Files:</b><p>";
while(list($id, $name) = mysql_fetch_array($result))
{
echo "<a href=\"index.php?id=".$id."\">".$name."</a> <br />";
}
echo "</p>";
}
?>
</body>
</html>
<?php
}
echo "</div>";
require_once "../../../footer.html";
?>
ah, okay...so basically any files I use with the login script need to be within the forums directory.
Thanks Smartys,
If I use the following (ie. without the slash on my define('PUN_ROOT'....) instead for my files.php page:
Code:
<?php
define('PUN_ROOT', './forums');
include 'forums/include/common.php';
include './login_function.inc.php';
login_menu();
?>
I get other errors like:
Warning: main(./forumsinclude/functions.php): failed to open stream: No such file or directory in /home/content/b/r/a/brainlung/html/forums/include/common.php on line 37
Warning: main(./forumsinclude/functions.php): failed to open stream: No such file or directory in /home/content/b/r/a/brainlung/html/forums/include/common.php on line 37
Fatal error: main(): Failed opening required './forumsinclude/functions.php' (include_path='.:/usr/local/lib/php') in /home/content/b/r/a/brainlung/html/forums/include/common.php on line 37
My "files.php" page (which is one level above my forums directory) looks like:
<?php
define('PUN_ROOT', './forums/');
include 'forums/include/common.php';
include './login_function.inc.php';
login_menu();
?>
My login function "login_function.inc.php" (which is also one level above my forums directory) looks like:
<?php
function login_menu() {
global $pun_user;
if ($pun_user['is_guest']) {
echo "<form id=\"login\" method=\"post\" action=\"/forums/login.php?action=in\" onsubmit=\"return process_form(this)\">
<input type=\"hidden\" name=\"form_sent\" value=\"1\" />
<input type=\"hidden\" name=\"redirect_url\" value=\"".$_SERVER['PHP_SELF']."?".$_SERVER['QUERY_STRING']."\" />
<input type=\"text\" name=\"req_username\" size=\"25\" maxlength=\"25\" />
<input type=\"password\" name=\"req_password\" size=\"16\" maxlength=\"16\" />
<input type=\"submit\" name=\"login\" value=\"Login\" />
</form>";
}
else {
echo "Logged in as: ".pun_htmlspecialchars($pun_user['username'])."<br> Last visit: ". format_time($pun_user['last_visit'])."
<br>Click <a href=\"/boards/login.php?action=out&id=".$pun_user['id']."\">Log out</a>here</a> to log out.</a>";
}
}
?>
Hi there, I'm having the same difficulties with the same script. I've tried a few variations of defining my path at the start but on login, I get an extra slash created for a relative link (in a similar manner as your post above)...like, my login is redirected to:
http://www.mypage.com/forums//files.php? instead of http://www.mypage.com/files.php?
Any suggestions?
Pages 1
PunBB Forums → Posts by lostcoin
Powered by PunBB, supported by Informer Technologies, Inc.