supermerc Posted February 21, 2009 Share Posted February 21, 2009 Hey I have a script that goes on a site and gets everything from the action log on the site then adds it to my database and I need to add some conditions so that when I update it doesnt add things twice. Right now what I have is working and its: $str = "SELECT * FROM actionlog WHERE itemid = $match[2]"; $qry = mysql_query($str); $num = mysql_num_rows($qry); if($num <1 ) But I want to add anothing condition, but when I do so then whenever I click update it adds everything again instead of checking both conditions. the code that doesnt work is : $str = "SELECT * FROM actionlog WHERE itemid = $match[2] && action = $v[3]"; $qry = mysql_query($str); $num = mysql_num_rows($qry); if($num <1 ) Thanks for helping. Link to comment https://forums.phpfreaks.com/topic/146271-solved-php-conditions/ Share on other sites More sharing options...
allworknoplay Posted February 21, 2009 Share Posted February 21, 2009 Hey I have a script that goes on a site and gets everything from the action log on the site then adds it to my database and I need to add some conditions so that when I update it doesnt add things twice. Right now what I have is working and its: $str = "SELECT * FROM actionlog WHERE itemid = $match[2]"; $qry = mysql_query($str); $num = mysql_num_rows($qry); if($num <1 ) But I want to add anothing condition, but when I do so then whenever I click update it adds everything again instead of checking both conditions. the code that doesnt work is : $str = "SELECT * FROM actionlog WHERE itemid = $match[2] && action = $v[3]"; $qry = mysql_query($str); $num = mysql_num_rows($qry); if($num <1 ) Thanks for helping. I think it should be: $str = "SELECT * FROM actionlog WHERE itemid = $match[2] AND action = $v[3]"; Secondly, if you are allowing duplicates in your database, then your tables aren't structured properly. Use the "UNIQUE" keyword to avoid duplicates at the DB level... Link to comment https://forums.phpfreaks.com/topic/146271-solved-php-conditions/#findComment-767906 Share on other sites More sharing options...
angelcool Posted February 21, 2009 Share Posted February 21, 2009 Use mysql_error() to see what MySQL complaints about. $qry = mysql_query($str) or die(mysql_error()); Try that. Link to comment https://forums.phpfreaks.com/topic/146271-solved-php-conditions/#findComment-767909 Share on other sites More sharing options...
supermerc Posted February 21, 2009 Author Share Posted February 21, 2009 Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/a9337486/public_html/vault.php on line 66 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '[3]' at line 1 Link to comment https://forums.phpfreaks.com/topic/146271-solved-php-conditions/#findComment-767913 Share on other sites More sharing options...
angelcool Posted February 21, 2009 Share Posted February 21, 2009 But I want to add anothing condition, but when I do so then whenever I click update it adds everything again instead of checking both conditions. the code that doesnt work is : I missed this part. If the query is running but you are not getting the expected results, then you have a query design issue. Besides that, I will still encourage you to use msyql_error in the feature. Link to comment https://forums.phpfreaks.com/topic/146271-solved-php-conditions/#findComment-767915 Share on other sites More sharing options...
Philip Posted February 21, 2009 Share Posted February 21, 2009 As angel said, add or die... I'm going to take a guess and say it's because you don't have single quotes around your values. $str = "SELECT * FROM `actionlog` WHERE `itemid` = '$match[2]' && `action` = '$v[3]'"; echo $str; // does this look correct, and does it run in something like PhpMyAdmin? $qry = mysql_query($str) or die(mysql_error()); $num = mysql_num_rows($qry); if($num <1 ) // rest of script.... Link to comment https://forums.phpfreaks.com/topic/146271-solved-php-conditions/#findComment-767917 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.