Jump to content

Recommended Posts

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

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...

 

 

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

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.

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....

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.