Create form using smarty function - php

Yes! that's the exact doubt I have. I was given an assignment of
Create a form using smarty functions
(fields should be First Name, Last Name, Address, Email, Gender,
Qualifications, Phone number, etc.)
and I don't have any idea what they are talking about. So I want to ask that is there any function() which is used for making form elements or any other possibilities?I tried searching on google but didn't get any positive result.

PHP Code
<?php
include_once "../prepengine-header.php";
$lets = $_POST['user_lang'][1];
$var = $_POST['user_lang'][0];
$var .= $lets;
$formdata = "";
if (isset($data['submit'])) {
$formdata .= $data['user_firstname']."\n" ;
$formdata .= $data['user_lastname']."\n" ;
$formdata .= $data['user_address']."\n" ;
$formdata .= $data['user_qual']."\n" ;
$formdata .= $data['user_gender']."\n" ;
$formdata .= $var."\n" ;
$formdata .= $data['user_email']."\n" ;
$formdata .= $data['user_num']."\n" ;
$formdata .= $data['user_select']."\n" ;
}
$theme->assign('data',$data);
$theme->assign('formdata',$formdata);
echo($theme->fetch('smartart/screen5-a (1).tpl'));
?>
Smarty code
<!DOCTYPE html>
<html>
<head>
<title></title>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
</head>
<body>
<div class="container">
<form class="form-horizontal" name="registration_form" id="registration_form" method="post" action="#">
<div class="form-group">
<label class="control-label col-lg-2" for="firstname">First Name: <sup style="color: #FF0000;">*</sup></label>
<div class="col-lg-10">
<input type="text" name="firstname" id="firstname" placeholder="Enter firstname" class="form-control" required="required" />
</div>
</div>
<div class="form-group row">
<label class="control-label col-lg-2" for="lastname">Last Name: <span style="color: #FF0000;">*</span></label>
<div class="col-lg-10">
<input type="text" name="lastname" id="lastname" placeholder="lastname" class="form-control" required="required" />
</div>
</div>
<div class="form-group row">
<label class="control-label col-lg-2" for="address">Address <span style="color: #FF0000;">*</span></label>
<div class="col-lg-10">
<textarea id="address" name="address" class="form-control" placeholder="Provide Address" required="required"></textarea>
</div>
</div>
<div class="form-group row">
<label class="control-label col-lg-2" for="gender">Gender <span style="color: #FF0000;">*</span></label>
<div class="col-lg-10">
<{html_radios name='gender' values=$cust_id output=$cust_gender selected=$custom_id separator='<br />'}>
</div>
</div>
<div class="form-group row">
<label class="control-label col-lg-2" for="user_lang">Languages</label>
<div class="col-lg-10">
<{html_checkboxes name='user_lang' values=$cust_ids output=$cust_names selected=$customer_id separator='<br/>'}>
</div>
</div>
<div class="form-group row">
<label class="control-label col-lg-2" for="user_country">Country</label>
<div class="col-lg-10">
<{html_options name='select' options=$myOptions class="form-control"}>
</div>
</div>
<div class="form-group">
<div class="col-sm-offset-2 col-sm-10">
<input type="submit" name="submit" id="submit_button" class="btn btn-default" value="Submit">
</div>
</div>
</form>
</div>
</body>
</html>

Related

As new to php i am not clear over the jumps betveen php-pages. My code below. is this the right way?

