Forum Moderators: coopster
Im working on a members area and this part is for the 'profiles' editing page, and i can't seem to be able to post the varialbles into the table when the clicks submit.
I have just got so confused that my code is all messed up and now my head is.
I am collecting the info by using a?username=*usernamehere* method, as you might guess i have only been doing this for a few weeks now.
So PLEASE could someone help me!
<table width="100%" align="center">
<form name="update" action="<?php echo $results;?>" method="post">
<?php
// Make a MySQL Connection
mysql_connect("localhost", "HotingName", "HostingPassword") or die(mysql_error());
mysql_select_db("MyDataBase") or die(mysql_error());
// selecting my table
$result = mysql_query("SELECT * FROM ALS_signup WHERE username = '$username'")
or die(mysql_error());
// This is showing the members pictue and there details in input boxes and this is where i am soooo confused
while($row = mysql_fetch_array( $result )) {
echo "<tr><Td align='center' colspan=2>";
echo "<a href='profilespics/";
echo $row['upload_picture'];
echo ".jpg' >";
echo "<img border=0 width='100' height='100' src='profilespics/";
echo $row['upload_picture'];
echo ".jpg' ></a><br>";
if ($row["userlevel"] < 0) {echo "Website Admin";}
echo "</td></tr>";
$username = $row['username'];
$id = $row['id'];
$mailadres = $row['mailadres'];
$signupdate = $row['signupdate'];
$lastlogintime = $row['lastlogin'];
$fullname = $row['fullname'];
$DOB = $row['DOB'];
$location = $row['location'];
$gender = $row['gender'];
$faveband = $row['faveband'];
$favetvshow = $row['favetvshow'];
$favegame = $row['favegame'];
$about_me = $row['about_me'];
$EDIT_fullname = @$HTTP_POST_VARS["Edit_fullname"];
$NewFullName = @$HTTP_GET_VARS["fullname"];
$EDIT_fullname2 = @$HTTP_GET_VARS["fullname"];
echo "<tr><td WIDTH=120 bgcolor='$bgcolor1'>UserName</td><td bgcolor='$bgcolor2'>$username";
echo "</td></tr><tr><td bgcolor='$bgcolor1'>User ID</td><td bgcolor='$bgcolor2'>$id";
echo "</td></tr><tr><td bgcolor='$bgcolor1'>eMail Address</td><td bgcolor='$bgcolor2'>";
echo "<a href='mailto:$mailadres'> $mailadres </a>";
echo "</td></tr><tr><td bgcolor='$bgcolor1'>Sign Up Date</td><td bgcolor='$bgcolor2'>
<input name='EDIT$signupdate' value='$signupdate'>
";
echo "</td></tr><tr><td bgcolor='$bgcolor1'>Last Login Time</td><td bgcolor='$bgcolor2'>
<input name='EDIT$lastlogintime' value='$lastlogintime'>
";
echo "</td></tr><tr><td bgcolor='$bgcolor1'>Full Name</td><td bgcolor='$bgcolor2'>
<input name='EDIT_fullname' value='$fullname'>
";
echo "</td></tr><tr><td bgcolor='$bgcolor1'>D.O.B</td><td bgcolor='$bgcolor2'>
<input name='EDIT$DOB' value='$DOB'>
";
echo "</td></tr><tr><td bgcolor='$bgcolor1'>location</td><td bgcolor='$bgcolor2'>
<input name='EDIT$location' value='$location'>
";
echo "</td></tr><tr><td bgcolor='$bgcolor1'>M/F (Gender)</td><td bgcolor='$bgcolor2'>
<input name='EDIT$gender' value='$gender'>
";
echo "</td></tr><tr><td bgcolor='$bgcolor1'>Fave Band</td><td bgcolor='$bgcolor2'>
<input name='EDIT$faveband' value='$faveband'>
";
echo "</td></tr><tr><td bgcolor='$bgcolor1'>Fave TV Show</td><td bgcolor='$bgcolor2'>
<input name='EDIT$favetvshow' value='$favetvshow'>
";
echo "</td></tr><tr><td bgcolor='$bgcolor1'>Fave Game</td><td bgcolor='$bgcolor2'>
<input name='EDIT$favegame' value='$favegame'>
";
echo "</td></tr><tr><td bgcolor='$bgcolor1'>About Me</td><td bgcolor='$bgcolor2'>
<input name='EDIT$about_me' value='$about_me'>
";
echo "</td></tr></table>";
}
echo "</select></tr></td>";
?>
<input type="submit" value="Update Profile">
</form>
<?php
$SQL = "UPDATE ALS_signup SET fullname = '$fullname', location = '$location', gender = '$gender', faveband = '$faveband', favetvshow = '$favetvshow', favegame = '$favegame', about_me = '$about_me' WHERE username = '$username'";
$result = mysql_query($SQL) or die(mysql_error());
?>
Please help!
/*
Take out my comments if they are getting in the way
Lookup how to make functions in php. It is on php.net
It looks like this:
function getForm()
{
do stuff in here
}//end getForm
I just made some minor changes but it looks like it should work
*/
echo '<table width="100%" align="center">';
echo '<form name="update" action="update.php" method="post">';
Make a MySQL Connection/mysql_connect("localhost", "HotingName", "HostingPassword") or die(mysql_error());
mysql_select_db("MyDataBase") or die(mysql_error());
selecting my table
$result = mysql_query("SELECT * FROM ALS_signup WHERE username = '$username'")or die(mysql_error());
// This is showing the members pictue and there details in input boxes and this is where i am soooo confused
while($row = mysql_fetch_array( $result )) {
echo "<tr><Td align='center' colspan=2>";
echo "<a href='profilespics/";
echo $row['upload_picture'];
echo ".jpg' >";
echo "<img border=0 width='100' height='100' src='profilespics/";
echo $row['upload_picture'];
echo ".jpg' ></a><br>";
if ($row["userlevel"] < 0) {echo "Website Admin";}
echo "</td></tr>";
$username = $row['username'];
$id = $row['id'];
$mailadres = $row['mailadres'];
$signupdate = $row['signupdate'];
$lastlogintime = $row['lastlogin'];
$fullname = $row['fullname'];
$DOB = $row['DOB'];
$location = $row['location'];
$gender = $row['gender'];
$faveband = $row['faveband'];
$favetvshow = $row['favetvshow'];
$favegame = $row['favegame'];
$about_me = $row['about_me'];
$EDIT_fullname = @$HTTP_POST_VARS["Edit_fullname"];
$NewFullName = @$HTTP_GET_VARS["fullname"];
$EDIT_fullname2 = @$HTTP_GET_VARS["fullname"];
echo "<tr><td WIDTH=120 bgcolor='$bgcolor1'>UserName</td><td bgcolor='$bgcolor2'>$username";
echo "</td></tr><tr><td bgcolor='$bgcolor1'>User ID</td><td bgcolor='$bgcolor2'>$id";
echo "</td></tr><tr><td bgcolor='$bgcolor1'>eMail Address</td><td bgcolor='$bgcolor2'>";
echo "<a href='mailto:$mailadres'> $mailadres </a>";
echo "</td></tr><tr><td bgcolor='$bgcolor1'>Sign Up Date</td><td bgcolor='$bgcolor2'>
<input name='EDIT$signupdate' value='$signupdate'>
";
echo "</td></tr><tr><td bgcolor='$bgcolor1'>Last Login Time</td><td bgcolor='$bgcolor2'>
<input name='EDIT$lastlogintime' value='$lastlogintime'>
";
echo "</td></tr><tr><td bgcolor='$bgcolor1'>Full Name</td><td bgcolor='$bgcolor2'>
<input name='EDIT_fullname' value='$fullname'>
";
echo "</td></tr><tr><td bgcolor='$bgcolor1'>D.O.B</td><td bgcolor='$bgcolor2'>
<input name='EDIT$DOB' value='$DOB'>
";
echo "</td></tr><tr><td bgcolor='$bgcolor1'>location</td><td bgcolor='$bgcolor2'>
<input name='EDIT$location' value='$location'>
";
echo "</td></tr><tr><td bgcolor='$bgcolor1'>M/F (Gender)</td><td bgcolor='$bgcolor2'>
<input name='EDIT$gender' value='$gender'>
";
echo "</td></tr><tr><td bgcolor='$bgcolor1'>Fave Band</td><td bgcolor='$bgcolor2'>
<input name='EDIT$faveband' value='$faveband'>
";
echo "</td></tr><tr><td bgcolor='$bgcolor1'>Fave TV Show</td><td bgcolor='$bgcolor2'>
<input name='EDIT$favetvshow' value='$favetvshow'>
";
echo "</td></tr><tr><td bgcolor='$bgcolor1'>Fave Game</td><td bgcolor='$bgcolor2'>
<input name='EDIT$favegame' value='$favegame'>
";
echo "</td></tr><tr><td bgcolor='$bgcolor1'>About Me</td><td bgcolor='$bgcolor2'>
<input name='EDIT$about_me' value='$about_me'>
";
echo "</td></tr></table>";
}//end if
echo "</select></tr></td>";
echo '<input type="submit" name = "submit" value="Update Profile">';
echo '</form>';
if (isset($_POST[submit]))//this will check the form to see if the button was pressed.
{
echo "button pressed";
echo "$_POST[EDIT_fullname]";
/*
I can't remember if sql will complain about thsi fullname = '$_POST[EDIT_fullname]' if it does then try setting $fullname equal to one of these {$_POST[EDIT_fullname]} or {$_POST['EDIT_fullname']}
You have to do this for every field because what's happening is that php is interpreting '$location' as a variable you just declared. So it asigns it a NULL value instead of the value in the form.
But you want the form values. In order to do that you need to access the POST data variables in that form.
To access POST data simply do this: $_POST[form_variable]
change this so that you submit all the POST data $SQL = "UPDATE ALS_signup SET fullname = '$_POST[EDIT_fullname]', location = '$location', gender = '$gender', faveband = '$faveband', favetvshow = '$favetvshow', favegame = '$favegame', about_me = '$about_me' WHERE username = '$username'";
*/
$result = mysql_query($SQL) or die(mysql_error());
echo "<b>profile updated</b>";
}
else
echo "button not pressed";
?>
--Nick
---------------------------------------------
<table width="100%" align="center">
<form name="update" action="update.php" method="post">
<input type="submit" name = "submit" value="Update Profile">
</form>
button not pressed
---------------------------------------------
Thats All im getting, Any Ideas?
[edited by: ergophobe at 8:41 pm (utc) on May 15, 2005]
[edit reason] long code dump - see forum charter [/edit]
For some suggestions on how to figure that out, see
[webmasterworld.com...]
Also, since this profile has a lot of information in it try and develop it incrementally (you probably already did this). Add one textbox with data, then test that, then add another box, and so on.
Add onto this as you need to.
function getUserForm($bgcolor1, $bgcolor2)
{
$getUserProfile = mysql_query("SELECT * FROM ALS_signup WHERE username = '$username'")or die(mysql_error());
$userProfile = mysql_fetch_array($getUserProfile);
echo '<table width="100%" align="center">';
echo '<form name="update" action="update2.php" method="post">';
print "<tr><td WIDTH=120 bgcolor='$bgcolor1'>UserName</td><td bgcolor='$bgcolor2'>$userProfile[fullname]";
print "</td></tr><tr><td>User ID</td><td>$userProfile[id]";
echo '</td></tr><tr><td>Sign Up Date</td><td>';
echo '<input type = "text" name="signupdate" value= $userProfile[signupdate]>';
echo '<input type="submit" name = "submit" value="Update Profile">';
echo '</form>';
}//end getUserForm
--Nick
Your Script Helped me treat, thank you so much for your help, i will be looking into using more simplifed statements like you said as i went back to my code and confused myself over what was what.
Once again thank you very much, all my website visitor are very happy to be able to update there profiles at last.
Del