0

I have changed my code and now I have a new error:

Parse error: syntax error, unexpected '<' in
 /webroot/c/o/..../...../www/a/drop_down_car_test.php on line 19 

here is the code:

<?php

//////connecting to our sql server
$db_connect=mysql_connect("xxxx", "xxxxxxxxx", "xxxxxxxxxx")     or die("not logged in");
//////now selecting our database
$db_select=mysql_select_db("coden003_car") or die(mysql_error());
////this query is used the first time the page loads
$query = mysql_query("SELECT * FROM car "); 

echo '<form action="drop_down_car_test.php?" method="GET">';
echo '<table border = \"1\">';
echo '<tr><td>id</td><td>car</td><td>name</td>';

while($row=mysql_fetch_array($query)){
echo "<tr><td>";
echo $row['id'];
echo "</td><td>";
echo "<select name='carDropDown." . $row['id'] . "' >";
<option value="1">ford</option>;  <---------line 19
<option value="2">toyota</option>;
<option value="3">gmc</option>;
</select>";
echo "</td><td>";
echo $row['name'];
echo "</td><td>";
}////end while
echo"<table>";

echo '<td bgcolor=#7FFF00><input type="submit" value="Update"></td>';
echo "</form>";

?>

im use to C++ usage of quotes and PHP confuses me.

3
  • the html at the top should have a <?php ?> tag for the PHP part, and in your PHP code at the bottom, you have a syntax error in $_GET[]. what are you trying to do and what's "not working?" Commented Dec 4, 2012 at 23:33
  • The problem is how you output the id_field in your html, you must switch to php: <select name="carDropDown<?php print $row['id_field']; ?>">. When you have a problem like this try printing out the contents of the array to see what's going on: print_r($_GET); Commented Dec 4, 2012 at 23:34
  • That's a poor name for select, but what you want is $_GET['carDropDown.$row[\'id_field'\]'] Commented Dec 4, 2012 at 23:55

3 Answers 3

1

In your code:

echo '<select name="carDropDown.$row['id']">

You need to make it:

echo "<select name=\"carDropDown.{$row['id']}\">

You were not escaping the ', but also you can't use a variable inside single quotes, but you can use one inside double quotes (array calls must be wrapped in { and }).

And of course the closing ' at the end of that string needs to be changed to "

And you're missing a semicolon at the end of that string.

And you didn't close the block (you forgot a closing }).

Sign up to request clarification or add additional context in comments.

Comments

0

Try these:

echo "<select name='carDropDown." . $row['id'] . "' >";

OR

echo "<select name=carDropDown.$row['id'] >";

In PHP you can CONCAT strings like this:

echo "hello" . "world" . $yourVariable . " Something else ";

http://php.net/manual/en/internals2.opcodes.concat.php

Comments

0

Another way to do the <select> name, which will make it a little easier to read on the $_GET[] is to make carDropDown an array with the $row['id'] as the array key.

echo '<select name="carDropDown['.$row['id'].']">

Now on the php side you can do -

foreach ($row['id'] as $id){
$carName=$_GET['carDropDown'][$id]];
echo $carName;}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.