parse error in drop down menu

  • (3 Pages)
  • +
  • 1
  • 2
  • 3

31 Replies - 2454 Views - Last Post: 08 January 2010 - 01:50 AM Rate Topic: -----

#1 raven21  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 34
  • Joined: 28-July 09

parse error in drop down menu

Post icon  Posted 06 January 2010 - 01:32 AM


echo '	   <table border="0" width="530" align="center" cellspacing="1">
					<col width="100" align="right">
				  <col width="410" align="left">				  
		
 		
 			<?php
 				
				$query = "SELECT cat_id,category from ffecategory";
 				$result = @mysql_query($query);
 				$options ="";
 				
 				while ($row = mysql_fetch_array ($result)){
 				 	$cat_id = $row['id'];
 				 	$category = $row['category'];
					echo'<option value=\"$cat_id\">".$category.'</option>';
					}

 			 ?>
 					 <tr><td>Category</td>
					 <td><SELECT NAME =cat_id>
					 <OPTION VALUE =0>Choose Category
					 <?=$options?>
					 </SELECT>
					 
					 
					 </td>
				  </tr>




It produces this error :
Parse error: parse error, unexpected T_STRING, expecting ',' or ';' in /var/www/html/ffe/update.php on line 120

need some help please

Is This A Good Question/Topic? 0
  • +

Replies To: parse error in drop down menu

#2 no2pencil  Icon User is offline

  • Admiral Fancy Pants
  • member icon

Reputation: 5345
  • View blog
  • Posts: 27,296
  • Joined: 10-May 07

Re: parse error in drop down menu

Posted 06 January 2010 - 01:40 AM

Don't you just love syntax highlighting?

Attached Image

Your single quote in the ROW array is closing the start quote of your echo command. Either escape your quotes or don't use them on array elements.
Was This Post Helpful? 0
  • +
  • -

#3 raven21  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 34
  • Joined: 28-July 09

Re: parse error in drop down menu

Posted 06 January 2010 - 02:12 AM

I tried removing the qoutes but still same error was showed.
Was This Post Helpful? 0
  • +
  • -

#4 no2pencil  Icon User is offline

  • Admiral Fancy Pants
  • member icon

Reputation: 5345
  • View blog
  • Posts: 27,296
  • Joined: 10-May 07

Re: parse error in drop down menu

Posted 06 January 2010 - 03:20 AM

Your errors are in your syntax. Can you post your updated code please?

Attached Image
Was This Post Helpful? 0
  • +
  • -

#5 raven21  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 34
  • Joined: 28-July 09

Re: parse error in drop down menu

Posted 06 January 2010 - 11:18 PM

echo '	   <table border="0" width="530" align="center" cellspacing="1">
					<col width="100" align="right">
				  <col width="410" align="left">				  
		
 		
 			<?php
 				
				$query = "SELECT cat_id,category from ffecategory";
 				$result = @mysql_query($query);
 				$options ="";
 				
 				while ($row = mysql_fetch_array ($result)){
 				 	$cat_id = $row[id];
 				 	$category = $row[category];
				 echo	<option value=\"$cat_id\">.$category."</option>;
					}

 			 ?>
 					 <tr><td>Category</td>
					 <td><SELECT NAME =cat_id>
					 <OPTION VALUE =0>Choose Category
					 <?=$options?>
					 </SELECT>
					 


- The drop down menu already appears but it doesn't contain list from the database except for the word "Choose Category". And it also shows
.$category."
before the drop down.

Attached image(s)

  • Attached Image

This post has been edited by raven21: 06 January 2010 - 11:25 PM

Was This Post Helpful? 0
  • +
  • -

#6 no2pencil  Icon User is offline

  • Admiral Fancy Pants
  • member icon

Reputation: 5345
  • View blog
  • Posts: 27,296
  • Joined: 10-May 07

Re: parse error in drop down menu

Posted 06 January 2010 - 11:25 PM

Should work :

  <table border="0" width="530" align="center" cellspacing="1">
	<col width="100" align="right">
	<col width="410" align="left">

<?php
  $query = "SELECT cat_id,category from ffecategory";
  $result = @mysql_query($query);
  $options ="";
?>
	<tr><td>Category</td>
	<td><SELECT NAME =cat_id>
	<OPTION VALUE =0>Choose Category</option>
<?php
  while ($row = mysql_fetch_array ($result)){
	$cat_id = $row[id];
	$category = $row[category];	
	echo "<option value=\"$cat_id\">$category</option>";
  }
?>
  </SELECT>


Was This Post Helpful? 1
  • +
  • -

#7 raven21  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 34
  • Joined: 28-July 09