I want to se available dates in a dropdown - done
After i´v choosen the date i want to see the available time - done
The customer should be able to book the choosen timeslot - I think i knowe this one, work in progress.
Problem: I want the customer to se the dropdown and the result in the same page and maybe change it when the time comes visably. I´v been playing around with action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>" but thats not it i belive.
I am a bit lost in best practice regarding files and jumps betveen them. I have separated the php and html code in different pages. When i´m ready i lift the php-files to includes folder offcourse.
HTML - form with dropdown and submit
php - fill dropdown with dates
html - form with result text fields
php - code for result (timeslot data)
form_date.php
<?PHP
require_once('booking_available_dates.php');
?>
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css">
<form name='date_registration' action='booking_available_dates.php' method='POST'>
<div class="form-group row">
<label for="select" class="col-2 col-form-label">Hämta första lediga tid för valt datum</label>
<div class="col-10">
<select id="date_input" name="date_input" class="custom-select">
<?php foreach ($dates as $row): ?>
<option><?=$row["date_booking_customer"]?></option>
<?php endforeach ?>
</select>
</div>
</div>
<div class="form-group row">
<div class="offset-4 col-8">
<button name="submit" type="submit" class="btn btn-primary">Hämta tid!</button>
</div>
</div>
</form>
booking_available_dates.php
<?php
require_once('dbhandler.php');
$dbh = new DBHandler();
if ($dbh->getInstance() === null) {
die("No database connection");
}
try {
$sql = "CALL `booking_dates_available`();";
$stmt = $dbh->getInstance()->prepare($sql);
$stmt->execute();
$dates=$stmt->fetchAll();
}
catch(PDOException $e) {
echo ($e->getMessage());
}
?>
booking_confirm_view.php (not ready - work in progress)
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css">
<form>
<div class="form-group row">
<label for="date" class="col-4 col-form-label">Datum</label>
<div class="col-8">
<input id="date" readonly="readonly" name="date" type="text" class="form-control">
</div>
</div>
<div class="form-group row">
<label for="time" class="col-4 col-form-label">Tid</label>
<div class="col-8">
<input id="time" readonly="readonly" name="time" type="text" class="form-control">
</div>
</div>
<div class="form-group row">
<label for="owner" class="col-4 col-form-label">Båtägare</label>
<div class="col-8">
<input id="owner" name="owner" type="text" class="form-control" required="required">
</div>
</div>
<div class="form-group row">
<label class="col-4">Medlem i HSS?</label>
<div class="col-8">
<div class="custom-control custom-radio custom-control-inline">
<input name="member" id="member_0" type="radio" required="required" class="custom-control-input" value="thru">
<label for="member_0" class="custom-control-label">Medlem</label>
</div>
<div class="custom-control custom-radio custom-control-inline">
<input name="member" id="member_1" type="radio" required="required" class="custom-control-input" value="false">
<label for="member_1" class="custom-control-label">Ej medlem</label>
</div>
</div>
</div>
<div class="form-group row">
<label for="boatname" class="col-4 col-form-label">Båtnamn</label>
<div class="col-8">
<input id="boatname" name="boatname" type="text" class="form-control">
</div>
</div>
<div class="form-group row">
<label for="email" class="col-4 col-form-label">E-post</label>
<div class="col-8">
<input id="email" name="email" type="text" class="form-control" required="required">
</div>
</div>
<div class="form-group row">
<label for="mobile" class="col-4 col-form-label">Mobilnummer</label>
<div class="col-8">
<input id="mobile" name="mobile" type="text" class="form-control" required="required">
</div>
</div>
<div class="form-group row">
<div class="offset-4 col-8">
<button name="submit" type="submit" class="btn btn-primary">Submit</button>
</div>
</div>
</form>
booking_available_time.php
<?php
require_once('dbhandler.php');
$dbh = new DBHandler();
if ($dbh->getInstance() === null) {
die("No database connection");
}
try {
$sql = "CALL `booking_date_input` (:date_input);";
$stmt = $dbh->getInstance()->prepare($sql);
$stmt->bindParam(':date_input', $date_input, PDO::PARAM_STR);
$date_input = $_POST["date_input"];
$stmt->execute();
$result=$stmt->fetchAll();
}
catch(PDOException $e) {
echo ($e->getMessage());
}
?>
$result is the array with the timeslot data.

Cannot insert when clicking a button in Mysql using PHP

