-1
我試圖嘗試根據重要的信息片斷(例如姓名,祈禱請求,電話號碼等)來保存用戶輸入。這個想法是一個人導航到網頁並且然後填寫信息,然後單擊提交按鈕,然後將數據保存到數據庫。每當我嘗試測試頁面時,沒有任何東西拉上來。我多次查看了我的代碼並找不到問題。我有一個粗略的模板來基於我的PHP。在它內部有一個「全部顯示」按鈕,根本不需要在頁面上。任何建議將不勝感激。我的代碼(包括「全部顯示」按鈕的代碼)可以發現如下:PHP代碼在測試代碼時不顯示
<?php
$Req_F_Name = $_POST["Req_F_Name"];
$Reg_L_Name = $_POST["Reg_L_Name"];
$Reg_Phone = $_POST["Reg_Phone"];
$Reg_Email= $_POST["Reg_Email"];
$Reg_Request = $_POST["Reg_Request"];
$Reg_Address_1= $_POST["Reg_Address_1"];
if ($Submit) {
$conn = mysql_connect('XXXXXX','XXXX','XXXXXX','prayer') or
die("Could not connect: " . mysql_error());
//select the database
$db = mysql_select_db("prayer");
$query = "INSERT INTO Request VALUES ('".$Req_F_Name."','".$Reg_L_Name."','".$Reg_Phone."','".$Reg_Email."','".$Reg_Request."',' ".$Reg_Address_1."')"or die(mysql_error());
echo "Your Query was successfully stored in the database :)";
mysql_close($conn);
}
if ($Show_All_Records) {
//establish connection to mysql
$conn = mysql_connect('XXXXXX','XXXXXX','XXXXXX','prayer')
or
die("Could not connect: " . mysql_error());
echo "Connected to MySql".'<br>'.'<br>';
//select the database
$db = mysql_select_db("prayer");
$result = mysql_query("SELECT * FROM 'Request'",$conn);
//display the results
echo 'First Name:', $Req_F_Name ,'<br>'
. 'Last Name:', $Reg_L_Name ,'<br>'
. 'Phone Number:', $Reg_Phone ,'<br>'
. 'Email:', $Reg_Email ,'<br>'
. 'Prayer Request:', $Reg_Request ,'<br>'
. 'Address:', $Reg_Address_1 ,'<br>'.'<br>';
//grabbing all data from the table
echo 'Your Query was succesfully stored in the database :)';
while ($myrow = mysql_fetch_array($result)) {
echo ''.$myrow["Req_F_Name"].' <br> '.$myrow["Reg_L_Name"].' <br>'.$myrow["Reg_Phone"].' <br> '.$myrow["Reg_Email"].' <br> '.$myrow["Reg_Request"].' <br> '.$myrow["Reg_Address_1"].' <br>';
}
mysql_close($conn);
}
?>
我不知道,如果你是通過教程或課程學習PHP,但你正在使用不推薦使用的'mysql()'函數。請使用['PDO'](http://be2.php.net/manual/en/book.pdo.php)(首選)或['mysqli()'](http://be2.php.net/手冊/ en/book.mysqli.php)。並檢查最近的教程或將其提交給您的教練。 – KarelG