This topic is locked

Cant get "check record exist to work"

5/30/2012 6:37:16 AM
PHPRunner General questions
S
scoobysteve author

Hi all I have a application whereby I want to score my members on content, I am trying to check to see if a value is present in a certain field, and then add points to another field if it is. I am trying to do this on the "after record updated" section, basically "AddImage6" field is a image file, so in this instance I want to direct to a page if this field has any value in there because the file name is random, but if its remains empty then it redirects to another page, I will replace this with "different code once I can get this to work. I am using the code below, what ever i put in the AddImage6<>''"; section it only diverts to the same page when the values are different.
Any help please would be appreciated
global $conn;

$strSQLExists = "select * from tblproperties where AddImage6<>''";

$rsExists = db_query($strSQLExists,$conn);

$data=db_fetch_array($rsExists);

if($data)

{

header("Location: http://www.fatbob.net/has.htm";);

exit();
}

else

{

header("Location: http://www.fatbob.net/hasnot.htm";);

exit();
}

C
cgphp 5/30/2012

What is the default value for the AddImage6 field in the database?
Try this:

$strSQLExists = "select * from tblproperties where AddImage6 IS NOT NULL";
S
scoobysteve author 5/30/2012



What is the default value for the AddImage6 field in the database?
Try this:

$strSQLExists = "select * from tblproperties where AddImage6 IS NOT NULL";



Thanks I thought this would work but it shows the same page in both instances
I hit save in on the edit page and it goes to the same page even if there is a value in the ADDImage6 field
I have checked the actual database in PHPMyAdmin and the default value is NULL when there is no value
strange

S
scoobysteve author 5/30/2012

OK this is the code I wish to run but for some reason it always goes for the first option even if there is a NULL value in the MySQL database in filed ADDImage6

If I delete the image and then hit save it still goes from the first option and adds 100 to the field score1 any ideas please, I guess this line is at fault somewhere
$strSQLExists = "select from tblproperties where ADDImage6 IS NOT NULL";
Code used on the Edit page "After record updated" Event
global $conn;

$strSQLExists = "select
from tblproperties where ADDImage6 IS NOT NULL";

$rsExists = db_query($strSQLExists,$conn);

$data=db_fetch_array($rsExists);

if($data)

{

global $conn;

$strUpdate = "update tblproperties set score1='100' where UserName='".$_SESSION["UserID"]."'";

db_exec($strUpdate,$conn);

}

else

{

global $conn;

$strUpdate = "update tblproperties set score1='0' where UserName='".$_SESSION["UserID"]."'";

db_exec($strUpdate,$conn);

}

S
scoobysteve author 5/31/2012



OK this is the code I wish to run but for some reason it always goes for the first option even if there is a NULL value in the MySQL database in filed ADDImage6

If I delete the image and then hit save it still goes from the first option and adds 100 to the field score1 any ideas please, I guess this line is at fault somewhere
$strSQLExists = "select from tblproperties where ADDImage6 IS NOT NULL";
Code used on the Edit page "After record updated" Event
global $conn;

$strSQLExists = "select
from tblproperties where ADDImage6 IS NOT NULL";

$rsExists = db_query($strSQLExists,$conn);

$data=db_fetch_array($rsExists);

if($data)

{

global $conn;

$strUpdate = "update tblproperties set score1='100' where UserName='".$_SESSION["UserID"]."'";

db_exec($strUpdate,$conn);

}

else

{

global $conn;

$strUpdate = "update tblproperties set score1='0' where UserName='".$_SESSION["UserID"]."'";

db_exec($strUpdate,$conn);

}


Any ideas on this please its driving me crazy,

Sergey Kornilov admin 5/31/2012

The typical suggestion is to print all your SQL queries on the page instead of executing them and run them manually against your database. This way you can see what exactly causes the trouble.

S
scoobysteve author 5/31/2012



The typical suggestion is to print all your SQL queries on the page instead of executing them and run them manually against your database. This way you can see what exactly causes the trouble.


Thanks but I am not sure what you mean by that I am afraid. I am using the code provided by PHPR for this and changing the values in red as needed

even if I use just the following I get the same results
global $conn;

$strSQLExists = "select * from tblproperties where ADDImage6 IS NOT NULL";

$rsExists = db_query($strSQLExists,$conn);

$data=db_fetch_array($rsExists);

if($data)

{

echo "<h5>Add 100 Points</h5>"

}

else

{

echo "<h5>Add 0 Points</h5>"

}