March 28, 201016 yr <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> <html> <head> <title>Search Page</title> </head> <?php if(isset($_POST['search'])) { include "db.php"; $prod = $_POST["prodname"]; $query = "SELECT prodname,features,details,moredet,picture,price FROM `nokia` WHERE prodname=$prod"; $result = mysql_query($query) or die(mysql_error()); while($row = mysql_fetch_array($result)){; ?> <body> <center> <form method="post" action="<?php echo $PHP_SELF; ?>"> Mobile Phone Type:<br /> <input type="text" name="prodname" value=""/> <input type="submit" name="search" value="Search!"/> </form> <table width="924" height="111" border="1"> <tr> <td width="140" height="36"><u>Product:</u></td> <td width="185"><u>Features:</u></td> <td width="198"><u>Details:</u></td> <td width="228"><u>More Details: </u></td> <td width="95"><u>Picture: </u></td> <td width="38"><u>Price: </u></td> </tr> <tr> <td height="62"><?php echo $row['prodname']; ?></td> <td><?php echo $row['features']; ?></td> <td><?php echo $row['details']; ?></td> <td><?php echo $row['moredet']; ?></td> <td><?php echo "<img src=\"".$row['picture']."\">"; ?></td> <td><?php echo "£".$row['price']; ?></td> <?php }; }; ?> </tr> </table> </center> </body> </html> The problem with this is it shows a blank page but not the table....can anyone help? Thankyou.
March 28, 201016 yr Either change this line : <?php echo $PHP_SELF; ?> to <?php echo $_SERVER['PHP_SELF']; ?> or leave the action blank action=""
March 28, 201016 yr oh and it looks like it depends on the $_POST['search'] to even display the form including the submit button Move your if(isset) condition after the submit button /form has been displayed
March 28, 201016 yr Author <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> <html> <head> <title>Search Page</title> </head> <?php if(isset(['search'])) { include "db.php"; $prod = $_POST["prodname"]; $query = "SELECT * FROM `nokia` WHERE prodname=$prod"; $result = mysql_query($query) or die(mysql_error()); while($row = mysql_fetch_array($result)){; ?> <body> <center> <form method="post" action=""> Mobile Phone Type:<br /> <input type="text" name="prodname" value=""/> <input type="submit" name="search" value="Search!"/> </form> <table width="924" height="111" border="1"> <tr> <td width="140" height="36"><u>Product:</u></td> <td width="185"><u>Features:</u></td> <td width="198"><u>Details:</u></td> <td width="228"><u>More Details: </u></td> <td width="95"><u>Picture: </u></td> <td width="38"><u>Price: </u></td> </tr> <tr> <td height="62"><?php echo $row['prodname']; ?></td> <td><?php echo $row['features']; ?></td> <td><?php echo $row['details']; ?></td> <td><?php echo $row['moredet']; ?></td> <td><?php echo "<img src=\"".$row['picture']."\">"; ?></td> <td><?php echo "£".$row['price']; ?></td> <?php }; }; ?> </tr> </table> </center> </body> </html> I did this but got this when loaded > Parse error: syntax error, unexpected '[', expecting T_STRING or T_VARIABLE or '$' in C:\xampp\htdocs\mobiles\search.php on line 7
March 28, 201016 yr if(isset(['search'])) needs to be if(isset($_POST['search'])) and your php needs to be after the </form> tag otherwise the form will never display
March 29, 201016 yr Author Hey all, I got this working....Thanks for all the help...here is the amended code... <center> <form method="post" action=""> <p><u>Mobile Phone Type:</u><br /> <select name="prodname"> <option value="Nokia N97">Nokia N97</option> <option value="Nokia 5800">Nokia 5800</option> <option value="LG 600">LG 600</option> <option value="Samsung 8210">Samsung 8210</option> <option value="Samsung 9000">Samsung 9000</option> <option value="Samsung 2010">Samsung 2010</option> <option value="Samsung 9685">Samsung 9685</option> </select> From Database: <select name="database"> <option value="nokia">Nokia Telecom</option> <option value="lg">Lifes Good (LG)</option> <option value="samsung">Samsung Mobile</option> </select> <br /> <input type="submit" name="search" value="Search!"/> </p> <p><u><strong>Invalid Selection of database will result in a NIL result</strong></u></p> </form> <?php if(isset($_POST['search'])) { include "db.php"; $prod = $_POST["prodname"]; $database = $_POST["database"]; $query = "SELECT * FROM `$database` WHERE prodname='$prod'"; $result = mysql_query($query) or die(mysql_error()); while($row = mysql_fetch_array($result)){ ?> <table width="924" height="111" border="1"> <tr> <td width="140" height="36"><u>Product:</u></td> <td width="185"><u>Features:</u></td> <td width="198"><u>Details:</u></td> <td width="228"><u>More Details: </u></td> <td width="95"><u>Picture: </u></td> <td width="38"><u>Price: </u></td> </tr> <tr> <td height="62"><?php echo $row['prodname']; ?></td> <td><?php echo $row['features']; ?></td> <td><?php echo $row['details']; ?></td> <td><?php echo $row['moredet']; ?></td> <td><?php echo "<img src=\"".$row['picture']."\">"; ?></td> <td><?php echo "£".$row['price']; ?></td> <?php }; }; ?> </tr> </table> </center>
Create an account or sign in to comment