Hey I am trying to run this in php:

// Retrieve data from table where row that match this passkey
$sql1="SELECT * FROM $tbl_name1 WHERE confirm_code ='$passkey'";
$result1=mysql_query($sql1) or die(mysql_error())

and I get this 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 '' at line 1

Any ideas on what I am doing wrong?

You've missed out on a semicolon after 'die'.
do this:
.... or die(mysql_error());
This will not give an error

hello try this may works:

$sql1="SELECT * FROM $tbl_name1 WHERE confirm_code =".$passkey;
$result1=mysql_query($sql1) or die(mysql_error());

You need to know whether the generated query is a valid or not. For this, print the query e.g.

$sql1="SELECT * FROM $tbl_name1 WHERE confirm_code ='$passkey'";
echo $sql1."<br>";
$result1=mysql_query($sql1) or die(mysql_error());

Post back the query you get.

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 'INSERT INTO raf_emails VALUES(1, 'Email Verification Link', 'You or someone else' at line 12.


Any ideas on what to do?

Its for a raffle system.

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 'INSERT INTO raf_emails VALUES(1, 'Email Verification Link', 'You or someone else' at line 12.


Any ideas on what to do?

Its for a raffle system.

I am having the same problem. Any help will be appreciated

Hi first check that your PHP variables are passing values to your query...

Try your code like this

// Retrieve data from table where row that match this passkey
echo $sql1="SELECT * FROM $tbl_name1 WHERE confirm_code ='".$passkey."'";
$result1=mysql_query($sql1) or die(mysql_error());

In the above query, if all the values are displaying, there is nothing wrong in your query...

Same case in your insert statements,
If your table contains more than 3 columns and you are passing only 3 values to your insert statement, then it will results to error.

so in order to avoid confusion for your insert query

try like this

INSERT INTO raf_emails (column1, column2, column3) VALUES (1, 'Email Verification Link','column3_value')

Hey I am trying to run this in php:

// Retrieve data from table where row that match this passkey
$sql1="SELECT * FROM $tbl_name1 WHERE confirm_code ='$passkey'";
$result1=mysql_query($sql1) or die(mysql_error())

and I get this 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 '' at line 1

Any ideas on what I am doing wrong?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.