Initial textfield values?
Posted: Thu Jan 08, 2004 4:38 am
Hi all, I have a website where users are able to log in, and for now, manage a wishlist (6 textfields, each textfield is a wish).
People can come to my site, sign up, and their information is stored in a USERS table. They have a unique (auto-increment, primary key) id, username, first name, last name, etc. Now, I have a wishlist for them to fill out when logged in, which uses the table WISHES.
The database works fine, everything is updated in the database perfectly, but the problem is this, it's simple:
For the wishlist textfields, if there is a value for, let's say, wish #1, called "MP3 PLAYER," I want it to show MP3 Player in the first textfield (as its initial value) for wish #1, if it exists.
I tried doing it with this command, and the initial value of the textfield is still blank:
WHY DOES $_POST['w1'] not exist? I am looking at it right now in my database...it's in there allright....Is there something I did wrong? If it did exist, it would show it in the textfield as its initial value. What can I fix?
People can come to my site, sign up, and their information is stored in a USERS table. They have a unique (auto-increment, primary key) id, username, first name, last name, etc. Now, I have a wishlist for them to fill out when logged in, which uses the table WISHES.
The database works fine, everything is updated in the database perfectly, but the problem is this, it's simple:
For the wishlist textfields, if there is a value for, let's say, wish #1, called "MP3 PLAYER," I want it to show MP3 Player in the first textfield (as its initial value) for wish #1, if it exists.
I tried doing it with this command, and the initial value of the textfield is still blank:
Code: Select all
<?php
require('db_connect.php'); // database connect script, includes session_start() and $logged_in.
if ($logged_in == 0) {
die('Sorry you are not logged in, this area is restricted to registered members.');}
if (isset($_POST['submit'])) { // if form has been submitted
echo $_SESSION['username'];?></span>, your classes have been updated!
<?php $idiot = $db_object->query("SELECT id FROM users WHERE username = ".$db_object->quote($_SESSION['username']));
$idiot = $idiot->fetchRow();
// now we add them to the database.
// check if wish exists
$query = "SELECT w_id from wishes WHERE w_id = " . $idiot["id"];
$result = mysql_query($query);
If ($tmp = mysql_fetch_row($result)) { // if wish exists, UPDATE it
$query = 'UPDATE wishes
SET w_id = '.$idiot['id'].',
w_username = "'.$_SESSION['username'].'",
w_wish1 = "'.$_POST['w1'].'",
w_wish2 = "'.$_POST['w2'].'",
w_wish3 = "'.$_POST['w3'].'",
w_wish4 = "'.$_POST['w4'].'",
w_wish5 = "'.$_POST['w5'].'",
w_wish6 = "'.$_POST['w6'].'",
w_wish7 = "'.$_POST['w7'].'",
w_wish8 = "'.$_POST['w8'].'",
w_wish9 = "'.$_POST['w9'].'",
w_wish10 = "'.$_POST['w10'].'"
WHERE
w_id = '.$idiot['id'].'';
mysql_query($query) or die(mysql_error());
} else { // wish does not exist, add new wish
$query = 'INSERT INTO wishes( //if wish doesnt exist, INSERT it.
w_id,
w_username,
w_wish1,
w_wish2,
w_wish3,
w_wish4,
w_wish5,
w_wish6)
VALUES (
'.$idiot['id'].',
"'.$_SESSION['username'].'",
"'.$_POST['w1'].'",
"'.$_POST['w2'].'",
"'.$_POST['w3'].'",
"'.$_POST['w4'].'",
"'.$_POST['w5'].'",
"'.$_POST['w6'].'")';
mysql_query($query) or die(mysql_error());
}}
//now here is the test to see if $_POST['w1'] exists...
else {
if (!$_POST['w1']){echo 'hello, w1 doesnt exist';} //this passes, and outputs "hello, w1 doesnt exist"
?>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post>
<input name="w1" type="text" size="60" maxlength="70" value="<?php echo $_POST['w1'];?>">
<input type="submit" name="submit" value="Update!">