2017-08-27 54 views
0

我正在嘗試構建一個html表單並將其連接到正在執行查詢並將信息插入到mysql數據庫的php文件中。html表單tp php文件

這裏是我的html代碼:

<!DOCTYPE html> 

<html lang="en"> 

<head> 

<meta charset="UTF-8"> 

<title>Add Record Form</title> 

</head> 

<body> 

<form action="/joomla_31/insert.php" method="post"> 


<label for="MGMT_IP">MGMT IP</label> 

<input type="text" name="MGMT_IP" id="MGMT_IP"> 

</p> 

<p> 

<label for="Vendor">Vendor</label> 

<input type="text" name="Vendor" id="Vendor"> 

</p> 

<p> 

<label for="Version">Version</label> 

<input type="text" name="Version" id="Version"> 

</p> 

<p> 

<label for="GUI_User">GUI User</label> 

<input type="text" name="GUI_User" id="GUI_User"> 

</p> 

<p> 

<label for="GUI_Pass">GUI Pass</label> 

<input type="text" name="GUI_Pass" id="GUI_Pass"> 

</p> 


<input type="submit" value="submit"> 

</form> 

</body> 

</html> 

,這裏是我的insert.php文件:

<?php 


$link = mysqli_connect("localhost", "root", "", "mysql"); 



// Check connection 

if($link === false){ 

die("ERROR: Could not connect. " . mysqli_connect_error()); 

} 



// Escape user inputs for security 

$MGMT_IP = mysqli_real_escape_string($link, $_REQUEST['MGMT IP']); 
$Vendor = mysqli_real_escape_string($link, $_REQUEST['Vendor']); 
$Version = mysqli_real_escape_string($link, $_REQUEST['Version']); 
$GUI_User = mysqli_real_escape_string($link, $_REQUEST['GUI User']); 
$GUI_Pass = mysqli_real_escape_string($link, $_REQUEST['GUI Pass']); 



// attempt insert query execution 

$sql = "INSERT INTO `cloud_team` (MGMT IP, Vendor, Version, GUI User, GUI Pass) VALUES (`$customer_number`, `$customer_name`, `$MGMT_IP`, `$Vendor`, `$Version`, `$GUI_User`, `$GUI_Pass`)"; 

if(mysqli_query($link, $sql)){ 

echo "Records added successfully."; 

} else{ 

echo "ERROR: Could not able to execute $sql. " . mysqli_error($link); 

} 


// close connection 

mysqli_close($link); 

?> 

但每次我點擊提交按鈕時,我得到一個空白頁... 這就像它是重定向正確的文件(http://x.x.x.x/joomla_31/insert.php)..但沒有執行...沒有錯誤顯示..只有一個空白頁

+0

[如何啓用PHP錯誤顯示](https://stackoverflow.com/questions/1053424/how-do-i-get-php-errors-to-display) - 這可能有助於調試您的代碼 – lumio

+0

謝謝lumio,我編輯php.ini文件從「display_errors = off」到「display_errors = on」 現在我收到此錯誤: 解析錯誤:語法錯誤,意外的''''(T_CONSTANT_ENCAPSED_STRING)在C:\ inetpub \ wwwroot \ joomla_31 \ joomla_31 \ insert.php在線23 –

+0

看來,Joomla預計一些其他類型的參數 – lumio

回答

0

啓用PHP錯誤顯示更好d調試你的代碼。請查看this答案瞭解更多詳情。