Member Avatar for Lomholdt

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 ass";

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!

WHERE users id = '$id'

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

Member Avatar for Lomholdt

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

Member Avatar for Lomholdt

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'");

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.

Member Avatar for Lomholdt

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! :)

Member Avatar for Lomholdt

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.