This question already has answers here:
PHP code is not being executed, but the code shows in the browser source code
(35 answers)
Closed 4 years ago.
I'm still stuck on this PHP code. I'm trying to code it where the user inputs some information and the PHP code displays the information the user inputted it. Basically I'm trying to build a confirmation page so the user sees the information inputted before submitted it.
HTML
<DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>DormAngel Booking Form</title>
</head>
<body>
<form action="welcome.php" method="POST">
<fieldset>
<legend> Personal Details: </legend>
<label for="fname>"></label>
<input type="text" name="Name" id="fname" required autofocus placeholder="First Name" pattern="[a-zA-Z]{3,}" title="Please enter more than three letters">
<label for="lname>"></label>
<input type="text" name="Last Name" id="lname" required autofocus placeholder="Last Name" pattern="[a-zA-Z]{3,}" title="Please enter more than three letters">
<label for="email">Email: </label>
<input type="text" name="email" id="email" required placeholder="Your school email" pattern="[a-zA-Z]{3,}#[a-zA-Z]{3,}[.]{1}[a-zA-Z{2} title="Please enter a valid email address>
<label for="phone">Phone: </label>
<input type="tel" name="phone" id="phone" required placeholder="Please enter in your phone number">
<select name="country" required>
<option value=""> </option>
<option value="US">US</option>
<option value="UK">UK</option>
<option value="AUS">AUS</option>
</select>
</fieldset>
<br>
<fieldset>
<legend> Booking Details: </legend>
<input type="date" name="date" min="2018-10-07" max="2018-10-31">
<input type=time min=9:00 max=17:00 step=900>
<br>
<br>
<label for="dorm">Dormitory: </label>
<br>
<select name="dorm" required>Dormitory
<option value="Cypress">Cypress Hall</option>
</select>
<br>
<br>
<label for="floor">Floor: </label>
<br>
<select name="floor" required>Floor:
<option value=""></option>
<option value="02">02</option>
<option value="03">03</option>
<option value="04">04</option>
<option value="05">05</option>
<option value="06">06</option>
<option value="07">07</option>
<option value="08">08</option>
</select>
<br>
<br>
<label for="roomnumber">Room Number: </label>
<br>
<select name="roomnumber">Room Number:
<option value=""></option>
<option value="22">22</option>
</select>
<br>
<br>
<label for="roomletter">Room Letter: </label>
<br>
<select name="roomletter" required="">Room Letter
<option value=""></option>
<option value="A">A</option>
<option value="B"> B</option>
</select>
<button type="submit">Submit</button>
</fieldset>
</form>
</body>
</html>
PHP
<html>
<head>
<title>Confirmation Page of Web Form</title>
</head>
<h1>Confirmation Page of Customer Info</h1>
<p>Thank you for submitting this form.</p>
<p>We have successfully received it.</p>
<p>Below is a summary of the information you provided.<br><br>
<?php
echo 'First Name: ' . $_POST ["Name"] . '<br>';
echo 'Last Name: ' . $_POST ["Last Name"] . '<br>';
echo 'Email Address: ' . $_POST ["email"] . '<br>';
echo 'Telephone Number: ' . $_POST ["phone"];
?>
</p>
</html>
What is wrong with my code?
You have forgotten the <body> tag in your html.
Replace the code to be this way.
<html>
<head>
<title>Confirmation Page of Web Form</title>
</head>
<h1>Confirmation Page of Customer Info</h1>
<p>Thank you for submitting this form.</p>
<p>We have successfully received it.</p>
<p>Below is a summary of the information you provided.<br><br>
<?php
echo 'First Name: ' . $_POST["Name"] . '<br>';
echo 'Last Name: ' . $_POST["Last Name"] . '<br>';
echo 'Email Address: ' . $_POST["email"] . '<br>';
echo 'Telephone Number: ' . $_POST["phone"];
?>
</p>
</html>
Related
Below is my HTML and PHP code. I'm trying to display my the inputted data, however, I'm getting nothing. What is wrong with my code?
HTML
<form action="welcome.php" method="POST">
<fieldset>
<legend> Personal Details: </legend>
<label for="fname>"></label>
<input type="text" name="Name" id="fname" required autofocus placeholder="First Name" pattern="[a-zA-Z]{3,}" title="Please enter more than three letters">
<label for="lname>"></label>
<input type="text" name="Last Name" id="lname" required autofocus placeholder="Last Name" pattern="[a-zA-Z]{3,}" title="Please enter more than three letters">
<label for="email">Email: </label>
<input type="text" name="email" id="email" required placeholder="Your school email" pattern="[a-zA-Z]{3,}#[a-zA-Z]{3,}[.]{1}[a-zA-Z{2} title="Please enter a valid email address>
<label for="phone">Phone: </label>
<input type="tel" name="phone" id="phone" required placeholder="Please enter in your phone number" pattern="[0-9]{4} [0-9]{3} [0-9]{3}" title="Please enter in a phone number in this format: #### ### ###">
<select name="country" required>
<option value=""> </option>
<option value="US">US</option>
<option value="UK">UK</option>
<option value="AUS">AUS</option>
</select>
</fieldset>
<br>
<fieldset>
<legend> Booking Details: </legend>
<input type="date" name="date" min="2018-10-07" max="2018-10-31">
<input type=time min=9:00 max=17:00 step=900>
<br>
<br>
<label for="dorm">Dormitory: </label>
<br>
<select name="dorm" required>Dormitory
<option value="Cypress">Cypress Hall</option>
</select>
<br>
<br>
<label for="floor">Floor: </label>
<br>
<select name="floor" required>Floor:
<option value=""></option>
<option value="02">02</option>
<option value="03">03</option>
<option value="04">04</option>
<option value="05">05</option>
<option value="06">06</option>
<option value="07">07</option>
<option value="08">08</option>
</select>
<br>
<br>
<label for="roomnumber">Room Number: </label>
<br>
<select name="roomnumber">Room Number:
<option value=""></option>
<option value="22">22</option>
</select>
<br>
<br>
<label for="roomletter">Room Letter: </label>
<br>
<select name="roomletter" required="">Room Letter
<option value=""></option>
<option value="A">A</option>
<option value="B"> B</option>
</select>
<br>
<br>
<label for="bedroomcleaning">Bedroom: </label><br>
<input type="checkbox" id="box-4" onclick="checkPrice()" value="4">Dust all ceiling fans/light/fixtures within reach.<br>
<input type="checkbox" id="box-5" onclick="checkPrice()" value="5"> Change sheets and/or fold clothes if requested by client.<br>
<input type="checkbox" id="box-6" onclick="checkPrice()" value="6"> Straighten up, put toys away, make beds, fold clothes and put on bed. Straighten papers and put in a pile. DO NOT THROW AWAY ANY PERSONAL ITEMS!<br><br>
<label for="bathroomcleaning">Bathroom: </label><br>
<input type="checkbox" id="box-1" onclick="checkPrice()" value="1"> Clean bowl and wipe down toilet cover, seat, under seat, base and behind the base.<br>
<input type="checkbox" id="box-2" onclick="checkPrice()" value="2"> Clean all mirrors.<br>
<input type="checkbox" id="box-3" onclick="checkPrice()" value="3"> Clean countertops and backsplashes.<br>
<label for="bathroomprice" id="price">Total Price: </label>
<br>
<br>
<input type="submit">
</fieldset>
</form>
PHP
Welcome <?php echo $_POST["Name"]; ?><br>
Your email address is: <?php echo $_POST["email"]; ?>
Your phone number is: <?php echo $_POST["phone"]; ?>
Check your pattern for the email input:
[a-zA-Z]{3,}#[a-zA-Z]{3,}[.]{1}[a-zA-Z{2}
[a-zA-Z]{3,}#[a-zA-Z]{3,}[.]{1}[a-zA-Z]{2}
Also:
<input type=time min=9:00 max=17:00 step=900>
<input type="time" min="9:00" max="17:00" step="900">
As said by Jon in the comments, you need a <form> div.
<form action="yourPhpPage.php" method="POST">
<label ...>...</label>
<input ... />
...
<input type="submit" value="Send" />
</form>
The action attribute tells which page to call when submitting form.
The method tells how to send data (GET or POST mainly)
The <input type="submit" /> is the submit button. When you click it the page indicated in action will be called with the values of the different inputs. The value of the submit input is what is shown on it.
Eventually you can use a submit <button> :
<button type="submit">What you want to be displayed on it.</button>
I prefer this one because it's easier to modify its style and behavior respectively with CSS and JS. But it's not the point.
Hope it helps you !Jean-Marc.
hi people i have these two scripts for fill a database table on my PC , with an HTML form . the HTML code works perfect but the php it just does not work , i have specified everything ,but it just doesn't work , when i give click on submit the browser just pop ups a download option but nothing else...
<html>
<head>
<tittle>
<h1 > <b> FORMAT FOR TECHNICAL ISSUES
<link rel="stylesheet" href="/var/www/html/proyecto/css/styles.css">
</b> </h1>
</tittle>
<hr> </hr>
</head>
<body>
<div>
<img src="logo.png" width=100% /img>
<hr> </hr>
<form method="POST" action="">
<input type="text" placeholder="NOMBRE" name="Nombre" maxlenght="30" size="20px" id="nombre" >
<input type="text" name="Extension" placeholder=EXTENSION maxlength="5" id="extension">
<br>
<hr> </hr>
<br>
<br>
<h2> CAMPAIGN /CAMPAÑA </h2>
<br>
<label for="Campaign"> Select your campaign:</label>
<select name="Campaign" id="campaign" >Campaign
<option value="Procall">Procall</option>
<option value="Tigo">Tigo</option>
<option value="Spanish">Spanish</option>
</select>
<hr> </hr>
<h2> KIND OF FAILURE </h2>
<label for="Tipo de incidente">Select the type of incident:</label>
<select id="incident" name="incidente" placeholder="Tipo de incidente">incident
<option value="Slow Computer">Slow Computer</option>
<option value="Headset fail"> Headset Fail </option>
<option value="Zoiper Issue">Zoiper Issue </option>
<option value="Crm Issue">Crm Issue </option>
<option value="Spark Issue">Spark Issue </option>
<option value="Vc Dialer Issue">VC Dialer Issue </option>
<option value="Network Issue">Network Issue </option>
</select>
<input type"text" id="description" name="Description" placeholder=DESCRIPTION style="width:300px;height:100px">
<br></br>
<h2>FAILURE DATE </h2>
<label for="failure date"> Enter the day and hour when failure occurred :</label>
<input name="failure_date" type="date-time-local" placeholder="yyyy/mm/dd/hh/mm" id="failure date" min="2018-05-01T08:30" max="2018-12-30T22:30" >
<br>
<hr></hr>
<label for="did you lose a call?" id="lost_call" >Did you lose any call?:</label>
<br>
<input type="radio" name="lost call" value="yes " id="lost_call" > Yes , i lost a call.
<br>
<input type="radio" name="lost_call" value="no" id="lost_call" >No i have not lost any call
<br
<br>
<label id="lost docmuent" for="did you lose any document?"> Did you lose any document or information?:</label>
<br>
<input type="radio" name="document" value="yes"> Yes i lost one or more documents
<br>
<input type="radio" name="document" value="no"> No have not lost any document.
<br>
<br>
<label for="did you have to log out?" id="logout" > Did you have to logout?:</label>
<br>
<input type="radio" name="logout" value="yes">Yes i had to logout
<br>
<input type="radio" name="logout" value="no">no i didn't have to logout
<br>
<br>
<br>
<br>
<input type="submit">
</form>
</div>
</body>
</html>
and here is the php script for the action and connect to the sql database
<?php
$con = mysql_connect("localhost","root","m0l0t0v" );
if (!$con) {
die('Could not connect: ' . mysql_error());
}
mysql_select_db("it", $con);
$sql="INSERT INTO tec-issues (Nombre,Extension ,Campaign ,incidente,Description,failure_date,lost_call,document,logout )
VALUES
('$_POST[Nombre]', '$_POST[Extension]', '$_POST[Campaign]', '$_POST[incidente]', '$_POST[Description]', '$_POST[failure_date]', '$_POST[lost_call]', '$_POST[document]', '$_POST[logout]' )";
if (!mysql_query($sql,$con)) {
die('Error: ' . mysql_error());
}
echo "1 record added";
mysql_close($con)
?>
PLEASE HELP ME EVERYTHING IS CORRECT , BUT IT JUST DONT WORK
Check syntax for mysql_select_db it should be mysql_select_db($con,"dbname") and please use mysqli prefix instead of mysql because it is safer.
I recommend using msqli_escape_string for every data you get from POST or GET to protect from sql injection
I have a form in html and I am saving it as search.php:
<form name="myform" action="" method="POST" onsubmit="search_clicked(); return false;">
Keyword<input type="text" name="Keyword" id="Keyword" value="XYZ" required/><!-- value is the default name that appears in the text box-->
<br>
Type
<select name="sel" id="sel" class="form-control" onchange="checkcolors(this.value)">
<option selected value="Users">Users</option>
<option value="Pages">Pages</option>
<option value="Events">Events</option>
<option value="Places">Places</option>
<option value="Groups">Groups</option>
</select>
</form>
<div id="loc_dist_displayarea" style="display:none;">
Location<input type="text" name="Location" value="90007" required/> Distance(meters)<input type="text" name="distance" value="10000" required/>
</div>
<br><br>
<input type="submit" name="Search"/>
<input type="submit" value="clear" id="clear" onclick="return clearclicked()"/>
</form>
and my php script is in the same file:
<div id="body_area" style="display:none">
<?php
echo "hi I am searching ";
if($_SERVER["REQUEST_METHOD"]=="POST")
{
//echo "yes value is selected";
//echo $_POST["Keyword"];
if (isset($_POST['sel'])) {
$selectedval= $_POST["sel"];
echo "$selectedval";
}
//echo $_POST["Location"];
}
echo "no value is selected";
?>
</div>
I am not able to display the $_POST['sel'] while $_POST['Keyword'] is echoed.Please help.
First of all, you arent using good programming practices, you use quotation marks (these " and these ') Indiscriminately. You should only alternate between them when you have them nested.
Next, on the action paramenter you should put the name of the file, even if it's the same.
This is a form that I get the user to enter data including their mobile number and mobile carrier. I am using concatenation of the mobile number and carrier to send a message to their phone. This works but I am having a problem with the concatenation for the email recipient. If I use a straight email address ("myemail#gmail.com"), it will deliver the content. It will not work using the concatenation of $phone and $carrier ($YourEmailAddress). I have tried several different methods but nothing is working. I have tried using "&" and "+". I need assistance in figuring out why the concatenation of the phone and carrier strings is not working. I am new to this site so I am not sure if I correctly posted this.
This is my php file:
<?php
if( count($_POST) )
{
$YourEmailSubject = "Form Submission From the Blog";
$name = stripslashes($_POST['name']);
$email = stripslashes($_POST['email']);
$comment = stripslashes($_POST['comment']);
$phone = ($_POST['phone']);
$selectOption = $_POST['carrier'];
$content = "$name\r\n$email\r\n$comment\r\n$selectOption\r\n";
$YourEmailAddress = $phone."#".$selectOption;
mail($YourEmailAddress,$YourEmailSubject,$content,"From: ABC Company");
header("Location:" . (isset($_POST['redirect']) ? $_POST['redirect'] : '/') );
exit;
}
?>
This is my form:
<form method="post" action="/simplecontact.php">
<input type="hidden" name="redirect" value="//www.google.com">
<p>
Name:<br>
<input type="text" name="name" style="width:200px;"></td>
</p>
<p>
Email:<br>
<input type="text" name="email" style="width:200px;"></td>
</p>
<p>
Comment:<br>
<textarea name="comment" style="width:200px; height:100px"></textarea></td>
</p>
<p>Phone Number:<br>
<input type="text" id="number" name="number" /></td>
</p>
Carrier: <br>
<select id="carrier" name="carrier">
<option value="tmomail.net">T-mobile</option>
<option value="vmobl.com">Virgin Mobile</option>
<option value="cingularme.com">Cingular</option>
<option value="messaging.sprintpcs.com">Sprint</option>
<option value="txt.att.net">AT&T</option>
<option value="vtext.com">Verizon</option>
<option value="messaging.nextel.com">Nextel</option>
<option value="email.uscc.net">US Cellular</option>
<option value="sms.mycricket.com">Cricket</option>
<option value="mymetropcs.com">Metro PCS</option>
<option value="myboostmobile.com">Boost Mobile</option>
</select>
<p>
<input type="submit" style="width:200px;" value="Submit Form"></td>
</p>
</form>
In your form the phone input name is "number", in the php code you are trying to get the phone number like the input name was "phone"
Just change the input name to "phone"
<input type="text" id="number" name="phone" /></td>
I have built a html form in which a user has to specify which product he likes to order and depending on his answer other input fields arise. I have used some javascript for that. But now i want to data the user enters to be passed on to email via php. I know very little of php and scripting in general (let's say about nothing) but i did find some tutorials and templates on it. The only thing is that they all seem slightly different and specific to a form (mostly contact forms). And if i follow them closely it works fine, it's just that when i want to customize a little i seem to get terribly lost.
I have posted this before (Can i post data from a select drop down to email using PHP?) and have gotten some answers. It's just that i didn't formulate my initial problem well enough and edited it afterwards, but i don't know if that's the way to go on this forum. So i posted a new question (sorry if that's overkill, i'm pretty new to all of this). This is my html:
<form method="post" name="contact_form" action="contact.php">
<div class="form-div1">
<label for="profile" class="label1">Select your profile</label>
<br>
<select id="user-type" class="selectlist">
<option value="option1">I'm a first-time user</option>
<option value="option2">I would like to renew or upgrade</option>
</select>
</div>
<div class="form-div2">
<label for="SEN" class="label2">SEN</label>
<br>
<input type "text" name="input1" class="input1">
</div>
<div class="form-div3">
<label for="email" class="label3">Email Address</label>
<br>
<input type "text" name="input2" class="input2">
</div>
<div class="form-div4">
<label for="product_choice" class="label4" name="select_menu">Select your product</label>
<br>
<select id="product" class="selectlist">
<option value="option1">JIRA</option>
<option value="option2">Confluence</option>
<option value="option3">JIRA Service Desk</option>
<option value="option4">Stash</option>
<option value="option5">Other</option>
</select>
</div>
<div class="form-div42">
<label for="product" class="label42">Specify your product</label>
<br>
<input type "text" name="input2" class="input2">
</div>
<div class="form-div5">
<label for="license_choice" class="label5">Select your license</label>
<br>
<select id="select" class="selectlist">
<option value="option1">25 users</option>
<option value="option2">50 users</option>
<option value="option3">100 users</option>
</select>
</div>
<div class="input_box_atlassian">
<input type="submit" name="submit" value="Submit" class="submit-button-atl" />
</div>
</form>
Now i want to build working php so i can pass the data to an email. Can somebody point me in the right direction or preferably show me some tutorials that tackle this issue more closely.
I havent dont any validation, try client side & server side validation along with code
Change the HTML as below
<form method="post" name="contact_form" action="contact.php">
<div class="form-div1">
<label for="profile" class="label1">Select your profile</label>
<br>
<select id="user_type" name="user_type" class="selectlist">
<option value="I'm a first-time user">I'm a first-time user</option>
<option value="I would like to renew or upgrade">I would like to renew or upgrade</option>
</select>
</div>
<div class="form-div2">
<label for="SEN" class="label2">SEN</label>
<br>
<input type "text" name="SEN" class="SEN">
</div>
<div class="form-div3">
<label for="email" class="label3">Email Address</label>
<br>
<input type "text" name="email" class="email">
</div>
<div class="form-div4">
<label for="product_choice" class="label4" name="select_menu">Select your product</label>
<br>
<select id="product" name="product" class="selectlist">
<option value="JIRA">JIRA</option>
<option value="Confluence">Confluence</option>
<option value="JIRA Service Desk">JIRA Service Desk</option>
<option value="Stash">Stash</option>
<option value="Other">Other</option>
</select>
</div>
<div class="form-div42">
<label for="product" class="label42">Specify your product</label>
<br>
<input type "text" name="product_specify" id="product_specify" class="input2">
</div>
<div class="form-div5">
<label for="license_choice" class="label5">Select your license</label>
<br>
<select id="license_choice" name="license_choice" class="selectlist">
<option value="25">25 users</option>
<option value="50">50 users</option>
<option value="100">100 users</option>
</select>
</div>
<div class="input_box_atlassian">
<input type="submit" name="submit" value="Submit" class="submit-button-atl" />
</div>
</form>
And make another PHP file by the name contact.php & paste the below code.
<?php
if($_REQUEST['submit']=='Submit'){
$user_type=$_REQUEST['user_type'];
$sen=$_REQUEST['SEN'];
$email=$_REQUEST['email'];
$product=$_REQUEST['product'];
$product_specify=$_REQUEST['product_specify'];
$license_choice=$_REQUEST['license_choice'];
$to = 'nobody#example.com'; //to whom the email have to besnd
$message = "User Type: $user_type \n Sen: $sen \n Email: $email \n Product: $product \n Product Specified: $product_specify \n License: $license_choice"; //content of the email
$subject = 'hello'; //shown as subject of the email
$headers = 'From: webmaster#example.com' . "\r\n" . //eamil header information
'Reply-To: webmaster#example.com' . "\r\n" .
'X-Mailer: PHP/' . phpversion();
if(mail($to, $subject, $message, $headers)){
echo "Mail Sucessfully Sent";
} else {
echo "Something went wrong";
}
}
?>
This will get the content from the form HTML & email its contents, however only if the email server is configured correctly
Consider the following URL http://www.freecontactform.com/email_form.php
Cheers!!