Jump to content

Recommended Posts

Hi every one  :shy:

 

I am trying to make my own php and MySQL data base game! However i have got stuck on the registration below is the error i get when i try to enter a record i to MySQL data base:

 

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 'Name) VALUES ('', 'freid', 'freid001@hotmail.co.uk, 'freid', 'clan')' at line 1

 

I am unsure as to what this means ? I have posted the php registration code i am using below:

 

"><?php

function showheader ($title) { 

}

 

function showfooter () {

 

}

 

$host= "mysql";

$mysql_user = "XXXXXXX";

$mysql_password = "XXXXXXX";

$mysql_database = "XXXXXXX";

$Name = $_POST['myusername'];

$Password = strtolower(strip_tags ($_POST['Password1']));

$Password2 = strtolower(strip_tags ($_POST['Password2']));

$myusername = strtolower(strip_tags ($_POST['myusername']));

$clan = $_POST['Clan'];

$email = $_POST['email'];

$myusername = $_POST['myusername'];

$check = $_POST['check'];

$check2 = "4720";

 

$connection = mysql_connect("$host","$mysql_user","$mysql_password") or die ("Unable to connect to MySQL server.");

 

mysql_select_db($mysql_database) or die ("Unable to select requested database.");

$db = mysql_select_db($mysql_user,$mysql_password);

 

if ($Password == $Password2) {

if ($check == $check2) {

if (strlen($Password)>25||strlen($Password)<6)

{

echo "Password must be between 6 and 25 characters! ";

}

if (strlen($myusername)>25||strlen($myusername)<3)

{

echo "Username must be between 3 and 25 characters! ";

}

    $user = mysql_query("SELECT * FROM Game WHERE user ='$myusername'");

    if (mysql_num_rows($user) > 0) {

    echo "We are sorry to inform you that the User Name echo $Name Has already Be Taken!";

 

        showfooter();

    }

    else {

$query = "INSERT INTO user (ID, User, Email, Password, Fac Name) VALUES ('', '$myusername', '$email, '$password', 'clan')";

mysql_query($query) or die (mysql_error());

 

 

 

include 'library/closedb.php';

echo "New MySQL user added";

    }

 

}

else { showheader("Registration Error!");

   

    echo "Please enter the conformation code correctly!";

    showfooter();

}

}

else {

    showheader("Registration Error!");

   

    echo "Your Two Passwords Did Not Match!";

   

    showfooter();

}

?>

 

 

 

I think that this part of the code is wrong but im not sure

 

$query = "INSERT INTO user (ID, User, Email, Password, Fac Name) VALUES ('', '$myusername', '$email, '$password', 'clan')";

mysql_query($query) or die (mysql_error());

 

Any help with the matter will be much appericiated.

to view the code on the web site please go to http://www.europeanwar.ulmb.com

 

thanks for any help!

Link to comment
https://forums.phpfreaks.com/topic/208663-mysql-syntax-error-please-help/
Share on other sites

Fac Name

^^^ If you in fact have a column with a two word name, it requires special handling. You must enclose it in back-ticks `` every time you put it into a query. You could also rename it to use an under-score Fac_Name instead of a space so that it would become a one-word column name.

I have made the adjustments you have send and i still get the 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 ''ID', 'User', 'Email', 'Password', 'Clan') VALUES ('', 'freid', 'freid, 'fireid001@hotmail.co.uk', 'freid'' at line 1

 

It appears that your field names in your list are in single quotes.  This is invalid because they will be treated as individual strings.  If you want to delimit the field values use the `.

 

i.e. INSERT INTO `blah` ( `id`, `blah2` ) VALUES ( NULL, 'Hi' )

 

That should resolve your issue.

 

~juddster

Freid001, not only did you change the column name that was causing the first error, you put single-quotes around each of your column names. Why did you do that and if you bother to look at the error message you got, it is complaining at the first single-quote that you put around your ID column name.

oh sorry i though you ment '' any way I see to be a step closer i now get a error message that says:

 

Unknown column '' in 'field list'

 

I have changing the name to faction but it still gives this error

 

$query = "INSERT INTO Game (`ID`, `User`, `Email`, `Password`, `Faction`) VALUES (``, `$myusername`, `$email`, `$password`, `$clan`)";

mysql_query($query) or die (mysql_error());

 

include 'library/closedb.php';

echo "New MySQL user added";

Thanks guys I have got it working!

 

Im only 17 and so the more advance php is a little unknown to me so thanks for your help :) :) :)

 

Glad you got it working but your code changed every time you posted it and it's hard for people to help when that happens.  You should also mark this thread as solved.

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.