0

When I remove the name="prod_info" from the option tag in the first document, I this error: Warning: Undefined array key "prod_info" in C:\xampp\htdocs\ordersummary.php on line 51, which I know is because there is not anything that is defined as prod_info. However, when I add the name="prod_info" line back in to the option tag in the first document, I get this error: Parse error: syntax error, unexpected identifier "prod_info", expecting "," or ";" in C:\xampp\htdocs\products.php on line 64. I've tried using separate echo statements to solve the problem of expecting the , or ; symbols, but I get the same error. I've also tried placing the name="prod_info line in the option tag outside of the php section, but I still just get the Warning: Undefined array key "prod_info" in C:\xampp\htdocs\ordersummary.php on line 51 error. I'm confused as to how to get the second page to recognize where to pull the data from without using the POST technique. Thank you in advance for any help you are able to provide! The code for the two pages mentioned is listed below:

//The page the info is to be pulled from:

<!DOCTYPE html>
<html>
<head>
   
   <title>Home</title>
   <link href="novusreset.css" rel="stylesheet" />
   <link href="novusstyles1.css" rel="stylesheet" />
   <link href="novusstyles2.css" rel="stylesheet" />
   <link href="novusflex.css" rel="stylesheet" /> 
   <link href="novusnavicon.css" rel="stylesheet" />
   <link href="novustables.css" rel="stylesheet" />
   <meta charset="utf-8" />
   <meta name="viewport" content="width=device-width, initial-scale=1" />  
</head>

<body>
   <header>
     <a href="index.html"><img src="novuslogo.png" alt="Novus LLC." /></a>
      
      <nav class="horizontal">
        <a id="navicon" href="#"><img src="novusnavicon.png" alt="" /></a>
         <ul id="navigation">
               <li><a href="index.html" class="first">Home</a></li>
             <li><a href="products.php">Products </a>
        <ul id="productlist">
           <li><a href="products.php">PC Parts</a></li>
           <li><a href="products.php">Peripherals</a></li>
            <li><a href="products.php">Networking</a></li>
            <li><a href="products.php">Drinks</a></li>
           <li><a href="products.php">Apparel</a></li>
           
       </ul>
             
           <li><a href="about.html">About</a></li>
           <li><a href="support.html">Support</a></li>
           <li><a href="account.html">Account</a></li>
           <li><a href="cart.html">Cart</a></li>
       </ul>
      </nav>
   </header>
   
   
   <section id="main">
      <article id="overview">
          <form action="ordersummary.php" method="post">
              <label for="products"><h1>Choose a product</h1></label>
  <select name="products" id="products">
      <option name="orderinfo">
      
<?php 


include('connection.php'); 

$query = "SELECT * FROM products";
$result = mysqli_query( $conn, $query );

if(mysqli_num_rows($result) > 0) {
 
while( $row = mysqli_fetch_assoc($result) ){
    echo "<option name="prod_info">" . $row["prod_name"] . " $" . $row["prod_price"] .      "</option>";
} 
   
} else{
    echo "Ahhh yes, the big empty.";
}
mysqli_close( $conn );
?>
      </br>
    </br>
          </option>
      </select>
      <label class="container">Gift Wrapping
<input type="checkbox">
<span class="checkmark"></span>
</label>
       </br>
<label class="container">Gift Tagging
<input type="checkbox">
<span class="checkmark"></span>
</label>
       </br>
       </br>
<input type="submit" value="Place Order">
</form>
</article>
</section>
 <footer>
       &copy;2021-Novus LLC. &#8226; 201 Main St. &#8226; Galena Il
   </footer>
</body>
</html>

//The page that displays the info pulled from the above page in table form for the customer.

<!DOCTYPE html>
<html>
<head>
   
   <title>Home</title>
   <link href="novusreset.css" rel="stylesheet" />
   <link href="novusstyles1.css" rel="stylesheet" />
   <link href="novusstyles2.css" rel="stylesheet" />
   <link href="novusflex.css" rel="stylesheet" /> 
   <link href="novusnavicon.css" rel="stylesheet" />
   <link href="novustables.css" rel="stylesheet" />
   <meta charset="utf-8" />
   <meta name="viewport" content="width=device-width, initial-scale=1" />  
</head>

<body>
   <header>
     <a href="index.html"><img src="novuslogo.png" alt="Novus LLC." /></a>
      
      <nav class="horizontal">
        <a id="navicon" href="#"><img src="novusnavicon.png" alt="" /></a>
         <ul id="navigation">
               <li><a href="index.html" class="first">Home</a></li>
             <li><a href="products.php">Products </a>
        <ul id="productlist">
           <li><a href="products.php">PC Parts</a></li>
           <li><a href="products.php">Peripherals</a></li>
            <li><a href="products.php">Networking</a></li>
            <li><a href="products.php">Drinks</a></li>
           <li><a href="products.php">Apparel</a></li>
           
       </ul>
             
           <li><a href="about.html">About</a></li>
           <li><a href="support.html">Support</a></li>
           <li><a href="account.html">Account</a></li>
           <li><a href="cart.html">Cart</a></li>
       </ul>
      </nav>
   </header>
   
   
   <section id="main">
      <article id="overview">
          <h1>Order Summary</h1></br>
         <table id="customers">
<?php
$prod_info = $_POST['prod_info'];                      
?>
  
             
<tr>
    <th>Order Details:</th>
    
</tr>
                <tr>
      <td><?php echo prod_info;?></br></td>
</tr>
  
</table>
          
      </article>
                
   </section>       
 
   <footer>
       &copy;2021-Novus LLC. &#8226; 201 Main St. &#8226; Galena Il
   </footer>
</body>
</html>
M. Eriksson
  • 13,450
  • 4
  • 29
  • 40
wno7736
  • 1
  • 2

1 Answers1

0

Let's take a look at this error: "Parse error: syntax error, unexpected identifier "prod_info", expecting "," or ";" in". The offending line is:

echo "<option name="prod_info">" . $row["prod_name"] . " $" . $row["prod_price"] .      "</option>";

The issue here is that you are using double quotes nested inside another set of double quotes. Let's just look at the part before the first period [.].

The first thing happening here is that a string is defined and there is no syntax error:

"<option>"

Next, an attribute is added to the html <option> tag:

"<option name="prod_info">"

There is a set of double quotes inside another set of double quotes which introduces a syntax error. I would suggest using single quotes for the outside and double quotes for the inside. The following code should fix your error:

echo '<option name="prod_info">' . $row["prod_name"] . " $" . $row["prod_price"] . "</option>";

Fixing this issue should also fix your undefined index issue however, I should add that it is always best to check if an array key exists before calling it. Instead of:

$prod_info = $_POST['prod_info'];

You might want to do something like:

$prod_info = isset($_POST['prod_info']) ? $_POST['prod_info'] : '';

or, if you are using php 7.4+:

$prod_info = $_POST['prod_info'] ?? '';
Rowan
  • 1
  • 1