Page 1 of 1
Trouble entering data
Posted: Thu Apr 10, 2008 10:32 am
by khushbush
I'm having trouble with this code:
Code: Select all
$user = mysql_real_escape_string($_SESSION['username']);
$password = addslashes($_POST['userPassword']);
$query = "INSERT INTO user(userPassword) VALUES ('$password') WHERE username = '$user'";
$result = mysql_query($query) or die(mysql_error());
I keep getting the following error:
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'WHERE username = 'admin' at line 1.
I've had a good look at the INSERT query and I can't seem to find anything wrong with it.
Am I missing something?
Re: Trouble entering data
Posted: Thu Apr 10, 2008 10:40 am
by EverLearning
INSERT statements
don't have
WHERE clause.
You're probably looking for an
UPDATE statement
Code: Select all
$query = "
UPDATE user
SET userPassword = '$password'
WHERE username = '$user'";
Take a look at these links
MySql INSERT sytax
MySql UPDATE sytax
Re: Trouble entering data
Posted: Thu Apr 10, 2008 10:52 am
by khushbush
Oohhhhhhhhhhhhhhh....silly me!! Thank you ever so much!!
Ok...another question...
I'm trying to enter details into the database...or I guess...update the database with a new password...it nearly works.
But everytime I try to enter a new password, the field corresponding to that user's password shows up blank. It doesn't enter the new password, and it appears that the html form isn't capturing the values entered.
Here's the html form:
Code: Select all
<td><font face = "Arial" style ="font-size:12pt" color="#0B3A62">Current Password:</form></td>
<td><input type="password" name="userPassword" maxlength="30" value=" "</td>
Re: Trouble entering data
Posted: Thu Apr 10, 2008 12:02 pm
by EverLearning
<td><font face="Arial" style="font-size:12pt" color="#0B3A62">Current Password:</form></td>
<td><input type="password" name="userPassword" maxlength="30" value=""</td>
For data to be sent to your php script form tags must be around input fields. And above your form is closed
before the password input field.
This is how it should look like.
Code: Select all
<!-- FORM START -->
<form method="post" action="update.php">
<!-- some form fields ... -->
<td><font face="Arial" style="font-size:12pt" color="#0B3A62">Current Password:</td>
<td><input type="password" name="userPassword" maxlength="30" value=""</td>
<!-- some more form fields ... -->
</form>
<!-- FORM END -->
Re: Trouble entering data
Posted: Thu Apr 10, 2008 12:15 pm
by khushbush
Oh my goodness...I'm so silly!! That form tag was supposed to say font...I'm so embarrassed
There's more to come on this...I'm having issues with editing user details in a login system, and I shall be posting problematic code very soon!
Re: Trouble entering data
Posted: Thu Apr 10, 2008 12:39 pm
by khushbush
Ok, I'm officially lost
So here's the code:
Code: Select all
if ($session->logged_in){
$user = mysql_real_escape_string($_SESSION['username']);
$password = addslashes($_POST['userPassword']);
$query = "SELECT userPassword FROM user WHERE username = '$user'";
$result = mysql_query($query) or die(mysql_error());
if(!$result || (mysql_num_rows($result) < 1)){
return 1;
}
$query = "UPDATE user SET userPassword = '$password' WHERE username = '$user'";
$result = mysql_query($query) or die(mysql_error());}
?>
<html>
<body>
<form action="process.php" method="POST">
<table align="left" border="0" cellspacing="0" cellpadding="3">
<tr>
<td><font face = "Arial" style ="font-size:12pt" color="#0B3A62">Current Password:</font></td>
<td><input type="password" name="userPassword" maxlength="30" value="<?echo $form->value("userPassword"); ?>"></td>
<td><? echo $form->error("userPassword"); ?></td>
</tr>
<tr>
<td><font face = "Arial" style ="font-size:12pt" color="#0B3A62">New Password:</form></td>
<td><input type="password" name="newPassword" maxlength="30" value="<? echo $form->value("newPassword"); ?>"></td>
<td><? echo $form->error("newPassword"); ?></td>
</tr>
<tr>
<td><font face = "Arial" style ="font-size:12pt" color="#0B3A62">Email:</form></td>
<td><input type="text" name="email" maxlength="50" value="
<?
if($form->value("email") == ""){
echo $session->userinfo['email'];
}else{
echo $form->value("email");
}
?>">
</td>
<td><? echo $form->error("email"); ?></td>
</tr>
<tr><td colspan="2" align="right">
<input type="hidden" name="subedit" value="1">
<input type="submit" value="Edit Account"></td></tr>
<tr><td colspan="2" align="left"></td></tr>
<tr><td><font face = "Arial" style ="font-size:12pt" color="#0B3A62">Back to <a href = "userinfo.php">My Details</font></a></tr></td>
</table>
</form>
</body>
</html>
I can't seem to enter a new password into the database. Bear in mind that I want to test out entering any old password into the Current Password text box which will then enter it into the database...I am just testing it out and getting the basics to work before I move any further with this part of the login function. But it seems that something as simple as this won't work.
I got it to work on my registration form, but unfortunately, it's not working with this, despite the forms being very similar. Hmmmm...
I would be so grateful if anyone could come up with something to help me. Thanks.
Re: Trouble entering data
Posted: Thu Apr 10, 2008 1:02 pm
by EverLearning
Is your error reporting full on? If it isn't turn it on with
Code: Select all
error_reporting(E_ALL); ini_set('display_errors', true);
After submitting form data dump your $_POST array to see if everything is as it should be.
Also dump $_SESSION, since you use $_SESSION['username'] in your queries.
Re: Trouble entering data
Posted: Fri Apr 11, 2008 2:34 am
by Phoenixheart
Beside, I would suggest dusting away those <font> and <td> tags
