We're a community of 1077K IT Pros here for help, advice, solutions, professional growth and fun. Join us!
1,076,154 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Start New Discussion Reply to this Discussion

Problem while changing database with mysql_query

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!

2
Contributors
6
Replies
3 Hours
Discussion Span
3 Months Ago
Last Updated
11
Views
Question
Answered
Lomholdt
Newbie Poster
10 posts since Oct 2011
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 0

WHERE users id = '$id'

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

pritaeas
Posting Prodigy
Moderator
9,293 posts since Jul 2006
Reputation Points: 1,178
Solved Threads: 1,462
Skill Endorsements: 86

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

Lomholdt
Newbie Poster
10 posts since Oct 2011
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 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'");
Lomholdt
Newbie Poster
10 posts since Oct 2011
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 0

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.

pritaeas
Posting Prodigy
Moderator
9,293 posts since Jul 2006
Reputation Points: 1,178
Solved Threads: 1,462
Skill Endorsements: 86

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

Lomholdt
Newbie Poster
10 posts since Oct 2011
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 0

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.

Lomholdt
Newbie Poster
10 posts since Oct 2011
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 0
Question Answered as of 3 Months Ago by pritaeas

This question has already been solved: Start a new discussion instead

Post: Markdown Syntax: Formatting Help
 
You
View similar articles that have also been tagged:
 
© 2013 DaniWeb® LLC
Page rendered in 0.0826 seconds using 2.7MB