Re: [PHP] php and sql problem with mysql_query and insert

2003-01-29 Thread Ernest E Vogelsinger
At 05:17 29.01.2003, Sunfire said:
[snip]
hi ...

im having a little problem with mysql_query(insert into members
('$company', '$name1', '$name2', '$address1', '$address2', ''$ac1', '$ext2',
'$num1', '$ac2', '$ext2', '$num2', '$city', '$state', '$zip', '$desc',
'$flags'));

for some reason those variables are empty by the time they get into the
table...

Are these variables received by handling a form submit? You should use the
$_REQUEST array if you have register_globals off:

mysql_query(insert into members
('{$_REQUEST['company']}', '{$_REQUEST['name1']}', '{$_REQUEST['name2']}',
'{$_REQUEST['address1']}', '{$_REQUEST['address2']}', '{$_REQUEST['ac1']}',
'{$_REQUEST['ext2']}', '{$_REQUEST['num1']}', '{$_REQUEST['ac2']}',
'{$_REQUEST['ext2']}', '{$_REQUEST['num2']}', '{$_REQUEST['city']}',
'{$_REQUEST['state']}', '{$_REQUEST['zip']}', '{$_REQUEST['desc']}',
'{$_REQUEST['flags']}'));

Two other 'littles' I see:
- your original statement comes with two single quotes before $ac1, this
will break the query if it's not a message typo here.
- the ext2 value is inserted twice
- I personally prefer to explicitly name the columns on any insert, even if
I populate all columns. If by chance your table structure will change
(using ALTER TABLE) your insert statement will break.


-- 
   O Ernest E. Vogelsinger
   (\)ICQ #13394035
^ http://www.vogelsinger.at/



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




Re: [PHP] php and sql problem with mysql_query and insert

2003-01-29 Thread 1LT John W. Holmes
 im having a little problem with mysql_query(insert into members
 ('$company', '$name1', '$name2', '$address1', '$address2', ''$ac1',
'$ext2',
 '$num1', '$ac2', '$ext2', '$num2', '$city', '$state', '$zip', '$desc',
 '$flags'));

 for some reason those variables are empty by the time they get into the
 table...

Where are those variables coming from then? If the data in the table is
empty, then these variables are empty. They can't get lost along the way or
anything...

---John Holmes...


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




RE: [PHP] php and sql problem with mysql_query and insert

2003-01-29 Thread Bryan Brannigan
Have you tried echo'ing out the variable before and after the mysql_query?

 -Original Message-
 From: 1LT John W. Holmes [mailto:[EMAIL PROTECTED]]
 Sent: Wednesday, January 29, 2003 6:20 AM
 To: Sunfire; [EMAIL PROTECTED]
 Subject: Re: [PHP] php and sql problem with mysql_query and insert
 
 
  im having a little problem with mysql_query(insert into members
  ('$company', '$name1', '$name2', '$address1', '$address2', ''$ac1',
 '$ext2',
  '$num1', '$ac2', '$ext2', '$num2', '$city', '$state', 
 '$zip', '$desc',
  '$flags'));
 
  for some reason those variables are empty by the time they 
 get into the
  table...
 
 Where are those variables coming from then? If the data in 
 the table is
 empty, then these variables are empty. They can't get lost 
 along the way or
 anything...
 
 ---John Holmes...
 
 
 -- 
 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] php and sql problem with mysql_query and insert

2003-01-29 Thread Maxim Maletsky
Guess what?

add this on top of the file:


error_reporting(E_ALL);

this will probably tell you these variables are unset :) Why? Register
global... wrong logic... etc...

What php 4 is exactly installed there?


--
Maxim Maletsky
[EMAIL PROTECTED]



Sunfire [EMAIL PROTECTED] wrote... :

 hi ...
 
 im having a little problem with mysql_query(insert into members
 ('$company', '$name1', '$name2', '$address1', '$address2', ''$ac1', '$ext2',
 '$num1', '$ac2', '$ext2', '$num2', '$city', '$state', '$zip', '$desc',
 '$flags'));
 
 for some reason those variables are empty by the time they get into the
 table...
 im running mysql 3.2.3.x, php 4 used as module in apache, windows me and
 apache 1.3.4  the variables come from a form and then posted to a
 comfirmation page where all the contents of the variables are printed in a
 table before  user would click the continue link at the bottum of the
 page... after that the link would call a file called addtolist.php which
 would add the var list to a table and return either an error message or a
 success message.. i havent yet found how to have a php script load a new web
 page other than include() or require() and dont know if that is making my
 problem or just what it is... i will include the test file called
 addtolist.php below...:
 ?php
 mysql_db_query(wata, insert into members VALUES('$company', '$name1',
 '$name2', '$address1', '$address2', '$city', '$state', '$zip', '$ac1',
 '$ext1', '$num1', '$ac2', '$ext2', '$num2', '$desc', '$flags'));
 echo \n;
 echo mysql_error();
 
 echo ENDOF_BLOCK
 $post['name1']
 your entry was added
 
 go back to the main menu by clicking a href=main.htmhere/a.
 ENDOF_BLOCK;
 ?
 tnx for the help
 
 
 
 ---
 Outgoing mail is certified Virus Free.
 Checked by AVG anti-virus system (http://www.grisoft.com).
 Version: 6.0.443 / Virus Database: 248 - Release Date: 1/10/2003
 
 
 -- 
 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