tjverge Posted June 10, 2008 Share Posted June 10, 2008 $pagename1=$_GET['member']; $result = mysql_query("SELECT * FROM members"); mysql_query ("UPDATE members SET count = count + 1 WHERE pagename='$pagename1'"); This code should update the visit count for the members page but does not ex: http://url.com/index.php?member=X The member X should go from 0 to 1, but is staying at 0 Any help would be great. Quote Link to comment Share on other sites More sharing options...
tjverge Posted June 10, 2008 Author Share Posted June 10, 2008 not sure if it will help but here is the who code for the page in question. <code> <?php $db_host = "localhost"; $db_user = "xxx"; $db_pwd = "xxx"; $db_name = "viral"; mysql_connect($db_host, $db_user, $db_pwd); mysql_select_db($db_name); $pagename1=$_GET['member']; $result = mysql_query("SELECT * FROM members"); mysql_query ("UPDATE members SET count = count + 1 WHERE pagename='$pagename1'"); $countgame = mysql_num_rows($result); echo 'there are, ', $countgame, ' pages in our system'; ?> </p> <div align="center"> <table> <td>Name</td> <td>Visits</td> <?php $sql = "SELECT * FROM `members` ORDER BY `count` DESC LIMIT 10 "; $query = mysql_query($sql); while($row = mysql_fetch_array($query)) { $db_link_result = $row['url']; $db_link_text = $row['pagename']; $final_link = "<a href=\"" . $db_link_result . "\" >" . $db_link_text . "</a>"; echo "<tr>"; echo "<td> ",$final_link,"</td>"; echo "<td>".$row['count']."</td>"; echo "</tr>"; } ?></code> Quote Link to comment Share on other sites More sharing options...
lemmin Posted June 10, 2008 Share Posted June 10, 2008 Make sure $_GET['member'] holds the value that you expect. Print it out to test the current value. Also, it is always a good idea to look at mysql_error when a query doesn't work as expected. Change your query to include this at the end: ...pagename1'") or die(mysql_error()); Quote Link to comment Share on other sites More sharing options...
djcubez Posted June 10, 2008 Share Posted June 10, 2008 I'd say it's because you left out the '' in the UPDATE. So change it to SET count='count + 1'. Also, congrats on having url.com, that's awesome haha. Quote Link to comment Share on other sites More sharing options...
tjverge Posted June 10, 2008 Author Share Posted June 10, 2008 printed $_GET['member'] to the screen and it has the right vaule, also added to error request but no errors where returned. Quote Link to comment Share on other sites More sharing options...
tjverge Posted June 10, 2008 Author Share Posted June 10, 2008 tried to change to SET count='count + 1' did not have any effect. Quote Link to comment Share on other sites More sharing options...
djcubez Posted June 10, 2008 Share Posted June 10, 2008 tried to change to SET count='count + 1' did not have any effect. Delete this post, didn't read code correctly. Quote Link to comment Share on other sites More sharing options...
Psycho Posted June 10, 2008 Share Posted June 10, 2008 You should have proper error handling. Try this: <?php $pagename1=mysql_real_escape_string($_GET['member']); $query = "UPDATE members SET count = count + 1 WHERE pagename='$pagename1'"; mysql_query ($query) or die ("Error:<br>".mysql_error()."<br>Query:<br>$query"); //For testing purposes echo "Query:<br>$query<br>Rows Affected: ".mysql_affected_rows(); ?> Quote Link to comment Share on other sites More sharing options...
DarkWater Posted June 10, 2008 Share Posted June 10, 2008 No, don't use $count. And count is a mysql reserved word I think, because it's a function. So you need to do `count` = `count` +1 or you can just rename the column. You'd have known this if you just put OR die(mysql_error()) after query....*Sigh* Quote Link to comment Share on other sites More sharing options...
revraz Posted June 10, 2008 Share Posted June 10, 2008 There is no $count variable even set. Quote Link to comment Share on other sites More sharing options...
djcubez Posted June 10, 2008 Share Posted June 10, 2008 There is no $count variable even set. That's what was confusing me. Quote Link to comment Share on other sites More sharing options...
DarkWater Posted June 10, 2008 Share Posted June 10, 2008 There is no $count variable even set. That's what was confusing me. Read my post. Quote Link to comment Share on other sites More sharing options...
tjverge Posted June 10, 2008 Author Share Posted June 10, 2008 ok I tried to change count col to views, had no effect when I added the error checking it comes back UPDATE members SET views = views + 1 WHERE pagename='tjverge' Rows Affected: 0 so the information is right just not updating. Quote Link to comment Share on other sites More sharing options...
revraz Posted June 10, 2008 Share Posted June 10, 2008 And are you using mysql_error after the query? Quote Link to comment Share on other sites More sharing options...
tjverge Posted June 10, 2008 Author Share Posted June 10, 2008 yes the code now looks like this $pagename1=mysql_real_escape_string($_GET['member']); $query = "UPDATE members SET views = views + 1 WHERE pagename='$pagename1'"; mysql_query ($query) or die ("Error:<br>".mysql_error()."<br>Query:<br>$query"); //For testing purposes echo "Query:<br>$query<br>Rows Affected: ".mysql_affected_rows(); Quote Link to comment Share on other sites More sharing options...
djcubez Posted June 10, 2008 Share Posted June 10, 2008 I would personally think you'd have to set a variable first? $views = mysql_query("SELECT views FROM members WHERE pagename='tjverge'"; $views++; $query = mysql_query("UPDATE members SET views='$views' WHERE pagename='tjverge'"; Quote Link to comment Share on other sites More sharing options...
revraz Posted June 10, 2008 Share Posted June 10, 2008 You can add within SQL statements. Quote Link to comment Share on other sites More sharing options...
revraz Posted June 10, 2008 Share Posted June 10, 2008 And echo $query returns what? Quote Link to comment Share on other sites More sharing options...
tjverge Posted June 10, 2008 Author Share Posted June 10, 2008 echo $query returns: Resource id #2 Quote Link to comment Share on other sites More sharing options...
djcubez Posted June 10, 2008 Share Posted June 10, 2008 You can add within SQL statements. Guess I need to read up a bit lol. Quote Link to comment Share on other sites More sharing options...
DarkWater Posted June 10, 2008 Share Posted June 10, 2008 Are you sure that there is a 'tjverge' in the pageview column? Quote Link to comment Share on other sites More sharing options...
lemmin Posted June 10, 2008 Share Posted June 10, 2008 It seems to me that your database cannot find a row with a pagename that has the value 'tjverge'. Try doing a query to print out all of the pagenames to the browser and see if they are really what you expect. Quote Link to comment Share on other sites More sharing options...
revraz Posted June 10, 2008 Share Posted June 10, 2008 Resource ID is the Result of a mysql_query, are you re-using the $query variable somewhere else in your code? Echoing $query should return "UPDATE members SET views = views + 1 WHERE pagename='$pagename1'" With $pagename1 replaced with $_GET['member'] Quote Link to comment Share on other sites More sharing options...
tjverge Posted June 10, 2008 Author Share Posted June 10, 2008 Darkwater that is the problem, I feel like a fool for missing it thank you so much for finding it I did not have the right column name, it works now Thank you to everyone for he help. Quote Link to comment Share on other sites More sharing options...
DarkWater Posted June 10, 2008 Share Posted June 10, 2008 Darkwater that is the problem, I feel like a fool for missing it thank you so much for finding it I did not have the right column name, it works now Thank you to everyone for he help. Heh, simple errors are usually the hardest to find. Glad I could help. 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.