duanmu6231 2015-09-15 09:28
浏览 61

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

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

  • 写回答

1条回答 默认 最新

  • douzhan4522 2015-09-15 09:31
    关注

    Execute the query . In your code $qry is not executed

     $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);
    
    评论

报告相同问题?

悬赏问题

  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 划分vlan后不通了
  • ¥15 GDI处理通道视频时总是带有白色锯齿
  • ¥20 用雷电模拟器安装百达屋apk一直闪退
  • ¥15 算能科技20240506咨询(拒绝大模型回答)
  • ¥15 自适应 AR 模型 参数估计Matlab程序
  • ¥100 角动量包络面如何用MATLAB绘制
  • ¥15 merge函数占用内存过大
  • ¥15 使用EMD去噪处理RML2016数据集时候的原理
  • ¥15 神经网络预测均方误差很小 但是图像上看着差别太大