Jump to content

Submit Form Not Processing


SalientAnimal
Go to solution Solved by Ch0cu3r,

Recommended Posts

Hi all,

 

I have created a form that is submitting to my database. I have adjusted some of my submit script that I am using on my registration for to submit the data captured on the form, but for some reason the data isn't being captured into my database table.

 

Here is my code:

FORM:

<div id="container">
		<div id="content" style="margin-top:-45px;">
		<img src="images/logo.png" alt="TechDesignLab"></img>
			<h1>Auxilium</h1>
			
		
		<div id="stylized" class="form">
			<form id="form" name="form" method="post" action="process/submit_walkin.php">
			<h1>Walkin Customer Details</h1>
			<p>This is the basic form layout. We can edit it as required.</p>

			
			<label>User Logged In :
			<span class="small">You are logged in as</span>
			</label>
			<input type="text" name="name" id="name" value="<?php echo htmlentities($_SESSION['username']);?>" disabled>
			
			
			
			<label>Customer Name :
			<span class="small">Add the customer's name</span>
			</label>
			<input type="text" name="name" id="name"/>

			
			<label>Customer Surname :
			<span class="small">Add the customer's surname</span>
			</label>
			<input type="text" name="name" id="name"/>


			<label>Contact Number :
			<span class="small">Add a contact number</span>
			</label>
			<input type="text" name="email" id="email" />


			<label>E-Mail :
			<span class="small">Add an e-mail address</span>
			</label>
			<input type="text" name="password" id="password" />


			<label>Query Type :
			<span class="small">Select a query type</span>
			</label>
			<select id="select1" name="select1">
				<option value=""> -- Select the query Type --</option>
				<option value="3rd Party">3rd Party</option>
				<option value="Cashier">Cashier</option>
				<option value="Client Liaison Consultant">Client Liaison Consultant</option>
				<option value="Credit Control Consultant">Credit Control Consultant</option>
				<option value="Insurance Consultant">Insurance Consultant</option>
				<option value="Manager">Manager</option>
				<option value="Meeting/Interview">Meeting/Interview</option>
				<option value="Premier Client Consultant">Premier Client Consultant</option>
				<option value="Retail Shop Consultant">Retail Shop Consultant</option>
				<option value="Retention Collection">Retention Collection</option>
				<option value="Tech Deck Consultant">Tech Deck Consultant</option>
			</select>

			<input type="button" value="Submit" class="bt_login" onclick="formhash(this.form, this.form.password);"/> 
			</form></div>
			
		<br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br>
		</div><!-- / content -->		
	</div><!-- / container -->
</body>



<div id="container">
<div id="footer" style="margin-top:10px;">

<footer style="background:#E5E5E5; height:20px">
  <p>Copyright © TechDesignLab 2014 | <a href="mailto:leon.claassen@techdesignlab.co.za">Contact Us</a>.</p>
  <img src="images/logo.png" alt="Footer Logo" align="left"></img>
  <img src="images/level2.png" alt="level2" align="left"></img>
</footer>
</div><!-- / footer -->		
</div><!-- / container -->
</html>

My Submit Code:

<!-- process/submit_walkin.php -->


<?php
include_once '../includes/db_connect.php';
include_once '../includes/psl-config.php';

$error_msg = "";

