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" />
<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
$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);
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.