Jump to content

Recommended Posts

Empty database (Users_recover), no rows in it.

 

user_name    (varchar(20))

email    (varchar(150))

key    (varchar(150))

 

$query = "INSERT INTO Users_recover (user_name, email, key) VALUES ('$user_name', '$email', '$key')";
	mysql_query($query) or die("Erro");

 

I echo'ed $user_name, $email and $key above the query and these are all fine.

Link to comment
https://forums.phpfreaks.com/topic/206675-what-is-wrong-with-this-query/
Share on other sites

$query = "INSERT INTO `Users_recover` SET `user_name`='{$user_name}' , `email`='{$email}' , `key`='{$key} ";
	mysql_query($query) or die("Problem with the query: $query<br>" . mysql_error());

 

Problem with the query: INSERT INTO `Users_recover` SET `user_name`='admin' , `email`='test@gmail.com' , `key`='78bef654a197cdc4189342034a3c5c1b

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''78bef654a197cdc4189342034a3c5c1b' at line 1

In this case you forgot the closing quote on the {$key}

Change

<?php
$query = "INSERT INTO `Users_recover` SET `user_name`='{$user_name}' , `email`='{$email}' , `key`='{$key} ";
?>

to

<?php
$query = "INSERT INTO `Users_recover` SET `user_name`='{$user_name}' , `email`='{$email}' , `key`='{$key}' ";
?>

You don't really need all the "{ }" and back-ticks, so this should work fine:

<?php
$query = "INSERT INTO Users_recover SET user_name='$user_name' , email='$email' , `key`='$key' ";
?>

You only need the back-ticks if your using a MySQL reserved word for a fieldname.

 

Ken

Okay, I'm having problems with another query now also related to the above:

 

	$query = "UPDATE Users_recover SET 'key' = '$key' WHERE user_name = '$user_name'"; 
	mysql_query($query) or die("Error: Action could not be completed. Please email test@gmail.com about this.<br />" . mysql_error());

 

Error:

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''key' = 'baea9f5fb6eea96384efae608716d819' WHERE user_name = 'admin'' at line 1

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.