mysql - php edit TABLE A, display into textbox then save it into TABLE B -


table crew(a) - user_id, name, username, status table data(b) - user_id, name, username, password, month, status

records came table a. idea solve this:

search record table a, edit record add new textbox password , month save table b.

i have pullout record table unable save table b. it's able save record save user_id , month, rest of columns missing.

updateform.php:

<?php $sql = "select * crew user_id = $sel_record";         $result = mysql_query($sql, $con) or die (mysql_error());         if(!$result) {             print "<h1>something has gone wrong!</h1>";         } else {             while ($record = mysql_fetch_array($result)) {                 $user_id = $record['user_id'];                 $lname = $record['lname'];                 $username = $record['username'];                 $status = $record['status'];             }  <form id = "myform" method="post" action = "update.php">     <tr>         <td>             <label for="user_id">crew id*:</label></td><td>             <input type="text" name="user_id" id="user_id" value="$user_id" >         </td>     <tr>         <td>             <label for="lname">lastname*:</label></td><td>             <input type="text" name="lname" id="lname" value="$lname" >         </td>     </tr> <tr>         <td>             <label for="username">username*:</label></td><td>             <input type="text" name="username" id="username" value="$username" >         </td>     </tr>        <tr>         <td>             <label for="password">password*:</label></td><td>             <input type="text" name="password" id="password" value="$username" >         </td>     </tr>                                                            <tr>         <td>             <label for="month">month*:</label></td><td>             <input type="text" name="month" id="month" value="$month" >         </td>     </tr> <tr>         <td>             <label for="status">status*:</label></td><td>             <input type="text" name="status" id="status" value="$status" >         </td>     </tr>        <tr>     <td id="mysubmit">         <input type="submit" name="submit" value="modify record">        </td>     </form> ?>  ***update.php <?php include "connect.php"; $user_id = $_post[user_id]; $lname = $_post[lname]; $username = $_post[username]; $password = $_post[password]; $status = $_post[status]; $month = $_post[month];  $sql = "insert data (user_id, lname, username, password, month, status) values ('$user_id', '$lname', '$username', '$password', '$month', '$status')"; $result=mysql_query($sql) or die (mysql_error());`enter code here` ?> 

first, form incorrect, have change name attribute of input element accept array of input. current code use last one.

<form id = "myform" method="post" action = "update.php">     <tr>         <td>             <label for="user_id">crew id*:</label></td><td>             <input type="text" name="users[user_id][user_id]" id="user_id" value="$user_id" >         </td>     <tr>         <td>             <label for="lname">lastname*:</label></td><td>             <input type="text" name="users[user_id][lname]" id="lname" value="$lname" >         </td>     </tr>     <tr>         <td>             <label for="username">username*:</label></td><td>             <input type="text" name="users[user_id][username]" id="username" value="$username" >         </td>     </tr>            <tr>         <td>             <label for="password">password*:</label></td><td>             <input type="text" name="users[user_id][password]" id="password" value="$username" >         </td>     </tr>                                                            <tr>         <td>             <label for="month">month*:</label></td><td>             <input type="text" name="users[user_id][month]" id="month" value="$month" >         </td>     </tr>     <tr>         <td>             <label for="status">status*:</label></td><td>             <input type="text" name="users[user_id][status]" id="status" value="$status" >         </td>     </tr>        <tr>     <td id="mysubmit">         <input type="submit" name="submit" value="modify record">        </td> </form> 

the update.php file need updating, too.

$postusers = $_post['users'];  $sqlvalues = array();  foreach ($postusers $user) {     $user_id = $user[user_id];     $lname = $user[lname];     $username = $user[username];     $password = $user[password];     $status = $user[status];     $month = $user[month];      $sqlvalues[] = "('$user_id', '$lname', '$username', '$password', '$month', '$status')"; }   $sql = "insert data (user_id, lname, username, password, month, status) values " . implode(",", $sqlvalues); 

another thing, not use mysql_* commands anymore, use pdo instead.


Comments

Popular posts from this blog

apache - PHP Soap issue while content length is larger -

asynchronous - Python asyncio task got bad yield -

javascript - Complete OpenIDConnect auth when requesting via Ajax -