question about field editing

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
ex247
Forum Commoner
Posts: 34
Joined: Tue Oct 28, 2003 1:35 am
Location: Boston, MA, USA
Contact:

question about field editing

Post 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
lostboy
Forum Contributor
Posts: 329
Joined: Mon Dec 30, 2002 8:12 pm
Location: toronto,canada

Post 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.
ex247
Forum Commoner
Posts: 34
Joined: Tue Oct 28, 2003 1:35 am
Location: Boston, MA, USA
Contact:

Post 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 :)
Post Reply