-
Unable to INSERT record into Database
Why do i keep getting this kind of error message?
INSERT 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 '(usrip, user, status) VALUES ('', '', '')' at line 1
Here is my php code
PHP Code:
$ipaddr=$_SERVER['REMOTE_ADDR'];
$mycnct=mysql_connect("abc","xyz","pass");
if($mycnct){
if(mysql_select_db("mydb",$mycnct)){
$grpid=$_GET['gid'];
$thisuser=$_GET['usersid'];
$mylockr=$_GET['accessid'];
$grpmode=$_GET['gmode'];
$grplock=$_GET['islock'];
$isonline="online";
$groupFullName="GRP_".$grpid."_users";
if(mysql_query("INSERT INTO $groupFullName ('usrip', 'user', 'status') VALUES ('$ipaddr', '$thisuser', '$isonline')")){
echo "Success";
}else{
echo "INSERT ERROR:".mysql_error();
}
}
}
/*Link with variables:
mysite.com/testing.php?gid=bluebell&usersid=henry&gmode=join&islock=off&accessid=abc
*/
Before running the above code, this is how the table was created:
PHP Code:
if(mysql_query("CREATE TABLE $groupFullName(SL int(11) NOT NULL AUTO_INCREMENT, usrip text NOT NULL, user varbinary(35) NOT NULL, status varchar(15) NOT NULL, getreq varchar(15) NOT NULL, PRIMARY KEY (SL))")){
echo "DONE";
}else{
echo "Fail";
}
-
I even tried removing the Quotes. Still i get the same error
PHP Code:
INSERT INTO $groupFullName (usrip, user, status) VALUES ('$ipaddr', '$thisuser', '$isonline')
-
Hi,
it should work without the quotes
[code]insert into .... (usrip, user, status)[c/code]
You might try something like
Code:
$sql = "INSERT ........"
if(mysql_query(sql)) echo "success"; else echo "error for $sql " . mysql_error();
to see if anything not obvious happened to the sql code
Musicman
-
Still i get the error message.
I tried to echo my SQL statement to check whats happening with my variables...
PHP Code:
if(mysql_query("INSERT INTO $groupFullName (usrip, user, status) VALUES ('$ipaddr', '$thisuser', '$isonline')")){
echo "Success";
}else{
echo "INSERT ERROR:".mysql_error();
}
echo "<br/><br/><br/><br/>INSERT INTO $groupFullName (usrip, user, status) VALUES ('$ipaddr', '$thisuser', '$isonline')";
And I got this....
INSERT 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 '(usrip, user, status) VALUES ('', '', '')' at line 1
INSERT INTO (usrip, user, status) VALUES ('', '', '')
Empty variables? This is crazy. Why am I getting empty variables in my echo when I had passed this...
mysite.com/testing.php?gid=bluebell&usersid=henry&gmode=join& islock=off&accessid=abc
Remember i had used the same variable name($groupFullName) before to create the same table, but then it had worked well.
-
This is getting even more stranger...
When I inserted the below code....
PHP Code:
$copystr="GRP_".$groupFullName."_users";
if(mysql_query("INSERT INTO $copystr (usrip, user, status) VALUES ('$ipaddr', '$thisuser', '$isonline')")){
echo "Success";
}else{
echo "INSERT ERROR:".mysql_error();
}
echo "<br/><br/><br/><br/>INSERT INTO $copystr (usrip, user, status) VALUES ('$ipaddr', '$thisuser', '$isonline')"
I get this error...
INSERT ERROR:Table 'b20_mydb_chatbox.GRP__users' doesn't exist
INSERT INTO GRP__users (usrip, user, status) VALUES ('', '', '')
----------------------------------------
And then I tried replacing $groupFullName by $_GET['gid']
PHP Code:
$copystr="GRP_".$_GET['gid']."_users";
if(mysql_query("INSERT INTO $copystr (usrip, user, status) VALUES ('$ipaddr', '$thisuser', '$isonline')")){
echo "Success";
}else{
echo "INSERT ERROR:".mysql_error();
}
echo "<br/><br/><br/><br/>INSERT INTO $copystr (usrip, user, status) VALUES ('$ipaddr', '$thisuser', '$isonline')"
Now I got this...
INSERT INTO GRP_bluebell_users (usrip, user, status) VALUES ('', '', '')
I checked the table, and found that a record has been inserted into this table with empty datas under colums (usrip, user, status)
So why doesn't it work when i use $groupFullName?
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|