Jump to content

whats wrong with this php / sql command:


rickyj

Recommended Posts

this is the shothand sqlquerry(after connecting to the database an table):

 

$result= mysql_query("INSERT INTO sigparsed (a, b, c, d, e )  VALUES ('2', $var1, '1', $var2, '0' ) ") or die(mysql_error());

and my 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 '

 

But I see nothing wrong with my syntext

Link to comment
Share on other sites

Depends on what $var1 and $var2 contain.

 

try

<?php

$sql = "INSERT INTO sigparsed (a, b, c, d, e )  VALUES ('2', $var1, '1', $var2, '0' ) ";

$result = mysql_query($sql) or die (mysql_error()."<pre>$sql</pre>");

 

and see what is actually being sent.

 

 

@plutomed - only mandatory if the vars are non-numeric

Link to comment
Share on other sites

put your query in a separate variable to make sure you variables are going through correctly....and also echo the query out just to make sure

$query = 'INSERT INTO sigparsed (a, b, c, d, e )  VALUES ("2", $var1, "1", $var2, "0")';
$result= mysql_query($query) or die("Error with your SQL query: " . $query . "\n
Error: " . mysql_error());

Link to comment
Share on other sites

hmm now Im getting :

 

abDuplicate entry '119' for key 1

 

what does this mean, my querry is now:

print 'a';

$Querry = "INSERT INTO sigparsed (a, b, c, d, e )  VALUES ('2', '$var1', '1', '$var2', '0' ) ";

$result= mysql_query($Querry) or die(mysql_error());

print 'b';

 

$Querry2 = "INSERT INTO usertextfield (f, g)  VALUES ('$var3', '$var4') ";

$result2= mysql_query($Querry2) or die(mysql_error());

print 'c';

Link to comment
Share on other sites

You also might need to use the addslashes function on var1 and 2.

 

And, if possible, it's wise to use the mysqli functions for forward compatability.

 

Some hosts don't use both mysql and mysqli functions and just the older mysql functions. I agree with what you're saying... but what I don't understand is why people don't "wrapper" their database functions inside of a class so that it doesn't really matter if you use mysql or mysqli... you start out using mysql and then when the standard changes you change the class to mysqli and all your code works again... rather than having to hunt through code and change 1000 instances of mysql.... doing it my way you can even potentially change the underlying database... mysql->postgres...sql server... oracle, whatever.

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.