简体   繁体   English

SQL和PHP:UPDATE行不起作用

[英]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. 因此,我必须制作一个批准/拒绝数据库中特定行所获取的某些信息的php页面。 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. 如果看到该信息的管理员批准了该操作,则他会放置一些附加值并更新数据库中的特定行(这些附加值在批准前为0),但最终不起作用。 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. 我认为问题在于提交表单重定向到的approve.php文件,我认为它没有读取Admin输入的值。

Here is the form (lecturermeet.php): 这是表格(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: 这是表单重定向到的approve.php,以更新特定行:

 <?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' 即: 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() . or die(mysql_error())mysql_query()

Edit: 编辑:

You also have multiple <form></form> tags. 您还具有多个<form></form>标记。 Put everything inside the one <form>...</form> plus you need to specify the method. 将所有内容放入一个<form>...</form>您需要指定方法。

<form method="post">

<form> defaults to GET if omitted. 如果省略, <form>默认为GET

All of your variables used for DB insertion, are $_POST . 用于数据库插入的所有变量都是$_POST

This is equal to a GET method 这等于GET方法

<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. 并且不会在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. 而对于headers already sent ,去掉echo从上面的header ,或者如果你想让它呼应了消息将元刷新。


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 . 您当前的代码可以进行SQL注入
Use prepared statements , or PDO with prepared statements . 使用准备好的语句 ,或使用带有准备好的语句的PDO

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. 和其他输入。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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