在Mysql表中插入值

时间:2012-12-10 14:54:29

标签: php html mysql sql

我试图使用php将值插入mysql表。但是我无法使用php代码插入值。我附加了My table结构和mysql查询。任何人都可以帮我解决这个问题。

enter image description here

PHP代码

<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: 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

5 个答案:

答案 0 :(得分:4)

语法错误是缺少VALUES关键字:

INSERT INTO wp_paperAds VALUES (DEFAULT,...)

答案 1 :(得分:1)

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

答案 2 :(得分:0)

您回显的其中一个值是数组。你需要回显数组项

答案 3 :(得分:0)

您的查询(VALUES)中似乎缺少INSERT INTO t1 VALUES ...

您可以随时调试查询:

$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;

您还需要养成使用列列表的习惯。

答案 4 :(得分:0)

您缺少VALUES关键字。尝试指定要插入数据的表行,这样您甚至不必指定DEFAULT。像这样:

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

我总是指定表行,因为这样我不必在查询中获得正确的顺序,而且我不必担心指定默认值。但是请注意,您不应该将数组插入数据库。另外,我会在表名之后和第一个之前放置一个空格(在查询中,它看起来更好。:)

希望有所帮助。