This topic is locked
[SOLVED]

 Check if Record exsits

12/8/2009 7:07:04 PM
PHPRunner General questions
J
junior79 author

Ok here is the code.
global $conn;

$strSQLExists = "select * from items where barcode='".$data["barcode"]."'";

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

$data=db_fetch_array($rsExists);

if($data)

{

echo "Item Is in DataBase";

}

else

{

header("Location: items_add.php");

exit();

}
I am using this on the List page: after record is processed
What i want it to do is when i enter a search value and it does not exist in the database to send me to the items_add.php page
I can get it to Echo "item is in database" at the top of the page when i enter a known DB entry but when i search a value that i know isn't in the DB it just says it normal "no records found" and will not process the else statement at all, I've tried every why i know how but i cant get this to go.
any ideas would be greatly appreicated
Junior

J
Jane 12/9/2009

Junior,
List page: After record processed event is executed if there is at least one record on the page.

I recommend you to use List page: Before SQL query event for this purpose. Here is a sample:

$rstmp = CustomQuery($strSQL);

if (!$datatmp = db_fetch_array($rstmp))

{

//no records on the page

header("Location: items_add.php");

exit();

}
J
junior79 author 12/9/2009

Many Many thanks
I pulled my hair out for 6 hours trying to figure that out.

I am new to PHP about 10 years ago i used to do a bunch in TCL and perl but that was 10 years ago and sadly this isn't like riding a bike.
I am trying to build a web based grocery/shopping list for me and my wife.
My next task it to interface my add page to www.upcdatabase.com
Before i spend a bunch more time on this next project is there a easy way to access the value that i have input into the search on the main list page in list page: before sql query like $values[search] or $values[barcode]
i need to collect the value that was in the search that turned up no results and pass it to a bit of code that will query upcdatabase.com with the barcode.
I thank you greatly for your help.

junior

J
Jane 12/10/2009

Hi,
search values are in the session variables:

http://www.xlinesoft.com/phprunner/docs/phprunner_session_variables.htm
Use $_SESSION["<table name>_asearchfor"] array for example:

print_r($_SESSION["<table name>_asearchfor"]);
J
junior79 author 12/10/2009

I thanks you once again.
I book marked that page and it open the door to many more features i have been wondering about.
Thanks Again

Junior