简体   繁体   中英

SQL & PHP: UPDATE row doesn't work

So I have to make a php page that approves/rejects some information taken by a specific row in a database. If the Admin that sees the info Approves it, he puts some extra values and updates the specific row in the database (these extra values are 0 before approval), but it ultimately doesn't work. I think the problem is with the approve.php file the submit form redirects to, i think it doesn't read the values the Admin inputs.

Here is the form (lecturermeet.php):

 <div class="wrapper col3">
 <div class="container">
  <h1>Pending Meeting Submissions</h1>

    <?php
    mysql_connect("localhost","root","") or die(mysql_error());
    mysql_select_db("dissdb") or die(mysql_error());
    $statuscheck = 0;
    $result = mysql_query("SELECT status FROM meeting WHERE status = '$statuscheck'");
    if ($result != NULL) {
    $result = mysql_query("SELECT id,username,date,subject,report FROM meeting WHERE status =       '$statuscheck'");
    while ($row = mysql_fetch_assoc($result)){
    $uploader = $row['username'];
    $date = $row['date'];
    $subject = $row['subject'];
    $report = $row['report'];
    $id = $row['id'];
    echo ' <font size=6> <p>Meeting: #' .$id. ' </font><br><br>Submitted by: '.$uploader.'<br>Date: ' .$date. '<br>Subject: ' .$subject. '<br>Report: '  .$report. '<br> <br></p>'   ;

    $showbuttons = 1;

    if($showbuttons == 1) : ?>


    <form>
      Meeting #:
      <input type="number" name="id" id="id" value='$id' min="1" max="20">
    </form>

    <form>
      Project Progression Status (between 1 and 6):
      <input type="number" name="progress" id="progress" min="1" max="6">
    </form>

    <form>
    <br>  Effort Shown (between 1 and 6):
      <input type="number" name="effort" id="effort" min="1" max="6">
    </form>

    <form>
    <br>  Dissertation Projection (between 1 and 6):
      <input type="number" name="projection" id="projection" min="1" max="6">
    </form>

    <form>
    <br>  Lecturer Satisfaction (between 1 and 6):
      <input type="number" name="satisfaction" id="satisfaction" min="1" max="6">
    </form>

    <form>
    <br>  Overall (between 1 and 10):
      <input type="number" name="mark" id="mark" min="1" max="10">
    <br><br><br></form>




    <form action="approve.php" method="post"
    enctype="multipart/form-data">
    <input type="submit" name="approve" value="Approve">
    </form>

    <label for="rejectinfo"><br><br><br>Rejection comments:</label>
    <textarea name="rejectinfo" cols="60" rows="7" id="rejectinfo" ></textarea>

    <p><form action="reject.php" method="post"
    enctype="multipart/form-data">
    <input type="submit" name="reject" value="Reject">
    <br><br></form></p>
    <?php endif;
    }} ?>






 </div>
 </div>

and here is the approve.php the form redirects to in order to update the specific row:

 <?php



  require "config.php";
  require "lecturerarea.php";

  $id = $_POST['id'];
   $progress = $_POST['progress'];
    $effort = $_POST['effort'];
    $projection = $_POST['projection'];
    $satisfaction = $_POST['satisfaction'];
    $mark = $_POST['mark'];
    $status = 1;
    mysql_connect("localhost","root","") or die(mysql_error());
   mysql_select_db("dissdb") or die(mysql_error());
    mysql_query("UPDATE meeting SET 'progress'='$progress', 'effort'='$effort',
'projection'='$projection', 'satisfaction'='$satisfaction', 'mark'='$mark', 'status'='$status'     WHERE id = '$id'");
    echo "The meeting submission is approved! <br> Redirecting now ....";
        header("Refresh: 3; lecturerarea.php");



 ?>

Remove the quotes from around your column names. Those are not the right identifiers .

Ie: SET 'progress'='$progress'

which should read as (using backticks example)

 SET `progress`='$progress' // etc.

or remove the quotes and do the same for the others.

 SET progress='$progress' // etc.

Having error reporting on, would have signaled that.

error_reporting(E_ALL);
ini_set('display_errors', 1);

Also or die(mysql_error()) to mysql_query() .

Edit:

You also have multiple <form></form> tags. Put everything inside the one <form>...</form> plus you need to specify the method.

<form method="post">

<form> defaults to GET if omitted.

All of your variables used for DB insertion, are $_POST .

This is equal to a GET method

<form>
<br>  Overall (between 1 and 10):
  <input type="number" name="mark" id="mark" min="1" max="10">
<br><br><br></form>

and will not be entered in DB.

It should read as

<form method="post">
<br>  Overall (between 1 and 10):
  <input type="number" name="mark" id="mark" min="1" max="10">
<br><br><br></form>

and do the same for the others.

As for the headers already sent , remove the echo from above the header or use a meta refresh if you want it to echo the message.


Ideally, this is what you should be doing:

<form action="approve.php" method="post" enctype="multipart/form-data">
Meeting #:
<input type="number" name="id" id="id" value='$id' min="1" max="20">

Project Progression Status (between 1 and 6):
<input type="number" name="progress" id="progress" min="1" max="6">

<br>  Effort Shown (between 1 and 6):
<input type="number" name="effort" id="effort" min="1" max="6">

<br>  Dissertation Projection (between 1 and 6):
<input type="number" name="projection" id="projection" min="1" max="6">

<br>  Lecturer Satisfaction (between 1 and 6):
<input type="number" name="satisfaction" id="satisfaction" min="1" max="6">

<br>  Overall (between 1 and 10):
<input type="number" name="mark" id="mark" min="1" max="10">
<br><br><br>

<input type="submit" name="approve" value="Approve">

<label for="rejectinfo"><br><br><br>Rejection comments:</label>
<textarea name="rejectinfo" cols="60" rows="7" id="rejectinfo" ></textarea>

<input type="submit" name="reject" value="Reject">
<br><br>
</form>

Sidenote:

Your present code is open to SQL injection .
Use prepared statements , or PDO with prepared statements .

Okay you are getting the the errors because when you are clicking submit approve you only take the values of that form, so if you want the data of projection and the others make something like it.

<form action="approve.php" method="post"
    enctype="multipart/form-data">
    <input type="submit" name="approve" value="Approve">
 <br>  Dissertation Projection (between 1 and 6):
      <input type="number" name="projection" id="projection" min="1" max="6">
    </form>

And the other inputs.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM