Php 更新数据库中的用户表

Php 更新数据库中的用户表,php,mysql,phpmyadmin,Php,Mysql,Phpmyadmin,我已经创建了一个会员区,用户可以在这里更新他们的简历。问题是用户提交的信息没有更新数据库中的行 会员区 <body bgcolor="#E6E6FA"> <a href="logout.php"><button>Log Out</button></a><br><br> <input type="text" name="age"placeholder="Enter a your age."><br

我已经创建了一个会员区,用户可以在这里更新他们的简历。问题是用户提交的信息没有更新数据库中的行

会员区

<body bgcolor="#E6E6FA">
<a href="logout.php"><button>Log Out</button></a><br><br>
<input type="text" name="age"placeholder="Enter a your age."><br>
<input type="text" name="bio"placeholder="Enter your bio.">
<input type="submit" name="submit" value="Submit your details!">




PHP

<?php
if(isset($_POST['submit'])){
  $con=mysql_connect("localhost","root","****","****");
  // Check connection
  if (mysql_errno()) {
    echo "Failed to connect to MySQL: " . mysqli_connect_error();
  }

  $age = mysql_real_escape_string($_POST['age']);
  $bio = mysql_real_escape_string($_POST['bio']);
  $name = mysql_real_escape_string($_SESSION['username']);

  mysql_query($con,"UPDATE accs SET age='.$age.' WHERE name='.$name.'");
  mysql_query($con,"UPDATE accs SET bio='.$bio.' WHERE name='.$name.'");

  mysql_close($con);
};
?> 
</body></html>

在HTML页面中,表单应位于
标记内

<form method="post" action="update.php">
<input type="text" name="age" placeholder="Enter a your age.">
<br>
<input type="text" name="bio" placeholder="Enter your bio.">
<input type="submit" name="submit" value="Submit your details!">
</form>


在您的PHP页面中-要检查结果,您可以临时
echo$age;echo$bio
当您使用
$\u会话['username']时我认为您缺少
会话_start()
到PHP代码的顶部

另外,
mysql\u query
只需要SQL命令,而不需要连接(
$con
),即mysqli,强烈建议使用mysqli代替mysql\u*

请注意,不要将数据库中的用户名作为更新标准。如果尚未引入,您可以将ID列添加到表中

a)创建适当的提交表单。在表单字段周围使用表单标记

b) 通过检查$\u POST数组,检查表单是否正确提交

var_dump($_POST);
c) 检查是否有要插入的字段的值。 在mysql_query()之前执行var_dump()以查看发生了什么

var_dump($age, $bio, $name);
d) 将两个查询调用合并为一个:

mysql_query($con, "UPDATE accs SET age='.$age.', bio='.$bio.' WHERE name='.$name.'");

如果要使用页面本身来处理请求,请清空表单的action属性。例如:

<form method="post" action="">
<input type="text" name="age"placeholder="Enter a your age."><br>
<input type="text" name="bio"placeholder="Enter your bio.">
<input type="submit" name="submit" value="Submit your details!">
</form>



会话是否打开?在执行mysql_query()之前,您是否有值$name?是否有任何错误?