I am a beginner in web development, I used have an html elements, like textbox and other type of elements, I want to use them as my object and when they have a value and click a button, it will save the value of all the elements in mysql.
I have a code like this, but it cannot be inserted and anything does not happen when clicking a button.
Please help.
PHP:
<?php
define('DB_SERVER', 'localhost');
define('DB_USERNAME', 'root');
define('DB_PASSWORD', '');
define('DB_DATABASE', 'ytp');
$db = mysqli_connect(DB_SERVER,DB_USERNAME,DB_PASSWORD,DB_DATABASE);
if(!$db ) {
die('Could not connect: ' . mysqli_error());
}
$fname = "";
$mname = "";
$lname = "";
$funame = "";
$cnum = "";
$bday = "";
$age = "";
$add = "";
if (isset($_POST['submit'])){
$fname = $_POST['fName'];
$mname = $_POST['mName'];
$lname = $_POST['lName'];
$funame = $_POST['fuName'];
$cnum = $_POST['Cnumber'];
$bday = $_POST['bday'];
$age = $_POST['age'];
$add = $_POST["address"];
}
$sql = "INSERT INTO employee ".
"(fName,mName,lName,fuName,cNumber,bDay,Age,Address) ".
"VALUES ('$fname','$mname','$lname','$funame','$cnum','$bday','$age','$add' )";
if (! mysqli_query($db , $sql)){
echo 'Cannot Insert';
}
else{
echo 'Success';
}
?>
HTML:
<div class="content">
<div class="row">
<div class="col-md-10">
<div class="card">
<div class="card-header">
<h5 class="title">Add User Information</h5>
</div>
<div class="card-body">
<form method="POST" action="php_functions\saveEmployee.php" name="INSERT">
<div class="row">
<div class="col-md-5 pr-md-1">
<div class="form-group">
<label>Company (disabled)</label>
<input type="text" class="form-control" disabled="" placeholder="Company" value="Benchmark Valuer's Inc.">
</div>
</div>
<div class="col-md-3 px-md-1">
<div class="form-group">
<label>ID</label>
<input type="text" class="form-control" placeholder="User ID" value="" id="id" name ="id" disabled>
</div>
</div>
<div class="col-md-4 pl-md-1">
<div class="form-group">
<label for="exampleInputEmail1">Email address</label>
<input type="email" class="form-control" placeholder="s.sample#gmail.com" id="email" name ="email">
</div>
</div>
</div>
<div class="row">
<div class="col-md-4 pr-md-1">
<div class="form-group">
<label>First Name</label>
<input type="text" class="form-control" placeholder="First Name" id="fName" name ="fName">
</div>
</div>
<div class="col-md-4 pl-md-1">
<div class="form-group">
<label>Middle Name</label>
<input type="text" class="form-control" placeholder="Middle Name" id="mName" name ="mName">
</div>
</div>
<div class="col-md-4 pl-md-1">
<div class="form-group">
<label>Last Name</label>
<input type="text" class="form-control" placeholder="Last Name" id="lName" name ="lName">
</div>
</div>
<div class="col-md-4 pl-md-1" hidden>
<div class="form-group">
<label>Fullname</label>
<input type="text" class="form-control" placeholder="Full Name" id="fuName" name ="fuName">
</div>
</div>
</div>
<div class="row">
<div class="col-md-4 pr-md-1">
<div class="form-group">
<label>Contact Number</label>
<input type="tel" class="form-control" placeholder="Contact Number" id="Cnumber" name="Cnumber">
</div>
</div>
<div class="col-md-4 pl-md-1">
<div class="form-group">
<label>Age</label>
<input type="number" class="form-control" placeholder="Age" id="age" name="age">
</div>
</div>
<div class="col-md-4 pl-md-1">
<div class="form-group">
<label>Birthday</label>
<input type="date" class="form-control" placeholder="Birthday" id="bday" name="bday">
</div>
</div>
</div>
<div class="row">
<div class="col-md-12">
<div class="form-group">
<label>Address</label>
<input type="text" class="form-control" placeholder="Home Address" id="address" name ="address">
</div>
</div>
</div>
<div class="row">
<div class="col-md-4 pr-md-1">
<div class="form-group">
<label>Username</label>
<input type="text" class="form-control" placeholder="Username" id="uName">
</div>
</div>
<div class="col-md-4 px-md-1">
<div class="form-group">
<label>Password</label>
<input type="password" class="form-control" placeholder="Password" id="pWord">
</div>
</div>
<div class="col-md-4 pl-md-1">
<div class="form-group">
<label>UserType</label>
<input type="number" class="form-control" placeholder="0" id="uType">
</div>
</div>
</div>
<div class="row" hidden>
<div class="col-md-12">
<div class="form-group">
<label>Image Path:</label>
<input type="text" class="form-control" placeholder="C:\\" id="imageURL">
</div>
</div>
</div>
</form>
</div>
<div class="card-footer">
<button type="submit" class="btn btn-fill btn-primary" id="submit" name="submit">Save</button>
<button class="btn btn-fill btn-success" id="btnBrowse">Browse</button>
<button class="btn btn-fill btn-danger" id="btnCancel">Cancel</button>
</div>
</div>
</div>
</div>
</div>
Your HTML form is closing before submit button. You should close that after submit button and also need to manage hierarchy of opening form tag as below:
<form method="POST" action="php_functions\saveEmployee.php" name="INSERT">
<div class="card-body">
<div class="row">
<div class="col-md-5 pr-md-1">
<div class="form-group">
<label>Company (disabled)</label>
<input type="text" class="form-control" disabled="" placeholder="Company" value="Benchmark Valuer's Inc.">
</div>
</div>
<div class="col-md-3 px-md-1">
<div class="form-group">
<label>ID</label>
<input type="text" class="form-control" placeholder="User ID" value="" id="id" name ="id" disabled>
</div>
</div>
<div class="col-md-4 pl-md-1">
<div class="form-group">
<label for="exampleInputEmail1">Email address</label>
<input type="email" class="form-control" placeholder="s.sample#gmail.com" id="email" name ="email">
</div>
</div>
</div>
<div class="row">
<div class="col-md-4 pr-md-1">
<div class="form-group">
<label>First Name</label>
<input type="text" class="form-control" placeholder="First Name" id="fName" name ="fName">
</div>
</div>
<div class="col-md-4 pl-md-1">
<div class="form-group">
<label>Middle Name</label>
<input type="text" class="form-control" placeholder="Middle Name" id="mName" name ="mName">
</div>
</div>
<div class="col-md-4 pl-md-1">
<div class="form-group">
<label>Last Name</label>
<input type="text" class="form-control" placeholder="Last Name" id="lName" name ="lName">
</div>
</div>
<div class="col-md-4 pl-md-1" hidden>
<div class="form-group">
<label>Fullname</label>
<input type="text" class="form-control" placeholder="Full Name" id="fuName" name ="fuName">
</div>
</div>
</div>
<div class="row">
<div class="col-md-4 pr-md-1">
<div class="form-group">
<label>Contact Number</label>
<input type="tel" class="form-control" placeholder="Contact Number" id="Cnumber" name="Cnumber">
</div>
</div>
<div class="col-md-4 pl-md-1">
<div class="form-group">
<label>Age</label>
<input type="number" class="form-control" placeholder="Age" id="age" name="age">
</div>
</div>
<div class="col-md-4 pl-md-1">
<div class="form-group">
<label>Birthday</label>
<input type="date" class="form-control" placeholder="Birthday" id="bday" name="bday">
</div>
</div>
</div>
<div class="row">
<div class="col-md-12">
<div class="form-group">
<label>Address</label>
<input type="text" class="form-control" placeholder="Home Address" id="address" name ="address">
</div>
</div>
</div>
<div class="row">
<div class="col-md-4 pr-md-1">
<div class="form-group">
<label>Username</label>
<input type="text" class="form-control" placeholder="Username" id="uName">
</div>
</div>
<div class="col-md-4 px-md-1">
<div class="form-group">
<label>Password</label>
<input type="password" class="form-control" placeholder="Password" id="pWord">
</div>
</div>
<div class="col-md-4 pl-md-1">
<div class="form-group">
<label>UserType</label>
<input type="number" class="form-control" placeholder="0" id="uType">
</div>
</div>
</div>
<div class="row" hidden>
<div class="col-md-12">
<div class="form-group">
<label>Image Path:</label>
<input type="text" class="form-control" placeholder="C:\\" id="imageURL">
</div>
</div>
</div>
</div>
<div class="card-footer">
<button type="submit" class="btn btn-fill btn-primary" id="submit" name="submit">Save</button>
<button class="btn btn-fill btn-success" id="btnBrowse">Browse</button>
<button class="btn btn-fill btn-danger" id="btnCancel">Cancel</button>
</div>
</form>
Hope it helps you.
the form has been closed before the submit button.
the </form> tag should be placed after the <div class="card-footer">...</div>.
please try it. hope it will help.

