如何在php中更新行

如何在php中更新行,php,mysql-5.5,Php,Mysql 5.5,我想从网页更新表中的记录。这意味着我将单击第行中的“更新”,它将重定向到“更新”页面,必填字段将得到更新 这是更新的代码 <!DOCTYPE html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <meta name="description" content="" /> <meta name="keywords

我想从网页更新表中的记录。这意味着我将单击第行中的“更新”,它将重定向到“更新”页面,必填字段将得到更新

这是更新的代码

  <!DOCTYPE html>
  <head>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  <meta name="description" content="" />
  <meta name="keywords" content="" />
  <meta name="author" content="" />
  <link rel="stylesheet" type="text/css" href="style.css"  />
  <title>First web page</title> 
  </head>

  <body>

  <div id="wrapper">

  <?php include('includes/header.php'); ?>

  <?php include('includes/nav.php'); ?>

  <div id="content">
  <h3>Paragraph Element</h3>
  <?php
   function renderForm($id, $name, $email, $date,$mobile,$gender,$lang,$error)
   {
   ?>
          <form action=""  method="post" enctype="multipart/form-data">
          <table class="tbldata" align="center" border="1px solid black"  style="background-color:!important" >
            <tr id="bgcolor">
            <td colspan="2" align="center"  style="background-color: #CF3">Submit Employee Information</td>
            </tr>
            <tr  id="bgcolor">
              <td   >Name</td>
              <td class="back"><input  type="text" name="name"  value="<?php echo $name ?>"/></td>
              </tr>
              <tr  id="bgcolor">
              <td>E-mail</td>
              <td class="back"><input  type="text" name="email"  value="<?php echo $email ?>" /></td>
              </tr>
              <tr  id="bgcolor">
              <td>DOB</td>
              <td class="back"><input type="date"  name="date"  value="<?php echo $date ?>" /></td>
              </tr>
              <tr  id="bgcolor">
              <td>Mobile_No</td>
              <td class="back"><input type="text" name="mobile"  value="<?php echo $mobile ?>"/></td>
              </tr>
              <tr  id="bgcolor">
              <td>Gender</td>
              <td class="back"><input id="bgcolor" type="radio" name="gender"   value="<?php echo $gender ?>" checked="checked">M</input> <input type="radio" name="gender" value="<?php echo $gender ?>">F</input></td>
              </tr>
              <tr  id="bgcolor">
              <td>Language</td>
              <td class="back"><select name="lang"><option  value="<?php echo $lang ?>" >English</option>
              <option  value="<?php echo $data->lang ?>">Marathi</option>
              <option  value="<?php echo $data->lang ?>">Hindi</option> </select></td>
          </tr>
          <tr id="bgcolor">
          <td>Photo</td>
          <td class="back"><input type="file" name="file"  value="<?php echo $file ?>" /></td>    </tr>
            <tr>
              <td colspan="7"><input type="submit" value="Submit" name="update" /> <a href="dashboard.php" style="text-decoration:none" > <input type="button"  value="Back"/></a> </td> 
              </tr>
          </table>
          </form>
  <?php } ?>

  </div>
  <?php 
  $con = mysql_connect("localhost","root","");
  mysql_select_db("firstweb");



       if (isset($_POST['update']))
        { 

                 if (is_numeric($_POST['id']))
                 {

                       $id = $_POST['id'];
                       $name = mysql_real_escape_string(htmlspecialchars($_POST['name']));
                       $email = mysql_real_escape_string(htmlspecialchars($_POST['email']));
                       $date = mysql_real_escape_string(htmlspecialchars($_POST['date']));
                       $mobile = mysql_real_escape_string(htmlspecialchars($_POST['mobile']));
                       $gender = mysql_real_escape_string(htmlspecialchars($_POST['gender']));
                       $lang = mysql_real_escape_string(htmlspecialchars($_POST['lang']));


                        if ($name == '' || $email == '' || date == '' || mobile == '' )
                       {

                           $error = 'ERROR: Please fill in all required fields!';

                           renderForm($id, $name, $email, $date,$mobile,$gender,$lang,$error);
                       }
                       else
                       {

                               mysql_query("UPDATE emp_data SET name='$name',email='$email',date='$date',mobile='$mobile',gender='$gender',lang='$lang',image='$image' where id='$id'")
                               or die(mysql_error());
                               header("Location: dashboard.php"); 
                       }
                 }
                 else
                 {
                       echo 'Error!';
                 }
            }
            else
            {
                 if (isset($_GET['id']) && is_numeric($_GET['id']) && $_GET['id'] > 0)
                 {

                       $id = $_GET['id'];
                       $result = mysql_query("SELECT * FROM emp_data WHERE id=$id")
                       or die(mysql_error()); 
                       $row = mysql_fetch_array($result);

                       if($row)
                       {


                            $name = $row['name'];
                            $email = $row['email'];
                            $date = $row['date'];
                            $mobile = $row['mobile'];
                            $gender = $row['gender'];
                            $lang = $row['lang'];
                       renderForm($id, $name, $email, $date,$mobile,$gender,$lang,'');
                       }
                       else
                       {
                       echo "No results!";
                       }
                 }
                else
                 {
                      echo 'Error!';
                 }
        }
 ?>



  <?php include('includes/sidebar.php'); ?>

  <?php include('includes/footer.php'); ?>

  </div>

  </body>

  </html>

第一个网页
段落元素
提交员工信息
名称

不能包含文本,它是一个自终止元素;使用
标签文本
代替。在呈现内容后,也不能发出
标题()。您应该在HTML之前执行SQL操作。这还有一个额外的好处,就是保持编程逻辑的独立性。除了前面的答案之外:如果您必须执行PHP任务,那么在发送任何响应之前,而不是在生成HTML时执行此操作更符合逻辑。您的块也有一些错误,例如同一级别的多个
else{}
块。你应该试着算出你的间距。这不仅仅是表面的,它实际上帮助你理解你的逻辑。