can someone please help i am trying to email the results of 4 radio boxes from my form by email. i receive the email fine but am not getting the results sent through.
can someone show me what im doing wrong?
html form:
<html>
<head>
<title>Site Feedback</title>
</head>
<body>
<form name="myform" action="send_feedback.php" method="POST">
<div class="wrapper_feedback" align="left">
<p>Website Design:</p>
<input type="radio" name="design" value="design1">
1
<input type="radio" name="design" value="design2">
2
<input type="radio" name="design" value="design3" checked>
3
<input type="radio" name="design" value="design4">
4
<input type="radio" name="design" value="design5">
5
</p>
<hr>
<p>Ease of Use:</p>
<input type="radio" name="easeuse" value="ease1">
1
<input type="radio" name="easeuse" value="ease2">
2
<input type="radio" name="easeuse" value="ease3" checked>
3
<input type="radio" name="easeuse" value="ease4">
4
<input type="radio" name="easeuse" value="ease5">
5
</p>
<hr>
<p>Fit for Purpose:</p>
<input type="radio" name="purpose" value="purpose1">
1
<input type="radio" name="purpose" value="purpose2">
2
<input type="radio" name="purpose" value="purpose3" checked>
3
<input type="radio" name="purpose" value="purpose4">
4
<input type="radio" name="purpose" value="purpose5">
5
</p>
<hr>
<p>Layout:</p>
<input type="radio" name="layout" value="layout1">
1
<input type="radio" name="layout" value="layout2">
2
<input type="radio" name="layout" value="layout3" checked>
3
<input type="radio" name="layout" value="layout4">
4
<input type="radio" name="layout" value="layout5">
5
</p>
<input type="submit" action="submit" value="submit" name="submit">
<br>
</div>
</form>
</body>
</html>
php:
<?php ob_start(); ?>
<?php
/* Set e-mail recipient */
$myemail = "info#mydomain.com";
$subject = "site Feedback";
/* Let's prepare the message for the e-mail */
$message = "somesite.com Feedback
$design
$easeuse
$purpose
$layout
End of message
";
/* Send the message using mail() function */
mail($myemail, $subject, $message);
/* Redirect visitor to the thank you page */
$_SESSION['feedback']="<div class=\"infobox-index\"><strong>Thank You</strong> - We appreciate you taking the time to tell us what you think.</div>";
header("Location: {$_SERVER['HTTP_REFERER']}");
exit();
?>
<?php ob_end_flush() ?>
Your code is relying on Register Globals which is deprecated and discouraged. You should access the data with:
$_POST['design']
Not:
$design
Instead of these variables:
$design
$easeuse
$purpose
$layout
use this:
$_POST['design']
$_POST['easeuse']
$_POST['purpose']
$_POST['layout']
You need to access the POST variables sent from the form using the following syntax:
$_POST['design']
$_POST['easeuse']
$_POST['purpose']
$_POST['layout']
Related
This question already has answers here:
PHP mail function doesn't complete sending of e-mail
(31 answers)
Closed 4 years ago.
I am trying to create an event registration form for my event (my first time using PHP), but am having trouble with the input text for my HTML/PHP form. I can submit the form and it sends me an email with the names of the inputs, but not the actual entered text/information.
Here is my HTML code:
<div class="WMF-form">
<form method="post" action="myform.php">
Name: <input type="text" name="name">
E-mail: <input type="text" name="email">
Family Count: <textarea name="familycount" rows="5" cols="40"></textarea>
Family Names:: <textarea name="familynames" rows="5" cols="40"></textarea>
Volunteer:
<input type="radio" name="volunteer" value="female">Female
<input type="radio" name="volunteer" value="male">Male
<input type="radio" name="volunteer" value="other">Other
Fee Options:
<input type="radio" name="feeoptions" value="female">Female
<input type="radio" name="feeoptions" value="male">Male
<input type="radio" name="feeoptions" value="other">Other
Lodging:
<input type="radio" name="lodging" value="female">Female
<input type="radio" name="lodging" value="male">Male
<input type="radio" name="lodging" value="other">Other
<br>
<input type="submit" name="submit" value="Submit">
</form>
</div>
</section>
Here is my PHP code:
PHP code
PHP code
PHP $_POST values are case sensitive. Your HTML has
<input type="text" name="name">
But you access it in the PHP file as
$Name = $_POST["Name"];
Make sure the cases match.
Try
$Name = $_POST["name"];
Capitalize your names in your form. the post variables have a capital Name Email FamilyNames etc and the form doesnt
I am making a poll with HTML and PHP and I want to post the poll answers in a text file. I have 6 things to choose from.
The name is answer and the values are a1, a2, a3, a4, a6. How to post a1 or a2 or a3... in the file.
You know when you click on the answer with id a1 to post in a new line a1 in the file.
HTML:
<form action="php/vote.php">
<b><strong>Vote:</strong></b> <br>
<input type="radio" name="answer" value="a1" id="a1">a<br>
<input type="radio" name="answer" value="a2" id="a2">b<br>
<input type="radio" name="answer" value="a3" id="a3">c<br>
<input type="radio" name="answer" value="a4" id="a4">d<br>
<input type="radio" name="answer" value="a5" id="a5">e
<br>
<input type="submit" name="submit" id="submit" value="Vote">
</form>
This should do what you are asking:
<?php
if(isset($_POST['answer'])){
file_put_contents("filename.txt", $_POST['answer']."\n");
}
?>
<html>
<head>
</head>
<body>
<form action="" method="POST">
<b><strong>Vote:</strong></b> <br>
<input type="radio" name="answer" value="a1" id="a1">a<br>
<input type="radio" name="answer" value="a2" id="a2">b<br>
<input type="radio" name="answer" value="a3" id="a3">c<br>
<input type="radio" name="answer" value="a4" id="a4">d<br>
<input type="radio" name="answer" value="a5" id="a5">e
<br>
<input type="submit" name="submit" id="submit" value="Vote">
</body>
</form>
</html>
I have added method="POST" to your original HTML so that the receiving PHP can inspect the $_POST variable to see what was sent through from the form. $_POST['answer'] contains the value of the "value" field corresponding to the selected radio button. Once you know this, it is easy to call file_put_contents to write that value to your file. Append a newline "\n" to ensure that each call writes to a separate line of the file.
I have fetch data from database in $tableRe. Now I have to print values in textarea and also have to check the radio button.
Here is my code,
$sql = "select (address, gender) from stud table";
if($result=mysqli_query($conn,$sql)) {
while($row = mysqli_fetch_array($result)) {
$tableRe[]=$row;
}
}
<form>
Address : <br>
<textarea value="<?php echo $tableRe[0]['address']; ?>"></textarea><br>
Gender : <br>
<input type="radio" value="Male">Male
<input type="radio" value="Female">Female <br>
<input type="submit" value="Save">
</form>
Please help me regarding this. Thanks in advance.
You need to apply condition on checked HTML attribute.
Try this:
<form>
Address : <br>
<textarea><?php echo $tableRe[0]['address']; ?></textarea> <br/>
Gender : <br>
<input type="radio" value="Male" <?php echo $tableRe[0]['gender'] == 'Male' ? 'checked' : ''; ?> >Male
<input type="radio" value="Female" <?php echo $tableRe[0]['gender'] == 'Female' ? 'checked' : ''; ?>>Female <br>
<input type="submit" value="Save">
</form>
Value has to be placed between the openning and closing tags :
<texterea name="whatever">Textarea value goes here</textarea>
To set a radio/checkbox as selected/checked, you need to add to it a "checkded" attribute :
<!-- HTML4 -->
<input type="radio" name="whatever" value="value1" checked="checked" /> Label 1
<input type="radio" name="whatever" value="value2" /> Label 2
<input type="radio" name="whatever" value="value3" /> Label 3
<!-- HTML5 -->
<input type="radio" name="whatever" value="value1" checked /> Label 1
<input type="radio" name="whatever" value="value2" /> Label 2
<input type="radio" name="whatever" value="value3" /> Label 3
So Im having a bit of a conundrum. Not too sure how I should go about doing the if/else statements with an Echo at the top with the answers, with bullets.
<?php
echo
?>
</p>
<p>
A Chicken
<input type="radio" name="radio" id="radio3" value="no">
<label for="radio3">Choose this answer</label>
</p>
<p dir="ltr">A Ear of Corn.
<input type="radio" name="radio" id="radio2" value="no">
<label for="radio2">Choose this answer</label>
</p>
<p dir="ltr"> A Heart.
<input type="radio" name="radio" id="radio" value="yes"> Choose this answer
</p>
<p dir="ltr">
<input type="button" name="button28" id="button28" value="Yes! That is the answer I chose!">
If your question is basically about how to output certain HTML code based on an if/else clause, then with such a lengthy amount of HTML code as you have posted you would do much better using HEREDOCS checkout the PHP manual here: http://php.net/manual/en/language.types.string.php.
Goodluck!
You can do this on many ways. Here is a small example to get you started working with forms.
<?php
$answer = '';
if(isset($_POST['send']) //check if the form has been sent
&& isset($_POST['answer'])){ //check if an answer is filled in
//You could also use a switch -> http://php.net/manual/en/control-structures.switch.php
if($_POST['answer'] == 'chicken'){ //check if post variable answer value = chicken
$answer = 'your answer is "a chicken"';
}elseif($_POST['answer'] == 'corn'){ //check if post variable answer value= corn
$answer = 'your answer is "A Ear of Corn."';
}elseif($_POST['answer'] == 'heart'){ //check if post variable answer value = heart
$answer = 'your answer is "A Heart"';
}
//echo the variable.
echo $answer;
}
?>
<form method="POST" action="">
<p> A Chicken
<input type="radio" name="answer" id="radio3" value="chicken">
<label for="radio3">Choose this answer</label>
</p>
<p dir="ltr">A Ear of Corn.
<input type="radio" name="answer" id="radio2" value="corn">
<label for="radio2">Choose this answer</label>
</p>
<p dir="ltr">A Heart.
<input type="radio" name="answer" id="radio" value="heart">Choose this answer
</p>
<input type="submit" name="send" id="button28" value="Yes! That is the answer I chose!">
</form>
I'm getting a strange error when I try to submit user-generated data to a database via PHP commands. When I hit the submit button below, instead of the PHP page running its' function I am presented with a display of the raw code on my browser. I have a command at the bottom of my HTML page that looks like this:
<form action="insert.php" method="post">
<input type="submit">
</form>
So that when the user hits the submit button, the PHP file insert.php (detailed below) is called to input the answers onto a database, separating each answer into it's own field.
Here is the code I'm working with:
<?php
$con=mysqli_connect("host","username","password","database");
// Check connection
if (mysqli_connect())
{
echo "Failed to connect to MySQL: " . mysqli_errno();
}
$sql="INSERT INTO Persons (Name, Serif, Width, Height, Spacing, Weight)
VALUES
('$_POST[answer]','$_POST[answer]','$_POST[answer]','$_POST[answer]','$_POST[answer]','$_POST[answer]')";
if (!mysqli_query($con,$sql))
{
die('Error: ' . mysqli_error($con));
}
echo "1 record added";
mysqli_close($con);
?>
Right now, the questions are in a and not a (is there a functional difference in this case?). They look like:
<form class="testAns" id="widthAns">
<input type="radio" name="answer" value="skinny">-25%
<input type="radio" name="answer" value="skinny">-10%
<input type="radio" name="answer" value="mid">normal
<input type="radio" name="answer" value="fat">+10%
<input type="radio" name="answer" value="fat">+25%
</form>
<form class="testAns" id="spaceAns">
<input type="radio" name="answer" value="small">-25%
<input type="radio" name="answer" value="small">-10%
<input type="radio" name="answer" value="mid">normal
<input type="radio" name="answer" value="wide">+10%
<input type="radio" name="answer" value="wide">+25%
</form>
<form class="testAns" id="weightAns">
<input type="radio" name="wanswer" value="light">-25%
<input type="radio" name="answer" value="light">-10%
<input type="radio" name="answer" value="mid">normal
<input type="radio" name="answer" value="heavy">+10%
<input type="radio" name="answer" value="heavy">+25%
</form>
<form method="post" action="insert.php" class="testAns" id="heightAns">
<input type="radio" name="answer" value="short">-25%
<input type="radio" name="answer" value="short">-10%
<input type="radio" name="answer" value="mid">normal
<input type="radio" name="answer" value="tall">+10%
<input type="radio" name="answer" value="tall">+25%
</form>
The important part is for the "value" associated with each button to be logged into the database. For example, if a user selects "+10%" I want be able to log the word "heavy".And then there are two text input fields:
<form id="intro">
City: <input type="text" name="answer"><br>
Why you are using this tool:<input type="text" name="answer">
</form>
So for these text fields I need the user input logged as the answer.
I see you got the PHP thing fixed.
Now you need to fill your form with data. This:
<form action="insert.php" method="post">
<input type="submit">
</form>
sends only the submit value. You need to add input fields inside that form tag, otherwise, nothing else will get sent. So, since you're sending an answer array, you should add those (adding them as text fields, as an example):
<form action="insert.php" method="post">
<input type="text" name="answer[]" />
<input type="text" name="answer[]" />
etc...
<input type="submit" />
</form>
And make sure you filter all user inputs before writing anything into the database, as otherwise my buddy Bobby Tables might come to visit you.
Make sure in your XAMPP Control Panel that Apache and MySQL are running. Then check if your input fields are inside the <form action='insert.php' method='POST'> input fields </form>
Your HTML code would look like this:
<html>
<body>
<form action='insert.php' method='POST'>
<table>
<tr><td>Width: </td><td>
<input type="radio" name="width" value="skinny">-25%
<input type="radio" name="width" value="skinny">-10%
<input type="radio" name="width" value="mid">normal
<input type="radio" name="width" value="fat">+10%
<input type="radio" name="width" value="fat">+25%
</td></tr>
<tr><td>Spacing: </td><td>
<input type="radio" name="spacing" value="small">-25%
<input type="radio" name="spacing" value="small">-10%
<input type="radio" name="spacing" value="mid">normal
<input type="radio" name="spacing" value="wide">+10%
<input type="radio" name="spacing" value="wide">+25%
</td></tr>
<tr><td>Weight: </td><td>
<input type="radio" name="weight" value="light">-25%
<input type="radio" name="weight" value="light">-10%
<input type="radio" name="weight" value="mid">normal
<input type="radio" name="weight" value="heavy">+10%
<input type="radio" name="weight" value="heavy">+25%
</td></tr>
<tr><td>Height: </td><td>
<input type="radio" name="height" value="short">-25%
<input type="radio" name="height" value="short">-10%
<input type="radio" name="height" value="mid">normal
<input type="radio" name="height" value="tall">+10%
<input type="radio" name="height" value="tall">+25%
</td></tr>
<tr><td>City: </td><td><input type="text" name="city"></td></tr>
<tr><td>Why you are using this tool: </td><td><input type="text" name="tool"></td></tr>
<tr><td></td><td><input type='submit'></td></tr>
</table>
</form>
</body>
</html>
What are you using in creating your php files? Dreamweaver? Notepad? Try this: SAVE AS your file, Save As Type: All Files and name it insert.php.
<?php
$con=mysqli_connect("localhost","YourUsername","YourPassword(if any)","NameOfYourDatabase");
// Check connection
if (mysqli_connect())
{
echo "Failed to connect to MySQL: " . mysqli_errno();
}
$width=$_POST['width'];
$spacing=$_POST['spacing'];
$weight=$_POST['weight'];
$height=$_POST['height'];
$city=mysqli_real_escape_string($con,$_POST['city']);
$tool=mysqli_real_escape_string($con,$_POST['tool']);
/* REAL ESCAPE STRING WOULD PREVENT A BIT OF SQL INJECTION */
$sql="INSERT INTO Persons (Name, Serif, Width, Height, Spacing, Weight)
VALUES
('$city','$tool','$width','$height','$spacing','$weight')";
if (!mysqli_query($con,$sql))
{
die('Error: ' . mysqli_error($con));
}
echo "1 record added";
mysqli_close($con);
?>