data is not coming through in php form [duplicate]

This question already has answers here:
Warning: mysqli_real_escape_string() expects exactly 2 parameters, 1 given... what I do wrong? [duplicate]
(11 answers)
Can I mix MySQL APIs in PHP?
(4 answers)
Reference - What does this error mean in PHP?
(38 answers)
Closed 5 years ago.
this is the code please help me I am connected to the database
so i use mysqli_real_escape_string to get the clear data and save it into my table but it give me a nothing in my data
<?php
$db_connect = mysqli_connect("localhost", "root", "", "master_wn");
if(isset($_POST['send']))
{
session_start();
$name = mysqli_real_escape_string($_POST['name']);
$name2 = mysqli_real_escape_string($_POST['name2']);
$email = mysqli_real_escape_string($_POST['email']);
$case = mysqli_real_escape_string($_POST['case']);
$phone = mysqli_real_escape_string($_POST['phone']);
$adress = mysqli_real_escape_string($_POST['adress']);
$sex = mysqli_real_escape_string($_POST['sex']);
$prove = mysqli_real_escape_string($_POST['prove']);
$quali = mysqli_real_escape_string($_POST['quali']);
$exper = mysql_real_escape_string($_POST['exper']);
$query = "INSERT INTO `stu_data` (`number`,`name`,`name2`,`email`,`phone`,`address`,`sex`,`cases`,`prove`,`quali`,`exper`) VALUES ('','$name','$name2','$email','$phone','$adress','$sex','$case','$prove','$quali','$exper')";
$q = mysqli_query($db_connect,$query);
if ($q){
header("location:step2.php");
}
else
{
"try again";
}
}
?>
<html>
<head>
<title>
test
</title>
<meta charset="utf-8">
<link rel="stylesheet" href="../css/bootstrap.min.css"/>
<link rel="stylesheet" href="../css/normliaze.css"/>
<link rel="stylesheet" href="../css/style.css"/>
</head>
<body>
<div>
<div class="global">
<!--Star Header-->
<div class="header">
<div class="boy">
<h1>خطوات التقديم لحجز مقعد للدراسات العليا</h1>
<img src="../images/logo.PNG" alt="logo" width="90" height="80">
<p>موقع التقديم للدراسات العليا</p>
</div>
</div>
<!--End Header-->
<div class="holdForm">
<div class="container">
<form class="well form-horizontal" action="step1.php" method="post" id="contact_form">
<fieldset>
<!-- Form Name -->
<legend>الخطوة الاولي </legend>
<!-- Text input-->
<div class="form-group">
<label class="col-md-4 control-label">Name</label>
<div class="col-md-4 inputGroupContainer">
<div class="input-group">
<span class="input-group-addon"><i class="glyphicon glyphicon-user"></i></span>
<input placeholder="Name" class="form-control" type="text" name = "name">
</div>
</div>
</div>
<!-- Text input-->
<div class="form-group">
<label class="col-md-4 control-label" >الاسم</label>
<div class="col-md-4 inputGroupContainer">
<div class="input-group">
<span class="input-group-addon"><i class="glyphicon glyphicon-user"></i></span>
<input placeholder="الاسم بالعربي" class="form-control" type="text" name="name2">
</div>
</div>
</div>
<!-- Text input-->
<div class="form-group">
<label class="col-md-4 control-label">E-Mail</label>
<div class="col-md-4 inputGroupContainer">
<div class="input-group">
<span class="input-group-addon"><i class="glyphicon glyphicon-envelope"></i></span>
<input placeholder="E-Mail Address" class="form-control" type="text" name="email">
</div>
</div>
</div>
<!-- radio checks -->
<div class="form-group">
<label class="col-md-4 control-label">الحالة الاجتماعية</label>
<div class="col-md-4">
<div class="radio">
<label>
<input type="radio" name="case" value="marig" /> متزوج
</label>
</div>
<div class="radio">
<label>
<input type="radio" name="case" value="single" /> اعزب
</label>
</div>
<div class="radio">
<label>
<input type="radio" name="case" value="widow" /> ارمل
</label>
</div>
</div>
</div>
<!-- Text input-->
<div class="form-group">
<label class="col-md-4 control-label">الهاتف</label>
<div class="col-md-4 inputGroupContainer">
<div class="input-group">
<span class="input-group-addon"><i class="glyphicon glyphicon-earphone"></i></span>
<input placeholder="(+249)555-1212" class="form-control" type="text" name="phone">
</div>
</div>
</div>
<!-- Text input-->
<div class="form-group">
<label class="col-md-4 control-label">السكن</label>
<div class="col-md-4 inputGroupContainer">
<div class="input-group">
<span class="input-group-addon"><i class="glyphicon glyphicon-home"></i></span>
<input placeholder="Address" class="form-control" type="text" name="adress">
</div>
</div>
</div>
<div class="form-group">
<label class="col-md-4 control-label">الجنس</label>
<div class="col-md-4">
<div class="radio">
<label>
<input type="radio" name="sex" value="mail" /> ذكر
</label>
</div>
<div class="radio">
<label>
<input type="radio" name="sex" value="fmail" /> اثتي
</label>
</div>
</div>
</div>
<!-- Text area -->
<div class="form-group">
<label class="col-md-4 control-label">اثبات شخصية</label>
<div class="col-md-4 inputGroupContainer">
<div class="input-group">
<span class="input-group-addon"><i class="glyphicon glyphicon-file"></i></span>
<input placeholder="Address" class="form-control" type="text" name="prove">
</div>
</div>
</div>
<div class="form-group">
<label class="col-md-4 control-label">المؤهل العلمي</label>
<div class="col-md-4 selectContainer">
<div class="input-group">
<span class="input-group-addon"><i class="glyphicon glyphicon-list"></i></span>
<select class="form-control selectpicker" name="quali">
<option value=" " >... اختر مؤهل</option>
<option name="select1">دبلوم عالي</option>
<option name="select2">بكلاريوس</option>
</select>
</div>
</div>
</div>
<div class="form-group">
<label class="col-md-4 control-label">سنوات الخبرة</label>
<div class="col-md-4 inputGroupContainer">
<div class="input-group">
<span class="input-group-addon"><i class="glyphicon glyphicon-user"></i></span>
<input name="exper" placeholder="Address" class="form-control" type="text">
</div>
</div>
</div>
<!-- Success message -->
<div class="alert alert-success" role="alert" id="success_message">Success <i class="glyphicon glyphicon-thumbs-up"></i> Thanks for contacting us, we will get back to you shortly.</div>
<!-- Button -->
<div class="form-group">
<label class="col-md-4 control-label"></label>
<div class="col-md-4">
<input type="submit" class="btn btn-warning glyphicon glyphicon-send" name="send" value="التالي" >
</div>
</div>
</fieldset>
</form>
</div>
</div><!-- /.container -->
</div>
<div id="footer">
<p class="p2">جميع الحقوق محفوظة للمبرمج محمد تاج الدين © 2017-2018</p>
</div><!--end footer-->
</div><!--end all-->
<!--End content-->
<script src="/js/bootstrap.js"></script>
<script src="/js/bootstrap.min.js"></script>
<script src="/js/plugin.js"></script>
</body>
</html>
this is the code please help me I am connected to the database
so i use mysqli_real_escape_string to get the clear data and save it into my table but it give me a nothing in my data this is the code please help me I am connected to the database
so i use mysqli_real_escape_string to get the clear data and save it into my table but it give me a nothing in my data

