Below is the html code for my form and the php code which i am using to pass data to a class method.Now the problem that i have is that the control does not seem to enter the if loop which i concluded by testing as you can see."test0" gets printed but "test1" and other subsequent "tests" do not get printed.
<form action="" method="post" enctype=multipart/form-data>
<div class="form-group">
<label for="job name">Job name:</label>
<input type="text" class="form-control" id="jobnm" value="<?php echo $_GET['jobnm'];?>" disabled>
</div>
<div class="form-group">
<label for="name">Name:</label>
<input type="text" class="form-control" name="name" required>
</div>
<div class="form-group">
<label for="email">Email address:</label>
<input type="email" class="form-control" name="mail" required>
</div>
<div class="form-group">
<label for="phone">Enter a phone number:</label><br><br>
<input type="tel" id="phone" name="phone" placeholder="+91-1234567890" pattern="[0-9]{10}" required><br><br>
<small>Format: 1234567890</small><br><br>
</div>
<label >Gender</label>
<div class="radio">
<label><input type="radio" name="optradio" value="m">Male</label>
</div>
<div class="radio">
<label><input type="radio" name="optradio" value="f">Female</label>
</div>
<div class="radio">
<label><input type="radio" name="optradio" value="o">Other</label>
</div>
<div class="custom-file">
<input type="file" class="custom-file-input" name="cvFile" required>
<label class="custom-file-label" for="customFile">Upload resume</label>
</div>
<button type="submit" class="btn btn-primary">Submit</button>
<button type="reset" class="btn btn-danger" >Reset</button>
</form>
<?php
require_once 'db-config.php';
require_once 'classCandi.php';
echo "test0";
if(isset($_POST['submit']))
{
echo "test1";
$jobID = $_GET['jobid'];
echo "test2";
$canName = $_POST['name'];
$canEmail = $_POST['mail'];
$canPhone = $_POST['phone'];
$canRadio = $_POST['optradio'];
echo "test3";
//Upload file
$fnm = "cv/";
$cvDst = $fnm . basename($_FILES["cvFile"]["name"]);
move_uploaded_file($_FILES["cvFile"]["tmp_name"],$cvDst);
echo "test4";
$obj = new Candi($conn);
$obj->storeInfo($jobID,$canName,$canEmail,$canPhone,$canRadio,$cvDst);
echo "test5";
echo '<script language="javascript">';
echo 'alert("Submitted");';
echo '</script>';
echo "test6";
}
The below code won't be true anytime! It's because you didn't understand how $_POST works.
if(isset($_POST['submit']))
There's no input element in your frontend that has name="submit". And to see, there's none of the inputs have name attribute at all.
Instead, the better way to do is, understand how this works and change your code so that, it includes:
a name attribute for all the input and form elements.
a check on the values and not $_POST['submit']
And finally...
don't copy and paste without understanding the code.
don't check on $_POST['submit'] truthness.
Example, for $canName = $_POST['name']; to work, you need to have:
<input type="text" name="name" id="name" value="<?php echo $something; ?>" />
// ^^^^^^^^^^^
And have your attribute and values in quotes please:
enctype="multipart/form-data"
// ^ ^
Related
I want only 4 columns from database in below
I have to get only 4 column from database for displaying in textfield please give suggestion for that. The table is shown below thank you
$sql_getnm = "SELECT * FROM util WHERE util_head IN ('wc_email', 'wc_contact_us', 'wc_mobile', 'wc_google_map');";
$result_getnm = $connect->query($sql_getnm);
while($row_getnm = $result_getnm->fetch_array())
$util_value_email_data=?
$util_value_mobile_data=?;
$util_value_map_data=?;
$util_value_data=?;
html form
<form id="submitForm" method="post" role="form" name="hl_form" method="post" enctype="multipart/form-data">
<div class="box-body">
<div class="form-group">
<label for="mobile_number">Email*</label>
<input class="form-control" id="util_value_email" name="util_value_email" value="<?Php echo $util_value_email_data; ?>" maxlength="250" placeholder="Enter Email Address" type="text">
</div>
<div class="form-group">
<label for="mobile_number">Mobile*</label>
<input class="form-control" id="util_value_mobile" name="util_value_mobile" value="<?Php echo $util_value_mobile_data; ?>" maxlength="250" placeholder="Enter Mobile Number" type="text">
</div>
<div class="form-group">
<label for="mobile_number">Map*</label>
<input class="form-control" id="util_value_map" name="util_value_map" value="<?Php echo $util_value_map_data; ?>" maxlength="250" placeholder="Enter Map Address" type="text">
</div>
<div class="form-group">
<label for="description" class="required">Description*</label>
<textarea class="form-control" style="resize: none;" id="util_value" name="util_value" rows="3" placeholder="Enter Description"><?Php echo $util_value_data; ?></textarea>
</div>
<div class="box-footer">
<button type="submit" name="submit" class="btn btn-primary">Submit</button>
</div>
</form>
Below is the code from which you can get all the four data that you want.
$sql_getnm = "SELECT * FROM util WHERE util_head IN ('wc_email', 'wc_contact_us', 'wc_mobile', 'wc_google_map');";
$result_getnm = $connect->query($sql_getnm);
while($row_getnm = $result_getnm->fetch_array()) {
if($row_getnm['util_head'] == 'wc_email'){
$util_value_email_data = $row_getnm['util_value'];
}
if($row_getnm['util_head'] == 'wc_contact_us'){
$util_value_contact_data = $row_getnm['util_value'];
}
if($row_getnm['util_head'] == 'wc_mobile'){
$util_value_mobile_data = $row_getnm['util_value'];
}
if($row_getnm['util_head'] == 'wc_google_map'){
$util_value_map_data = $row_getnm['util_value'];
}
}
You need to replace * with columns name with comma separation.
$sql_getnm = "SELECT Columname1,Columname2,Columname3,Columname4 FROM util WHERE util_head IN ('wc_email', 'wc_contact_us', 'wc_mobile', 'wc_google_map');";
$result_getnm = $connect->query($sql_getnm);
while($row = mysql_fetch_array($result_getnm, MYSQL_ASSOC)
$util_value_email_data= $row['Columname1'];
$util_value_mobile_data= $row['Columname2'];
$util_value_map_data= $row['Columname3'];
$util_value_data= $row['Columname4'];
I'm developing a script for online admission in a website. Below is php code of the page. The problem is that it's not submitting.
<?php
include ("include/header.php"), include ("include/config.php");
if(isset($_POST['applyAdmission'])) {
$admission_no = $_POST['admission_no'];
$f_name = $_POST['f_name'];
$l_name = $_POST['l_name'];
$p_add = $_POST['p_add'];
$c_add = $_POST['c_add'];
$dob = $_POST['dob'];
$education = $_POST['education'];
$mobile = $_POST['mobile_no'];
$course = $_POST['course'];
$subjects = $_POST['subjects'];
$timing = $_POST['timing'];
$filepath_pic = $_FILES['picture']['name'];
$res_move_pic = move_uploaded_file($_FILES['picture']['tmp_name'], "/admission/".$filepath_pic);
$filepath_sign = $_FILES['sign']['name'];
$res_move_sign = move_uploaded_file($_FILES['sign']['tmp_name'], "/admission/".$filepath_sign);
$agree_terms = $_POST['agree_terms'];
$agree_cond = $_POST['agree_cond'];
if ($res_move_pic == 1 && $res_move_sign == 1 ) {
$query = "INSERT into online_admission (f_name, l_name, p_add, c_add, dob, degree, mobile_no, course, subjects, timing, pic, sign, agree_terms, agree_cond, applied_on)
values ('$f_name','$l_name','$p_add','$c_add','$dob','$education','$mobile','$course','$subjects','$timing','$filepath_pic','$filepath_sign','$agree_terms','$agree_cond','now()')";
$res = mysql_query($query) or die("ERROR: Unable to insert into database.");
if ($res == 1) {
header('Location:http://adarshclasses.in/admission_success.php/');
exit();
} else {
header('Location:http://adarshclasses.in/admission_failed.php/');
exit();
}
} else {
echo "Error in updateing profile pic and sign";
}
} else {
//echo "Please submit the form, thanks!";
}
;?>
Everything in form is correct like I added same name in form which i used in $_POST but still it's not working, please help me to fix this issue.
Here is html codes of form:
<form class="form-horizontal" id="admission_form" method="post" action="" enctype="multipart/form-data">
<!--div class="row">
<div class="col-lg-6">
<label for="admission_no"> Admission No. </label>
<input type="hidden" class="form-control" name="admission_no" value="<?php echo $admission_no ;?>" readonly disabled>
</div>
</div--><br>
<div class="row">
<div class="col-lg-6">
<label for="f_name"> First Name <span class="required">*</span> </label>
<input type="text" class="form-control" name="f_name" placeholder="Your first name" value="<?php echo $f_name ;?>" required>
</div>
<div class="col-lg-6">
<label for="l_name"> Last Name <span class="required">*</span></label>
<input type="text" class="form-control" name="l_name" placeholder="Your last name" value="<?php echo $l_name ;?>" required>
</div>
</div><br>
<div class="row">
<div class="col-lg-12">
<label for="p_add"> Permanent Address <span class="required">*</span></label>
<textarea class="form-control" name="p_add" placeholder="Please write your permanent address" value="<?php echo $p_add ;?>" required></textarea>
</div>
</div><br>
<div class="row">
<div class="col-lg-12">
<label for="c_add"> Current Address in Jodhpur <span class="required">*</span></label>
<textarea class="form-control" name="c_add" placeholder="Please write your address where you currently living" value="<?php echo $c_add ;?>" required></textarea>
</div>
</div><br>
<div class="row">
<div class="col-lg-6">
<label for="dob"> Date of birth <span class="required">*</span></label>
<input type="date" class="form-control" name="dob" placeholder="Your date of birth eg:- 25/11/1996" value="<?php echo $dob ;?>" required>
</div>
<div class="col-lg-6">
<label for="education"> Recent passed degree/exam - </label>
<input type="text" class="form-control" name="education" placeholder="for example - BA/ B.Sc etc." value="<?php echo $education ;?>" >
</div>
</div><br>
<div class="row">
<div class="col-lg-6">
<label for="mobile_no"> Mobile Number <span class="required">*</span></label>
<input type="number" class="form-control" name="mobile_no" placeholder="Enter your mobile number, eg - 8384991980" value="<?php echo $mobile_no ;?>" required>
</div>
<div class="col-lg-6">
<label for="course"> Select course <span class="required">*</span> </label>
<select class="form-control" name="course" required>
<option value="none"> --- Select one course --- </option>
<option value="IAS"> IAS </option>
<option value="RAS"> RAS </option>
<option value="Police constable"> Police constable </option>
<option value="SI"> SI </option>
<option value="Railway"> Railway </option>
<option value="REET"> REET </option>
<option value="Teacher"> Teacher </option>
<option value="Patwar"> Patwar </option>
<option value="Bank PO"> Bank PO </option>
<option value="Jr Accountant"> Jr Accountant </option>
<option value="Rajasthan police"> Rajasthan police </option>
<option value="SSC (10+2)"> SSC (10+2) </option>
</select>
</div>
</div><br>
<div class="row">
<div class="col-lg-6">
<label for="subjects"> Subjects - </label>
<input type="text" class="form-control" name="subjects" placeholder="Enter your subject you want to read" value="<?php echo $subjects ;?>" required>
</div>
<div class="col-lg-6">
<label for="timing"> Classes Timing - </label>
<input type="text" class="form-control" name="timing" placeholder="Your preferred time for coaching" value="<?php echo $timing ;?>" required>
</div>
</div><br>
<div class="row">
<div class="col-lg-6">
<label for="picture"> Upload your picture <span class="required">*</span></label>
<input type="file" class="form-control" name="picture" required>
</div>
<div class="col-lg-6">
<label for="sign"> Upload your signature <span class="required">*</span></label>
<input type="file" class="form-control" name="sign" required>
</div>
</div><br>
<div class="row">
<div class="col-md-12">
<input type="checkbox" aria-label="..." name="agree_terms" value="1"> I agree with Rules and Regulations mentioned below.<br>
<input type="checkbox" aria-label="..." name="agree_cond" value="1"> I hearbly declare that Adarsh Classes can use my pictures after my selection for advertising purpose.
</div><!-- /.col-lg-6 -->
</div><!-- /.row -->
<div class="row">
<div class="col-lg-6">
<div class="form-group">
<button type="text" name="submit" class="btn btn-success btn-lg btn-block" name="applyAdmission"> Submit my application form </button>
</div>
</div>
</div>
</form>
The reason behind that in the input type of the HTML Page for the submit you are using <input type="button"
instead of <input type="submit". Use <input type="submit" that's work.
Example:
<input type="submit" name="" value="Submit">
Changed
<button type="text">
to
<button type="submit">
Change
button type="text" to type="button" Or input type ="submit/button"
You need to change this code:
<button type="text" name="submit" class="btn btn-success btn-lg btn-block" name="applyAdmission"> Submit my application form </button>
with below code :
<input type="submit" name="applyAdmission" value="Submit my application form" class="btn btn-success btn-lg btn-block" />
You also need to make sure that your wrote PHP code in same file, otherwise you have to add PHP file name in action tag in below line:
<form class="form-horizontal" id="admission_form" method="post" action="" enctype="multipart/form-data">
You also have some PHP error in your code, so you have to add first line in your PHP code and then fix your PHP Fatal error.
ini_set('display_errors', '1');
I see a little syntax error and I think fixing this will fix your issue.
Change
include ("include/header.php"), include ("include/config.php");
to
include ("include/header.php");
include ("include/config.php");
To show you the syntax error, here is an example:
<?php
error_reporting(E_ALL);
ini_set('display_errors', 'On');
include("test.php"), include("someother.php");
The response:
Parse error: syntax error, unexpected ',' in ...\tests\includeTest.php on line 6
Incorrect input type
You should also change your button type.
Change
<button type="text"...
to
<button type="submit"...
Change <button> to <input>. Buttons can work with javascript but with only php button cant work with post data. You can not get POST data by <button>. For this you have to use <input>
Change this
<button type="text" name="submit" class="btn btn-success btn-lg btn-block" name="applyAdmission"> Submit my application form </button>
to
<input type="submit" name="applyAdmission">
Second:
Here is looking syntax error include ("include/header.php"), include ("include/config.php");
PHP requires instructions to be terminated with a semicolon at the end of each statement. Make them seperate by ; not by ,.
include ("include/header.php");
include ("include/config.php");
You can see documentation for more deep information
I am designing a website, and i encountered a problem.
In the following page "samgatha.org/register.php", wherever i click inside the form-box, it redirects to "samgatha.org/register.php". I am not able to find the problem.
Below i am posting the main code for the registeration form, i am not including the template code.
<div id="register-box">
<?php
require 'connection.php';
if($_SERVER['REQUEST_METHOD']=='POST') {
if((isset($_POST['enthu_name']))&&(isset($_POST['enthu_email']))&&(isset($_POST['enthu_contact']))&&(isset($_POST['college_name']))&&(isset($_POST['branch']))&&(isset($_POST['pass']))) {
$var_name = mysql_real_escape_string($_POST['enthu_name']);
if(!preg_match("/^[a-zA-Z ]*$/",$var_name)) {
die('Only letters and white spaces allowed in Name<br>');
}
$var_email = mysql_real_escape_string($_POST['enthu_email']);
if(!filter_var($var_email, FILTER_VALIDATE_EMAIL)) {
die("Invalid email format<br>");
}
$var_contact = mysql_real_escape_string($_POST['enthu_contact']);
$var_college = mysql_real_escape_string($_POST['college_name']);
$var_branch = mysql_real_escape_string($_POST['branch']);
$passwd = mysql_real_escape_string(md5($_POST['pass']));
$v1 = rand(0,getrandmax());
$v2 = rand(0,getrandmax());
$ac_conf = $v1.$v2;
$ac_conf_hash = md5($v1.$v2);
$v1 = rand(0,getrandmax());
$v2 = rand(0,getrandmax());
$fo_pass = $v1.$v2;
$query = "insert into student_detail (name,email,phno,college,branch,password,acc_confirm_code,forgot_pass_code)".
"values".
"('$var_name','$var_email','$var_contact','$var_college','$var_branch','$passwd','$ac_conf','$fo_pass')";
$retval = mysql_query($query);
if(!$retval) {
die('Could not register'.mysql_error());
}
$reg_conf_code = "http://samgatha.org/reg_conf.php?acconf=".$ac_conf_hash."&suse=".$var_email;
$reg_conf = "Please click on the link to activate<br>".$reg_conf_code;
mail($_POST['enthu_email'],"Samgatha Account Confirmation (no reply) link",$reg_conf);
header('Location: http://samgatha.org/login.php');
}
else {
echo "Please enter details to continue <br>";
}
}
?>
Welcome to samgatha registrations. <br>
Please fill out the following form to participate in samgatha.
<form id="sam_register" action="register.php" method="post">
<div class="reg-box-in">
<label class="i2" id="ii1" for="enthu_name">Name : </label>
<input class="i1" type="text" name="enthu_name" id="enthu_name"> <br>
</div>
<div class="reg-box-in">
<label class="i2" id="ii2" for="enthu_email">E-mail Address : </label>
<input class="i1" type="text" name="enthu_email" id="enthu_email"> <br>
</div>
<div class="reg-box-in">
<label class="i2" id="ii3" for="enthu_contact">Phone No : +91</label>
<input class="i1" type="text" name="enthu_contact" id="enthu_contact"> <br>
</div>
<div class="reg-box-in">
<label class="i2" id="ii4" for="college_name">Institute : </label>
<input class="i1" type="text" name="college_name" id="college_name"> <br>
</div>
<div class="reg-box-in">
<label class="i2" id="ii5" for="branch">Discipline : </label>
<input class="i1" type="text" name="branch" id="branch"> <br>
</div>
<div class="reg-box-in">
<label class="i2" id="ii6" for="password">Password : </label>
<input class="i1" type="text" name="pass" id="pass" maxlength="30"> <br>
</div>
<div class="reg-box-in">
<button type="submit" name="register">Register</button> <br>
</div>
</form>
</div>
And this is not the problem only with the register page.
You can check the website samgatha.org.
Various html issues
Unclosed link
<a href="login.php"><div id="register" class="lay2"><div id="registert">Sign In/Up</div></div>
<div id="register-box">
<?php
require 'connection.php';
if (!empty($_POST)) {
$var_name = mysql_real_escape_string(<?php echo htmlspecialchars($_POST["name"]); ?>);
//-- same used for post ------------
header('Location: http://samgatha.org/login.php');
}
else {
echo "Please enter details to continue <br>";
}
}
?>
Welcome to samgatha registrations. <br>
Please fill out the following form to participate in samgatha.
<form action=<?php echo htmlspecialchars($_SERVER["PHP_SELF"]); ?> method="post">
<div class="reg-box-in">
<label class="i2" id="ii1" for="enthu_name">Name : </label>
<input class="i1" type="text" name="enthu_name" id="enthu_name"> <br>
</div>
<div class="reg-box-in">
<label class="i2" id="ii2" for="enthu_email">E-mail Address : </label>
<input class="i1" type="text" name="enthu_email" id="enthu_email"> <br>
</div>
<div class="reg-box-in">
<label class="i2" id="ii3" for="enthu_contact">Phone No : +91</label>
<input class="i1" type="text" name="enthu_contact" id="enthu_contact"> <br>
</div>
<div class="reg-box-in">
<label class="i2" id="ii4" for="college_name">Institute : </label>
<input class="i1" type="text" name="college_name" id="college_name"> <br>
</div>
<div class="reg-box-in">
<label class="i2" id="ii5" for="branch">Discipline : </label>
<input class="i1" type="text" name="branch" id="branch"> <br>
</div>
<div class="reg-box-in">
<label class="i2" id="ii6" for="password">Password : </label>
<input class="i1" type="text" name="pass" id="pass" maxlength="30"> <br>
</div>
<div class="reg-box-in">
<button type="submit" name="register">Register</button> <br>
</form>
</div>
</div>
There is <a> tag on register-box which redirects to login.php. Please check your code it puts <a> tag.
So I am working on a file upload form that seems to lose the information in the file super global from one step to another. So what I do is I print out the file super global before I verify through captcha and then print it out once I validate through the captcha. For some way I lose the information after verifying the captcha. I have tried storing the information in a cookie and a session variable but with no luck. In terms of the cookie direction it saves the file super global information into the cookie only if I hit refresh before captcha validation. In terms of session storage it stores the information in the session variable before I verify the captch but then lose it after I verify the captach. Can you guys people help, and thanks in advance. My code is below:
$DIRECTORY_NAME = "/home/www/xxx/xxxPhotos/";
$FILES = array();
$SPEAKER_STATUS_DROPDOWN = '<option value="">...</option><option value="Suggested">Suggested</option><option value="Invited">Invited</option><option value="Confirmed">Confirmed</option>';
if (empty($_SESSION['captcha']) || strtolower(trim($_REQUEST['captcha'])) != $_SESSION['captcha']) {
$captcha = false;
} else {
$captcha = true;
}
if (!empty($_POST) && $captcha) {
$UNIQ_ID = $_POST['uniq_id'];
$FORM_ID = $_POST['form_id'];
//$uniqid = createuniqid();
// Upload file
if ($_FILES["file"]["name"] != "") {
if ($_FILES["file"]["error"] > 0)
{
echo "Return Code: " . $_FILES["file"]["error"] . "<br />";
die();
}
else
{
$allowedExtensions = array("jpg","gif","tiff","pdf");
if ($file["file"]['tmp_name'] != '') {
if (!in_array(end(explode(".",
strtolower($file["file"]['name']))),
$allowedExtensions)) {
die($file["file"]['name'].' is an invalid file type!<br/>'.
'<a href="javascript:history.go(-1);">'.
'<< Go Back</a>');
}
}
$filename = "AS_".$uniqid."". strrchr($_FILES["file"]["name"], '.');
move_uploaded_file($_FILES["file"]["tmp_name"],
$DIRECTORY_NAME . $filename);
$filenamequery = ", attachment='$filename' ";
$filenameemailbody = "<br>Attachment: http://www.verney.ca/viewabstract.php?filename=$filename";
}
die('reached here');
}
HTML Form
<form name="frmAbstract" id ="frmAbstract" method="post" action="storiesv.php" onSubmit="return validation();" enctype="multipart/form-data" style="margin-left:20px;">
<input type="hidden" name="uniq_id" value="">
<input type="hidden" name="form_id" value="6">
<div><label class="labelHeader"><strong><h1>Form</h1></strong></label><br/></div>
<div class="formrow">
<label for="question_390">First Name of Submitter: <span style="color:#FF0000">*</span></label>
<input type="text" id="question_390" name="question_390" style="width:500px" maxlength="255" value="">
</div>
<div class="formrow">
<label for="question_391">Last Name of Submitter: <span style="color:#FF0000">*</span></label>
<input type="text" id="question_391" name="question_391" style="width:500px" maxlength="255" value="">
</div>
<div class="formrow">
<label for="question_392">Title: </label>
<input type="text" id="question_392" name="question_392" style="width:500px" maxlength="255" value="">
</div>
<div class="formrow">
<label for="question_393">Organization: </label>
<input type="text" id="question_393" name="question_393" style="width:500px" maxlength="255" value="">
</div>
<div class="formrow">
<label for="question_394">Phone: </label>
<input type="text" id="question_394" name="question_394" style="width:500px" maxlength="255" value="">
</div>
<div class="formrow">
<label for="question_395">Email: <span style="color:#FF0000">*</span></label>
<input type="text" id="question_395" name="question_395" style="width:500px" maxlength="255" value="">
</div>
<div class="formrow">
<label for="question_396">Involvement with the CBS: </label>
<input type="text" id="question_396" name="question_396" style="width:500px" maxlength="255" value="">
</div>
<div class="formrow">
<label for="question_397">First became a CBS member in (yyyy): <span style="color:#FF0000">*</span></label>
<input type="text" id="question_397" name="question_397" style="width:500px" maxlength="255" value="">
</div>
<div class="formrow">
<label for="question_398">Your story/experience/anecdote (limit of 250 words): </label>
<textarea name="question_398" name="question_398" style="width:500px;height:200px;"></textarea>
</div>
<div class="formrow" >
<label>Do you have a photo / graphic to upload (scans of print photos are acceptable)? </label>
<div class="checkboxdiv"><input type="radio" style="width:20px;float:left;border:0px;"id="question_399_0" name="question_399[]" value="Yes"><label for="question_399_0">Yes</label></div><div class="checkboxdiv"><input type="radio" style="width:20px;float:left;border:0px;"id="question_399_1" name="question_399[]" value="No"><label for="question_399_1">No</label></div><strong><em></em></strong><div style="clear:both;"></div></div>
<div>
<label for="question_400">Attachment: (Only jpg, gif, tiff, pdf, will be accepted) </label>
<input type="file" id="question_400" name="question_400" style="width:500px;">
</div>
<div class="formrow">
<label for="question_401">For photos submitted, please include names of people in the photo, location, and date. </label>
<textarea name="question_401" name="question_401" style="width:500px;height:200px;"></textarea>
</div>
<div class="formrow" >
<label>Do we have permission to publish this photo in a slide show to be featured at the 2014 CBS Conference and possibly in a printed collection of memoirs intended for past and present CBS members? </label>
<div class="checkboxdiv"><input type="radio" style="width:20px;float:left;border:0px;"id="question_402_0" name="question_402[]" value="Yes"><label for="question_402_0">Yes</label></div><div class="checkboxdiv"><input type="radio" style="width:20px;float:left;border:0px;"id="question_402_1" name="question_402[]" value="No"><label for="question_402_1">No</label></div><strong><em></em></strong><div style="clear:both;"></div></div><div><label class="labelHeader"><strong>Questions</strong></label><br/></div>
<div class="formrow">
<label for="question_404">Tell us about your experience(s) with the CBS. </label>
<input type="text" id="question_404" name="question_404" style="width:500px" maxlength="255" value="">
</div>
<div class="formrow">
<label for="question_405">How did you become involved in the CBS? </label>
<input type="text" id="question_405" name="question_405" style="width:500px" maxlength="255" value="">
</div>
<div class="formrow">
<label for="question_406">What is your best memory of the CBS? </label>
<input type="text" id="question_406" name="question_406" style="width:500px" maxlength="255" value="">
</div>
<div class="formrow">
<label for="question_407">Who have been your role models in the field? </label>
<input type="text" id="question_407" name="question_407" style="width:500px" maxlength="255" value="">
</div>
<div class="formrow">
<label for="question_408">What has been the most significant accomplishment of Canadian bioethics? </label>
<input type="text" id="question_408" name="question_408" style="width:500px" maxlength="255" value="">
</div>
<div class="formrow">
<label for="question_409">What is our biggest challenge going forward? </label>
<input type="text" id="question_409" name="question_409" style="width:500px" maxlength="255" value="">
</div>
</fieldset>
<div style="clear:both;"><br><input type="submit" name="btnSave" id="btnSave" value="Next" class="submitbutton" "></div>
<p> </p>
</form>
So the code above is the original code I have been working with. It essentially does the file upload after the captcha is validated, and this is where I lose $_FILES super global
ANSWER: Thanks for all those who viewed my question. The issue was the captcha was in a form on it own page with a enctype set. Therefore the $_FILES super global was overwritten with that forms $_FILES, which of course is not set.
The name of your file input is question_400, so you would need $_FILES["question_400"]["name"], etc.
I have a php order form named (order.php) and when the user clicks the (submit button "Next Step") it takes him to another page called (confirm-order.php)
The (confirm-order.php) shows the information that the user submitted from the (order.php) using the $_POST[] and by assigning each one of these to a variable.
Data showing on the (confirm-order.php) plain text like for example :
$itemName = $_POST['itemName'];
<?php echo $itemName; ?>
at the end of page there is a form contains only one element as (submit button)
How can i insert the $itemName data into mysql database only (after the submit button is clicked and the form actions take me to the confirmation page)?
I know how to insert data into mysql, but it didn't work with the isset() function
Do i have to write the isset function inside the form first? and below it the mysql database code?
order.php page:
<form class="form-horizontal well" action="confirm-order.php" method="POST">
<fieldset>
<legend>Personal Shopper Order Form</legend>
<div class="control-group">
<label class="control-label" for="select01">Choose a plan</label>
<div class="controls">
<select id="select01" name="plan">
<option>Lite Plan $0 per order</option>
</select>
</div>
</div>
<div class="control-group">
<label class="control-label" for="itemName">Item Name</label>
<div class="controls">
<input type="text" class="input-xlarge" id="itemName" name="itemName">
<p class="help-block">Item name exapmle: iPad3 White 32GB wifi & 3G.</p>
</div>
</div>
<div class="control-group">
<label class="control-label" for="itemID">Item ID</label>
<div class="controls">
<input type="text" class="input-xlarge" id="itemID" name="itemID">
<p class="help-block">example: Ebay Item ID, Amazon Item ID.</p>
</div><br>
<div class="control-group">
<label class="control-label" for="itemURL">Item URL</label>
<div class="controls">
<input type="text" class="input-xxlarge" id="itemURL" name="itemURL">
<p class="help-block">Direct web link to the item.</p>
</div>
</div>
<div class="control-group">
<label class="control-label" for="textarea">Item Details</label>
<div class="controls">
<textarea class="input-xlarge" id="textarea" name="itemDetails" rows="6"></textarea>
<p class="help-block">Item details (name, color, specifications etc...)</p>
</div>
</div>
<li id="li_3" data-pricefield="money_simple" data-pricevalue="0">
<div class="input-prepend input-append">
<label class="control-label" for="element_3_1">Item Price</label>
<div class="controls">
<span class="add-on">$</span>
<input id="element_3_1" data-price-value="10.00" name="element_3" type="text" class="element text large">
<p class="help-block">Item exact price on the US online store.</p>
</div>
</div>
</li>
<li id="li_7" data-pricefield="money_simple" data-pricevalue="0">
<div class="input-prepend input-append">
<label class="control-label" for="element_7_1">Local Shipping Cost</label>
<div class="controls">
<span class="add-on">$</span>
<input id="element_7_1" data-price-value="10.00" name="element_7" type="text" class="element text large">
</div>
<p class="help-block">Local shipping fee from the US Store to Sky2ship (if applicable).</p>
</div>
</li>
<li id="li_8" data-pricefield="radio" data-pricevalue="0">
<div class="control-group">
<div class="controls">
<p class="help-block">Order Processing Service Fee.</p>
<label class="radio">($0) Standard 2-3 days
<input id="element_8_1" data-pricedef="00.00" name="element_8" class="element radio" type="radio" value="$0 Standard 2-3 Day">
</label>
<label class="radio">($10) Express 1 day
<input id="element_8_2" data-pricedef="10.00" name="element_8" class="element radio" type="radio" value="$10 Express Same Day">
</label>
</div>
</div>
</li>
<legend>Personal Information & Shipping Address</legend>
<div class="control-group">
<label class="control-label" for="input04">Full Name</label>
<div class="controls">
<input type="text" class="input-medium" id="fullName" name="fullName">
<p class="help-block">First & last name.</p>
</div>
</div>
<div class="control-group">
<div class="controls">
<label class="radio">Male
<input type="radio" name="optionsRadios" id="optionsRadios1" value="option1" checked>
</label>
<label class="radio">
<input type="radio" name="optionsRadios" id="optionsRadios2" value="option2">Female
</label>
</div>
</div>
<div class="input-prepend">
<label class="control-label" for="prependedInput">Email Address</label>
<div class="controls">
<span class="add-on">#</span>
<input type="text" class="span2" id="prependedInput" name="Email">
<p class="help-block">Your email address.</p>
</div>
</div>
<div class="control-group">
<label class="control-label" for="input06">Address</label>
<div class="controls">
<input type="text" class="input-xxlarge" id="input06" name="streetAddress" placeholder="Street Address">
<p class="help-block">Your shipping address.</p>
</div>
</div>
<div class="control-group">
<div class="controls controls-row">
<input type="text" class="span2" id="City" name="City" placeholder="City">
<input type="text" class="span3" id="State" name="State" placeholder="State / Province">
</div>
</div>
<div class="control-group">
<div class="controls controls-row">
<input type="text" class="span2" id="PostalCode" name="PostalCode" placeholder="Postal Code">
<input type="text" class="span3" id="Phone" name="Phone" placeholder="Phone Number">
</div>
</div>
<div class="control-group">
<label class="control-label" for="select01">Country</label>
<div class="controls">
<select id="select02" name="Country">
<option>IRAQ</option>
<option>JORDON</option>
</select>
</div>
</div>
<li class="total_payment" align="right" data-basetotal="0">
<span>
<h3 class="alert-success">$<var>0</var></h3>
<h5>Total</h5>
</span>
</li>
<div class="control-group">
<label class="control-label" for="optionsCheckbox">Read & Agree</label>
<div class="controls">
<label class="checkbox">
<input type="checkbox" id="optionsCheckbox" value="option1">
I agree to the site's Terms of Service & Privacy Policy.
</label>
</div>
</div>
<div class="form-actions">
<button type="submit" class="btn btn-primary">Confirm Order</button>
<button type="reset" class="btn">Cancel Order</button>
</div>
</fieldset>
</form>
confirm-order.php page:
<?php
$itemName = $_POST['itemName'];
$plan = $_POST['plan'];
$itemID = $_POST['itemID'];
$itemPrice = $_POST['element_3'];
$processService = $_POST['element_8'];
$itemDetails = $_POST['itemDetails'];
$streetAddress = $_POST['streetAddress'];
$City = $_POST['City'];
$State = $_POST['State'];
$PostalCode = $_POST['PostalCode'];
$Phone = $_POST['Phone'];
$Country = $_POST['Country'];
$fullName = $_POST['fullName'];
$Email = $_POST['Email'];
$itemURL = $_POST['itemURL'];
$itemLocalShipCost = $_POST['element_7'];
?>
<?php
$db_host = "localhost";
$db_user = "root";
$db_pass = "000000";
$db_name = "dbname";
if (isset($_POST['submit'])) {
$db_connect = mysqli_connect($db_host,$db_user,$db_pass,$db_name);
// Check connection
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$sql ="INSERT INTO lite_order (lite_plan, lite_item_name)
VALUES
('$plan','$item')";
if (!mysqli_query($db_connect,$sql))
{
die('Error: ' . mysqli_error($db_connect));
}
echo "1 record added";
}
?>
<address>
<strong>Shipping Address.</strong><br>
<?php echo $streetAddress; ?><br>
<?php echo $City; ?>, <?php echo $State; ?>, <?php echo $PostalCode; ?><br><?php echo $Country; ?><br>
<abbr title="Phone">P:</abbr><?php echo $Phone; ?>
</address>
<address>
<strong><?php echo $fullName; ?></strong><br>
<?php echo $Email; ?>
</address>
<table class="table">
<thead>
<tr>
<th>Plan</th>
<th>Item Name</th>
<th>Item ID</th>
<th>Local Shipping Cost</th>
<th>Item Price</th>
<th>Order Processing Fee</th>
</tr>
</thead>
<tbody>
<tr class="success">
<td><?php echo $plan; ?></td>
<td><?php echo $itemName; ?></td>
<td><?php echo $itemID; ?></td>
<td><?php echo "$" . $itemLocalShipCost; ?></td>
<td><?php echo "$" . $itemPrice; ?></td>
<td><?php echo $processService; ?></td
></tr>
</tbody>
</table>
<strong>Item URL</strong><p class="alert alert-info"><?php echo $itemURL; ?></p>
<pre class="pre-scrollable"><?php echo $itemDetails; ?></pre>
<p>Your Total <h3 class="question"><?php echo "$" . $orderTotal; ?></h3></p>
<div class="form-actions"><form action="pending-order.php" method="post" name="confirmed-order">
<button type="submit" name="submit" class="btn btn-primary">Submit Order</button>
<button type="button" class="btn">Previous</button></form>
</div>
</div>
</div>
</div>
</div>
</div>
Whereto insert the mysql database code to insert all the variables into database after the submit button is clicked? where to place the isset() function? i tried it, it didn't insert any data into my table.
EDIT: a simple example
do <form>, validation and inserting in one file, say form.php:
<? // check if FORM has been posted
$posted = isset($_POST['submit']);
if ($posted) { // form has been posted...
// validate input
if (!isset($_POST['item']) || strlen(trim($_POST['item'])) == 0)
$error['item'] = "please insert an item-name!";
if (!isset($_POST['price']) || !is_numeric($_POST['price']))
$error['price'] = "please enter a valid price!";
// ready for input?
if (!isset($error)) { // no $error --> go insert!
// I'll do the db-operation with PDO and a prepared statement.
// this is cool, easy and safe. LEARN IT!
$sql = "INSERT INTO table (item,price) VALUES (:item,:price)";
$insert = $db->prepare($sql);
$insert->execute(array(
':item' => $_POST['item'],
':price' => $_POST['price']
));
} // $error
} // submit
?>
Now, in the <body> of the same page...
<? // check whether to display confirmation or form...
if ($posted && !isset($error)) {
// form was sent AND no error --> confirm
?>
<h1>Confirmed!</h1>
<p>Your data has been sent, thank you very much!</p>
go to somepage
<?
} else {
// form not sent or errors --> display form
?>
<h1>Please enter data</h1>
<? // display error-message, if there's one:
if (isset($error)) {
$output = "";
foreach ($error as $field => $msg)
$output .= (strlen($output) > 0?', ':'') . "[$field]: $msg";
echo "<p>There were errors: $output</p>";
} // $error
?>
<form method="post">
<!-- if the form has been sent, bring back the field's value from $_POST -->
<p>item-name: <input type="text" name="item"
value="<?=($posted?$_POST['item']:'')?>" /></p>
<p>price: <input type="text" name="price"
value="<?=($posted?$_POST['price']:'')?>" /></p>
<p><input type="submit" name="submit" value="submit" /></p>
</form>
<?
} // submit & $error
?>
See the use of a ternary-operator for setting the value-attribute of the <input>-elements:
(<condition>?<what to do if true>:<what to do if false>)
There are two specific things I can contribute.
First, isset tests for null... which is different than empty. If you have a form field that is submitted empty, then set a local variable to that posted value, then test it with isset; isset will return true because the value exists which is different than the variable not having been registered in the page load at all.
Second... ANYTHING can post to your form (think evil autonomous Korean hacker bots). Also, there are many ways a form can get submitted without having activated the submit button itself so there is no guarantee you will even see a submit key in your $_POST vars. What you need to define in your processing script is a "default action". What I mean by that is a very basic and SAFE behavior (like redirecting to a 'something is wrong' page) that kicks off by default such that the only way around it is to submit a correct form with all anticipated values correctly set.
If you do this, you can ignore the value of the submit button itself and instead focus on the contents of the POST. Did I receive everything I expected to receive? Was it all in the correct format? Was the user authenticated correctly? Only after all these questions have been tested to your satisfaction would you switch from the default behavior to a form processing behavior in which the posted data can be inserted into your database.
Example using your 3 page structure:
reference: filter vars
Page 1:
<form action=./page2 method=POST>
<input type=text value=1234 name=numericValue />
<input type=text value="dummytext" name=stringValue />
<input type=submit value=submit name=submit />
</form>
Page 2:
<?php
$args = array('numericValue' => FILTER_VALIDATE_INT
,'stringValue' => FILTER_SANITIZE_STRING);
$clean_data = filter_input_array(INPUT_POST,$args);
if (is_array($clean_data))
{
$_SESSION["saved_clean_data"] = $clean_data;
}
else
{
Header(<something wrong page>);
die();
}
?>
<form action=./page3 method=POST>
<input type=submit name=submit value=No />
<input type=submit name=submit value=Yes />
</form>
Page 3:
<?php
if ($_POST["submit"] === "Yes")
{
$cleanNum = $_SESSION["saved_clean_data"]["numericValue"];
$cleanStr = $_SESSION["saved_clean_data"]["stringValue"];
// DB insert Query, use advice from michi about PDO
// parameterize your queries to help prevent sql injection
}
else
{
Header(<somewhere for declined submits>);
die();
}
?>
Well we can do this in the following ways
You store all the data in session and use it in confirmation page and then on data insertion page. Do remember to update or delete it if user updates or cancel the order.
You can dynamically create the confirm order page using javascript and HTML and when user clicks confirm button then only we post it to the PHP page. This will also reduce a server call.
One other ways is to again send the collected posted values and keep it as hidden fields in the confirmation page and post it when clicked confirm.
create a form and store variables in hidden fields , then create this submit button in the form
So clicking this form will store the info. See the exmple here
<form class="form-horizontal well" action="confirm-order.php" method="POST">
<input type="hidden" value="<?php echo $itemName; ?>" />
<input type="submit" value="Confirm Order" />
</form>
Well there are couple of ways about doing this:
Store all the data from the previous page i.e. from order.php in the $SESSION[] variables:
Explaination: Setting it in Session will enable you to access the same variable from anywhere in the site until the session of the user. Means that after you store it in session you can access it in pending-order.php page.
How to do it: In this page at the top, instead of setting the variables at top write the following:
$SESSION['itemName'] = $_POST['itemName']
then echo it using:
echo $SESSION['itemName']
and then in the pending-order.php you can assign a value to a variable like so:
$itemName = $SESSION['itemName']
and now you can store the variable in the db.
Put hidden fields inside the form of confirm-order.php page:
Explaination: Create hidden input fields in confirm-order.php form and set the values that are in the variables. This way when you click the submit button you can access them in pending-order.php in the same way you are doing on confirm-order.php.
How to do it: Simply put the variables in value attribute of the hidden input like so:
<form action="pending-order.php" method="post" name="confirmed-order">
<input type="hidden" value="<?php $itemID ?>" id="someID">
</form>
Try
<button type="submit" class="btn btn-primary" NAME="submit">Confirm Order</button>
And use
IF (isset($_POST['submit]) {
$itemName = $_POST['itemName'];
$plan = $_POST['plan'];
$itemID = $_POST['itemID'];
$itemPrice = $_POST['element_3'];
$processService = $_POST['element_8'];
$itemDetails = $_POST['itemDetails'];
$streetAddress = $_POST['streetAddress'];
$City = $_POST['City'];
$State = $_POST['State'];
$PostalCode = $_POST['PostalCode'];
$Phone = $_POST['Phone'];
$Country = $_POST['Country'];
$fullName = $_POST['fullName'];
$Email = $_POST['Email'];
$itemURL = $_POST['itemURL'];
$itemLocalShipCost = $_POST['element_7'];
// your mysql INSERT codes here
}
EDIT 1:
change <button type="submit" class="btn btn-primary">Confirm Order</button>
TO <input type="submit" class="btn btn-primary" value="Confirm Order">
isset() function work when the input field type is submit.like
<input type="submit" value="Confirm Order" />
so update the code form
<div class="form-actions">
<button type="submit" class="btn btn-primary">Confirm Order</button>
<button type="reset" class="btn">Cancel Order</button>
</div>
to
<div class="form-actions">
<input type="submit" class="btn btn-primary" value="Confirm Order" />
<input class="btn" type="reset" value="Cancel Order" />
</div>