if (isset($_POST['username'], $_POST['fname'], $_POST['lname'], $_POST['msisdn'], $_POST['email'], $_POST['query1'])) 
{
    // SANITIZE AND VALIDATE THE DATA BEING PROCESSED BY THE FORM
		$username = filter_input(INPUT_POST, 'username', FILTER_SANITIZE_STRING);
		$fname = filter_input(INPUT_POST, 'fname', FILTER_SANITIZE_STRING);
		$lname = filter_input(INPUT_POST, 'lname', FILTER_SANITIZE_STRING);
		$email = filter_input(INPUT_POST, 'email', FILTER_SANITIZE_EMAIL);
		$query1 = filter_input(INPUT_POST, 'query1', FILTER_SANITIZE_STRING);
		$email = filter_var($email, FILTER_VALIDATE_EMAIL);

  

    $stmt = $mysqli->prepare($prep_stmt);

    // TODO: 
    // We'll also have to account for the situation where the user doesn't have
    // rights to do registration, by checking what type of user is attempting to
    // perform the operation.

    if (empty($error_msg)) 
	{
        // Insert the new user into the database 
        if ($insert_stmt = $mysqli->prepare("INSERT INTO walkin (username, fname, lname, msisdn, email, query1, creation_time) 
														 VALUES (?, ?, ?, ?, ?, ?, now())")) 
		{
            $insert_stmt->bind_param($fname, $lname, $msisdn, $email, $query1, $creation_time);
            // Execute the prepared query.
            if (! $insert_stmt->execute()) 
			{
                header('Location: ../error.php?err=Registration failure: INSERT');
            }
        }
        header('Location: ./success.html');
    }
}

?>


Edited by SalientAnimal
Link to comment
Share on other sites

Your $_POST keys you're checking aren't the same as the input name's

<input type="text" name="name" id="name" value="<?php echo htmlentities($_SESSION['username']);?>" disabled>
<input type="text" name="name" id="name"/>
<input type="text" name="name" id="name"/>
<input type="text" name="email" id="email" />
<input type="text" name="password" id="password" />
<select id="select1" name="select1">

if you submit this the $_POST will be filled with these inputs.

The keys of the $_POST array will be formed by the name propperty from your input fields.

 

Example:

$_POST['name'] = 'Lorem';
$_POST['email'] = 'Lorem';
$_POST['password'] = 'Lorem';
$_POST['select1'] = 'Lorem';

However, your check starts with:

if (isset($_POST['username'], $_POST['fname'], $_POST['lname'], $_POST['msisdn'], $_POST['email'], $_POST['query1'])) 

Change your <input> name propperties to username, fname, lname, msisdn, email and query1

Link to comment
Share on other sites

I added

$username = $_SESSION['username']

at the top of my page and I get the undefined variable error, so I have just made the field hidden on the form. It would nice to have it, but I just can't get it to work. The form is now processing through to the success.php, but no form data is being submitted to the database table.

 

My code as it looks now:

 

Form:

 <div id="container">
		<div id="content" style="margin-top:-45px;">
		<img src="images/logo.png" alt="TechDesignLab"></img>
			<h1>Auxilium</h1>
			
		
		<div id="stylized" class="form">
			<form id="form" name="form" method="post" action="process/submit_walkin.php">
			<h1>Walkin Customer Details</h1>
			<p>This is the basic form layout. We can edit it as required.</p>

			
			<label>User Logged In :
			<span class="small">You are logged in as</span>
			</label>
			<input type="text" name="username" id="username" value="<?php echo htmlentities($_SESSION['username']);?>" hidden>
			
			
			
			<label>Customer Name :
			<span class="small">Add the customer's name</span>
			</label>
			<input type="text" name="fname" id="fname"/>

			
			<label>Customer Surname :
			<span class="small">Add the customer's surname</span>
			</label>
			<input type="text" name="lname" id="lname"/>


			<label>Contact Number :
			<span class="small">Add a contact number</span>
			</label>
			<input type="text" name="msisdn" id="msisdn" />


			<label>E-Mail :
			<span class="small">Add an e-mail address</span>
			</label>
			<input type="text" name="email" id="email" />


			<label>Query Type :
			<span class="small">Select a query type</span>
			</label>
			<select id="query1" name="query1">
				<option value=""> -- Select the query Type --</option>
				<option value="3rd Party">3rd Party</option>
				<option value="Cashier">Cashier</option>
				<option value="Client Liaison Consultant">Client Liaison Consultant</option>
				<option value="Credit Control Consultant">Credit Control Consultant</option>
				<option value="Insurance Consultant">Insurance Consultant</option>
				<option value="Manager">Manager</option>
				<option value="Meeting/Interview">Meeting/Interview</option>
				<option value="Premier Client Consultant">Premier Client Consultant</option>
				<option value="Retail Shop Consultant">Retail Shop Consultant</option>
				<option value="Retention Collection">Retention Collection</option>
				<option value="Tech Deck Consultant">Tech Deck Consultant</option>
			</select>
			<input type="button" value="Submit" class="bt_login" onclick="form.submit()"/> 
			</form></div>
			
		<br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br>
		</div><!-- / content -->		
	</div><!-- / container -->
</body>



<div id="container">
<div id="footer" style="margin-top:10px;">

<footer style="background:#E5E5E5; height:20px">
  <p>Copyright © TechDesignLab 2014 | <a href="mailto:leon.claassen@techdesignlab.co.za">Contact Us</a>.</p>
  <img src="images/footer-logo.png" alt="Footer Logo" align="left"></img>
  <img src="images/level2.png" alt="level2" align="left"></img>
</footer>
</div><!-- / footer -->		
</div><!-- / container -->
</html>

And the post form:

<!-- process/submit_walkin.php -->


<?php
include_once '../includes/db_connect.php';
include_once '../includes/psl-config.php';

$error_msg = "";


/* var_dump($_POST);exit;  USED FOR ERROR CHECKING*/

if (isset($_POST['username'], $_POST['fname'], $_POST['lname'], $_POST['msisdn'], $_POST['email'], $_POST['query1'])) 
{
    // SANITIZE AND VALIDATE THE DATA BEING PROCESSED BY THE FORM
		$username = filter_input(INPUT_POST, 'username', FILTER_SANITIZE_STRING);
		$fname = filter_input(INPUT_POST, 'fname', FILTER_SANITIZE_STRING);
		$lname = filter_input(INPUT_POST, 'lname', FILTER_SANITIZE_STRING);
		$email = filter_input(INPUT_POST, 'email', FILTER_SANITIZE_EMAIL);
		$query1 = filter_input(INPUT_POST, 'query1', FILTER_SANITIZE_STRING);
		$email = filter_var($email, FILTER_VALIDATE_EMAIL);

  

    $stmt = $mysqli->prepare($prep_stmt);



    if (empty($error_msg)) 
	{
        // INSERT THE NEW FOR INFORMATION INTO THE DATABASE TABLE
        if ($insert_stmt = $mysqli->prepare("INSERT INTO walkin (username, fname, lname, msisdn, email, query1, creation_time) 
		
														 VALUES (?, ?, ?, ?, ?, ?, now())")) 
		{
			$insert_stmt->bind_param($username, ucfirst($fname), ucfirst($lname), $msisdn, $email, $query1, $creation_time);
            // EXECUTE THE PREPARED QUERY
            if (! $insert_stmt->execute()) 
			{
                header('Location: ../error.php?err=Registration failure: INSERT');
            }
        }
        header('Location: ../success.html');
    }

}

?>


Link to comment
Share on other sites

if you dont want people to be able to edit their username do not make it an input element in your form.

 

if $_SESSION['username'] gives you an error it means that there is no username key in your session.

Check with var_dump($_SESSION) what your session contains.

 

Also, place an exit; right after you set your header(Location .......)  to prevent your code from continuing after setting the header.

header('Location: ../error.php?err=Registration failure: INSERT');
exit;
}
}
header('Location: ../success.html');
exit;
Link to comment
Share on other sites

Ok now I am really confused.

 

I get

Notice: Undefined variable: _SESSION in C:\Development_Tracker\htdocs\process\submit_walkin.php on line 11

 however I started the session on my start page i.e form_template.php using:

<?php
sec_session_start();
if (login_check($mysqli) == true) 
	{
    $logged = 'in';
	} 
else 
	{
    $logged = 'out';
	}
?>

form_template.php is my template that I am going to be using to create my forms. So it is the name of the form that I am currently testing.

Link to comment
Share on other sites

Yip. This is the entire code of the form, I left out the top part of the code cause it has all my java and css includes which is not needed:

<!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" xml:lang="en" lang="en">
<!-- INCLUDING REQUIRED AUTHENTICATION FILES, DATABASE CONNECTIONS, FUNCTIONS. -->


<?php
include_once 'includes/db_connect.php';
include_once 'includes/functions.php';
include_once 'includes/register.inc.php';
?>

<?php
sec_session_start();
if (login_check($mysqli) == true) 
	{
    $logged = 'in';
	} 
else 
	{
    $logged = 'out';
	}
?>

<!--
	Copyright 2014 TechDesignLab
	CRM TRACKING UTILITY
-->







<!-- HEADER CONTENT OF PAGE - THIS CONTAINS ALL SCRIPT, CSS, AND META TAG RELATED INFORMATION FOR THE WEBPAGE -->

<head>
  	<title>TechDesignLab - Auxilium</title>
	<link rel="shortcut icon" href="favicon.ico?v=2"/>	
  	<meta name="description" content="TechDesignLab - Tracker Login Page" />
  	<meta name="keywords" content="login, register, login page, techdesignlab, tech design lab, computer, components, hardware, software, peripherals" />
	<meta http-equiv="content-type" content="text/html; charset=utf-8" />	

	
	<!-- REFERENCING FOR ALL STYLE SHEETS -->
  	<link rel="stylesheet" href="css/style.css" type="text/css" media="screen"/>
  	<link rel="stylesheet" href="css/slide.css" type="text/css" media="screen"/>
	<link rel="stylesheet" href="css/navigation.css" type="text/css" media="screen"/>
	<link rel="stylesheet" href="css/form_template.css" type="text/css" media="screen"/>	
	<!--<link rel="stylesheet" href="css/accordian2.css" type="text/css" media="screen"/>		-->
	

	
 
    <!-- REFERNCE TO MAIN CORE OF jQUERY SCRIPT -->
	<script src="js/jquery-2.0.3.min.js" type="text/javascript"></script>
	
    <!-- REFERNCE TO MAIN CORE OF jQUERY SCRIPT OLD jQUERY SCRIPT
	<script src="js/jquery-1.3.2.min.js" type="text/javascript"></script>
	-->
	<!-- FORM FUNCTIONS - ACCORDION MENU jQUERY -->
	<script src="js/accordion.js" type="text/javascript"></script>	

	
	<!-- MENU SLIDE EFFFECT -->
	<script src="js/slide.js" type="text/javascript"></script>
	
	<!-- SHA512 PASSWORD ENCRIPTION ALGORYTHM -->	
	<script src="js/sha512.js" type="text/javascript"></script>

	<!-- FORM FUNCTIONS -->	
    <script src="js/forms.js" type="text/javascript"></script> 
	
	<!-- EXTERNAL SOURCE FOR jQUERY -->
	<!-- <script src="http://code.jquery.com/jquery-1.10.1.min.js"></script>
	<script src="http://code.jquery.com/jquery-migrate-1.2.1.min.js"></script> 
	-->


	


</head>




<!-- BODY CONTENT OF THE WEBPAGE - THIS IS HOW THE PAGE WILL BE DISPLAYED TO THE USER -->

<body>

<!-- LOGIN / DROP DOWN PANEL START -->

<!-- LEFT SECTION OF THE LOGIN PANEL IS DEFINED HERE. THE SECTION BELOW IS WHAT WILL BE SEEN BY USERS WHO ARE LOGGED IN-->
<div id="toppanel">
	<div id="panel">
	
		<div class="content clearfix">
		<div class="left">
				<h1>Altech Autopage - AUXILIUM</h1>
				<h2>Welcome <?php echo htmlentities($_SESSION['username']);?> <?php echo htmlentities($_SESSION['level']);?></h2>
				<!--<h2>You are currently logged <?php echo $logged?>.</h2><br> -->
				<p class="grey">You can put anything you want in this sliding panel: videos, audio, images, forms... The only limit is your imagination!</p>
				<h2>Altech Autopage Website</h2>
				<p class="grey">Click the link <a href="http://www.autopage.co.za" title="Autopage Website">to visit the Autopage Website »</a></p>
		</div>
		<div class="left">
		
		
		<!-- CHECK TO SEE IF THERE WERE ANY ERRORS WHEN ATTEMPTING TO LOGIN -->
		<?php
        if (isset($_GET['error'])) {
            echo '<p class="error">Error Logging In! Please verify that you are using the correct username and password combination.</p>';
        }
		?>	
			
			
		<!-- MIDDLE SECTION OF THE SLIDING PANEL - CONTROLS THE LOGIN OF A USER -->
        <form class="clearfix" action="includes/logout.php" method="post" name="logout_form">  		
			<h1>Agent Logout</h1>
				<p class="grey">Click on the button to logout.</p>
        		<div class="clear"></div>
				<input type="button" value="Logout" class="bt_login" onclick="form.submit()"/> 
        </form>
		</div>
		
		
		
		<!-- RIGHT SECTION OF THE SLIDING PANEL - CONTROLS THE REGISTRATION OF A USER -->		
		<div class="left">
		
		<?php
        if (isset($_GET['error'])) {
            echo '<p class="error">Error Logging In! Please verify that you are using the correct username and password combination.</p>';
        }
		?>	
			
		<!-- FAR RIGHT PANNEL - LOGS USERS OUT OF THE SYSTEM. -->
        <form class="clearfix" action="includes/logout.php" method="post" name="logout_form">  		
			<h1>Third Side Panel</h1>
				<p class="grey">Will add some nice information over here.</p>
        </form>
		</div>
		</div>
	</div> 

<!-- LOGIN AND REGISTRATION END -->	



	<!-- DETAILS TO CONFIGURE THE LOGIN TAB -->	
	<div class="tab">
		<ul class="login">
			<li class="left"> </li>
			<li>Nice to see you again</li>
			<li class="sep">|</li>
			<li id="toggle">
				<a id="open" class="open" href="#"><?php echo htmlentities($_SESSION['username']);?>!</a>
				<a id="close" style="display: none;" class="close" href="#">Close Panel</a>			
			</li>
			<li class="right"> </li>
		</ul> 
	</div> <!-- / top -->
	
</div> <!--panel -->


<!-- INCLUDING THE NAVIGATION MENU -->

<div id="menu">
<?php
include '/includes/menu.html';
?>
</div>





    <div id="container">
		<div id="content" style="margin-top:-45px;">
		<img src="images/logo.png" alt="TechDesignLab"></img>
			<h1>Auxilium</h1>
			<!-- <h2>Sliding login panel with jQuery - Demo</h2>	 -->
		
		<div id="stylized" class="form">
			<form id="form" name="form" method="post" action="process/submit_walkin.php">
			<h1>Walkin Customer Details</h1>
			<p>This is the basic form layout. We can edit it as required.</p>

			
			<label>User Logged In :
			<span class="small">You are logged in as</span>
			</label>
			<input type="text" name="username" id="username" value="<?php echo htmlentities($_SESSION['username']);?>" readonly>
			
			
			
			<label>Customer Name :
			<span class="small">Add the customer's name</span>
			</label>
			<input type="text" name="fname" id="fname"/>

			
			<label>Customer Surname :
			<span class="small">Add the customer's surname</span>
			</label>
			<input type="text" name="lname" id="lname"/>


			<label>Contact Number :
			<span class="small">Add a contact number</span>
			</label>
			<input type="text" name="msisdn" id="msisdn" />


			<label>E-Mail :
			<span class="small">Add an e-mail address</span>
			</label>
			<input type="text" name="email" id="email" />


			<label>Query Type :
			<span class="small">Select a query type</span>
			</label>
			<select id="query1" name="query1">
				<option value=""> -- Select the query Type --</option>
				<option value="3rd Party">3rd Party</option>
				<option value="Cashier">Cashier</option>
				<option value="Client Liaison Consultant">Client Liaison Consultant</option>
				<option value="Credit Control Consultant">Credit Control Consultant</option>
				<option value="Insurance Consultant">Insurance Consultant</option>
				<option value="Manager">Manager</option>
				<option value="Meeting/Interview">Meeting/Interview</option>
				<option value="Premier Client Consultant">Premier Client Consultant</option>
				<option value="Retail Shop Consultant">Retail Shop Consultant</option>
				<option value="Retention Collection">Retention Collection</option>
				<option value="Tech Deck Consultant">Tech Deck Consultant</option>
			</select>
			<input type="button" value="Submit" class="bt_login" onclick="form.submit()"/> 
			</form></div>
			
		<br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br>
		</div><!-- / content -->		
	</div><!-- / container -->
</body>



<div id="container">
<div id="footer" style="margin-top:10px;">

<footer style="background:#E5E5E5; height:20px">
  <p>Copyright © TechDesignLab 2014 | <a href="mailto:leon.claassen@techdesignlab.co.za">Contact Us</a>.</p>
  <img src="images/footer-logo.png" alt="Footer Logo" align="left"></img>
  <img src="images/level2.png" alt="level2" align="left"></img>
</footer>
</div><!-- / footer -->		
</div><!-- / container -->
</html>




Edited by SalientAnimal
Link to comment
Share on other sites

Ok so just to be clear, all the includes that I have at the top of the form_template.php file must also be in the process\submit_walkin.php?

 

i.e.

<?php
include_once 'includes/db_connect.php';
include_once 'includes/functions.php';
include_once 'includes/register.inc.php';
?>

I'm assuming I don't need the register.inc file as it is only for processing registrations?

 

After that, do I also include:

<?php
sec_session_start();
if (login_check($mysqli) == true) 
	{
    $logged = 'in';
	} 
else 
	{
    $logged = 'out';
	}
?>

or what is a better way to start the session.
Sorry guys, I know my code is really dirty and it probably needs a lot of work, but I'm trying to learn the best ways of doing things.

 

Really appreciate your help thus far.
 

Link to comment
Share on other sites

Ok a new error...

Notice: Undefined variable: prep_stmt in C:\Development_Tracker\htdocs\process\submit_walkin.php on line 44

Warning: mysqli_stmt::bind_param(): Number of elements in type definition string doesn't match number of bind variables in C:\Development_Tracker\htdocs\process\submit_walkin.php on line 55
 array(6) { ["username"]=> string(13) "Salientanimal" ["fname"]=> string(4) "Leon" ["lname"]=> string( "Claassen" ["msisdn"]=> string(10) "0763068384" ["email"]=> string(31) leon.claassen@techdesignlab.co.za ["query1"]=> string(9) "3rd Party" } 

Looks like we at least getting somewhere.

Link to comment
Share on other sites

That undefined variable message comes from the following line:

$stmt = $mysqli->prepare($prep_stmt);

Based on a cursory look, you don't need that line. The script calls the prepare() method later.

if (empty($error_msg)) 
{
        // Insert the new user into the database 
        if ($insert_stmt = $mysqli->prepare("INSERT INTO walkin (username, fname, lname, msisdn, email, query1, creation_time) 
VALUES (?, ?, ?, ?, ?, ?, now())")) 
{
Link to comment
Share on other sites

Thanks guys, took that line out shortly after posting the reply. I am however still getting this error:

Warning: mysqli_stmt::bind_param(): Number of elements in type definition string doesn't match number of bind variables in C:\Development_Tracker\htdocs\process\submit_walkin.php on line 58
array(6) { ["username"]=> string(13) "Salientanimal" ["fname"]=> string(0) "" ["lname"]=> string(0) "" ["msisdn"]=> string(0) "" ["email"]=> string(0) "" ["query1"]=> string(0) "" } 

I left the fields blank just to return the message, there is currently no check in place to ensure that all fields are infact filled in. I will do this later. i have also tried submitting it with data captured, but recieve the same error.

 

Do I need to update this section as follows including my id field, even though it is auto incremented?

    if (empty($error_msg)) 
	{
        // INSERT THE NEW FOR INFORMATION INTO THE DATABASE TABLE
        if ($insert_stmt = $mysqli->prepare("INSERT INTO walkin (ADD_ID_FIELD?, username, fname, lname, msisdn, email, query1, creation_time) 
		
														 VALUES (?, ?, ?, ?, ?, ?, now())")) 
		{
			$insert_stmt->bind_param(ADD_ID_FIELD?, $username, ucfirst($fname), ucfirst($lname), $msisdn, $email, $query1, $creation_time);
            // EXECUTE THE PREPARED QUERY
            if (! $insert_stmt->execute()) 
			var_dump($_POST);exit;  
			{
                header('Location: ../error.php?err=Registration failure: INSERT');
				exit;

When adding the id field to the first  if ($insert_stmt = $mysqli->prepare, the forms seems to process all the way through, however the data isn't written to my database table.

 

Here is a MySQL dump showig my table structure:

-- phpMyAdmin SQL Dump
-- version 4.0.9
-- http://www.phpmyadmin.net
--
-- Host: 127.0.0.1
-- Generation Time: Jan 22, 2014 at 08:42 AM
-- Server version: 5.6.14
-- PHP Version: 5.5.6

SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO";
SET time_zone = "+00:00";


/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
/*!40101 SET NAMES utf8 */;

--
-- Database: `techdesinglab_tracker`
--

-- --------------------------------------------------------

--
-- Table structure for table `walkin`
--

CREATE TABLE IF NOT EXISTS `walkin` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `username` varchar(100) NOT NULL,
  `fname` varchar(100) NOT NULL,
  `lname` varchar(100) NOT NULL,
  `msisdn` bigint(10) NOT NULL,
  `email` varchar(100) NOT NULL,
  `query1` varchar(100) NOT NULL,
  `creation_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;

/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;


Edited by SalientAnimal
Link to comment
Share on other sites

Ok, finally I got the script to actually submit to my table. The problem however is that I am being taken to the error page:

				header('Location: ../error.php?err=Registration failure: INSERT');
				exit;

and not to:

				header('Location: ../success.html');
				exit;

What needs to be done to fix this? Thanks guys, your help thus far has really added value and I am learning every step of the way.

 

Here's what my code looks like:

<?php
include_once '../includes/db_connect.php';
include_once '../includes/functions.php';
?>

<?php
sec_session_start();
if (login_check($mysqli) == true) 
	{
    $logged = 'in';
	} 
else 
	{
    $logged = 'out';
	}


$error_msg = "";
$username = $_SESSION['username'];


/* USED FOR ERROR CHECKING */

/* 
var_dump($_SESSION); exit; 
var_dump($_POST);exit; 
*/



if (isset($_POST['username'], $_POST['fname'], $_POST['lname'], $_POST['msisdn'], $_POST['email'], $_POST['query1'])) 
{
    // SANITIZE AND VALIDATE THE DATA BEING PROCESSED BY THE FORM
		$username = filter_input(INPUT_POST, 'username', FILTER_SANITIZE_STRING);
		$fname = filter_input(INPUT_POST, 'fname', FILTER_SANITIZE_STRING);
		$lname = filter_input(INPUT_POST, 'lname', FILTER_SANITIZE_STRING);
		$msisdn = filter_input(INPUT_POST, 'msisdn', FILTER_SANITIZE_STRING);
		$email = filter_input(INPUT_POST, 'email', FILTER_SANITIZE_EMAIL);
		$query1 = filter_input(INPUT_POST, 'query1', FILTER_SANITIZE_STRING);
		$creation_time = filter_input(INPUT_POST, 'creation_time', FILTER_SANITIZE_STRING);		
		$email = filter_var($email, FILTER_VALIDATE_EMAIL);


if (mysqli_connect_errno()) 
	{
		printf("Connect failed: %s\n", mysqli_connect_error());
		exit();
	}


    if (empty($error_msg)) 
	{
        // INSERT THE NEW FOR INFORMATION INTO THE DATABASE TABLE
        if ($insert_stmt = $mysqli->prepare("INSERT INTO walkin (username, fname, lname, msisdn, email, query1, creation_time) 
											VALUES (?, ?, ?, ?, ?, ?, ?)"))
		{
			$insert_stmt->bind_param('sssisss', $username, ucfirst($fname), ucfirst($lname), $msisdn, $email, $query1, $creation_time);
            // EXECUTE THE PREPARED QUERY
            if (! $insert_stmt->execute());
			
			//PRINT THE NUMBERS OF ROWS THAT HAVE BEEN AFFECTED
			printf("%d Row inserted.\n", $insert_stmt->affected_rows);
 
			{
				header('Location: ../error.php?err=Registration failure: INSERT');
				exit;

            }
        }
				header('Location: ../success.html');
				exit;
		
		/* CLOSE THE STATEMENT */
		$stmt->close();

		/* CLOSE THE CONNECTION */
		$mysqli->close();
    }

}
Link to comment
Share on other sites

You have a ; after your if statement

if (! $insert_stmt->execute());

remove that ; because a ; means that no action will follow if the if statement is valid.

Also, put this line in comments

printf("%d Row inserted.\n", $insert_stmt->affected_rows);

Otherwise you'll get a syntax error because the { will open too late.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.