Jump to content

Recommended Posts

Hi,

 

I am trying to debug my first php script.  When I run it I get the following error

 

Parse error: syntax error, unexpected T_LNUMBER, expecting T_VARIABLE or '$' in C:\wamp\www\Guana_Plant_Key\test.php on line 52

 

I am running all of this on my pc on wampserver.

I tried looking up the error but I couldn't find an example that matched my situation.  I have included my script up until the error just for completeness.  It is getting stuck on the last line.  I am just trying to get the numerical index of the entry in the array being accessed.  Is "key" the wrong command.  I looked through the manual & couldn't find a good alternative but I may have missed it.

 

Kate

 

P.S.  Sorry for the excessive remarks - Since I am just learning it helps me keep track

 

<?php
// sets variables for opening guana_plants
$dbhost = 'localhost';
$dbuser = 'root';
$dbpass = '';
$dbname = 'guana_plant_db';

// connect to mysql to use guana_plants
$conn = mysql_connect($dbhost, $dbuser, $dbpass) or die('Error connecting to mysql');
mysql_select_db($dbname);

$seperator = " ~ ";							// define seperator
$picstorage = array();  					// make link or jpeg output-storage array
$scinamestorage = array(); 					// make scientific name storage array
$comnamestorage = array();					// make common name storage array
$comnamemysql = array ();					// make input from mysql common name array
$scinamemysql = array(); 					// make input from mysql scientific name array
$picmysql = array();						// make input from mysql link or jpeg storage array
$picexplode = array();						// make temp array for exploding

// load links or jpeg names from guana_plants db into $picmysql
$query = "SELECT flower_pics FROM guana_plants WHERE flower_pics <> 'none' AND flower_pics <> 'flower_pics'";
$result = mysql_query($query);
while ($row = mysql_fetch_array ($result, MYSQL_NUM)) {
$picmysql [] = $row [0];
}
// load scientific names from guana_plants db into $scinamemysql
$query = "SELECT Concat(genus, ' ', species) FROM guana_plants WHERE flower_pics <> 'none' AND flower_pics <> 'flower_pics'";
$result = mysql_query($query);
while ($row = mysql_fetch_array ($result, MYSQL_NUM)) {
$scinamemysql [] = $row [0];
}
// load common names from guana_plants db into $comnamemysql
$query = "SELECT common_names FROM guana_plants WHERE flower_pics <> 'none' AND flower_pics <> 'flower_pics'";
$result = mysql_query($query);
while ($row = mysql_fetch_array ($result, MYSQL_NUM)) {
$comnamemysql [] = $row [0];
}
foreach (picmysql as $pics); 					// begin to go through the array 1 entry at a time
if(strstr($pic,$seperator))  {					// If $pics contains the separator execute
$picexplode = array(); 							// Reset $picexplode to an empty array
$picexplode = explode(" ~ ", pics); 			// explode any string with a ~ into the picexplode array
$count = count ($picexplode); 					// count number of link or jpeg names in $picexplode
$countedlinks = $countedlinks + $count;	 		// add count of link or jpeg names to $counted variable so I will get # of links
$1key = key ($picmysql);						// load the location or key of the current link or jpeg name into $1key

The problem is you're starting a variable name with a number. Variable names can only begin with a letter or an underscore. You can use numbers afterwards.

$1key = key ($picmysql); // load the location or key of the current link or jpeg name into $1key

Change $1key to $key1 or $_1key

 

EDIT: Beaten to it. :)

also, you are missing several dollar signs on variables, and your foreach loop has a semi-colon at the end...should be like this:

 

foreach ($picmysql as $pics){                // begin to go through the array 1 entry at a time
  if(strstr($pic,$seperator))  {               // If $pics contains the separator execute
    $picexplode = array();                      // Reset $picexplode to an empty array
    $picexplode = explode(" ~ ", $pics);          // explode any string with a ~ into the picexplode array
    $count = count ($picexplode);                // count number of link or jpeg names in $picexplode
    $countedlinks = $countedlinks + $count;          // add count of link or jpeg names to $counted variable so I will get # of links
    $key = key ($picmysql);                  // load the location or key of the current link or jpeg name into $1key
  }
}

Wow that was amazingly fast  :o.  Thanks everybody for the help.

 

I guess this one is solved though I don't know how to put the green checkmark on it that indicates that.

 

I am sure I will be back for more.  Maybe even momentarily when I try to run this again.

 

Wild,

 

by the brackets I assume you mean the

<?php

?>

 

If so you needn't reply.

 

Thanks again

 

Kate

Wild,

 

by the brackets I assume you mean the

<?php

?>

I think you mean what ohdang888 said:

put your code on this forum in the

 

/

 code brackets.... 
<?php
echo "It colors it so when can see whats wrong";
?>

By that he/she meant to use


tags when posting code to the forum. It helps to make code more readable and separates the code form what you're saying (text).  I edited you post earlier and added the code tags.

 

To mark topic solved, the button is in the menu at the bottom of page (before the quick reply box).

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.