954,568 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

php / sql insert script error

Hi guys,

I have this sql statement that is trying to insert data from some fields

<?php $con = mysql_connect("xxx","xx","xx"); if (!$con) { die('Could not connect: ' . mysql_error()); }

mysql_select_db("xxx", $con); $sql="INSERT INTO guests (guest_name, guest_email) VALUES"; for($i=0;$i

but it returns the errorError: 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

jinx_uk_98
Newbie Poster
8 posts since Apr 2008
Reputation Points: 10
Solved Threads: 0
 

you have forgotten a period after $sql"

$sql.="INSERT INTO guests (guest_name, guest_email) VALUES";
ryan_vietnow
Posting Pro
578 posts since Aug 2007
Reputation Points: 28
Solved Threads: 71
 

cheers Ryan. have added the period but the error still happens

jinx_uk_98
Newbie Poster
8 posts since Apr 2008
Reputation Points: 10
Solved Threads: 0
 

Print your query and execute it in mysql console/phpmyadmin.. Also show us the query ..

nav33n
Purple hazed!
Moderator
4,465 posts since Nov 2007
Reputation Points: 524
Solved Threads: 356
 
Print your query and execute it in mysql console/phpmyadmin.. Also show us the query ..

not sure what you mean here. please elaborate?

jinx_uk_98
Newbie Poster
8 posts since Apr 2008
Reputation Points: 10
Solved Threads: 0
 
$sql="INSERT INTO guests (guest_name, guest_email) VALUES";
for($i=0;$i<sizeof($_POST['username']);$i++){

$sql.="('".mysql_real_escape_string($_POST['username'][$i])."','".mysql_real_escape_string($_POST['email'][$i])."')";
if(!$i==sizeof($_POST['username'])){
$sql.=",";
}
}
echo $sql;

What does it print ?

nav33n
Purple hazed!
Moderator
4,465 posts since Nov 2007
Reputation Points: 524
Solved Threads: 356
 

oh i understand now.

it prints :
INSERT INTO guests (guest_name, guest_email) VALUES

jinx_uk_98
Newbie Poster
8 posts since Apr 2008
Reputation Points: 10
Solved Threads: 0
 

Thats it ? Its not entering the for loop ? Well, then there is the problem. Check your for loop and see if the values are being posted.

nav33n
Purple hazed!
Moderator
4,465 posts since Nov 2007
Reputation Points: 524
Solved Threads: 356
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You