1.11M Members

Problem while changing database with mysql_query

 
0
 

Please help. I am trying to change data in my MySql database. I am able to input new data, but when i try to change anything, it doesn't work. Here is my code:

<?php

$id = $_REQUEST['id'];
$newname = $_REQUEST['newname'];
$newemail = $_REQUEST['newemail'];
$newpassword = $_REQUEST['newpassword'];

mysql_connect("localhost", "root", "") or die("problem with connection");
mysql_select_db("testsite");

mysql_query("UPDATE users SET name='$newname', email='$newemail', password='$newpassword' WHERE users id='$id'");

echo "Your values have been updated! Now kiss my ###";

mysql_close();

include('links.php');

?>

I am doing this on a localhost, so the login is correct (and with no password!). As far as i can tell, the problem lies within the mysql_query. But what am i doing wrong? Please keep in mind that I am a total beginner to PHP and MySql databases.
Thank you!

 
1
 

WHERE users id = '$id'

Do you really have a space between users and id in your column name?

 
0
 

My table is called 'users'. And the column in the MySql database is is called 'id'. Is it the right syntax i am using?

 
0
 

I removed the 'users' from the WHERE statement. But still no luck. I now have the following code:

mysql_query("UPDATE users SET name='$newname', email='$newemail', password='$newpassword' WHERE id='$id'");
 
1
 

If you are querying a single table then you don't need to reference the table. If you do, table and column are separated by a dot.

 
0
 

I have updated the line to change the database as follows:

mysql_query("UPDATE users SET name='$newname', email='$newemail', password='$newpassword' WHERE id='$id'");

I recieve no error while doing so, but the change still doesn't occur. I am only querying that single table. Also, i am able to add new data to the table, so i don't think there is anything wrong with the connection. But for some reason, it doesn't understand what it is, i am trying to do. And thanks for your help btw! :)

 
1
 

IT WORKS! :) Thank you so much for your help! And thx for helping me kickstarting my brain ;) I found the problem by echoing out the paramiters (id, name, email and password) and discovered that it wasn't recieving the 'id' paramater! Found a typo in the file it was recieving from and BOOM! Now it works! Your help is very much appreciated. Thanks again.

Question Answered as of 1 Year Ago by pritaeas
You
This question has already been solved: Start a new discussion instead
Post:
Start New Discussion
View similar articles that have also been tagged: