Re: [PHP] Unable to send variables to MySQL table

2005-11-10 Thread Richard Lynch
On Wed, November 9, 2005 1:15 pm, Stewart Priest wrote:
 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);

echo hr /$queryhr /;
mysql_query($add_to_db) or die(mysql_error());

 ?


-- 
Like Music?
http://l-i-e.com/artists.htm

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



[PHP] Unable to send variables to MySQL table

2005-11-09 Thread Stewart Priest
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);

?

RE: [PHP] Unable to send variables to MySQL table

2005-11-09 Thread Jay Blanchard
[snip]
Any ideas? The code is below.
[/snip]

Does your MySQL connection have permission to insert to the table?

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



Re: [PHP] Unable to send variables to MySQL table

2005-11-09 Thread Richard Davey
Hi Stewart,

Wednesday, November 9, 2005, 7:15:39 PM, you wrote:

 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.

 $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);

?

On the surface it looks fine, so I would echo out your query and then
paste it into MySQL (phpmyamin, SQLyog, etc) and check it works!

Or you could capture the result of the query and check for an error.

If there isn't one, it's probably a table design issue.

Cheers,

Rich
-- 
Zend Certified Engineer
PHP Development Services
http://www.corephp.co.uk

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



Re: [PHP] Unable to send variables to MySQL table

2005-11-09 Thread Dan McCullough
print $add_to_db;

should print out the entire insert line and you can just double check
that your values are full, otherwise like Jay said I would check and
make sure the user you have in your connect string can write to the
db.

On 11/9/05, Stewart Priest [EMAIL PROTECTED] wrote:
 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



RE: [PHP] Unable to send variables to MySQL table

2005-11-09 Thread Jim Moseby
snippity snip
 
 Any ideas? The code is below.
snip snip
 mysql_query($add_to_db);

Hi Stewart.  Your query is failing for some reason (as others here have
mentioned). I would change the above line to read:

mysql_query($add_to_db) or die(mysql_error().br$add_to_db);

This will make the script die, and will print the mysql error and the SQL
statement that caused it.

JM

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



Re: [PHP] Unable to send variables to MySQL table

2005-11-09 Thread Stewart Priest
snip
print $add_to_db;
/snip

Thanks for all your replies! I didn't expect to get one so quick, so thanks!

After I did the above, I pasted the output into MySQL. Guess what? It didn't
work!

I was only sending values for $item1_desc and $item1_cost. Because I was not
sending values for the other columns, I was getting an error message saying
the data was truncated for the empty variables.

Now I need to figure out how to send empty values... would NULL do the job?

Thanks again!
Stewart

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



Re: [PHP] Unable to send variables to MySQL table

2005-11-09 Thread Dan McCullough
What is the structure of that table?

On 11/9/05, Stewart Priest [EMAIL PROTECTED] wrote:
 snip
 print $add_to_db;
 /snip

 Thanks for all your replies! I didn't expect to get one so quick, so thanks!

 After I did the above, I pasted the output into MySQL. Guess what? It didn't
 work!

 I was only sending values for $item1_desc and $item1_cost. Because I was not
 sending values for the other columns, I was getting an error message saying
 the data was truncated for the empty variables.

 Now I need to figure out how to send empty values... would NULL do the job?

 Thanks again!
 Stewart

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



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



Re: [PHP] Unable to send variables to MySQL table

2005-11-09 Thread lonewolf
I code all my apps to look for an empty variable and dump and empty set
into it.  That way when I code the rest of the information into the
database, the files are cleaner and I don't have to worry about users
and bad sets.

$var = '';

Robert

- Original Message -
From: Stewart Priest [EMAIL PROTECTED]
Date: Wednesday, November 9, 2005 2:43 pm
Subject: Re: [PHP] Unable to send variables to MySQL table

 snip
 print $add_to_db;
 /snip
 
 Thanks for all your replies! I didn't expect to get one so quick, 
 so thanks!
 
 After I did the above, I pasted the output into MySQL. Guess what? 
 It didn't
 work!
 
 I was only sending values for $item1_desc and $item1_cost. Because 
 I was not
 sending values for the other columns, I was getting an error 
 message saying
 the data was truncated for the empty variables.
 
 Now I need to figure out how to send empty values... would NULL do 
 the job?
 
 Thanks again!
 Stewart
 
 -- 
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, visit: http://www.php.net/unsub.php
 
 

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



Re: [PHP] Unable to send variables to MySQL table

2005-11-09 Thread Stewart Priest
snip
What is the structure of that table?
/snip

+---+--+--+-+-+---+
| Field | Type | Null | Key | Default | Extra |
+---+--+--+-+-+---+
| invoice_no| int(10)  | YES  | | NULL|   |
| item1_desc| varchar(255) | YES  | | NULL|   |
| item1_cost| float| YES  | | NULL|   |
| item2_desc| varchar(255) | YES  | | NULL|   |
| item2_cost| float| YES  | | NULL|   |
| item3_desc| varchar(255) | YES  | | NULL|   |
| item3_cost| float| YES  | | NULL|   |
| item4_desc| varchar(255) | YES  | | NULL|   |
| item4_cost| float| YES  | | NULL|   |
| delivery_cost | float| YES  | | NULL|   |
| customer_id   | int(10)  | YES  | | NULL|   |
| comments  | varchar(255) | YES  | | NULL|   |
+---+--+--+-+-+---+

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



Re: [PHP] Unable to send variables to MySQL table

2005-11-09 Thread M

Stewart Priest wrote:

snip
What is the structure of that table?
/snip

+---+--+--+-+-+---+
| Field | Type | Null | Key | Default | Extra |
+---+--+--+-+-+---+
| invoice_no| int(10)  | YES  | | NULL|   |
| item1_desc| varchar(255) | YES  | | NULL|   |
| item1_cost| float| YES  | | NULL|   |
| item2_desc| varchar(255) | YES  | | NULL|   |
| item2_cost| float| YES  | | NULL|   |
| item3_desc| varchar(255) | YES  | | NULL|   |
| item3_cost| float| YES  | | NULL|   |
| item4_desc| varchar(255) | YES  | | NULL|   |
| item4_cost| float| YES  | | NULL|   |
| delivery_cost | float| YES  | | NULL|   |
| customer_id   | int(10)  | YES  | | NULL|   |
| comments  | varchar(255) | YES  | | NULL|   |
+---+--+--+-+-+---+



This is not a good structure. Have you thought about taking item* 
columns to a separate table?


Table invoices:
+---+--+--+-+-+---+
| Field | Type | Null | Key | Default | Extra |
+---+--+--+-+-+---+
| invoice_no| int(10)  | YES  | | NULL|   |
| delivery_cost | float| YES  | | NULL|   |
| customer_id   | int(10)  | YES  | | NULL|   |
| comments  | varchar(255) | YES  | | NULL|   |
+---+--+--+-+-+---+

Table invoices_items:
+---+--+--+-+-+---+
| Field | Type | Null | Key | Default | Extra |
+---+--+--+-+-+---+
| item_no   | int(10)  | YES  | | NULL|   |
| invoice_no| int(10)  | YES  | | NULL|   |
| item_desc | varchar(255) | YES  | | NULL|   |
| item_cost | float| YES  | | NULL|   |
+---+--+--+-+-+---+

And columns should be able to hold NULL values only if they can be 
empty. I'm sure you don't want invoice_no to be NULL ;)


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