Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > PHP/MySQL > PHP Databases
Password Reminder
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
PHP Databases Using PHP in conjunction with databases. PHP questions not specific to databases should be directed to one of the other PHP forums.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the PHP Databases section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old July 3rd, 2003, 04:11 AM
Registered User
Join Date: Jul 2003
Location: , , .
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default mysql_fetch_array problem...

Hey I appreciate the help just before the weekend...

This snippet is a simplified version of what I'm running, but it produces the same error

>>parse error, expecting `T_STRING' or `T_VARIABLE' or `T_NUM_STRING'<<

and refers to the 7th line of code below when I run it.

Here it is:

include 'connect.inc';
$a_office = 'El Dorado Hills';
$a_os = 'winme';
$srch = mysql_query( "SELECT os_id FROM os WHERE operating_sys = '$a_os'", $db);
$sql = "INSERT INTO agent (office_id, os_id) VALUES ('$array[\"os_id\"]')";

Can anyone help, please???

Thanks again!

Reply With Quote
  #2 (permalink)  
Old July 3rd, 2003, 12:30 PM
Friend of Wrox
Points: 2,570, Level: 21
Points: 2,570, Level: 21 Points: 2,570, Level: 21 Points: 2,570, Level: 21
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
Join Date: Jun 2003
Location: San Diego, CA, USA
Posts: 836
Thanks: 0
Thanked 0 Times in 0 Posts

The problem is that PHP is trying to substitute an array variable in a string, but your index begins with the double-quote character. The only allowable tokens in a string index are a character string (T_STRING), another variable (T_VARIABLE), or a number (T_NUM_STRING).

Rewrite that line like this:

$sql = "INSERT INTO agent (office_id, os_id) VALUES ('$array[os_id]')";
PHP assumes anything within square brackets is the index to the array, since it's already parsing it from within string context.

For more information on how PHP performs variable substitution within strings, read the manual at:

Take care,

Reply With Quote
  #3 (permalink)  
Old July 4th, 2003, 12:10 AM
Registered User
Join Date: Jul 2003
Location: , , .
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts

Thank you for your help, Nik ;)

Reply With Quote

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
mysql_fetch_array and if .. else Jeff Smitherman Beginning PHP 3 November 21st, 2005 09:08 AM
chapter 15 cart.php Warning: mysql_fetch_array(): pink BOOK: Beginning PHP5, Apache, and MySQL Web Development ISBN: 978-0-7645-7966-0 0 July 19th, 2005 07:49 PM
Problem with mysql_fetch_array insomne PHP Databases 0 September 27th, 2004 02:03 PM
mysql_fetch_array with a variable string aeres PHP How-To 7 August 18th, 2003 01:01 PM

All times are GMT -4. The time now is 08:59 AM.

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.