PHP submit to self FAILING

** SOLVED: submit to self now working.**
My simple html/php (bootstrap) form refuses to submit to self. Can you see anything wrong with my code? I've tried the obvious $_SERVER['PHP_SELF'] and a number of other failures. Out of ideas.
<!DOCTYPE HTML>
<html>
<head>
</head>
<body>
<div class="row">
<div class="col-lg-12">
<h2>Contact us!</h2>
<!-- changed this
<form name="enquiryform" method="post" action="">
<form class="form-horizontal">
-->
<!-- to this: --> <form class="form-horizontal" name="enquiryform" method="post" action="">
<div class="form-group-lg">
<label class="control-label col-xs-4" for="first_name">Name *</label>
<div class="col-xs-8">
<input type="text" class="form-control" id="name" placeholder="First name" name="first_name" required>
</div>
</div>
<div class="form-group-lg">
<label class="control-label col-xs-4" for="last_name">Surname</label>
<div class="col-xs-8">
<input type="text" class="form-control" id="surname" placeholder="Last name" name="last_name">
</div>
</div>
<div class="form-group-lg">
<label class="control-label col-xs-4" for="inputEmail">Email *</label>
<div class="col-xs-8">
<input type="email" class="form-control" id="inputEmail" placeholder="you#example.com" name="email" required>
</div>
</div>
<div class="form-group-lg">
<label class="control-label col-xs-4" for="telephone">Mobile</label>
<div class="col-xs-8">
<input type="tel" class="form-control" id="Mobile" placeholder="Phone number" name="telephone">
</div>
</div>
<div class="form-group-lg">
<label class="control-label col-xs-4" for="exampleTextarea" name="comments"></label>
<textarea class="form-control" id="exampleTextarea" rows="6" name="comments" placeholder="What is your enquiry?" required></textarea>
<div class="form-group">
<div class="col-xs-12">
<input type="submit" class="btn btn-primary" value="Submit">
</div>
</div>
</form>
</div>
</div>
</div>
<p></p>
<?php
//if "email" variable is filled out, send email
if (isset($_REQUEST['email'])) {
//Email information
$admin_email = "########gmail.com";
$first_name = $_REQUEST['first_name'];
$last_name = $_REQUEST['last_name'];
$email = $_REQUEST['email'];
$telephone = $_REQUEST['telephone'];
$comments = $_REQUEST['comments'];
//send email
mail($admin_email, "$first_name", $last_name, "$telephone", "$comments", "From:" . $email);
//Email response
echo "Thank you for contacting us!";
}
//if "email" variable is not filled out, display the form
else {
?>
<?php
}
?>
</body>
</html>
Change this
<form name="enquiryform" method="post" action="">
<h2>Contact us!</h2>
<form class="form-horizontal">
to
<form class="form-horizontal" name="enquiryform" method="post" action="#">
<h2>Contact us!</h2>

