Jump to content

Recommended Posts

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!

Link to comment
https://forums.phpfreaks.com/topic/198145-problem-editing-a-row/
Share on other sites

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;
}

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.

 

 

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.

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

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.