TheFilmGod Posted March 18, 2007 Share Posted March 18, 2007 Hi. I'm trying to get a php script working, but it still has errors. Any help is appreciated! What it does: If a visitor likes a video than he will click on "I Like It" link. This is supposed to trigger a php script that refreshes the page and adds a count to the total number who like the video. Sorta like "Favorited this many times." Here is the code for the page with the link: <?php $page="1"; ?> <a href="fav.php?page=$page">I like it!</a> <?php require("connect.php"); $result = mysql_query("SELECT fav_count FROM favs WHERE page_id = $page"); // echo the number of hits echo $result; ?> And here is the script that is supposed to be triggered: <?php // Page ID $page = $_GET['page']; require("connect.php"); $result = mysql_query("SELECT fav_count FROM favs WHERE page_id = $page"); $t_count = mysql_num_rows($result); if($t_count > 0){ $cnt = mysql_result($result, 0, 'fav_count'); $cnt++; mysql_query("UPDATE favs SET fav_count = $cnt WHERE page_id = $page"); }else{ mysql_query("INSERT INTO favs ( page_id , fav_count ) VALUES ($page, '1')"); } echo "Thank you for telling us you like this!<br />Please wait..."; echo "<META HTTP-EQUIV=Refresh CONTENT=\"2; URL=favs.php\">"; ?> Connecting and the table on the Mysql works fine. It is the above code that has errors. Please help! Link to comment https://forums.phpfreaks.com/topic/43296-solved-better-than-a-newb/ Share on other sites More sharing options...
TheFilmGod Posted March 18, 2007 Author Share Posted March 18, 2007 you can test the script out at: http://www.TheFilmGod.com/test/favs.php I don't really know what is happending, help! Link to comment https://forums.phpfreaks.com/topic/43296-solved-better-than-a-newb/#findComment-210225 Share on other sites More sharing options...
drewbee Posted March 19, 2007 Share Posted March 19, 2007 Take this: $result = mysql_query("SELECT fav_count FROM favs WHERE page_id = $page"); $t_count = mysql_num_rows($result); if($t_count > 0){ $cnt = mysql_result($result, 0, 'fav_count'); $cnt++; mysql_query("UPDATE favs SET fav_count = $cnt WHERE page_id = $page"); }else{ mysql_query("INSERT INTO favs ( page_id , fav_count ) VALUES ($page, '1')"); } and replace it with $result = mysql_query("SELECT fav_count FROM favs WHERE page_id = $page"); $t_count = mysql_num_rows($result); if($t_count > 0){ mysql_query("UPDATE favs SET fav_count = fav_count + 1 WHERE page_id = $page"); }else{ mysql_query("INSERT INTO favs ( page_id , fav_count ) VALUES ($page, '1')"); } See how that works out for you... Link to comment https://forums.phpfreaks.com/topic/43296-solved-better-than-a-newb/#findComment-210264 Share on other sites More sharing options...
najibk Posted March 19, 2007 Share Posted March 19, 2007 fav.php?page=$page <<<<< I think for what you're trying to do you need to have >>>> fav.php?page=<?php echo $page ?> Link to comment https://forums.phpfreaks.com/topic/43296-solved-better-than-a-newb/#findComment-210275 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.