Display information from MySQL Database on page using PHP -
i have database called test. in there table called people. people has 4 fields: fname, lname, age, city. have page form people can enter in data.
<?php include('header.php'); ?> <body> <form action="getinformation.php" method="post" id="getinformation"> <div id="header"> <h1><strong>search data</h1></strong> </div> <div id="main"> <table border="0" width="75%"> <tr> <td align="right" width="10%">first name: </td> <td><input type="text" name="fname" id="fname" size="20" /></td> </tr> <tr> <td align="right" width="10%">last name: </td> <td><input type="text" name="lname" id="lname" size="20" /></td> </tr> <tr> <td align="right" width="10%">age: </td> <td><input type="text" name="age" id="age" size="3" /></td> </tr> <tr> <td align="right" width="10%">city: </td> <td><input type="text" name="city" id="city" size="20" /></td> </tr> </table> <input type="submit" /> </div> </body> <?php include('footer.php'); ?> when submit button clicked send data page named getinformation.php.
<?php require_once('model.php'); $query = "select * people where"; if (isset ($post_fname) { $fname = $_post['fname']; $query = $query . " fname = " . $fname . " and" } if (isset ($post_lname) { $lname = $_post['lname']; $query = $query . " lname = " . $lname . " and" } if (isset ($post_age) { $age = $_post['age']; $query = $query . " age = " . $age . " and" } if (isset ($post_city) { $city = $_post['city']; $query = $query . " city = " . $city . " and" } $query = rtrim($query, " and"); ?> <div id=/"header/"> <h1><strong>this information requested</h1></strong> </div> <div id=/"main/"> <?php $statement = $db->prepare($query); $statement->execute(); $products = $statement->fethall(); $statement->closecursor(); foreach ($products $product) { echo $product['fname'] . " " . $product['lname'] . " | " . $product['age'] . " | " . $product['city'] . '<br />'; ?> </div> <?php include('footer.php'); ?> i error
parse error: syntax error, unexpected '{' in c:\program files\wamp\www\testwebpage\model\getinformation.php on line 6 i have had problem before isset function aside working i'm wondering if rest of code looks fine (assuming isset worked perfectly)
you have syntax error - missing closing parenthesis:
if (isset ($post_fname) { should be
if (isset ( ..... ) ) {
Comments
Post a Comment