我正在尝试使用复选框在注册表单期间按一个条目将对象数组插入到mySQL数据库中。
目前,该条目仅显示为“数组”,而该数组中没有条目。
我尝试了for循环,但它多次将整个条目插入数据库中,而不仅仅是复选框条目。
有想法该怎么解决这个吗?
<table border="0" cellpadding="3" cellspacing="1">
<tr>
<form id="callAjaxForm">
<div data-role="fieldcontain">
<td width="150">Name:</td>
<td width="300"><input type="text" name="inputName" value="" /> </td>
</tr>
<tr>
<td width="150">Username:</td>
<td width="300"><input type="text" name="inputUsername" value="" /></td>
</tr>
<tr>
<td width="150">Password:</td>
<td width="300"><input type="password" name="inputPassword" value="" /></td>
</tr>
<tr>
<td width="150">Date of Birth:</td>
<td width="300"><input type="date" name="inputDOB" value="" /></td>
</tr>
<tr>
<td width="150">Core Competencies:</td>
<td width="300">
<input type="checkbox" name="coreComp[]" value="1" />Honesty<br />
<input type="checkbox" name="coreComp[]" value="2" />Loyalty<br />
<input type="checkbox" name="coreComp[]" value="3" />Trust<br />
<input type="checkbox" name="coreComp[]" value="4" />Empathy<br />
<input type="checkbox" name="coreComp[]" value="5" />Respect</td>
</tr>
<tr>
<td colspan="2">
<button data-theme="b" id="submit" type="submit">Submit</button>
</td>
</tr>
<tr>
<td colspan="2">
<h3 id="notification"></h3>
</td>
</tr>
</div>
</form>
</table>
PHP代码
<?php
include 'includes/Connect.php';
$name = $_POST['inputName'];
$username = $_POST['inputUsername'];
$password = $_POST['inputPassword'];
$dob = $_POST['inputDOB'];
$aCC = $_POST['coreComp'];
$encrypt_password=md5($password);
if(empty($aCC))
{
echo("Please pick at least one");
}
else
{
mysql_query("INSERT INTO Profile (`Name`,`Username`,`Password`,`D.O.B`,`CC`) VALUES('$name','$username','$encrypt_password','$dob','$aCC')") or die(mysql_error());
mysql_close();
echo("You have successfully registered!");
}
?>
使用爆破和爆炸。
$aCC = implode( ';' , $_POST['coreComp'] );
$aCC will contain all values glued together with a ';' in between them.
这样,您可以将其存储在数据库中。当您从数据库中检索数据时,请确保使用爆炸。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句