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我的意思是,连接是好的,所以我能够提交数据到我的数据库 –