MDanz Posted February 15, 2010 Share Posted February 15, 2010 what i'm trying to do is every term that is searched is inserted into mysql, if the term is already there it adds 1 to the counter. this code doesn't work, where did i go wrong? counter is INT type... <?php $search = $_GET['search']; mysql_connect("localhost", "Master", "password"); mysql_select_db("db"); $bad2 = mysql_query("SELECT * FROM tags WHERE tagName='$search'"); $num_rows2 = mysql_num_rows($bad2) or die (mysql_error()); if($num_rows2==0){ $query10 = "INSERT INTO tags"; $query10 .= "(`tagName`,`counter`) VALUES ('$search','1')"; mysql_query($query10) or die (mysql_error()); } elseif($num_rows2>0) { $query11= mysql_query("UPDATE tags SET counter=+1 WHERE tagName='$search' ") or die (mysql_error()); } ?> Quote Link to comment https://forums.phpfreaks.com/topic/192195-help-with-mysql-not-working/ Share on other sites More sharing options...
premiso Posted February 15, 2010 Share Posted February 15, 2010 $query11= mysql_query("UPDATE tags SET counter=counter+1 WHERE tagName='$search' ") or die (mysql_error()); Give that a try. Quote Link to comment https://forums.phpfreaks.com/topic/192195-help-with-mysql-not-working/#findComment-1012847 Share on other sites More sharing options...
MDanz Posted February 15, 2010 Author Share Posted February 15, 2010 thx, that part now works but this part doesn't, i rephrased it but still not working. if($num_rows2<1){ $query10 = mysql_query("INSERT INTO tags (`tagName`,`counter`) VALUES ('$search',1)") or die (mysql_error()); } Quote Link to comment https://forums.phpfreaks.com/topic/192195-help-with-mysql-not-working/#findComment-1012864 Share on other sites More sharing options...
fenway Posted February 16, 2010 Share Posted February 16, 2010 Define "not working". Quote Link to comment https://forums.phpfreaks.com/topic/192195-help-with-mysql-not-working/#findComment-1013149 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.