好吧,它正在工作......現在它突然停止了。我不知道爲什麼。我添加的唯一東西是刪除功能..之後,它不再提交。我雖然可以刪除條目= d表單已停止提交到數據庫中
PHP代碼的形式
<?php
if (isset($_POST['submit'])){
$con = mysql_connect("localhost", "", "");
if (!$con){
die("Cannot connect:" . mysql_error());
}
$Firstname = $_POST['Firstname'];
$Email = $_POST['Email'];
$Prayer = $_POST['Prayer'];
//if there is no input these messages will come up//
if($Firstname==''){
echo "<script>alert('Please enter your name!')</script>";
exit();
}
if($Email==''){
echo "<script>alert('Please enter your email!')</script>";
exit();
}
if($Prayer==''){
echo "<script>alert('Please enter your prayer request!')</script>";
exit();
}
mysql_select_db("dxh6110",$con);
//if everything is good, information will be submitted to database
$sql = "INSERT INTO ChurchPrayer (Firstname, Email, Prayer) VALUES('$_POST[Firstname]','$_POST[Email]','$_POST[Prayer]')";
if(mysql_query($sql,$con)){
echo "<script>alert('Congratulations, You have successfully submitted your prayer requests. You will hear from us very soon!')</script>";
}
mysql_close($con);
}
?>
哦,我知道,我應該使用準備好的語句,以防止SQL注入......但我不知道到底它是什麼或它看起來像什麼。當我進一步進入我的學校項目時,我一定會在後面添加它們。目前擔心的功能..
不知道需要添加些什麼......我要添加delete.php
<?php session_start(); //starting the session?>
<?php
//connecting to database
$con = mysql_connect("localhost","","","dxh6110");
//defining variable
$delete_id = $_GET['del'];
//command to remove input from SQL DB
$query = "delete from ChurchPrayer where id='$delete_id'";
if(mysql_query($con,$query)){
echo "<script>window.open('view_prayers.php?deleted=User has been deleted!','_self')</script>";
}
?>
我的管理員登錄的作品,當在管理日誌它將它們帶到一個頁面,這將允許他們查看條目並刪除對數據庫的條目。目前有兩個,但是當我嘗試添加更多的請求....他們不去數據庫。單擊提交時不會發生錯誤。
請,[停止使用'mysql_ *'功能](http://stackoverflow.com/questions/12859942/why-shouldnt-i-use-mysql-functions-in-php)。他們不再被維護,並[正式棄用](https://wiki.php.net/rfc/mysql_deprecation)。瞭解[準備的陳述](http://en.wikipedia.org/wiki/Prepared_statement),並使用[PDO](http://jayblanchard.net/demystifying_php_pdo.html)。 服務器升級了嗎? –
在打開'<?php'標記'error_reporting(E_ALL)後立即在文件頂部添加錯誤報告; ini_set('display_errors',1);' 向查詢添加錯誤檢查,例如'或die(mysql_error())'。您會在當前的錯誤日誌中找到問題。 –
'(「localhost」,「dxh6110」,「tcqfoz7」,「dxh6110」)'不符合您的想法。另外,'$ _GET ['del']'和'?deleted = User'檢查。這些是我突出的兩件事。 –