-2

I am trying to insert the value to the mysql table using php. But I couldn't insert the value using php code. I have attached My table structure and mysql query. can any one please help me to fix this issue.

enter image description here

PHP Code

<body>
<?php 
$lahipita=$_POST['pso'];
$hitAd=$_POST['pso1'];
$silumina=$_POST['ph'];
$sunday_observer=$_POST['pl'];
$virakesari=$_POST['p3'];
$thinakaran=$_POST['p4'];
$hitAd_bl=$_POST['ph3'];
$hitAd_bs=$_POST['ph2'];
$sunday_observer_bl=$_POST['p5'];
$sunday_observer_bs=$_POST['p6'];
$words=$_POST['words'];
$payment_method=$_POST['type'];

$total=0;
if($lahipita!=""){
    $total=$total+900;
}
if($hitAd!=""){
    $total=$toal+300;
}
if($silumina!=""){

    $total=$total+500;
}
if($sunday_observer!=""){
    $total=$total+300;
}
if($thinakaran!=""){

    $total=$total+200;

}
if($virakesari!=""){
    $total=$total+600;
}
if($hitAd_bl!=""){

    $total=$total+2750;

}
if($hitAd_bs!=""){
    $total=$total+1650;
}
if($sunday_observer_bl!=""){

    $total=$total+2000;
}
if($sunday_observer_bs!=""){

    $total=$total+1000;
}


$result=iud("INSERT INTO  wp_paperAds(DEFAULT,'$lahipita','$hitAd','$silumina','$sunday_observer','$virakesari','$thinakaran','$hitAd_bl','$hitAd_bs','$sunday_observer_bl','$sunday_observer_bs','$words','','$payment_method','$total')");

?>

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 'DEFAULT,'','','','','selected','','','','','','dfdfdfd','','Array','600')' at line 1
Sirojan Gnanaretnam
  • 601
  • 1
  • 22
  • 45
  • 1
    You should take care of [SQL Injection](http://stackoverflow.com/questions/60174/how-to-prevent-sql-injection). – j0k Dec 10 '12 at 15:03

5 Answers5

4

The syntax error is the lack of the VALUES keyword:

INSERT INTO wp_paperAds VALUES (DEFAULT,...)
GarethL
  • 1,473
  • 1
  • 15
  • 16
1

INSERT INTO wo_paperAds (column1, column2, column3) VALUES (value1, value2, value3)

martskins
  • 2,920
  • 4
  • 26
  • 52
0

one of the values you are echoing is an array. you need to echo the array item instead

Matanya
  • 6,233
  • 9
  • 47
  • 80
0

It appears you are missing VALUES in your query (INSERT INTO t1 VALUES ...).

You can always debug your query like so:

$sql = "INSERT INTO  wp_paperAds(DEFAULT,'$lahipita','$hitAd','$silumina','$sunday_observer','$virakesari','$thinakaran','$hitAd_bl','$hitAd_bs','$sunday_observer_bl','$sunday_observer_bs','$words','','$payment_method','$total')";

echo $sql;

You also need to get in the habit of using a column list.

Kermit
  • 33,827
  • 13
  • 85
  • 121
0

You are missing the VALUES keyword. Try specifying the table rows that you are inserting data into, that way you won't even have to specify DEFAULT. Like this:

 $q = "INSERT INTO table (field1,field2) VALUES ('value1', 'value2')";
 $run = mysql_query($q);

I always specify table rows because that way I don't have to get the order right in the query, and I don't have to worry about specifying default values. But on a side note, you shouldn't be inserting an array into the database. Also, I would put a space after the table name and before the first ( in the query, it just looks better. :)

Hope that helps.

SISYN
  • 2,209
  • 5
  • 24
  • 45