Hi, I have problem..umm..perhaps a little bit problem that I can`t figured it out...below is my half script. I think the problem is in this part: (This script is part of a register form)
$day= $_POST['day'];
$sql = "INSERT INTO `rute` (`rute_id`, `from_id`, `to_id`, `flight_no`, `flight_time`, `flight_time2`, `via`, `type`, `day`)
VALUES ('$id', '$from', '$to, '$no', '$tm1', '$tm2', '$via', '$type' ' ";
for($i=0;$i<count($day);$i++){
$sql .= " ".$day[$i].", " ;
}
$sql .= "".$day[$i]." ')";
mysql_query($sql);
The colored text related to this select tags :
<select name="from" class="textField" id="from">
<option>--Arrival City--</option>
<?php
include "mainFunction.php";
$sql="SELECT * FROM `from_city` ORDER BY `from_id` ASC";
if (! $res=mysql_query($sql, $dbh)) {
echo mysql_error();
return 0;
}
$num=mysql_numrows($res);
$i=0;
while ($i < $num)
{
$row=mysql_fetch_row($res);
$id=mysql_result($res,$i,"from_id");
$city=mysql_result($res,$i,"city");
++$i;
print "<option value=$id>$city</option>";
}
?>
</select>
This Check box get the data from database. And then whe visitor checked this option the database will insert the data to Mysql. The Error message was :
error in executing query INSERT INTO `rute` (`rute_id`, `from_id`, `to_id`, `flight_no`, `tm1`, `tm2`, `via`, `type`, `day`) VALUES ('1', '1', '1', '24234', '11:02', '23:09', 'Idaho', 'B21-3423' ' 2, 3, ')
please click here to go back
Thanks a lot for any help...
Insert Data Problem[Please Help]
Moderator: General Moderators
Re: Insert Data Problem[Please Help]
You are missing a comma after 'B21-3423'
There also seems to be an extra ' at the end of the query.
There also seems to be an extra ' at the end of the query.
Re: Insert Data Problem[Please Help]
I`ve been fixing the error, but there`s still errors...astions wrote:You are missing a comma after 'B21-3423'
There also seems to be an extra ' at the end of the query.
error in executing query INSERT INTO `rute` (`rute_id`, `from_id`, `to_id`, `flight_no`, `tm1`, `tm2`, `via`, `type`, `day`) VALUES ('1', '1', '1', '3234-NDAS', '11:01', '23:09', 'Idaho', 'PN-2423', 1, 2, )
Re: Insert Data Problem[Please Help]
The end of your query has a , with nothing after it. You can retrieve details of the last error with the mysql_error() function.
http://us2.php.net/manual/en/function.mysql-error.php
http://us2.php.net/manual/en/function.mysql-error.php
Re: Insert Data Problem[Please Help]
I used that function, and showed up this sign on frontend page:astions wrote:The end of your query has a , with nothing after it. You can retrieve details of the last error with the mysql_error() function.
http://us2.php.net/manual/en/function.mysql-error.php
0:
0:
I think theres something wrong with this script :
$day= $_POST['day'];
$sql = "INSERT INTO `rute` (`rute_id`, `from_id`, `to_id`, `flight_no`, `flight_time`, `flight_time2`, `via`, `type`, `day`)
VALUES ('$id', '$from', '$to, '$no', '$tm1', '$tm2', '$via', '$type' ' ";
for($i=0;$i<count($day);$i++){
$sql .= " ".$day[$i].", " ;
}
$sql .= "".$day[$i]." ')";
I think something wrong with (") and (') position....could you help me to solve this??
Thanks...Best Regards,
Re: Insert Data Problem[Please Help]
1. Please use [code = php] tags when posting code. (without spaces)
2. This is untested. The code you posted is very insecure. Please use mysql_real_escape_string or other measures to prevent sql injection.
If the query fails please post the query, your table structure and the results of mysql_error().
2. This is untested. The code you posted is very insecure. Please use mysql_real_escape_string or other measures to prevent sql injection.
Code: Select all
$day = $_POST['day'];
$sql = "INSERT INTO `rute` (`rute_id`, `from_id`, `to_id`, `flight_no`, `flight_time`, `flight_time2`, `via`, `type`, `day`)
VALUES ('" . mysql_real_escape_string($id) . "', '" . mysql_real_escape_string($from) . "', '" . mysql_real_escape_string($to) . ", '" . mysql_real_escape_string($no) . "', '" . mysql_real_escape_string($tm1) . "', '" . mysql_real_escape_string($tm2) . "', '" . mysql_real_escape_string($via) . "', '" . mysql_real_escape_string($type) . "', '";
for($i = 0; $i <= count($day); $i++)
{
$sql .= mysql_real_escape_string($day[$i]) . ",";
}
$sql = substr($sql, 0, -1) . "')";
echo $sql;
Re: Insert Data Problem[Please Help]
The error is not in that script but the "if" condition that I wrote under that script above. There`s variabel that not called and then gave the error output. I`m sorry from my mistaken...Thank You So Much for the respond...quite fast too...
Thanks a lot...