Reputation: 1619
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.
Upvotes: 0
Views: 98
Reputation: 12433
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;}
Upvotes: 0
Reputation: 1698
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
Upvotes: 0
Reputation: 1389
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 }
).
Upvotes: 1