•
•
•
•
What is DaniWeb IT Discussion Community?
You're currently browsing the PHP section within the Web Development category of DaniWeb, a massive community of 391,689 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 3,224 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our PHP advertiser: Lunarpages PHP Web Hosting
Views: 431 | Replies: 7
![]() |
•
•
Join Date: Apr 2008
Posts: 8
Reputation:
Rep Power: 0
Solved Threads: 0
Hi guys,
I have this sql statement that is trying to insert data from some fields
but it returns the error
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<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.=",";
}
}
//
if (!mysql_query($sql,$con))
{
die('Error: ' . mysql_error());
}
echo "record added";
?>
but it returns the error
•
•
•
•
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
•
•
Join Date: Aug 2007
Location: Cavite,Philippines
Posts: 503
Reputation:
Rep Power: 3
Solved Threads: 67
you have forgotten a period after $sql"
php Syntax (Toggle Plain Text)
$sql.="INSERT INTO guests (guest_name, guest_email) VALUES";
"death is the cure of all diseases..."
http://ryantetek.wordpress.com
http://ryantetek.wordpress.com
•
•
Join Date: Nov 2007
Location: Bangalore, India
Posts: 3,098
Reputation:
Rep Power: 8
Solved Threads: 238
Print your query and execute it in mysql console/phpmyadmin.. Also show us the query ..
Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning.
*PM asking for help will be ignored*
*PM asking for help will be ignored*
•
•
Join Date: Nov 2007
Location: Bangalore, India
Posts: 3,098
Reputation:
Rep Power: 8
Solved Threads: 238
php Syntax (Toggle Plain Text)
$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;
Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning.
*PM asking for help will be ignored*
*PM asking for help will be ignored*
•
•
Join Date: Nov 2007
Location: Bangalore, India
Posts: 3,098
Reputation:
Rep Power: 8
Solved Threads: 238
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.
Last edited by nav33n : May 16th, 2008 at 6:18 am.
Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning.
*PM asking for help will be ignored*
*PM asking for help will be ignored*
![]() |
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
•
•
•
•
•
•
•
•
DaniWeb PHP Marketplace
- A little problem with a script (PHP)
- Upload images to a folder script problem (PHP)
- Page Redirection error (PHP)
- PHP problem! (PHP)
- Cannot get php script to enter data (MySQL)
- insert csv file into mysql through php (PHP)
- $rs=mysql_query($sql) or die("error in common.inc.php at line 257"); (PHP)
- I need help with a parse error! (PHP)
Other Threads in the PHP Forum
- Previous Thread: dynamic query
- Next Thread: Variables in Variables



Linear Mode