kate_rose Posted June 13, 2008 Share Posted June 13, 2008 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 Quote Link to comment https://forums.phpfreaks.com/topic/110093-solved-debugging-1st-php-script-getting-key-of-array/ Share on other sites More sharing options...
ohdang888 Posted June 13, 2008 Share Posted June 13, 2008 put your code on this forum in the / code brackets.... <?php echo "It colors it so when can see whats wrong"; ?> Quote Link to comment https://forums.phpfreaks.com/topic/110093-solved-debugging-1st-php-script-getting-key-of-array/#findComment-564988 Share on other sites More sharing options...
kenrbnsn Posted June 13, 2008 Share Posted June 13, 2008 A variable name can not start with a number. Ken Quote Link to comment https://forums.phpfreaks.com/topic/110093-solved-debugging-1st-php-script-getting-key-of-array/#findComment-564989 Share on other sites More sharing options...
wildteen88 Posted June 13, 2008 Share Posted June 13, 2008 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. Quote Link to comment https://forums.phpfreaks.com/topic/110093-solved-debugging-1st-php-script-getting-key-of-array/#findComment-564990 Share on other sites More sharing options...
rhodesa Posted June 13, 2008 Share Posted June 13, 2008 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 } } Quote Link to comment https://forums.phpfreaks.com/topic/110093-solved-debugging-1st-php-script-getting-key-of-array/#findComment-564991 Share on other sites More sharing options...
kate_rose Posted June 13, 2008 Author Share Posted June 13, 2008 Wow that was amazingly fast . 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 Quote Link to comment https://forums.phpfreaks.com/topic/110093-solved-debugging-1st-php-script-getting-key-of-array/#findComment-565015 Share on other sites More sharing options...
wildteen88 Posted June 13, 2008 Share Posted June 13, 2008 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). Quote Link to comment https://forums.phpfreaks.com/topic/110093-solved-debugging-1st-php-script-getting-key-of-array/#findComment-565022 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.