Jump to content

php/mysql help


davelearning

Recommended Posts

Hi all,

 

I am relatively new to php and am stuck on a simple query, I just dont know what my error is.

Basically I am just trying to save some information to a database and I am getting:

 

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) VALUES ('testuser','dc23053d9ada11806420839fd42aa9c9','admin@jollyhosting' at line 1Something Went Wrong = Please click back and try again

 

The code I am using is

<?php
include('config.php');
require('class.phpmailer.php');

$username = $_POST['username'];
$hide = md5($_POST['password']);
$password = $hide;
$email = $_POST['email'];
$number = rand();
$key = md5($number);

$query ="INSERT INTO user (username, password, email, key)
VALUES
('$username','$password','$email', '$key')";

if (!mysql_query($query))
{
echo mysql_error();
echo "Something Went Wrong = Please click back and try again";
}

 

Many thanks for anyhelp

 

Link to comment
Share on other sites

Your column 'key' is a reserved MySQL word.  You can place backticks `key` around the column name everywhere it's referenced.  You should try to avoid naming your columns after reserved words.

Link to comment
Share on other sites

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.