我一整天都在这里,并且有一种感觉,它可能非常简单。 我试图让我的用户选择更新其用户配置文件中的一些条目,而不必每次都填写所有内容。尝试使用PHP更新从HTML表单到MySQL的配置文件
我会在下面发布我的代码,但基本上我没有得到任何答复。
我的HTML表格如下;
<table width="500" border="0" cellpadding="3" cellspacing="1">
<tr>
<form method="post" action="edit.php">
<div data-role="fieldcontain">
<td width="200">Name:</td>
<td width="450"><input type="text" name="inputName" value="" /> </td>
</tr>
<tr>
<td width="200">Password:</td>
<td width="450"><input type="password" name="inputPassword" value="" /></td>
</tr>
<tr>
<td width="200">Date of Birth:</td>
<td width="450"><input type="date" name="inputDOB" value="" /></td>
</tr>
<tr>
<td width="200">Core Competencies:</td>
<td width="450">
<input type="checkbox" name="coreComp[]" value="Honesty" />Honesty<br />
<input type="checkbox" name="coreComp[]" value="Loyalty" />Loyalty<br />
<input type="checkbox" name="coreComp[]" value="Trust" />Trust<br />
<input type="checkbox" name="coreComp[]" value="Empathy" />Empathy<br />
<input type="checkbox" name="coreComp[]" value="Respect" />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>
</div>
</form>
</tr>
</table>
而我的PHP目前看起来像这样;
<?php
session_start();
include 'includes/Connect.php';
$name = $_POST['inputName'];
$password = $_POST['inputPassword'];
$dob = $_POST['inputDOB'];
$aCC = implode(',' , $_POST['coreComp']);
$encrypt_password=md5($password);
$username=$_SESSION['myusername'];
if(!empty($name))
{
mysql_query("UPDATE Profile SET `Name`='$name' WHERE Username='$username'" or die(mysql_error());
echo("You have successfully updated your Name");
}
if(!empty($password))
{
mysql_query("UPDATE Profile SET Password='$encrypt_password' WHERE Username='$username'" or die(mysql_error());
echo("You have successfully updated your Password");
}
if(!empty($dob))
{
mysql_query("UPDATE Profile SET DOB='$dob' WHERE Username='$username'" or die(mysql_error());
echo("You have successfully updated your Date of Birth");
}
if(!empty($aCC))
{
mysql_query("UPDATE Profile SET CC='$aCC' WHERE Username='$username'" or die(mysql_error());
echo("You have successfully updated your Core Values");
}
mysql_close();
?>
我假设'Connect.php'有你的数据库信息。确保它们是正确的 – Idris
而且对于密码,'MD5'不再是一个好的选择。阅读关于它在这里http://stackoverflow.com/questions/770900/is-md5-less-secure-than-sha-et-al-in-a-practical-sense – Idris
是的Connect.php具有所有连接信息和工作中。 – Phughes