Wrox Programmer Forums
Go Back   Wrox Programmer Forums > PHP/MySQL > PHP Databases
|
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 software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old July 3rd, 2003, 04:11 AM
Registered User
 
Join Date: Jul 2003
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:

<?php
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!


 
Old July 3rd, 2003, 12:30 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 836
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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:

Code:
$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:
  http://www.php.net/types.string


Take care,

Nik
http://www.bigaction.org/
 
Old July 4th, 2003, 12:10 AM
Registered User
 
Join Date: Jul 2003
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thank you for your help, Nik ;)






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





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