Re: parse error in drop down menu

Posted 07 January 2010 - 12:38 AM

The codes before the drop down menu disappeared and it still not contain the list from the database.

Attached image(s)

  • Attached Image

This post has been edited by raven21: 07 January 2010 - 12:40 AM

Was This Post Helpful? 0
  • +
  • -

#8 no2pencil  Icon User is offline

  • Admiral Fancy Pants
  • member icon

Reputation: 5345
  • View blog
  • Posts: 27,296
  • Joined: 10-May 07

Re: parse error in drop down menu

Posted 07 January 2010 - 12:57 PM

One of these is not like the other...


  $query = "SELECT cat_id,category from ffecategory";
  $cat_id = $row[id];


Was This Post Helpful? 0
  • +
  • -

#9 RPGonzo  Icon User is offline

  • // Note to self: hmphh .... I forgot
  • member icon

Reputation: 151
  • View blog
  • Posts: 954
  • Joined: 16-March 09

Re: parse error in drop down menu

Posted 07 January 2010 - 01:40 PM

You should ALWAYS ALWAYS ALWAYS enclose the array element with quotes, PHP will throw notices if you have it without them and could cause more issues down the row.

The error with your original code was in this one line

echo'<option value=\"$cat_id\">.$category.'</option>';



you stepped out of your echo quote with a double quote instead of a single quote, should look like

echo'<option value="' . $cat_id . '">' . $category . '</option>';



notice the step out of the single quote before the variable $cat_id and $category and also the removlal of the escaping of the double quotes around $cat_id

if you don't want to have to step in and out of the echo line you could also use something along the lines of

echo"<option value='$cat_id'>$category</option>";



as long as all your data within your variables are properly escaped

again i can't stress how much you NEED the quotes in the array elements

RIGHT
$cat_id = $row['id'];



WRONG
$cat_id = $row[id];


This post has been edited by RPGonzo: 07 January 2010 - 01:50 PM

Was This Post Helpful? 0
  • +
  • -

#10 relic5.2  Icon User is offline

  • D.I.C Head

Reputation: 8
  • View blog
  • Posts: 50
  • Joined: 26-November 08

Re: parse error in drop down menu

Posted 07 January 2010 - 02:26 PM

only use echo"<option value='$cat_id'>$category</option>"; when the variable doesn't use a single quote. It'd be preferable enclose the variable in escaped double quotes for that reason.

This post has been edited by relic5.2: 07 January 2010 - 02:29 PM

Was This Post Helpful? 0
  • +
  • -

#11 RPGonzo  Icon User is offline

  • // Note to self: hmphh .... I forgot
  • member icon

Reputation: 151
  • View blog
  • Posts: 954
  • Joined: 16-March 09

Re: parse error in drop down menu

Posted 07 January 2010 - 03:15 PM

hence my statement right after that line of properly escaped data, i have no issues using this method in ALL of my code but i do insure all data is properly sanitized before hand
Was This Post Helpful? 0
  • +
  • -

#12 relic5.2  Icon User is offline

  • D.I.C Head

Reputation: 8
  • View blog
  • Posts: 50
  • Joined: 26-November 08

Re: parse error in drop down menu

Posted 07 January 2010 - 07:44 PM

Normal methods of escaping data for displaying on a webpage will not escape single quotes. addslashes in that case is not correct. a str_replace would have to be done, and that's not taught in most manuals, so it makes sense to highlight a method of escaping them properly.

This post has been edited by relic5.2: 07 January 2010 - 07:45 PM

Was This Post Helpful? 0
  • +
  • -

#13 raven21  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 34
  • Joined: 28-July 09

Re: parse error in drop down menu

Posted 07 January 2010 - 08:07 PM

@relic5.2

I'd already tried doing your codes but it gives me the parse error instead

This post has been edited by raven21: 07 January 2010 - 08:07 PM

Was This Post Helpful? 0
  • +
  • -

#14 relic5.2  Icon User is offline

  • D.I.C Head

Reputation: 8
  • View blog
  • Posts: 50
  • Joined: 26-November 08

Re: parse error in drop down menu

Posted 07 January 2010 - 08:10 PM

did you use echo"<option value="$cat_id">$category</option>" ?

echo"<option value=\"$cat_id\">$category</option>" is what should be used.
Was This Post Helpful? 0
  • +
  • -

#15 raven21  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 34
  • Joined: 28-July 09

Re: parse error in drop down menu

Posted 07 January 2010 - 08:15 PM

What should i do next????

I already check my query as well as my connection to database. it works fine.
Was This Post Helpful? 0
  • +
  • -

  • (3 Pages)
  • +
  • 1
  • 2
  • 3