使用php更新配置文件

时间:2016-05-04 05:51:11

标签: php mysql

我正在做项目,我想点击时使用php mysql更新用户配置文件 在更新按钮上它显示第17行有错误。请帮助找到错误。

    <?php
    session_start();
    if(!isset($_SESSION["n"]))
       {
         header("location:error.php");
       }
    if(isset($_POST["s"]))
     {

      $name=$_POST["nm"];
      $lname=$_POST["lnm"];
      $address=$_POST["ad"];
      $u=$_SESSION["un"];

      $query = "SELECT * FROM signup";

      $result=mysqli_query($result,$query) or die(mysqli_connect_error());
      $i=0;
      while($row=mysqli_fetch_array($result))
      {
          $roll[$i]=$row['rollno'];
          $i++;
      }
      $total_elmt=count($roll);
         require_once("vars.php");
$conn=mysqli_connect(host,uname,pass,db) or die(mysqli_connect_error());


         $query="update signup set name='$nm',lname='$lnm',address='$ad' where user_id='$value'";
         $execute=mysqli_query($conn,$query);$r=mysql_affected_rows();
         mysqli_close($conn);
$msg="Your information is submitted successfully";
    }   
    ?>

2 个答案:

答案 0 :(得分:0)

  1. 您需要先打开数据库才能运行选择查询。

    将此行移至顶部:

    $conn=mysqli_connect(host,uname,pass,db) or die(mysqli_connect_error());

  2. 您使用mysqli_query功能错误。它应该是

    $result=mysqli_query($conn,$query) or die(mysqli_connect_error());

答案 1 :(得分:0)

现在我已经更新了你的代码

 <?php
    session_start();
    if(!isset($_SESSION["n"]))
       {
         header("location:error.php");
       }
    if(isset($_POST["s"]))
     {

      $name = $_POST["nm"];
      $lname = $_POST["lnm"];
      $address = $_POST["ad"];
      $u = $_SESSION["un"];

$conn = mysqli_connect(host,uname,pass,db) or die(mysqli_connect_error());

      $query = "SELECT * FROM signup";

      $result = mysqli_query($conn, $query);
      $i=0;
      while($row=mysqli_fetch_array($result))
      {
          $roll[$i]=$row['rollno'];
          $i++;
      }
      $total_elmt=count($roll);
         require_once("vars.php");    

 $query="update signup set name='$nm',lname='$lnm',address='$ad' where user_id='$value'";
    $execute=mysqli_query($conn,$query);
    $r=mysql_affected_rows();
    mysqli_close($conn);
    $msg="Your information is submitted successfully";
        }   
        ?>