php - Update specific column in loop -


is right way update specific column 1 row in mysqli_array_fetch? doesn't work me.

<!doctype html> <html> <head> <meta charset="utf-8"> <title>الرد على التذكرة</title> <style>  .table, tr, td {border: 1px solid black; text-align:center} .contents { position:static} p1 {font-size:15px; font-weight:bolder}  .inputresponse {resize:none} </style> </head> <body class="body"> <div class="contents" align="right"> <?php  include 'config.php';    $sql = "select * contact order id";  $con->set_charset('utf8'); $users = mysqli_query($con,$sql);  ?> <table class="table"> <?php  while($row = mysqli_fetch_array($users)) {  ?>  <form id="<?php echo $row[id] ?>" method="post" name="respone" action="addresponse.php"> <tr> <td> <p1> الإسم </p1> </td> <tr> <td> <?php echo $row[name] ?> </td> </tr> <tr> <td> <p1> رقم التذكرة</p1> </td> </tr> <tr> <td> <?php echo $row[ticketnumber] ?> </td> </tr> <tr> <td> <p1> الإيميل</p1> </td> </tr> <tr> <td> <?php echo $row[email] ?> </td>  </tr> <tr> <td> <p1>  الموضوع </p1> </td> </tr> <tr> <td> <?php echo $row[subject] ?> </td> </tr> <tr> <td> <p1> الرد </p1> </td> </tr> <tr> <td>  <textarea name="response" rows="5" dir="rtl" class="inputresponse"> </textarea> </td> </tr> <tr> <td> <input type="submit" value="إرسال" name="send"> </td> </tr> <tr> <td> <?php   if(isset($_post['send'])){          $repsonse = $_post['response'];          $result = ("update contact set response ='$response' id= $row[id]");          $rst = mysqli_query($con,$result);  if($rst){     echo "تم الإرسال";  } else {      echo " لم يتم الإرسال"; } } } ?> </form> </table> </div> </body> </html> 

after editing, think did in wrong again

    <!doctype html> <html> <head> <meta charset="utf-8"> <title>الرد على التذكرة</title> <style>  .table, tr, td {border: 1px solid black; text-align:center} .contents { position:static} p1 {font-size:15px; font-weight:bolder}  .inputresponse {resize:none} .inputid {text-align:center; font-size:10px} </style> </head> <body class="body"> <div class="contents" align="right"> <?php  include 'config.php';    $sql = "select * contact order id";  $con->set_charset('utf8'); $users = mysqli_query($con,$sql);     ?> <table class="table"> <?php while($row = mysqli_fetch_array($users)) {  ?>   <form id="<?php echo $row['id'] ?>" method="post" name="respone" action="addresponse.php"> <tr> <td> <input value="<?php echo $row['id'] ?>" name="id" class="inputid" readonly> </td> <tr> <tr> <td> <p1> الإسم </p1> </td> <tr> <td> <?php echo $row['name'] ?> </td> </tr> <tr> <td> <p1> رقم التذكرة</p1> </td> </tr> <tr> <td> <?php echo $row['ticketnumber'] ?> </td> </tr> <tr> <td> <p1> الإيميل</p1> </td> </tr> <tr> <td> <?php echo $row['email'] ?> </td>  </tr> <tr> <td> <p1>  الموضوع </p1> </td> </tr> <tr> <td> <?php echo $row['subject'] ?> </td> </tr> <tr> <td> <p1> الرد </p1> </td> </tr> <tr> <td>  <textarea name="response" rows="5" dir="rtl" class="inputresponse"> </textarea> </td> </tr> <tr> <td> <input type="submit" value="إرسال" name="send"> </td> </tr> <tr> <td> <?php   if(isset($_post['send'])){           $response = $_post['response'];            $result = ("update contact set response ='$response' id= $row[id]");          $rst = mysqli_query($con,$result);    if($rst){     echo "تم الإرسال";  } else {      echo " لم يتم الإرسال"; } } } ?> </form> </table> </div> </body> </html> 

your html formatting strange think should accomplish want.

<!doctype html> <html> <head> <meta charset="utf-8"> <title>الرد على التذكرة</title> <style> .table, tr, td {     border: 1px solid black;     text-align:center } .contents {     position:static } p1 {     font-size:15px;     font-weight:bolder } .inputresponse {     resize:none } .inputid {     text-align:center;     font-size:10px } </style> </head> <body class="body"> <div class="contents" align="right"> <?php include 'config.php'; $sql = "select * contact order id"; $con->set_charset('utf8'); $users = mysqli_query($con,$sql); ?> <table class="table"> <?php while($row = mysqli_fetch_array($users)) { ?> <form id="<?php echo $row['id'] ?>" method="post" name="respone" action="addresponse.php">     <tr>     <td><input value="<?php echo $row['id'] ?>" name="id" class="inputid" type="hidden"></td>     <tr>     <tr>     <td><p1> الإسم </p1></td>     <tr>     <td><?php echo $row['name'] ?></td>     </tr>     <tr>     <td><p1> رقم التذكرة</p1></td>     </tr>     <tr>     <td><?php echo $row['ticketnumber'] ?></td>     </tr>     <tr>     <td><p1> الإيميل</p1></td>     </tr>     <tr>     <td><?php echo $row['email'] ?></td>     </tr>     <tr>     <td><p1> الموضوع </p1></td>     </tr>     <tr>     <td><?php echo $row['subject'] ?></td>     </tr>     <tr>     <td><p1> الرد </p1></td>     </tr>     <tr>     <td><textarea name="response" rows="5" dir="rtl" class="inputresponse"> </textarea></td>     </tr>     <tr>     <td><input type="submit" value="إرسال" name="send"></td>     </tr>     </form>     <?php  } ?>     </table> <?php     if(isset($_post['send'])){         $response = $_post['response'];         $result = "update contact set response = ? id= ?";         $rst = mysqli_prepare($con,$result);         mysqli_stmt_bind_param($rst, 'si', $response, $_post['id']);         mysqli_stmt_execute($rst);         if($rst){             echo "تم الإرسال";         } else {             echo " لم يتم الإرسال";             echo mysqli_stmt_error($rst);         }     } ?> </div> </body> </html> 

changes/potential improvements:

  1. using prepared statements in place of inline values.
  2. moved update outside of while loop since irrelevant.
  3. moved closing form tag inside while loop. making multiple forms every 1 child of first because never closed.
  4. the p1s might headings? if should outside of loop.
  5. if want display message next row updated move whole update process before page process. assign variable status variable in outputting when on record output message well.
  6. your table rows seem closing incorrectly.

Comments

Popular posts from this blog

sublimetext3 - what keyboard shortcut is to comment/uncomment for this script tag in sublime -

java - No use of nillable="0" in SOAP Webservice -

ubuntu - Laravel 5.2 quickstart guide gives Not Found Error -