0
我試圖使用PHP將數據從Web表單發送到我的數據庫。用戶在文本框中輸入full_name
,contact_number
和best_time_to_call
的詳細信息。當這些框填充了相關信息並點擊提交後,數據將被完美地添加到數據庫中,只是這些列是空白的。我怎麼能解決這個問題?Web表單正在向數據庫提交空白數據
HTML
<form name="frmContact" action="<?php $_PHP_SELF ?>" id="frmCallContact" method="POST">
enter code here<table width="100%" border="0" cellspacing="1" cellpadding="0" class="TableFormat">
<tr>
<th align="left" valign="top" colspan="2">Call me back</td>
</tr>
<tr>
<td align="right" valign="top">Full Name:</td>
<td><input type="text" name="FullName" id="FullName_R" style="width:250px;" title="Please enter your full name"/></td>
</tr>
<tr>
<td align="right" valign="top">Contact Number:</td>
<td><input type="text" name="ContactNumber" id="ContactNumber_R" style="width:250px;" /></td>
</tr>
<tr>
<td align="right" valign="top">Best Time to Call:</td>
<td><input type="text" name="BestTime" id="BestTime_R" style="width:250px;" title="Please enter your best time to call"/></td>
</tr>
<tr>
<td align="right" valign="top"> </td>
<td><!--<a name="submit" href="#"><img src="/img/bn_submit.png" width="93" height="28" /></a>--><input type="submit" name="Submit" value="Submit">
</tr>
</table>
</form>
PHP
<?php
require_once($_SERVER['DOCUMENT_ROOT'].'/inc/bootstrap.php');
include("config/cn.php");
$template['template']="page";
if($_POST){
// Data pulled from input form
$full_name = $_POST['full_name'];
$contact_number = $_POST['contact_number'];
$best_time_to_call = $_POST['best_time_to_call'];
$enter_sql = "INSERT INTO contact (full_name,contact_number,best_time_to_call) VALUES('$full_name','$contact_number','$best_time_to_call')";
/*print($enter_sql);*/
$enter_query = mysql_query($enter_sql) or die(mysql_error());
header('Location: /thankyou.php');
exit;
}
?>
在窗體中有以下內容: 'NAME = 「全名」',並在PHP代碼中使用: 'FULL_NAME' 。使用print_r($ _ POST);看看你得到了什麼。 – Pakspul
你是什麼意思「數據添加到數據庫完全罰款只有列是空白」?如果數據完美添加,列不應該是空白的? –
@SandeepNayak我的意思是,連接是好的,所以我能夠提交數據到我的數據庫 –