Re: Unable to send variables to MySQL table

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



It is a good idea to check for errors, like this:


mysql_query($add_to_db) or die('Error inserting SQL data at ' . __LINE__ . ' 
<br/>' . $add_to_db .'<br/>' . mysql_error());

If there is no error (non-null return value from mysql_query()) the 
expresion after the OR does even get looked at, since (TRUE or whatever) is 
TRUE so it doesn't even bother to check 'whatever'.  If the first evaluates 
as FALSE (in this case null) then it needs to evaluate the part after the 
OR, which is irrelevant in this case since it will die.




""Stewart Priest"" <smiley@xxxxxxxxxxxxxxxxx> wrote in message 
news:003001c5e561$f882fe90$0201a8c0@xxxxxxxxxxxxxxxxxxxx
Hi folks... a bit of a newbie question I'm afraid...

I've written this script shown below. It gets its variables from a form, and 
then it (supposedly!) writes these values into a MySQL table ('invoices').

The script executes with no errors, but when I check the table, the table is 
still empty. I can manually insert the data directly into the table, and 
when I echo the variables in the script, the values are displayed whe I run 
it, but for reasons unknown, the values are not written to the table.

Any ideas? The code is below.

Many thanks.
Stewart

<?php

// this opens the connection to the db
include 'library/opendb.php';

// this adds detals to the invoice table
$item1_desc = $_REQUEST['item1_desc'];
$item2_desc = $_REQUEST['item2_desc'];
$item3_desc = $_REQUEST['item3_desc'];
$item4_desc = $_REQUEST['item4_desc'];
$item1_cost = $_REQUEST['item1_cost'];
$item2_cost = $_REQUEST['item2_cost'];
$item3_cost = $_REQUEST['item3_cost'];
$item4_cost = $_REQUEST['item4_cost'];
$delivery_cost = $_REQUEST['delivery_cost'];

$add_to_db = "insert into invoices (item1_desc, item1_cost, item2_desc, 
item2_cost, item3_desc, item3_cost, item4_desc, item4_cost, delivery_cost) 
values ('$item1_desc', '$item1_cost', '$item2_desc', '$item2_cost', 
'$item3_desc', '$item3_cost', '$item4_desc', '$item4_cost', 
'$delivery_cost')";
mysql_query($add_to_db);

?> 

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux