-1

I want to create a drop down menu list for quantity of stock avilable. This is the code I have done so so far but it does not work at all. This error appears:

Parse error: syntax error, unexpected 'basket' (T_STRING), expecting ',' or ';'

    <?php

include("db.php");
//create a variable called $pagename which contains the actual name of the page
$pagename="Product Information";

//call in the style sheet called ystylesheet.css to format the page as defined in the style sheet
echo "<link rel=stylesheet type=text/css href=mystylesheet.css>";

//display window title
echo "<title>".$pagename."</title>";
//include head layout 
include ("headfile.html");

echo "<p></p>";
//display name of the page and some random text
echo "<h2>".$pagename."</h2>";


//retrieve the product id passed from the previous page using the $_GET superglobal variable
//store the value in a variable called $prodid
$prodid=$_GET['u_prodid'];
//echo "<p>Selected product Id: ".$prodid;

//query the product table to retrieve the record for which the value of the product id 
//matches the product id of the product that was selected by the user
$prodSQL="select prodId, prodName, prodPicName, 
prodDescrip , prodPrice, prodQuantity from product
where prodId=".$prodid;
//execute SQL query
$exeprodSQL=mysql_query($prodSQL) or die(mysql_error());
//create array of records & populate it with result of the execution of the SQL query

$thearrayprod=mysql_fetch_array($exeprodSQL);

//display product name in capital letters

echo "<p><left><b>".strtoupper($thearrayprod['prodName'])."</b></left>";
echo "<p><img src=images/".($thearrayprod['prodPicName']).">";
echo "<p><left>".($thearrayprod['prodDescrip'])."</left>";

echo "<br>";
echo "<br>";
echo "GBP<left> ".($thearrayprod['prodPrice'])."</left>";
echo "<br>";
echo "<br>";
echo "Number in stock:<left> ".($thearrayprod['prodQuantity'])."</left>";

//display form made of one text box and one button for user to enter quantity
//pass the product id to the next page basket.php as a hidden value
echo "<form action="basket.php" method=post>";
echo "<p><span style="text-align: center";>Enter required Quantity: ";
echo '<select name="options">';
for($i=1; $i<=4; $i++)
{
    echo "<option value=".$i.">".$i."</option>";
}
echo '</select>';

echo "<input type=hidden name=h_prodid value=".$prodid.">";
echo "<input type=submit value='Add to Basket'>";
echo "</span>";
echo "</form>";

//include head layout
include("footfile.html");
?> 
mymiracl
  • 583
  • 1
  • 16
  • 24
Majed Mahmood
  • 1
  • 1
  • 1
  • 4

1 Answers1

0

The submit button has to be outside the <select> tag, not inside the loop creating options.

echo "<form action='basket.php' method='post'>";
echo "<p><span style='text-align: center';>Enter required Quantity: ";
echo '<select name="options">';
for($i=1; $i<=4; $i++)
{
    echo "<option value=".$i.">".$i."</option>";
}
echo '</select>';

echo "<input type='hidden' name='h_prodid' value='".$prodid."'>";
echo "<input type='submit' value='Add to Basket'>";
echo "</span>";
echo "</form>";

You should also use a span with CSS instead of the obsolete <center> tag. And you were missing quotes around the <select name="options"> string. And you should put quotes around attribute values in tags.

Barmar
  • 741,623
  • 53
  • 500
  • 612
  • I edited my code above to show the whole code and I think the error is on the basket – Majed Mahmood Jan 24 '17 at 23:15
  • You have a quoting problem. `echo "
    ";` should be `echo "
    ";` or `echo "
    ";`. You can't use the same quotes inside the string as you use to delimit the string unless you escape them.
    – Barmar Jan 25 '17 at 16:53