tyfobpo Posted December 9, 2007 Share Posted December 9, 2007 hello, i am still pretty new to php/mysql. currently, on my ste i have conversations which i post on the site. i made it so that theres an admin area, i post the convo and it adds it to the database, then use a page to view the conversation when its link is clicked./ well i added a new field to my table called count, with the goal of making it so everytime a link is clicked, it adds 1 to the count field for that row. but its not working, the count field have stayed at zero. here is my code. // Make a mysql Connection mysql_connect(localhost,$user,$pass); @mysql_select_db($db) or die( "Unable to select database"); if($_GET['id']) { $theid=$_GET['id']; $query = 'select * from convo where id='.$_GET['id']; $result = mysql_query($query); $num_results = mysql_num_rows($result); $row = mysql_fetch_array($result); //display page echo $row['info']; //count page $counter=$row['count']; $newcount=$counter+1; mysql_db_query($db, "update convo set id='',who='',date='',time='',name='',info='' count='$newcount' where id='$theid'") or die(mysql_error()); } ?> Quote Link to comment Share on other sites More sharing options...
JacobYaYa Posted December 9, 2007 Share Posted December 9, 2007 mysql_connect(localhost,$user,$pass); @mysql_select_db($db) or die( "Unable to select database"); if(isset($_GET['id'])) { $theid=$_GET['id']; $query = "SELECT * FROM convo WHERE id=$theid"; $result = mysql_query($query); $num_results = mysql_num_rows($result); $row = mysql_fetch_array($result); //display page echo $row['info']; //count page $newcount=$row['count']++; mysql_query("UPDATE convo SET count=$newcount WHERE id=$theid") or die(mysql_error()); } ?> Quote Link to comment Share on other sites More sharing options...
JacobYaYa Posted December 9, 2007 Share Posted December 9, 2007 You don't need single quotes around int values in your SQL, that is for strings. mysql_db_query() is deprecated, use mysql_query() in it's place. Quote Link to comment Share on other sites More sharing options...
tyfobpo Posted December 9, 2007 Author Share Posted December 9, 2007 thank you, i tried that code, but it still is not adding to the count field, they all stay as 0. im wondering if i set the field up wrong? its an int, not null. is that right? Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.