digitaldragoon Posted January 28, 2010 Share Posted January 28, 2010 I'm fairly new to php and I can very well have syntax mistakes so please don't pull any punches. I'm trying to set up a page that shows a form then once it is submitted, pulls database info. Unfortunately, as soon as I load the page, it comes up blank. I can see the form in Dreamweaver, so I have no idea. Here is the script: <?php if(!isset($_POST['submit'])) { // form not submitted ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Therapy Summary</title> </head> <body> <form action="therapy_summary.php" method="post"> First Name: <input type="text" name="firstname"> Last Name: <input type="text" name="lastname"> <input type="submit" name="submit"> </form> <?php } else{ // form submitted, set server access variables $host = "+++"; $user = "+++"; $pass = "+++"; $db_name = "+++"; $table_name = "total2"; // open connection $mysqli = new mysqli($host, $user, $pass, $db); // check for connection errors if (mysqli_connect_errno()){ die("Unable to connect!"); // get form input, check that it's all there, escape input values for safety $firstN = empty($_POST['firstname']) ? die ("Error: Enter a first name") : mysqli_escape_string($_POST['firstname']); $lastN = empty($_POST['lastname']) ? die ("Error: Enter a first name") : mysqli_escape_string($_POST['lastname']); // query to get records $query = "SELECT * FROM `$table_name` WHERE `first_name` = '$firstN' and `last_name` = 'lastN' "; // execute query if ($result = $mysqli->query($query)){ // see if any rows were returned if($result->num_rows > 0){ //yes, then print them one after another echo "<table cellpadding=10 border=1>"; while($row = $result->fetch_array()){ echo "<tr>"; echo "<td>".$row[0]."</td>"; echo "<td>".$row[1]."</td>"; echo "<td>".$row[3]."</td>"; echo "<td>".$row[4]."</td>"; echo "<td>".$row[5]."</td>"; echo "</tr>"; } } // free result set memory $result->close(); }// close connection mysqli_close($dbh); } ?> </body> </html> Any assistance would be greatly appreciated. Link to comment https://forums.phpfreaks.com/topic/190075-form-wont-appear-on-page-load/ Share on other sites More sharing options...
teamatomic Posted January 28, 2010 Share Posted January 28, 2010 You need to close your else. Add a closing curly bracket above the ending php tag/ HTH Teamatomic Link to comment https://forums.phpfreaks.com/topic/190075-form-wont-appear-on-page-load/#findComment-1002848 Share on other sites More sharing options...
Yucky Posted January 28, 2010 Share Posted January 28, 2010 Just to point out that the HTML is going to be displayed regardless of whether or not the form has been filled out given that it's outside of PHP's control. I presume the intention was to hide the form if it'd been filled out anyway. Link to comment https://forums.phpfreaks.com/topic/190075-form-wont-appear-on-page-load/#findComment-1002873 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.