Jump to content

MYSQL Error?


jbman223

Recommended Posts

$con=mysql_connect("****","****","****");
mysql_select_db("****");

$queryuser=mysql_query("SELECT * FROM users WHERE name='$name'");
$checkuser=mysql_num_rows($queryuser);
if($checkuser != 0)
{ $error = $name." is already in the database. <br /> <a href='****'>Return</a>"; 
$errortype = "1";}
else {
/* Now we will write a query to insert user details into database */
$insert = mysql_query("INSERT INTO users (name, group, sex, grouprank) VALUES ('$name', '$group', '$sex', '$grouprank')");

if($insert)
{ $error = $name. "Was successfully added to the database. <br /> <a href='****'>Return</a>"; 
$errortype = "0";}
else
{ $error = "Error in registration: ".mysql_error(); 
$errortype = "1";}

/* closing the if else statements */
}
echo $error;
?>

Error:

Error in registration: 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 'group, sex, grouprank) VALUES ('ljkh', 'lnkb', 'female', 'lkjh')' at line 1

 

Please help. THanks

Link to comment
https://forums.phpfreaks.com/topic/255941-mysql-error/
Share on other sites

since we dont know where your inputs are coming from, simplest way to check is to do this

<?php
echo "INSERT INTO users (name, group, sex, grouprank) VALUES ('$name', '$group', '$sex', '$grouprank')";
?>

throw the query into SQL manually to see what the error is.

One possibility is that SQL doesn't like variable names.  you can try one of these two options to see if it helps (I dont know the reasoning behind it, but i read it somewhere once before :) )

 

<?php
$insert = mysql_query("INSERT INTO users (name, group, sex, grouprank) VALUES ('{$name}', '{$group}', '{$sex}', '{$grouprank}')");
$insert = mysql_query("INSERT INTO users (name, group, sex, grouprank) VALUES ('".$name."', '".$group."', '".$sex."', '".$grouprank."')");
?>

Link to comment
https://forums.phpfreaks.com/topic/255941-mysql-error/#findComment-1311995
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.