我有以下的php腳本,但我插入到我的文本框中的數據沒有被髮布到數據庫中,一旦按鈕被點擊。我沒有收到錯誤,我不知道我的錯誤在哪裏。數據沒有發佈到mySQL數據庫
<?php
if (isset($_POST['submit'])){
$con = mysqli_connect("localhost","branchaw","211018556","basketball") or die("Could not connect");
$pId = mysqli_real_escape_string($con,$_POST['pid']);
$Hometown = mysqli_real_escape_string($con,$_POST['Hometown']);
$Year = mysqli_real_escape_string($con,$_POST['Year']);
$Position = mysqli_real_escape_string($con,$_POST['Position']);
$Season = mysqli_real_escape_string($con,$_POST['Season']);
$Date_Of_Birth = mysqli_real_escape_string($con,$_POST['Date_Of_Birth']);
$query = "INSERT INTO `General` (`pId`,`Hometown`,`Year`,`Position`,`Season`,`Date_Of_Birth`) VALUES ('".$pId."','".$Hometown."','".$Year."','".$Position."''".$Season."','".$Date_Of_Birth."')";
$result = mysqli_query($con,$query);
if($result){
echo 'Data Inserted';
} else{
echo die(mysqli_error($con));
}
//mysqli_free_result($result);
mysqli_close($con);
}
?>
<html>
<head>
<title>Add Data to General Information</title>
</head>
<body>
<form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
<label>pId<input type="text" name="pid"/></label>
<label>Hometown<input type="text" name="Hometown"/></label>
<label>Year<input type="text" name="Year"/></label>
<label>Position<input type="text" name="Position"/></label>
<label>Season<input type="text" name="Season"/></label>
<label>Date of Birth<input type="text" name="Date_Of_Birth"/></label>
<br />
<input type="submit" value="Add new data" name="submit"/>
</form>
</body>
</html>
sqli_connect?使用mysqli_connect –
它仍然是不添加到我的數據庫。出於某種原因,我沒有收到數據插入或數據未插入的消息 –
參考http://www.tutorialrepublic.com/php-tutorial/php-mysql-insert-query.php –