Take the 2-minute tour ×

I'm trying to update my database records with the following code but am having no luck what so ever. Anybody care to help? Thanks

<?php include "base.php"; ?>

<title>Project Sproom</title>
<?php if(!empty($_SESSION['LoggedIn']) && !empty($_SESSION['Username']))

$newusername = mysql_real_escape_string($_POST['username']);
$newemail = mysql_real_escape_string($_POST['email']);
$edit = mysql_query("UPDATE users (Username, EmailAddress) VALUES('".$newusername."', '".$newemail."') WHERE UserID=".$_SESSION['UserID']."");
// }
<div id="container">
<div id="homemenu">
<ul id="navlist">
<li id="active"><a href="index.php" id="current">Home</a></li>
<li><a href="profile.php">Edit Profile</a></li>
<div id="homemain">
<h1>Edit Profile</h1>
<p>This will be the edit profile when i have figured out how to do it...</p>
<br />
<form method="post" action="profile.php" name="editprofile" id="editprofile">
<label for="username">Username: </label> <input type="text" name="username" id="username" value="<?=$_SESSION['Username']?>"/><br />
<label for="email">E-Mail: </label> <input type="text" name="email" id="email" value="<?=$_SESSION['EmailAddress']?>"/> <br />
<input type="submit" name="editprofile" id="editprofile" value="Submit" />
<meta http-equiv="refresh" content="0;index.php">
share|improve this question
You're also missing a closing bracket somewhere. Maybe the one you've commented out just below the query? Or maybe you already found it, since your comment is gone... –  grossvogel Aug 3 '10 at 23:45

3 Answers 3

up vote 3 down vote accepted

You're using INSERT syntax for an UPDATE query. The syntax should be like this:

UPDATE users SET Username = 'username', EmailAddress = 'email' WHERE UserID = 1;

Docs here.

share|improve this answer

You haven't connected to the MySQL database, have you?

I didn't see that in this code...

Or is that part of the included "base.php" on top of this script?

I am afraid you need fist establish a connection to a certain MySQL database before trying to update a row in a table.


Okay, well then. Try issue the following line of code after the update:

echo "edit was " .$edit;

This is to check whether the update query was executed successfully (in which case it should echoes true) or failed (in which case it echoes false).

So at least you can tell the result of such a mysql_query.

share|improve this answer
Yes, I have connected to the database in the base.php file. :) –  ritch Aug 3 '10 at 23:18
$edit = mysql_query("UPDATE users SET Username='".$newusername."', EmailAddress='".$newemail."' WHERE  UserID=".$_SESSION['UserID']."");

Try this

share|improve this answer

Your Answer