Php Registration form doesn't work

I have created a registration form using php, but it doesn't work, and it doesn't show any errors.
register.html
<!DOCTYPE html>
<head>
<title>abc</title>
</head>
<body>
<div class="container">
<div class="row">
<div class="col-md-5 col-md-offset-4">
<div class="panel panel-default">
<div class="panel-heading"> <strong class="login">Sign Up</strong>
</div>
<div class="panel-body">
<form class="form-horizontal" role="form" name="registration" method="post" action="registration.php">
<!--first name-->
<div class="form-group">
<label for="fname" class="col-sm-3 control-label">First Name</label>
<div class="col-sm-9">
<input type="text" class="form-control" id="fname" name="fname" placeholder=" First Name" required="">
</div>
</div>
<!--/first name-->
<!--last name-->
<div class="form-group" >
<label for="lname" class="col-sm-3 control-label">Last Name</label>
<div class="col-sm-9">
<input type="text" class="form-control" id="lname" placeholder=" Last Name" required="">
</div>
</div>
<!--/last name-->
<!--email-->
<div class="form-group">
<label for="email" class="col-sm-3 control-label">Email</label>
<div class="col-sm-9">
<input type="email" class="form-control" id="email" name="email" placeholder="Email" required="">
</div>
</div>
<!--email-->
<!--Gender-->
<div class="form-inline form-group">
<label class=" col-sm-3 control-label"> Gender</label>
<label class="male">
<input value="male" type="radio" id="gender" name="male">Male
</label>
<label class="female">
<input value="female" type="radio" id="gender" name="male">Female
</label>
</div>
<!--/gender-->
<!--address-->
<div class="form-group">
<label for="address" class="col-sm-3 control-label">Address</label>
<div class="col-sm-9">
<input type="text" class="form-control" id="address" name="address" placeholder=" Address" required="">
</div>
</div>
<!--/address-->
<!--telno-->
<div class="form-group">
<label for="telno" class="col-sm-3 control-label">Contact No</label>
<div class="col-sm-9">
<input type="text" class="form-control" id="telno" placeholder=" Contact No" required="">
</div>
</div>
<!--/telno-->
<!--password-->
<div class="form-group">
<label for="password" class="col-sm-3 control-label">Password</label>
<div class="col-sm-9">
<input type="password" class="form-control" id="password" name="password" placeholder="Password" required="">
</div>
</div>
<!--password-->
<!--password-->
<div class="form-group">
<label for="repassword" class="col-sm-3 control-label">Re-enter Password</label>
<div class="col-sm-9">
<input type="password" class="form-control" id="repassword" name="repassword" placeholder="Re-enter Password" required="">
</div>
</div>
<!--password-->
<div class="form-group">
<div class="col-sm-offset-3 col-sm-9">
<div class="checkbox">
<label class="">
<input type="checkbox" class="">Remember me</label> forget password
</div>
</div>
</div>
<div class="form-group last">
<div class="col-sm-offset-3 col-sm-9">
<button type="submit" class="btn btn-warning btn-sm">Sign Up</button>
<button type="reset" class="btn btn-default btn-sm">Reset</button>
</div>
</div>
</form>
</div>
<div class="panel-footer">If you are already Registered? LogIn here
</div>
</div>
</div>
</div>
</div>
</body>
</html>
this is the registration.php
<!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">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>
<body>
<?php //start php tag
//include config.php page for database connection
Include('config.php');
//if submit is not blanked i.e. it is clicked.
If(isset($_REQUEST['submit'])!='')
{
If($_REQUEST['fname']=='' || $_REQUEST['email']=='' || $_REQUEST['password']==''|| $_REQUEST['repassword']=='')
{
Echo "please fill the empty field.";
}
Else
{
$sql="insert into user(firstname,email,password) values('".$_REQUEST['fname']."', '".$_REQUEST['email']."', '".$_REQUEST['password']."')";
$res=mysql_query($sql);
If($res)
{
Echo "Record successfully inserted";
}
Else
{
Echo "There is some problem in inserting record";
}
}
}
?>
</body>
</html>
this is the config.php
<!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">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>
<body>
<?php
$hostname="localhost"; //local server name default localhost
$username="root"; //mysql username default is root.
$password=""; //blank if no password is set for mysql.
$database="rcjcompany"; //database name which you created
$con=mysql_connect($hostname,$username,$password);
if(! $con)
{
die('Connection Failed'.mysql_error());
}
mysql_select_db($database,$con);
?>
</body>
</html>
this is the sql for database
Create database student;
use student;
create table student(id int,name varchar(40),email varchar(80),password varchar(40));
The first if seems useless as long as you don't have any field named "submit". I used your code and debug with firefox and you can see there is no field called submit sent to server:
Try to remove the first if or add an else condition so at least you get any print.

Categories