[英]Blank field when I send a variable to phpmyadmin
I am trying to create a form where the variable fields is sent to a database in phpmyadmin. 我正在尝试创建一个将变量字段发送到phpmyadmin中的数据库的表单。 The problem is that the fields in phpmyadmin are blank, as if I hadn't write anything in the form.
问题是phpmyadmin中的字段为空,好像我没有在表单中写任何东西。 The code is the following in PHP:
代码是PHP中的以下代码:
$name = $_POST["name"];
$institution = $_POST["institution"];
$email = $_POST["email"];
$country = $_POST["country"];
$hcp = $_POST["hcp"];
$texto = $_POST["texto"];
$state = $_POST["state"];
$license = $_POST["license"];
$connection = mysql_connect($database_host, $database_username, $database_password);
if(!$connection) { // if our attempt to connect failed
die('Could not connect: ' . mysql_error());
}
mysql_select_db($database_name, $connection) or die("You cannot select data base");
$consulta = ("INSERT INTO `1264`(`name`, `institution`, `email` , `country`, `hcp` , `texto` , `state` , `license`) VALUES ('".$name."','".$institution."','".$email."','".$country."','".$hcp."','".$texto."','".$state."','".$license."');");
echo $consulta; die;
mysql_query($consulta,$connection) or die("You cannot register. Try it later, please.");
And in HTML the format of the form is the following: 在HTML中,表单的格式如下:
<form method="post" action="php/enviar.php">
<span class="texto azul">Name</span><input class="caja texto" name="name" type="text"/><br /><br />
<span class="texto azul">Institution</span><input class="caja texto" name="institution" type="text"/><br /><br />
<span class="texto azul">Email address</span><input class="caja texto" name="email" type="text"/><br /><br />
<span class="texto azul">Country</span><select id="country" class="caja texto" name="country">
<option value="">Country...</option>
<option value="Afganistan">Afghanistan</option>
...
</select>
<div id="fadein">
<span id="usa" class="texto azul inputText">HCP Designation</span><select name="hcp" class="caja inputText texto" disabled>
<option value="des">Designation...</option>
<option value="md">MD</option>
<option value="np">NP</option>
<option value="rn">RN</option>
<option value="other">Other</option>
</select><br /><br />
<span id="texto" class="texto azul inputText">If other, please specify</span>
<textarea class="caja inputText texto" name="texto" disabled></textarea><br /><br />
<span class="texto azul inputText">State of Licensure</span><input class="caja inputText texto" name="state" type="text" disabled/><br /><br />
<span class="texto azul inputText">License number</span><input class="caja inputText texto" name="license" type="text" disabled/><br /><br />
</div>
</form>
Does anybody know why it doesn't accept the fields that I write in the form? 有人知道为什么它不接受我以表格形式填写的字段吗?
This line is the problem. 这条线是问题所在。
echo $consulta; die;
You're instructing the script to exit even before getting to the mysql_query($consulta,$connection)
line. 您正在指示脚本甚至在进入
mysql_query($consulta,$connection)
行之前也要退出。 Remove the die
and it should be good to go provided your connection is good and there's no syntax error in your query. 卸下
die
,只要连接良好并且查询中没有语法错误,就可以进行操作了。
You also don't require the (
and )
when storing the query as string. 将查询存储为字符串时,您也不需要
(
和)
。 So 所以
$consulta = "INSERT INTO `1264`(`name`, `institution`, `email` , `country`, `hcp` , `texto` , `state` , `license`) VALUES ('".$name."','".$institution."','".$email."','".$country."','".$hcp."','".$texto."','".$state."','".$license."')";
Sidenote : You should stop using mysql_*
functions as they are deprecated post v5.5. 旁注 :您应该停止使用
mysql_*
函数,因为v5.5之后已弃用这些函数。 Switch to PDO or mysqli instead. 改用PDO或mysqli。
You should first check post array you get. 您应该首先检查您获得的帖子数组。
Do this first: 首先执行以下操作:
echo '<pre>';print_r($_POST);exit;
Check what values you get. 检查您得到什么值。
Note : Also check value name fields in form & key of post array should be same. 注意 :还要检查帖子数组的形式和键中的值名称字段是否相同。
Also replace query with given below. 也用下面给出的替换查询。
$consulta = "INSERT INTO `1264`(`name`, `institution`, `email` , `country`, `hcp` , `texto` , `state` , `license`) VALUES ('".$name."','".$institution."','".$email."','".$country."','".$hcp."','".$texto."','".$state."','".$license."')";
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.