Im building a form page for prospective clients to complete a survey.
first they log in:
function print_form() {
?>
<form action="index.php" method="POST">
<h3>Please Login</h3>
User Name: <input type="text" name="username">
<br>Password: <input type="password" name="user_password">
<input type="submit" name="submit1" value="Login">
</form>
<?
}
if(isset($submit1)):
if(!$db = mysql_connect("$dbhost","$dbusername","$dbuserpassword")):
print("<h1>Can't Connect to the Database</h1>\n");
else:
mysql_select_db("$default_dbname");
endif;
$sql = "select * from user where username = '$username'";
$result = mysql_query($sql);
$row_count = mysql_num_rows($result);
if($row_count == 0):
?>
<h3>Invalid User Name!</h3>
<?
print_form();
else:
$row = mysql_fetch_array($result);
if($user_password != $row["user_password"]):
?>
<h3>Incorrect Password!</h3>
<?
print_form();
else:
?>
Pretty straight forward, if correct username and password:
up comes the survey form:
<?php
if(isset($submit2)):
$db = mysql_connect("$dbhost", "$dbusername", "$dbuserpassword");
mysql_select_db("$default_dbname", $db);
$sql = "INSERT INTO $user_tablename
VALUES('$client_id','$name','$title','$email','$url')";
mysql_query($sql);
print("<table border=\"0\" width=\"100%\" align=\"left\"><tr>");
print("<td colspan=\"4\" align=\"left\">");
print("<h2>Thank you <br>Your Data Has Been Entered</h2><br>");
//print("<b>Click <a href=\"result.php\">here</a> to see the results.</b>\n");
print("<br>");
print("</td></tr>");
print("<tr><td>");
endif;
?>
The HTML form is here and ends with:
<tr><td colspan="4" align="center"><input type="submit" name="submit2" value="Submit">
</form>
<?php
endif;
endif;
else:
print_form();
endif;
?>
On submit it the script seems to call the 1st "if(isset($submit1)):" and the login form gets printed to the page. Is there a simple fix? I dont want to go throught the trouble of having separate pages and creating a session. Thanks a bunch for any help -Eron