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:
- using prepared statements in place of inline values.
- moved update outside of
while
loop since irrelevant. - moved closing
form
tag insidewhile
loop. making multiple forms every 1 child of first because never closed. - the
p1
s might headings? if should outside of loop. - 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.
- your table rows seem closing incorrectly.
Comments
Post a Comment