I'm currently trying to add a data input form to a login system.
However currently my code won't let me input anything, but just logs me out instead. I have a sign up page that works perfectly, but adding another page for data input has been tricky. Any help would be appreciated.
The page that causing me issues....
<?
include("include/activity.php");
?>
<?
/**
* If user is not logged in, then do not display anything.
* If the user is logged in they cab book
* account information, with the current email address
* already in the field.
*/
if($session->logged_in){
if(isset($_SESSION['bookingSuccess'])){
/* Registration was successful */
if($_SESSION['bookingSuccess']){
echo "<h1>Booked</h1>";
echo "<p>Thanks!".$_SESSION['bookingName']."</b>, your booking is now part of the system! "
."Click here <a href=\"main.php\">to go back</a>.</p>";
}
/* Registration failed */
else{
echo "<h1>Failed to Book</h1>";
echo "<p>Theres been a error for that roomname<b>".$_SESSION['bookingName']."</b>, "
."could not be completed.<br>Please try again at a later time.</p>";
}
unset($_SESSION['bookingSuccess']);
unset($_SESSION['bookingName']);
}
?>
<html>
<title>Room Booking</title>
<body>
<?
if($form->num_errors > 0){
echo "<td><font size=\"2\" color=\"#ff0000\">".$form->num_errors." error(s) found</font></td>";
}
?>
<h1>Room Booking in name of: <? echo $session->username; ?></h1>
<form action="process.php" method="POST">
Room Name : <input type="text" name="roomname" maxlength="10" value="<? echo $form->value("roomName"); ?>"></td><td><? echo $form->error("roomName"); ?>
<input name="send" type="submit" value="Submit">
<tr><td colspan="2" align="left"><a href="main.php">Back to Main</a></td></tr>
</table>
</form>
<?
}
?>
</body>
</html>
Taken from my sql php page:
function bookingAdd($roomname){
$q = "INSERT INTO ".tb_booking." VALUES ('$roomname')";
return mysql_query($q, $this->connection);
}
The function from activity.php that relates to this page.
function booking($roomname){
global $database, $form, $mailer; //The database, form and mailer object
/* Username error checking */
$field = "roomName"; //Use field name for roomname
if(!$roomname || strlen($roomName = trim($roomName)) == 0){
$form->setError($field, "* Roomname not entered");
}
else{
/* Spruce up username, check length */
$subuser = stripslashes($subuser);
if(strlen($subuser) < 2){
$form->setError($field, "* Roomname below 2 characters");
}
else if(strlen($subuser) > 10){
$form->setError($field, "* Roomname above 30 characters");
}
}
}
and finally the function related to process.php
function procBooking(){
global $session, $form;
/* Convert username to all lowercase (by option) */
if(ALL_LOWERCASE){
$_POST['roomName'] = strtolower($_POST['roomName']);
}
/* Registration attempt */
$retval = $session->booking($_POST['roomName']);
/* Registration Successful */
if($retval == 0){
$_SESSION['bookingName'] = $_POST['user'];
$_SESSION['bookingSuccess'] = true;
header("Location: ".$session->referrer);
}
/* Error found with form */
else if($retval == 1){
$_SESSION['value_array'] = $_POST;
$_SESSION['error_array'] = $form->getErrorArray();
header("Location: ".$session->referrer);
}
/* Registration attempt failed */
else if($retval == 2){
$_SESSION['bookingName'] = $_POST['roomName'];
$_SESSION['bookingSuccess'] = false;
header("Location: ".$session->referrer);
}
}