mysql - Want to edit database with update query -


i want update records database got error , record isn't getting updated. my problem:
dealing database first run select query , second insert data database. select query , insert query working when update records , want edit in other page got error

my code

<?php   $con=mysqli_connect("localhost","root","","new");   // check connection   if (mysqli_connect_errno())   {     echo "failed connect mysql: " . mysqli_connect_error();   }   $result = mysqli_query($con,"select * img");   echo "<table border='1'>   <tr>          <th>name</th>     <th>age</th>     <th>phonenum</th>     <th>email</th>     <th>date</th>   </tr>";    while($row = mysqli_fetch_array($result))   {     echo '<form action=""> ';       echo '<input type="hidden" name="rec_id" value="'.$row['id'].'" />';       echo "<tr>";         echo "<td>" . $row['name'] . "</td>";         echo "<td>" . $row['age'] . "</td>";         echo "<td>" . $row['phonenum'] . "</td>";         echo "<td>" . $row['email'] . "</td>";         echo "<td>" . $row['date'] . "</td>";         echo "<td><<a href=edit.php?id=$row[id]'>update</a></td>";       echo "</tr>";     echo '</form>';   }   echo "</table>";    mysqli_close($con);        $name = $age = $phonenum = $email = $date = $id="";    if ($_server["request_method"] == "get")   {     $id = $_get['id'];     if (empty($_post["name"]))     {       $nameerr = "name required";     }     else     {       $name = ($_post["name"]);     }      if (empty($_post["age"]))     {       $emailerr = "age required";     }     else     {       $email = ($_post["phonenum"]);     }      if (empty($_post["email"]))     {       $password = "";     }     else     {       $password = ($_post["password"]);     }      if (empty($_post["date"]))     {       $phone = "";     }     else     {       $phone =($_post["date"]);     }      // $name =  $age = $phonenum = $email = $date = "";   }   $con=mysqli_connect("localhost","root","","new");   // check connection   if (mysqli_connect_errno())   {     echo "failed connect mysql: " . mysqli_connect_error();   }   $sql = "update img set name = '".$name."', age = '".$age."', phonenum = '".$phonenum."', email = '".$email."'   id = ".$id;   if (!mysqli_query($con,$sql))   {     die('error: ' . mysqli_error($con));   }    mysqli_close($con);   ?>    <div style="clear:both">     <form action="manage.php" method="post" style="margin-left:502px">       <table>         <tr>           <td>name</td>           <td><input type="text" name="name"  autocomplete="off"/></td>         </tr>          <tr>           <td>age</td>           <td><input type="text" name="age"  /></td>         </tr>         <tr>           <td>phone no</td>           <td><input type="text" name="phonenum"  /></td>         </tr>           <td>e-mail</td>           <td><input type="text" name="email"  /></td>         </tr>         <tr>           <td>date</td>           <td><input type="text" name="date"  /></td>         </tr>         <tr>           <td><input type="submit" name="submit" value="submit"  /></td>         </tr>       </table>     </form>   </div> 

i think know doing :

you doing post here:

<form action="manage.php" method="post" style="margin-left:502px"> 

to same page.

and trying value method here:

if ($_server["request_method"] == "get") 

you have use:

if ($_server["request_method"] == "post") 

to submitted value.

and there lot of bad practice in code.


Comments

Popular posts from this blog

windows - Single EXE to Install Python Standalone Executable for Easy Distribution -

c# - Access objects in UserControl from MainWindow in WPF -

javascript - How to name a jQuery function to make a browser's back button work? -