This topic is locked

inserting variables and some other intersing things

12/11/2009 8:47:03 PM
PHPRunner General questions
J
junior79 author

OK heres the code
//** Check if specific record exists ****

global $conn;

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

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

$data=db_fetch_array($rsExists);

$add = $values['add'];

if($data)

{

// if record exists Do nothing and tell user Record Exsists

echo "record exists";

return false;

}

else

{

//record dosent exists make call to upcdatabase.com to gather info if available

require_once 'XML/RPC.php';

$params = array(new XML_RPC_Value($values["barcode"]));

$msg = new XML_RPC_Message('lookupUPC', $params);

$cli = new XML_RPC_Client('/rpc', 'http://www.upcdatabase.com';);

$resp = $cli->send($msg);

$val = $resp->value();

//Decode the value, into an array.

$data = XML_RPC_decode($val);
// if found = 1 in the array then upcdb sent us a entry

if($data['found']==1)

{

echo "record found";
//save the info we want to sessions so that the page can get the info

$_SESSION["desc"] = $data['description'];

$_SESSION["unit"] = $data['size'];

$_SESSION["barcode"] = $data['upc'];

header("Location: items_add.php");

}else{
//if upcdb did have any info then have to manully add it

echo "record not found";

}

}
After all that here's what i am trying to do
When you scan a barcode it collects the number and checks to see if it already in the database if it does not then it calls a XML_RPC to upcdatabase.com and grabs the results. I then have it take that info and store my wanted info from an array into a $_session and have it reload the items_add.php so that the info pops into the fields of the add page.

I have unset$_session in the main list before display and after record added so that it destorys my session varis so they are clear for next time.
Heres my problem the way my code is right now; it adds the info to the items_add.php but does not allow me to finish adding the record cause i cant figure out where to put the return true; so that is will add the record
all this code is in the Add page: before record added
am i doing this right ?

J
Jane 12/14/2009

Hi,
you can just save values in the database in this event (without redirect):

$values["desc"] = $data['description'];

$values["unit"] = $data['size'];

$values["barcode"] = $data['upc'];