Page 1 of 1

question about field editing

Posted: Mon Aug 16, 2004 12:37 pm
by ex247
what im trying to do is if the certain user (shown by $loggedin) is loggedin, they can edit their profile, but, i can grab all the info for them to edit it, but when they go to submit it doesnt change anything. so here is the code:

Code: Select all

$result = mysql_fetch_array(mysql_query("SELECT * FROM users WHERE user = '$loggedin'")) or die(mysql_error());
print "<form action="admin.php?action=edit" method="post">
<br>E-Mail: <input type="text" name="email" size="40" value="$result[email]">
<br>First Name: <input type="text" name="first" size="40" value="$result[first]">
<br>Last Name: <input type="text" name="last" size="40" value="$result[last]">
<br>Bio: <input type="text" name="bio" size="40" value="$result[bio]">
<input type="submit" value="Submit">
</form>";
$sql = "INSERT INTO users WHERE user= '$loggedin' (first, last, email, bio) VALUES ('','$first','$last','$email','$bio')";
$query = mysql_query($sql) or die ("ERROR :: " . mysql_error());
}
i thought that

Code: Select all

$sql = "INSERT INTO users WHERE user= '$loggedin' (first, last, email, bio) VALUES ('','$first','$last','$email','$bio')";
you could makie it so, it grabs the for with the user = $loggedin (the user that is logged in) and only edit those fields (first, last, email, bio) but to no avail its not working. can anyone shed the light on this one.

thanks

edit i get this error also before i edit anything: ERROR :: You have an error in your SQL syntax near 'WHERE user= 'mroach' (first, last, email, bio) VALUES ('','','','','')' at line 1

Posted: Mon Aug 16, 2004 2:11 pm
by lostboy
well, edits of existing information are usually UPDATES, as in

Code: Select all

$sql = "UPDATE users set first='$first' , last='$last' , email='$email' , bio= '$bio' where user= '$loggedin' ";
INSERTS are for new information.

Posted: Mon Aug 16, 2004 3:16 pm
by ex247

Code: Select all

if(isset($_POST["submit"])){
$sql = "UPDATE users set first='$first',last='$last', email='$email', bio='$bio' WHERE user= '$loggedin' ";
$query = mysql_query($sql) or die ("ERROR :: " . mysql_error());
print 'Bio Update Was Successful';
}
else{
$result = mysql_fetch_array(mysql_query("SELECT * FROM users WHERE user = '$loggedin'")) or die(mysql_error());
print "<form action="admin.php?action=edit" method="post">
<br>E-Mail: <input type="text" name="email" size="40" value="$result[email]">
<br>First Name: <input type="text" name="first" size="40" value="$result[first]">
<br>Last Name: <input type="text" name="last" size="40" value="$result[last]">
<br>Bio: <input type="text" name="bio" size="40" value="$result[bio]">
<input type="submit" name="submit" value="Submit">
</form>";
} 
}

that works :)