1

请帮忙。。我放弃了。。

试图更新MySql表..文件是settings.php(自行提交)表单代码是:

<form method="POST" action="settings.php">
  First Name <input type="text" name="fname" id="set_fname"  />
  Last name <input type="text" name="lname" id="set_lname"  />
  Email: <input type="text" name="email" id="set_email"  />
  mobile <input type="text" name="mobile" id="set_mobile" />
  Bio: <textarea name="bio" id="set_bio"  cols="" rows="5" maxlength="1000" ></textarea>
  <input type="submit" id="personal_submit" value="Update" />
</form>

php部分

$id=$_SESSION['id'];   

$fname_update =$_POST['fname'];
$lnam_update = $_POST['lname'];
$email_update = $_POST['email'];
$mobile_update =$_POST['mobile'];
$bio_update =$_POST['bio'];

$db_host="localhost";
$db_uname="admin";
$db_pass="mypass";
$db_db="main_db";
$db_table="mebers_general";

mysql_connect("$db_host","$db_uname","$db_pass") or die (mysql_error());
mysql_select_db("$db_db") or die("no database by that name");

if($_POST['fname']){

  $sql_personal_update=mysql_query("UPDATE members_general SET first_name='$fname_update' WHERE id='$id' ") or die (mysql_error()) ;
    if($sql_personal_update){
      echo "should be ok but no record is updated....Heeelppp";
      }else{
      echo "Smth is Wrong";
      }  
}

我没有错误..

结果我得到了回显字符串“应该没问题,但没有更新记录....Heeelppp”;所以它检测到更新没有问题我在 phpMyadmin 中尝试了相同的查询 - 工作得很好。我检查了变量-它们不是空的..一切似乎都应该如此。请帮忙..在这里已经堆了 2 天//

4

4 回答 4

4
  $sql_personal_update=mysql_query("UPDATE members_general SET firs_name='".$fname_update."' WHERE id='".$id."' ") or die (mysql_error()) ;
于 2012-10-09T18:13:46.200 回答
4

您实际上并没有运行您的查询:

$sql_personal_update=("UPDATE members_general SET firs_name='$fname_update' WHERE id='$id' ") or die (mysql_error()) ;
                     ^^^^^--- where's mysql_query()?

它应该是

$sql_personal_update = mysql_query(blah blah blah) or die(mysql_error());
于 2012-10-09T18:14:05.667 回答
3

我想这是因为您实际上并没有调用该mysql_query函数!

对于初学者,尝试

$sql_personal_update=mysql_query("UPDATE members_general SET firs_name='$fname_update' WHERE id='$id' ") or die (mysql_error()) ;

另外,是firs_name拼写错误,还是您真的将您的数据库列称为?

编辑:正如 JoachimIsaksson 建议的那样,不推荐使用 mysql_connect 等。请改用 mysqli,如下所示:

$mysqli = new mysqli($db_host,$db_uname,$db_pass, $db_db) or die (mysql_error());
if($_POST['fname']){
    $sql_personal_update=$mysqli->query("UPDATE members_general SET first_name='$fname_update' WHERE id='$id' ") or die (mysql_error()) ;
    if($sql_personal_update) {
        echo "should be ok but no record is updated....Heeelppp";
    } else {
        echo "Smth is Wrong";
    }  
}
于 2012-10-09T18:14:06.673 回答
0

Thanks for everything, guys, i just recoded all page from blank and it worked..have no idea what was the reason..maybe the 20th hour in a row of coding..thanx..

于 2012-10-10T18:17:04.750 回答