我想使用 PHP 的 PDO 将数据插入 mysql 数据库。但是没有插入数据。我之前使用过 PDO,但没有遇到任何问题。但是在以下情况下,我不明白我在哪里做错了。谁能帮帮我吗?输出显示良好的回声。
<?php
include 'includes/config.php';
$name1 = $_POST['name1'];
$address = $_POST['address'];
$city = $_POST['city'];
$state = $_POST['state'];
$zip_code = $_POST['zip_code'];
$telephone = $_POST['telephone'];
$email = $_POST['email'];
$fiance = $_POST['fiance'];
$wedding_date = $_POST['wedding_date'];
$number_of_guest = $_POST['number_of_guest'];
$radio = $_POST['radio'];
if($radio=='on') $radio = 'yes';
$newspaper = $_POST['newspaper'];
if($newspaper=='on') $newspaper = 'yes';
$facebook = $_POST['facebook'];
if($facebook=='on') $facebook = 'yes';
$website = $_POST['website'];
if($website=='on') $website = 'yes';
$hear_by_other = $_POST['hear_by_other'];
if($hear_by_other=='on') $hear_by_other = 'yes';
$by_other = $_POST['by_other'];
$date1 = date("m-d-Y");
$status = 0;
echo $name1.'<br />';
echo $address.'<br />';
echo $city.'<br />';
echo $state.'<br />';
echo $zip_code.'<br />';
echo $telephone.'<br />';
echo $email.'<br />';
echo $fiance.'<br />';
echo $wedding_date.'<br />';
echo $number_of_guest.'<br />';
echo $radio.'<br />';
echo $newspaper.'<br />';
echo $facebook.'<br />';
echo $website.'<br />';
echo $hear_by_other.'<br />';
echo $by_other.'<br />';
echo $date1.'<br />';
echo $status.'<br />';
$statement = $pdo->prepare('INSERT INTO arefin (name1,address,city,state,zip_code,telephone,email,fiance,wedding_date,number_of_guest,radio,newspaper,facebook,website,hear_by_other,by_other,date1,status) VALUES (:var1,:var2,:var3,:var4,:var5,:var6,:var7,:var8,:var9,:var10,:var11,:var12,:var13,:var14,:var15,:var16,:var17,:var18)');
$statement->bindParam(':var1',$name1);
$statement->bindParam(':var2',$address);
$statement->bindParam(':var3',$city);
$statement->bindParam(':var4',$state);
$statement->bindParam(':var5',$zip_code);
$statement->bindParam(':var6',$telephone);
$statement->bindParam(':var7',$email);
$statement->bindParam(':var8',$fiance);
$statement->bindParam(':var9',$wedding_date);
$statement->bindParam(':var10',$number_of_guest);
$statement->bindParam(':var11',$radio);
$statement->bindParam(':var12',$newspaper);
$statement->bindParam(':var13',$facebook);
$statement->bindParam(':var14',$website);
$statement->bindParam(':var15',$hear_by_other);
$statement->bindParam(':var16',$by_other);
$statement->bindParam(':var17',$date1);
$statement->bindParam(':var18',$status);
$statement->execute();
?>
我的 config.php 文件在这里:
<?php
$dbhost = 'localhost';
$dbname = 'arefinDB';
$dbuser = 'root';
$dbpass = '';
try {
$pdo = new PDO("mysql:host={$dbhost};dbname={$dbname}", $dbuser, $dbpass);
$conn = $pdo;
}
catch( PDOException $excepiton ) {
echo "Connection error :" . $excepiton->getMessage();
}
?>
数据库表如下所示: