physaux Posted April 9, 2010 Share Posted April 9, 2010 Hey guys I am trying to edit a row, with a function that I have. Here is the function: function updateid($edit_id,$edit_name,$edit_email,$edit_verified){ $mysql_query = "UPDATE users SET name='$edit_name',email='$edit_email',verified='$edit_verified' WHERE user_id=$edit_id"; $results = mysql_query($sqlquery); echo "RAN UPDATE ID FUNCTION"; } The problem is that when I check in PHPMYADMIN if the changes happened, they don't. But my screen echos "RAN UPDATE ID FUNCTION". So I know the function is running but there is something wrong. So my questions are: -do you see any obvious problems? -how can I 'see' the MYSQL 'response'? I'm sure it throws an error, but IDK how to see that error. THanks! Quote Link to comment https://forums.phpfreaks.com/topic/198145-problem-editing-a-row/ Share on other sites More sharing options...
Ken2k7 Posted April 9, 2010 Share Posted April 9, 2010 My guess is that either $edit_id is wrong OR the other variables are not escaped and secured. Read up on mysql_real_escape_string Quote Link to comment https://forums.phpfreaks.com/topic/198145-problem-editing-a-row/#findComment-1039648 Share on other sites More sharing options...
ddubs Posted April 9, 2010 Share Posted April 9, 2010 When are you creating mysql connection? Do you have a valid link identifier that you can pass along to the mysql_query() function? You can use echo mysql_error($link_id); to throw out the error message. Quote Link to comment https://forums.phpfreaks.com/topic/198145-problem-editing-a-row/#findComment-1039652 Share on other sites More sharing options...
litebearer Posted April 9, 2010 Share Posted April 9, 2010 try this... function updateid($edit_id,$edit_name,$edit_email,$edit_verified){ $mysql_query = "UPDATE users SET name='$edit_name',email='$edit_email',verified='$edit_verified' WHERE user_id=$edit_id"; $results = mysql_query($sqlquery); echo mysql_num_rows($results) . "<br>"; if(mysql_num_rows($result)<1) { echo "record not found"; } return; } Quote Link to comment https://forums.phpfreaks.com/topic/198145-problem-editing-a-row/#findComment-1039653 Share on other sites More sharing options...
PFMaBiSmAd Posted April 9, 2010 Share Posted April 9, 2010 do you see any obvious problems? Yes, the variable name you are building the query string in is not the variable you are putting into the mysql_query() statement. If you were developing and debugging php code on a system with error_reporting set to E_ALL and display_errors set to ON, php would help you find basic errors like that. You will save a TON of time. Quote Link to comment https://forums.phpfreaks.com/topic/198145-problem-editing-a-row/#findComment-1039655 Share on other sites More sharing options...
Pikachu2000 Posted April 9, 2010 Share Posted April 9, 2010 I'm posting from my phone, and for some reason, the block of php code is cut off, but it looks like you define the query string as $mysql_query, but you call mysql_query($sqlquery). Also, the echo statement isn't in a conditional, so it will echo without regard to the success or failure of the query. Quote Link to comment https://forums.phpfreaks.com/topic/198145-problem-editing-a-row/#findComment-1039656 Share on other sites More sharing options...
physaux Posted April 9, 2010 Author Share Posted April 9, 2010 Wow thanks for all the help guys. I changed the variable name, thanks I didn't notice that mistake. I also added ini_set('display_errors',1); error_reporting(E_ALL|E_STRICT); To the top of my code. It spit out ~10 errors, give me a second to sift through them to see if it worked Quote Link to comment https://forums.phpfreaks.com/topic/198145-problem-editing-a-row/#findComment-1039671 Share on other sites More sharing options...
physaux Posted April 9, 2010 Author Share Posted April 9, 2010 Ok so I cleaned out all the errors, but the edit command is still not working. Here is the function now: function updateid($edit_id,$edit_name,$edit_email,$edit_verified){ $sqlquery = "UPDATE users SET name='$edit_name',email='$edit_email',verified='$edit_verified' WHERE user_id=$edit_id"; echo "[$sqlquery]"; $results = mysql_query($sqlquery); } It prints out [uPDATE users SET name='TESTNAME',email='[email protected]',verified='1' WHERE user_id=test123] (Just so I can be sure of the query). Here is a picture of the MYSQL table entry called 'users', right after I run this command. Notice the 'verified' doesn't get changed to 1. http://img193.imageshack.us/img193/4632/picture1mgh.png *I run other commands that work already, so I know the database connection works fine. Here is a copy of WORKING function: function doesidexist($user_id){ $user_id = mysql_real_escape_string($user_id); if(mysql_num_rows(mysql_query("SELECT * FROM users WHERE user_id = '$user_id'"))){ return true; }else{ return false; } } So does anyone see a problem? If it matters 'verified' data type is boolean. Thanks Quote Link to comment https://forums.phpfreaks.com/topic/198145-problem-editing-a-row/#findComment-1039734 Share on other sites More sharing options...
physaux Posted April 9, 2010 Author Share Posted April 9, 2010 OK nevermind I got it now. This part of the sql query was bad: user_id=test123 Changed to user_id='test123' Quote Link to comment https://forums.phpfreaks.com/topic/198145-problem-editing-a-row/#findComment-1039735 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.