简体   繁体   English

PHP MySQL更新成功,但数据库未更新

[英]PHP MySQL update success but database not updated

Ok, i have some problems with updating my table; 好的,我在更新表时遇到了一些问题; i have no errors and it alerts me that update is successful, but there is no change in my table. 我没有错误,它警告我更新成功,但是我的表没有变化。 This is my code for fetch and output data in table: 这是我的代码,用于在表中获取和输出数据:

session_start();
require_once ('dbconnect.php');

$query = mysql_query("SELECT p_id, p_name, p_authors, p_corresponding, p_email, p_cauthor, p_abstract, p_keywords, p_jname, p_date FROM papers INNER JOIN users ON papers.user_id = users.user_id WHERE p_url = '$val' AND username='{$_SESSION['user']}'");
$last = mysql_num_rows($query);
$output1 = "";
$outarray1 = array();

if ($last > 0) {
while ($output1 = mysql_fetch_array($query)) {
    $outarray1[] = $output1;
       if(is_array($outarray1)){
            foreach($outarray1 as $values){
            $id = $values['p_id'];
            $paper = $values['p_name'];
            $author = $values['p_authors'];
            $corresponding = $values['p_corresponding'];
            $mail = $values['p_email'];
            $coauthors = $values['p_cauthor'];
            $abstract = $values['p_abstract'];
            $keywords = $values['p_keywords'];
            $journal = $values['p_jname'];
            $date = $values['p_date'];
            }
        }
    }   
}                           
echo <<<HERE
<div id="collapse{$counter}" style="display:none">                      
<table class="responstable">                         
<tr>
    <th>ID</th>
    <th>Paper</th>
    <th>Author</th>
    <th>Corresponding author</th>
    <th>Email</th>
    <th>Coauthors</th>
    <th>Abstract</th>
    <th>Keywords</th>
    <th>Journal</th>
    <th>Date</th>
</tr>                                
<tr>
    <td>{$id}</td>
    <td>{$paper}</td>
    <td>{$author}</td>
    <td>{$corresponding}/td>
    <td>{$mail}</td>
    <td>{$coauthors}</td>
    <td>{$abstract}</td>
    <td>{$keywords}</td>
    <td>{$journal}</td>
    <td>{$date}</td>
    <td><a href="editdata.php?id={$id}">Update</a></td>
  </tr>                          
 </table>                   
 </div>
 HERE;

And this is my script for update the records: 这是我用于更新记录的脚本:

session_start();
require_once ('dbconnect.php');
<form method="post" action="" role="form">            
<div>ID<input type="text" name="id" value="<?php echo $_GET['id'];?>"/</div>    
<div>Paper<input type="text" name="paper" /></div>  
<div>Author<input type="text" name="author" /></div>    
<div>Corresponding author<input type="text" name="corr"  /></div>   
<div>Email<input type="text" name="mail"  /></div>
<div>Co-authors<input type="text" name="cauthors" /></div>
<div>Abstract<input type="text" name="abstract"/></div>
<div>Keywords<input type="text" name="keywords" /></div>
<div>Journal<input type="text" name="journal"  /></div>
<div>Date<input type="text" name="date"  /></div>               
<div class="sub">
    <input type="submit" class="btn btn-primary" name="submit" value="Update" />&nbsp;
    <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
</div>
</form>
<?php   
if (isset($_POST['submit'])) {
    $paper = $_POST['paper'];
    $author = $_POST['author'];
    $corresponding = $_POST['corr'];
    $mail = $_POST['mail'];
    $coauthors = $_POST['cauthors'];
    $abstract = $_POST['abstract'];
    $keywords = $_POST['keywords'];
    $journal = $_POST['journal'];
    $date = $_POST['date'];     
    $qry = "UPDATE papers INNER JOIN users ON papers.user_id = users.user_id SET p_name = '$paper', p_authors = '$author', p_corresponding = '$corresponding', p_email = '$mail', p_cauthor = '$coauthors', p_abstract = '$abstract', p_keywords = '$keywords', p_jname = '$journal', p_date = '$date' WHERE p_id = '{$_GET['id']}' AND username = '{$_SESSION['user']}'";
    if($qry){
        ?>
        <script>alert('Paper details uploaded to database !');
                        window.location.href = "home.php";
        </script>
        <?php
        }
        else {
            ?>
            <script>alert('Data error !<?php die(mysql_error()); ?>');</script>
            <?php
        }

        }   
    }

 ?>

So, it gives me alert of successful update, but record in table stays the same. 因此,它给我成功更新的警报,但表中的记录保持不变。 Any suggestions ? 有什么建议么 ? Thx 谢谢

Execute the query . 执行查询。 In your code $qry is not executed 在您的代码中,未执行$qry

 $db_connection = mysqli_connect("localhost", "username", "password", "database");
 $qry = "UPDATE papers INNER JOIN users ON papers.user_id = users.user_id SET p_name = '$paper', p_authors = '$author', p_corresponding = '$corresponding', p_email = '$mail', p_cauthor = '$coauthors', p_abstract = '$abstract', p_keywords = '$keywords', p_jname = '$journal', p_date = '$date' WHERE p_id = '{$_GET['id']}' AND username = '{$_SESSION['user']}'";
 mysqli_query($db_connection, $qry);

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

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