I have the following form asking for simple information, yet the data will not parse to my database. I have similar forms on other parts of my site, and they are connected to the database and retrieving data perfectly. Have pasted the code below and believe that MYSQL script is written as it is supposed to be. Why is the data not being retrieved once a use presses the submit button?
<?php
// Written by KV Ghumaan
session_start(); // Start session first thing in script
// Script Error Reporting
error_reporting(E_ALL);
ini_set('display_errors', '1');
// Connect to the MySQL database
include "storescripts/connect_to_mysql.php";
?>
<?php
// Parse the form data and add inventory item to the system
if(isset($_POST['fName'])){
$id = mysql_real_escape_string($_POST['id']);
$fName = mysql_real_escape_string($_POST['fName']);
$lName = mysql_real_escape_string($_POST['lName']);
$address = mysql_real_escape_string($_POST['address']);
$city = mysql_real_escape_string($_POST['city']);
$state = mysql_real_escape_string($_POST['state']);
$zipCode = mysql_real_escape_string($_POST['zipCode']);
//Add this product into the database now
$sql = mysql_query("INSERT INTO checkoutInfo (id, fName, lName, address, city, state, zipCode)
VALUES('$id','$fName','$lName','$address','$city','$state','$zipCode')") or die (mysql_error());
$pid = mysql_insert_id();
}
?>
<html>
<head>
<!--JQUERY-->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
<script src="jqueryui/jquery-ui.js"></script>
<link rel="stylesheet" type="text/css" href="jqueryui/jquery-ui.css"/>
<link rel="stylesheet" type="text/css" href="jqueryui/jquery-ui.structure.css"/>
<link rel="stylesheet" type="text/css" href="jqueryui/jquery-ui.theme.css"/>
<!--GOOGLE FONT & EXTERNAL LIBS-->
<link href="https://fonts.googleapis.com/css?family=Raleway:100" rel="stylesheet">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
<link rel="stylesheet" type="text/css" href="style/style.css"/>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>CHECKOUT</title>
</head>
<body>
<?php include_once("template_header.php");?>
<table width="100%" height="76vh" border="10%" cellspacing="10" style="padding: 2vh 10vw 0vh 10vw; border-style:none;">
<tr height="75%" cellspacing="0" style="border-style:none;">
<td width="30%" style="border-style:none; padding-top: 10vh;">
<form class="form" action="confirmation.php" enctype="multipart/form-data" name="checkoutForm" id="checkoutForm" method="POST">
<div id="billingQuestions">
<h3><strong>BILLING ADDRESS:</strong></h3>
<div id="formQuestions">
<label>First Name:*</label><br />
<input type="text" name="fName" size="40vw" required>
</div>
<div id="formQuestions">
<label>Last Name:*</label><br />
<input type="text" name="lName" size="40vw" required>
</div>
<div id="formQuestions">
<label>Address 1:*</label><br />
<input type="text" name="address" size="40vw" required>
</div>
<div id="formQuestions">
<label>Address 2:*</label><br />
<input type="text" size="40vw">
</div>
<div id="formQuestions">
<label>City: *</label><br />
<input name="city" type="text" size="40vw" required>
</div>
<div id="formQuestions">
<label>State: *</label><br />
<input name="state" type="text" size="40vw" required>
</div>
<div id="formQuestions">
<label>Zip Code: *</label><br />
<input name="zipCode" type="text" size="40vw" required>
</div>
<input type="submit" value="Submit"/>
</div>
</form>
</td>
</tr>
</table>
<?php include_once("template_footer.php");?>
</body>
</html>
Related
im trying to make a madlibs kind of game, right now i got everything working besides 1 thing. the output should overwrite the questions instead of showing above the questions. how can i manage to do this?
<!DOCTYPE html>
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
<title>Mad Libs</title>
<link rel="stylesheet" type="text/css" href="MadLibs.css">
<link rel="preconnect" href="https://fonts.gstatic.com">
<link href="https://fonts.googleapis.com/css2?family=Libre+Baskerville:wght#700&display=swap" rel="stylesheet">
</head>
<body>
<form action="" method="POST">
<h1> MadLibs</h1>
<?php
if($_SERVER["REQUEST_METHOD"] == "POST"){
$Input1 = $_POST["Input1"];
$Input2 = $_POST["Input2"];
$Input3 = $_POST["Input3"];
$Input4 = $_POST["Input4"];
echo "here is a test $Input1. here is an other test $Input2 and again an other test
$Input4 test $Input3.";
}else{
<p id="Text">test question <input type="text" required name="Input1" placeholder="Enter your answer.."></p>
<p id="Text">test question <input type="text" required name="Input2" placeholder="Enter your answer.."></p>
<p id="Text">test question<input type="text" required name="Input3" placeholder="Enter your answer.."></p>
<p id="Text">test question <input type="text" required name="Input4" placeholder="Enter your answer.."></p>
<input id="Submit" type="submit" name="submit" value="Send">
</form>
?>
<footer>
<p> A #2021 website</p>
</footer>
</body>
</html>
The end result shows like this but the questions and the input field should be gone when the submit button is pressed
Here are codes that I have tried the last. With these codes I got nothing in input field. I want user can see what he has entered but cannot change the same. if he wants to change he has to go back to the previous page and refill the data with correct value.
For page 1 (with php extension)
<?PHP
session_start();
?>
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" type = "text/css" href="index.css"/>
<title>EduLife Welcomes You</title>
<link rel="icon" type="image/png" href="title-icon.png"/>
</head>
<body>
<?php
// Set session variables
$_SESSION['dob'] = $dob;
$_SESSION['class'] = $class;
?>
[...javascript for calculating age...]
<form>
<h3>Check Eligibility : </h3>
Enter Date of Birth of the child: <input type="date" name="dob" id="dob" required/><br>
<input class="btn" type="button" value="Check Eligibility" onclick="ageCalculate()"><br>
You are eligible for the Grade : <span id="class" class="eligible"></span>
</form>
OK, I want to apply!</button>
</body>
</html>
CODE FOR PAGE 2(with php extension)
<?PHP
session_start();
$dob = $_SESSION['dob'];
$class = $_SESSION['class'];
?>
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" type = "text/css" href="admn-form.css"/>
<title>EduLife</title>
<link rel="icon" type="image/png" href="title-icon.png"/>
</head>
<div id="admn-form">
<form action="insert.php" method="POST">
<h2 id="form-name">Apply For Admission </h2>
<h2 id="part"> Part A - Information of the student</h2>
<h3><span style="color:blue">You applying for the Grade:</span><input for="class" name="class" id="class" value="<?php echo $_SESSION['class'];?>" readonly> </input></h3>
<h3>1. Name of the student</h3>
<p class="quest">
<label for="first-name"> First Name * : </label>
<input type="text" Name="firstname" placeholder="First Name" pattern="[A-Z]{2,15}" required>
<label for="middle-name"> Middle Name : </label>
<input type="text" Name="middlename" placeholder="Middle Name" pattern="[^\s][A-Z]+{2,15}">
<label for="last-name"> Last Name : </label>
<input type="text" Name="lastname" placeholder="Last Name" pattern="[^\s][A-Z]+{2,15}">
</p>
<h3>2. Select Gender of the student *</h3>
<p class="quest">
<input type="radio" id="female" name="gender" value="Female" required>
<label for="female">Female</label>
<input type="radio" id="male" name="gender" value="Male" required>
<label for="male">Male</label>
<input type="radio" id="other" name="gender" value="Other" required>
<label for="other">Other</label>
</p>
<h3>4. Enter Birth-detail of the student</h3>
<p class="quest">
<label for="DOB"> Date of Birth *: </label>
<input type="date" name="dob" value="<?php echo $_SESSION['dob'];?>" readonly>
</p>
</form>
</div>
</HTML>
I have created a form for payment in html. The values in the form are added automaticaly usng session. when the user logs in, the values are added using the user infromation. my html is below:
<table>
<form name="postForm" action="form_process.php" method="POST" >
<tr><td><input type="hidden" name="txnid" value="<?php echo $txnid=time().rand(1000,99999); ?>" /></td></tr>
<tr><td>amount</td><td><input type="text" name="amount" value="<?php echo $_SESSION['amount']; ?>" /></td></tr>
<tr><td>firstname</td><td><input type="text" name="firstname" value="<?php echo $_SESSION['firstname']; ?>" /></td></tr>
<tr><td>email</td><td><input type="text" name="email" value="<?php echo $_SESSION['email']; ?>" /></td></tr>
<tr><td>phone</td><td><input type="text" name="phone" value="<?php echo $_SESSION['phone']; ?>" /></td></tr>
<tr><td>productinfo</td><td><input type="text" name="productinfo" value="<?php echo $_SESSION['productinfo']; ?>" /></td></tr>
<tr><td><input type="hidden" name="surl" value="success.php" size="64" /></td></tr>
<tr><td><input type="hidden" name="furl" value="fail.php" size="64" /></td></tr>
<tr><td><input type="submit" /></td><td><input type="reset" /></td></tr>
</form>
</table>
in the login page, i have stored the session as below:
<?php
session_start();
include("config.php");
if(isset($_POST['login']))
{
$user_email=$_POST['email'];
$user_pass=$_POST['pass'];
$check_user="select * from users WHERE user_email='$user_email'AND user_pass='$user_pass'";
$run=mysqli_query($dbcon,$check_user);
if(mysqli_num_rows($run)>0)
{
$result=mysqli_fetch_array($run);
$_SESSION['email']=$user_email;
$_SESSION['access']=$result['access'];
//here session is used and value of $user_email store in $_SESSION.
echo "<script>window.open('index.php','_self')</script>";
}
else
{
echo "<script>alert('Email or password is incorrect!')</script>";
}
}
?>
<html>
<head lang="en">
<meta charset="UTF-8">
<link type="text/css" rel="stylesheet" href="bootstrap-3.2.0-dist\css\bootstrap.css">
<title>Login</title>
<link rel="icon" type="image/png" href="images/imageedit_2_5125240109.gif"/>
<link href="css/bootstrap.css" rel="stylesheet" type="text/css" media="all" />
<link href="css/style.css" rel="stylesheet" type="text/css" media="all" />
<link href="css/appointment_style.css" rel="stylesheet" type="text/css" media="all" />
<link href="css/font-awesome.css" rel="stylesheet">
<!-- //for bootstrap working -->
<link href="//fonts.googleapis.com/css?family=Source+Sans+Pro:300,300i,400,400i,600,600i,700" rel="stylesheet">
</head>
<style>
.login-panel {
margin-top: 150px;
}
</style>
<body>
<div class="container">
<div class="row">
<div class="col-md-4 col-md-offset-4">
<div class="login-panel panel panel-success">
<div class="panel-heading">
<h3 class="panel-title">Sign In</h3>
</div>
<div class="panel-body">
<form role="form" method="post" action="login.php">
<fieldset>
<div class="form-group" >
<input class="form-control" placeholder="E-mail" name="email" type="email" autofocus>
</div>
<div class="form-group">
<input class="form-control" placeholder="Password" name="pass" type="password" value="">
</div>
<input type="submit" value="login" name="login" >
<!-- Change this to a button or input when using this as a form -->
<!-- Login -->
</fieldset>
</form>
</div>
</div>
</div>
</div>
</div>
</body>
</html>
the user email is correctly inputted in the form , but the mobile number and other details are not being added into the form. i tried string them as variables like above, but its not displaying. i think i need to fetch the details from database. can anyone tell me how to do this?
I have done alot of research and finally go the answer myself.
i used the $_SESSION and the select query to get the information of the current user from the database. and used the while loop to put them in variable.
the updated code is below:
<div class="sing"><?php
session_start();
if (isset($_SESSION['email']) && $_SESSION['email'] == true) {
echo "   Welcome " . $_SESSION['email'] ;
echo "<div style='float: right;'><a href='logout.php'>Logout</a> </div>";
} else {
}
?>
</div>
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<div>
<h2>Payment Gateway Testing Sample</h2>
<h3>Fill the form and submit it for starting the transaction...</h3>
</div>
<div>
<?php
include("config.php");
$user_email=$_SESSION['email'];
$check_user="select * from users WHERE user_email='$user_email'";
$run=mysqli_query($dbcon,$check_user);
while($row = $run->fetch_assoc())
{
$user_name=$row['user_name'];
$user_mobile=$row['user_mobile'];
}
//here session is used and value of $user_email store in $_SESSION.
?>
<table>
<form name="postForm" action="form_process.php" method="POST" >
<tr><td><input type="hidden" name="txnid" value="<?php echo $txnid=time().rand(1000,99999); ?>" /></td></tr>
<tr><td>amount</td><td><input type="text" name="amount" value="" /></td></tr>
<tr><td>Name</td><td><input type="text" name="firstname" value="<?php echo $user_name; ?>" /></td></tr>
<tr><td>email</td><td><input type="text" name="email" value="<?php echo $_SESSION['email']; ?>" /></td></tr>
<tr><td>phone</td><td><input type="text" name="mobile" value="<?php echo $user_mobile; ?>" /></td></tr>
<tr><td>productinfo</td><td><input type="text" name="productinfo" value="" /></td></tr>
<tr><td><input type="hidden" name="surl" value="success.php" size="64" /></td></tr>
<tr><td><input type="hidden" name="furl" value="fail.php" size="64" /></td></tr>
<tr><td><input type="submit" /></td><td><input type="reset" /></td></tr>
</form>
</table>
</div>
</body>
</html>
I am having trouble with a some php code. I was able to get the code to work on my test website. I am now trying to register a user with a popup register menu. When I enter the information and click on my register button nothing is sent to my database table.
Heres my code.
<!doctype html>
<html lang="en">
<head>
<title>untitled.com</title>
<meta name="description" content="">
<link rel="stylesheet" type="text/css" href="frontPage.css">
<script src="http://code.jquery.com/jquery-1.9.1.js" type="text/javascript"></script>
<script src="js/general.js" type="text/javascript">
</script>
</head>
<body>
<h1> untitled </h1>
<h2> description of website</h2>
<div id="wrapper">
<nav id="nav">
<ul id="navigation">
<a class="button" href="" >Login</a>
<div class="popup">
CLOSE
<form>
<P><span class="title">Username</span> <input name="" type="text" /></P>
<P><span class="title">Password</span> <input name="" type="password" /></P>
<P><input name="" type="button" value="Login" /></P>
</form>
</div>
</ul>
</nav>
<?php
require('db.php');
if (isset($_POST['username'])){
$username = $_POST['username'];
$password = $_POST['password'];
$email = $_POST['email'];
$city = $_POST['city'];
$state = $_POST['state'];
$zip = $_POST['zip'];
$phone = $_POST['phone'];;
$query = "INSERT into `users` (username, password, email, city, state, zip, phone) VALUES ('$username', '".md5($password)."', '$email', '$city', '$state', '$zip', '$phone' )";
$result = mysql_query($query);
if($result){
echo "<div class='form'><h3>You are registered successfully.</h3><br/>Click here to <a href='login.php'>Login</a></div>";
}
}else{
?>
<a class="Regbutton" href="#" >Register</a>
<div class="Regpopup">
CLOSE
<form>
<P><span class="title">Username</span> <input name="username" type="text" /></P>
<P><span class="title">Password</span> <input name="password" type="password" /></P>
<P><span class="title">Email</span> <input name="email" type="email" /></P>
<P><span class="title">City</span> <input name="city" type="text" /></P>
<P><span class="title">State</span> <input name="state" type="text" maxlength="2" /></P>
<P><span class="title">zip</span> <input name="zip" type="text" maxlength="5" /></P>
<P><span class="title">phone</span> <input name="phone" type="text" maxlength="15"/></P>
<P><input type="submit" name="submit" value="Register" /></P>
</form>
</div>
<?php } ?>
</body>
</html>
To get the value from input field by post method, it is important to define form method. Example
<form action="" method="POST">
</form>
I have the below form, and after the form the PHP requests a Curl which can take a while. Because of this they keep pressing the submit button thinking that nothing has happened. This causes multiple entries in the database. Could someone help me and let me know what to put in to stop this.
I tried the Javascript solution in the first answer but it stopped the PHP script that followed. Not what I wanted. Sorry
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<link href="css2/style.css" rel='stylesheet' type='text/css' />
<meta name="viewport" content="width=device-width, initial-scale=1">
<script type="application/x-javascript"> addEventListener("load", function() { setTimeout(hideURLbar, 0); }, false); function hideURLbar(){ window.scrollTo(0,1); } </script>
<!--webfonts-->
<link href='//fonts.googleapis.com/css?family=Open+Sans:400,300,600,700,800' rel='stylesheet' type='text.css'/>
<!--//webfonts-->
<center><img class="displayed" src="images/logo.jpg" alt="Logo" style="width:128px;height:128px;"></center>
</head>
<body>
<div class="main">
<form action="" method="POST" enctype="multipart/form-data" id="contactform" >
<input type="hidden" name="action" value="submit">
<h1><span>Sign Up</span> <lable> The Brook on Sneydes</lable> </h1>
<div class="inset">
<p>
<center><label ><?php echo $text; ?></label></center>
<label for="first">First Name</label>
<input type="text" name="first" id="first" value="" placeholder="" required/>
</p>
<p>
<label for="last">Surname</label>
<input type="text" name="last" id="last" value="" placeholder="" required/>
</p>
<p>
<label for="mobile">Mobile Number</label>
<input type="text" name="mobile" id="mobile" value="" placeholder="" required/>
</p>
<p>
<label for="email">Email Address</label>
<input type="text" name="email" id="email" value="" placeholder="" required/>
</p>
</div>
<p class="p-container">
<input type="submit" name="submit" id="submit" value="Submit">
</p>
</form>
</div>
<!-----start-copyright---->
<div class="copy-right">
<p> © 2016 Spearhead Digital. All rights reserved.</p>
</div>
<!-----//end-copyright---->
</body>
</html>
<?php
if(isset($_POST['submit']) && !empty($_POST) ){
$first = $_POST['first'];
$last = $_POST['last'];
$mobile = $_POST['mobile'];
$email = $_POST['email'];
// Other Code
}
You can disable the submit button when submitting the form.
An example using jQuery:
<script type="text/javascript">
$(document).ready(function() {
$('#contactform').submit(function() {
$('input[type=submit]', this).prop("disabled", true);
});
});
</script>