orange08 Posted May 26, 2009 Share Posted May 26, 2009 i faced with a weird problem here, when a link is clicked, will causing isset($_GET['afield']) is triggered... so, one of the field in my table will be updated with +1(e.g original field value is 10, after update it become 11)... the update is success...but, when the code continue, i found the field value will +1 itself eventhough no update query is performed... code that update myfield $update_myfield = mysql_query("UPDATE mytable SET myfield=$addview WHERE myid='$id'"); after this code is executed, the field will be increased one as expected code that causing myfield +1 again $other_row = "SELECT * FROM mytable,anothertable WHERE mytable.linkid=anothertable.linkid AND mytable.linkid='$_SESSION[subID]' AND mytable.myid<>'$_SESSION[show_ID]'"; $otherart_rows = mysql_query($other_row); $i=0; while(($row = mysql_fetch_array($otherart_rows,MYSQL_ASSOC))&&($i<5)){ echo "<tr>"; echo "<td><img src='".$row['pic1']."'></td><td>"; : : } after testing, found the code that causing myfield to auto +1 is echo "<td><img src='".$row['pic1']."'></td><td>"; can anyone here please help me to track the track the problem? Link to comment https://forums.phpfreaks.com/topic/159702-whats-problem-with-my-code/ Share on other sites More sharing options...
lonewolf217 Posted May 26, 2009 Share Posted May 26, 2009 i think more code is required. there is no possible way that line is updating the database. it is just displaying the contents of the row, there is no query run in that portion of code that could update the DB Link to comment https://forums.phpfreaks.com/topic/159702-whats-problem-with-my-code/#findComment-842368 Share on other sites More sharing options...
orange08 Posted May 26, 2009 Author Share Posted May 26, 2009 i think more code is required. there is no possible way that line is updating the database. it is just displaying the contents of the row, there is no query run in that portion of code that could update the DB that's my problem, can't figure out the reason for this error... this is the whole code <?php ini_set ("display_errors", "1"); error_reporting(E_ALL); session_start(); include '../config.php'; if (isset($_GET['select_article'])){ $urarticle = $_GET['select_article']; $art_result = "SELECT * FROM shrtbl,sbtbl WHERE shrtbl.submitter_id=sbtbl.submitter_id AND shrtbl.share_id='$urarticle'"; $result = mysql_query($art_result); if(mysql_num_rows($result)>0){ while($row = mysql_fetch_array($result,MYSQL_ASSOC)){ $_SESSION['subID'] = $row['submitter_id']; $_SESSION['show_shareID'] = $row['share_id']; $_SESSION['show_topic'] = $row['share_topic']; $_SESSION['show_article'] = $row['share_article']; $_SESSION['show_date'] = $row['publish_date']; $_SESSION['show_view'] = $row['view']; $_SESSION['show_submitter'] = $row['submitter_name']; } $get_view = $_SESSION['show_view']+1; $SQLquery = "START TRANSACTION"; $SQLrst = mysql_query($SQLquery); $update_viewtm = mysql_query("UPDATE shrtbl SET view=$get_view WHERE share_id='$_SESSION[show_shareID]'"); if(!$update_viewtm){ $SQLquery = "ROLLBACK"; $SQLrst = mysql_query($SQLquery); }else{ $SQLquery = "COMMIT"; $SQLrst = mysql_query($SQLquery); } $comment_result = "SELECT * FROM shrcomment WHERE share_id='$urarticle'"; $comment_rows = mysql_query($comment_result); $other_article = "SELECT * FROM shrtbl,sbtbl WHERE shrtbl.submitter_id=sbtbl.submitter_id AND shrtbl.submitter_id='$_SESSION[subID]' AND shrtbl.share_id<>'$_SESSION[show_shareID]'"; $otherart_rows = mysql_query($other_article); }else{ echo "<center><table><tr><td bgcolor=#241502><big><span style='color: rgb(255, 204, 51); font-weight: bold;'>Invalid Request!</span></big></td></tr></table></center>"; exit(); } } ?> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> <meta content="text/html; charset=UTF-8" http-equiv="content-type"><title>Share Article</title> <html> <head></head> <body style="background-color: rgb(37, 23, 4);"> <center> <table style="text-align: left; margin-right: auto; margin-left: auto;" bgcolor="#f5ba18" border="0" cellpadding="0" cellspacing="0" width="900px"> <tbody> <?php include 'header.php'; ?> </tbody> </table> </center> <center> <table style="text-align: left; margin-right: auto; margin-left: auto;" bgcolor="#f5ba18" border="0" cellpadding="0" cellspacing="0" width="900px"> <tbody> <tr> <td width="450px" height="300px"> <table height="300px"> <tr><td align="left">Topic: <?php if(!empty($_SESSION['show_topic']))echo $_SESSION['show_topic'];?></td></tr> <tr><td> <?php if(!empty($_SESSION['show_article']))echo nl2br(stripslashes($_SESSION['show_article'])); ?> </td></tr> <tr><td><br></td></tr> <tr><td align="left">Publish Date: <?php if(!empty($_SESSION['show_date']))echo $_SESSION['show_date'];?></td></tr> <tr><td align="left">View: <?php if(!empty($_SESSION['show_view']))echo $_SESSION['show_view'];?></td></tr> </table> </td> <td width="450px" height="300px"> <table><tr><td><b>Other Articles of this Author:</b></td></tr></table> <table width="300px"> <?php if(mysql_num_rows($otherart_rows)>0){ $i = 0; while(($row = mysql_fetch_array($otherart_rows,MYSQL_ASSOC))&&($i<5)){ echo "<tr>"; echo "<td><img src='".$row['shrpic1']."'></td><td>"; echo "<table width='350px'><tr><td>".$row['share_topic']."</td></tr>"; echo "<tr><td align='right'><a href='findart.php?select_article=".$row['share_id']."'><img src='../img/st.jpg' border=0></a></td></tr></table></td>"; echo "</tr>"; $i++; } } ?> </table> </td> </tr> </center> </body> </html> Link to comment https://forums.phpfreaks.com/topic/159702-whats-problem-with-my-code/#findComment-842431 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.