In a page I have a form that submits with Post method. In another page I'm just trying to retreive and echo those values. If I just:
var_dump($_POST)
I see every value I entered in the form.
If I do something like:
echo $_POST['name'];
echo $_POST['surname'];
echo $_POST['telephone'];
I see the correct values.
But if, at the beginning of the page, use:
$name = $_POST['name'];
$surname = $_POST['surname'];
$telephone = $_POST['telephone'];
echo $name . ' ' . $surname . ' ' . $telephone;
I notice that for example name and telephone are always empty.
HTML form:
<form id="dom_com_sci" class="form" name="dom_com_sci" action="./ricevuta-fiscale-2convention.php" method="post" enctype="application/x-www-form-urlencoded" target="_self" style="height: 2200px; width: 619px;">
<p>
<label for="name">name:</label>
<input id="name" class="focus capitalize" name="name" type="text" size="26" value="" maxlength="70" placeholder="es. Mario" autocomplete="off" />
</p>
<p>
<label for="surname">surname:</label>
<input id="surname" class="focus capitalize" name="surname" type="text" size="26" value="" maxlength="70" placeholder="es. Rossi" autocomplete="off" />
</p>
<p>
<label for="telephone">telephone:</label>
<input id="telephone" class="focus capitalize" name="telephone" type="text" size="26" value="" maxlength="70" placeholder="es. Rossi" autocomplete="off" />
</p>
<input type="submit" name="Send" value="Send" tabindex="34" />
</form>
The php script on the result page:
<?php
require_once('./function/generic_function.php');
if(isset($_POST['submit']) && $_POST['submit'] == "Send") {
$surname= $_POST['surname'];
$name = $_POST['name'];
$telephone = $_POST['telephone'];
}
?>
generic_function.php:
<?php
function replace($stringa) {
$stringa_r = str_replace('\\','',$stringa);
return $stringa_r;
}
function accesso($percorso,$opzione = "N") {
($opzione == "Y") ? $blank = "target=_blank" : $blank = "";
if(isset($_SESSION['access_level']) && $_SESSION['access_level'] > 1 && isset($_SESSION['logged']) && $_SESSION['logged'] == 1 && isset($_SESSION['user_id'])) {
print('href="'.$percorso.'"'.$blank);
} else {
print('href="'.$dir.'access.php"');
}
}
?>
you are missing on quote (') in these line
$surname= $_POST['surname];
$name = $_POST['name];
$telephone = $_POST['telephone];
it should be this
$surname= $_POST['surname'];
$name = $_POST['name'];
$telephone = $_POST['telephone'];
<?php
//error_reporting($level=NULL);
?>
<form id="dom_com_sci" class="form" name="dom_com_sci" action="" method="post" enctype="application/x-www-form-urlencoded" target="_self" >
<p>
<label for="name">name:</label>
<input id="name" class="focus capitalize" name="name" type="text" size="26" value="" maxlength="70" placeholder="es. Mario" autocomplete="off" />
</p>
<p>
<label for="surname">surname:</label>
<input id="surname" class="focus capitalize" name="surname" type="text" size="26" value="" maxlength="70" placeholder="es. Rossi" autocomplete="off" />
</p>
<p>
<label for="telephone">telephone:</label>
<input id="telephone" class="focus capitalize" name="telephone" type="text" size="26" value="" maxlength="70" placeholder="es. Rossi" autocomplete="off" />
</p>
<input type="submit" name="submit" value="submit" tabindex="34" />
</form>
<?php
//require_once('./function/generic_function.php');
if(isset($_POST['submit']) && $_POST['submit'] == "submit") {
$surname= $_POST['surname'];
$name = $_POST['name'];
$telephone = $_POST['telephone'];
echo $name . ' ' . $surname . ' ' . $telephone;
}
?>
Comment:: To style your form. You can put it inside the div and than can give that div style.
Thanks let me know it work or not.
Related
I have a problem when uploading image into database using mysql.
When I click button for upload the image, the error comes out like this:
"Undefined index image in C:\xampp\htdocs\fyp\kemaskinipemandu.php" at line 29 and 30.
I've tried other solution from StackOverflow but it didn't work out at all. So, here is my html and my php code.
if (isset($_POST['kemaskini'])){
$email = $_SESSION['driverEmail'];
$nama = $_POST['nama'];
$password = $_POST['password'];
$cpassword = $_POST['cpassword'];
$kp = $_POST['kp'];
$tel = $_POST['tel'];
$alamat = $_POST['alamat'];
$exdate = date('Y-m-d', strtotime($_POST['lesen']));
$class = $_POST['jenislesen'];
$image = $_FILES['image']['name'];//imageUpload
move_uploaded_file($_FILES['image']['tmp_name'], "img/".$_FILES['image']['name']);
if($password === $cpassword){
$query = "UPDATE driver SET driverName='$nama', driverPassword='$password', cpassword='$cpassword', driverICNum='$kp', contNum='$tel',
address='$alamat', licenseExDate='$exdate', class='$class', image='$image' WHERE driverID='$driverID';";
$result = mysqli_query($conn, $query) or die(mysqli_error($conn));
if($result)
{
?>
<script>
alert('Kemas Kini Pemandu Berjaya. ');
window.location.href="kemaskinipemandu.php";
</script>
<?php
}
}else {
?>
<script>
alert('Kata laluan tidak sama. ');
window.location.href="kemaskinipemandu.php";
</script>
<?php
}
}
and the line that have error are :
$image = $_FILES['image']['name'];//imageUpload
move_uploaded_file($_FILES['image']['tmp_name'], "img/".$_FILES['image']['name']);
Select image to upload:
<form action="kemaskinipemandu.php" method = "POST" enctype="multipart/form-data">
<center>
<?php
$email = $_SESSION['driverEmail'];
$query=" SELECT * from driver where driverID='$driverID'";
$result = mysqli_query($conn, $query) or die(mysqli_error($conn));
$count = mysqli_num_rows($result);
if (isset($count) and ($count > 0)) {
while($row = mysqli_fetch_assoc($result)){
$name = $row['driverName'];
$password = $row['driverPassword'];
$cpassword = $row['cpassword'];
$ic = $row['driverICNum'];
$contNum = $row['contNum'];
$address = $row['address'];
$exdate = $row['licenseExDate'];
$class = $row['class'];
$image = $row['image'];
?>
<div class="col-md-6">
<div class="form-group">
<img src="<?php echo $image ?>" height="200" width="200"/><br><br>
<div class="form-inline">
Select image to upload:
<input type="file" name="image" id="image" style="margin-left:2%"><br><br>
</div>
<label for="nama">Nama :</label>
<input type="nama" class="form-control" name="nama" value="<?php echo $name ?>" ><br>
<label for="email">Email :</label>
<input type="email" class="form-control" name="email" value="<?php echo $email ?>" ><br>
<label for="password">Kata Laluan :</label>
<input type="password" class="form-control" name="password" value="<?php echo $password ?>" ><br>
<label for="password">Pengesahan Kata Laluan :</label>
<input type="password" class="form-control" name="cpassword" value="<?php echo $cpassword ?>" ><br>
<label for="kp">No. Kad Pengenalan :</label>
<input type="kp" class="form-control" name="kp" value="<?php echo $ic ?>" ><br>
<label for="tel">No. Tel :</label>
<input type="tel" class="form-control" name="tel" value="<?php echo $contNum ?>" ><br>
<label for="alamat">Alamat :</label>
<textarea type="alamat" class="form-control" name="alamat" rows="6"><?php echo $address ?></textarea><br>
<label for="lesen">Tamat Tempoh Lesen Memandu :</label>
<input type="date" class="form-control" name="lesen" value="<?php echo $exdate ?>" ><br>
<label for="jenislesen">Lesen/Kelas:</label>
<input type="text" class="form-control" name="jenislesen" value="<?php echo $class ?>" >
</div>
</div>
<?php } }?>
<input type="submit" class="btn btn-primary" name="kemaskini" value="Kemas Kini"></br>
</center>
</form>
I hope someone can help me. Thank you.
this is the error i get after i reload the browser (Notice: Undefined index:) and also this (Uncaught exception 'PDOException' with message 'SQLSTATE[HY093]: Invalid parameter number: number of bound variables does not match number of tokens')
THIS IS MY CODE:
addform.php
<input type="text" name="EMPLOYEENO" placeholder="Employee No">
<input type="text" name="NAME" placeholder="Name">
<input type="text" name="OCCUPATION" placeholder="Occupation">
<input type="text" name="GENDER" placeholder="Gender"><br><br>
<input type="text" name="AGE" placeholder="Age">
<input type="text" name="ADDRESS" placeholder="Address">
<input type="text" name="CELLPHONE" placeholder="Cellphone No">
<input type="text" name="DATEOFBIRTH" placeholder="Date of Birth"><br><br>
<input type="text" name="CITIZEN" placeholder="Citizenship">
<input type="text" name="RELIGION" placeholder="Religion">
<input type="text" name="HEIGHT" placeholder="Height">
<input type="text" name="WEIGHT" placeholder="Weight"><br><br>
<input type="text" name="ELEMENTARY" placeholder="Elementary">
<input type="text" name="ELEMENTARYYEAR" placeholder="Year Graduated"><br><br>
<input type="text" name="HIGHSCHOOL" placeholder="High School">
<input type="text" name="HIGHYEAR" placeholder="Year Graduated"><br><br>
<input type="text" name="COLLEGE" placeholder="College">
<input type="text" name="COLLEGEYEAR" placeholder="Year Graduated"><br>
<button>SUBMIT</button>
</div>
AND ADDFORM_PROCESS.PHP
$idno = $_POST['EMPLOYEENO'];
$name = $_POST['NAME'];
$occ = $_POST['OCCUPATION'];
$gender = $_POST['GENDER'];
$age = $_POST['AGE'];
$address = $_POST['ADDRESS'];
$cell = $_POST['CELLPHONE'];
$birth = $_POST['DATEOFBIRTH'];
$citizen = $_POST['CITIZEN'];
$religion = $_POST['RELIGION'];
$height = $_POST['HEIGHT'];
$weight = $_POST['WEIGHT'];
$elementary = $_POST['ELEMENTARY'];
$elementaryyear = $_POST['ELEMENTARYYEAR'];
$highschool = $_POST['HIGHSCHOOL'];
$highschoolyear = $_POST['HIGHYEAR'];
$college = $_POST['COLLEGE'];
$collegeyear = $_POST['COLLEGEYEAR'];
if ($idno="" || $name="" || $occ="" || $gender="" || $age="" || $address="" || $cell="" || $birth="" || $citizen="" ||
$religion="" || $height="" || $weight="" || $elementary="" || $elementaryyear="" || $highschool="" ||
$highschoolyear="" || $college="" || $collegeyear=""){
echo "<script>
alert('Dont leave the textbox empty!');
window.location='addform.php';
</script>";
}else{
$stmt=$db->prepare("INSERT INTO tbl_employee_information(EmployeeNo,Name,Occupation,Gender,Age,Address,CellphoneNo,DateofBirth,Citizenship,Religion,Height,Weight,Elementary,YearGraduatedinElementary,HighSchool,YearGraduatedinHighSchool,College,YearGraduatedinCollege) VALUES(:EMPLOYEENO,:NAME,:OCCUPATION,:GENDER,:AGE,:ADDRESS,:CELLPHONE,
:DATEOFBIRTH,:CITIZEN,:RELIGION,:HEIGHT,:WEIGHT,:ELEMENTARY,:ELEMENTARYYEAR,:HIGHSCHOOL,:HIGHYEAR,:COLLEGE,:
COLLEGEYEAR)");
$stmt->bindParam(':EMPLOYEENO',$idno);
$stmt->bindParam(':NAME',$name);
$stmt->bindParam(':OCCUPATION',$occ);
$stmt->bindParam(':GENDER',$gender);
$stmt->bindParam(':AGE',$age);
$stmt->bindParam(':ADDRESS',$address);
$stmt->bindParam(':CELLPHONE',$cell);
$stmt->bindParam(':DATEOFBIRTH',$birth);
$stmt->bindParam(':CITIZEN',$citizen);
$stmt->bindParam(':RELIGION',$religion);
$stmt->bindParam(':HEIGHT',$height);
$stmt->bindParam(':WEIGHT',$weight);
$stmt->bindParam(':ELEMENTARY',$elementary);
$stmt->bindParam(':ELEMENTARYYEAR',$elementaryyear);
$stmt->bindParam(':HIGHSCHOOL',$highschool);
$stmt->bindParam(':HIGHYEAR',$highschoolyear);
$stmt->bindParam(':COLLEGE',$college);
$stmt->bindParam(':COLLEGEYEAR',$collegeyear);
$stmt->execute();
header("location:main.php");
Maybe if you put the names of the parameters in an array and use foreach loop to build your request text and multiple calls of bindParam it would be easyer to debug ?
i know this topic has been touched on so much, but a solution is still evading me. I keep getting an unidentified index error in this php file:
<?php
$name = isset($_POST['name']) ? $_POST['name'] : '';
$telephone = isset($_POST['telephone']) ? $_POST['telephone'] : '';
$email = isset($_POST['email']) ? $_POST['email'] : '';
$birthDate = isset($_POST["birthDate"]) ? $_POST['birthDate'] : '';
$gender = isset($_POST['gender']) ? $_POST['email'] : '';
$comments = isset($_POST['comments']) ? $_POST['comments'] : '';
?>
Thanks for submitting your application!<br>
The following is the information we received:<br>
Name: <?php echo $_POST['name'] ?><br>
Telephone: <?php echo $_POST['telephone']?><br>
E-Mail: <?php echo $_POST['email']?><br>
Birthday: <?php echo $_POST['birthDate '] ?><br>
Gender: <?php echo $_POST['gender'] ?><br>
When you first wanted to be a zookeeper: <?php echo $_POST['comments ']
?>
</body>
</html>
here's the html form that this php file is getting it's values from:
<form id="zooKeeperForm" action="zoo.php" method="GET" onsubmit="return validateForm()">
<p><i>Please complete the form. Mandatory fields are marked with a </i><em>*</em></p>
<fieldset>
<legend>Contact Details</legend>
<label for="name">Name <em>*</em></label>
<input id="name" placeholder="Jane Smith" autofocus required><br>
<label for="telephone">Telephone</label>
<input id="telephone" placeholder="(xxx) xxx-xxxx"><br>
<label for="email">Email <em>*</em></label>
<input id="email" type="email" required><br>
</fieldset>
<fieldset>
<legend>Personal Information</legend>
<label for="birthDate">Birth Date<em>*</em></label>
<input id="birthDate" type="date" required><br>
<label for="age">Age<em>*</em></label>
<input id="age" type="number" min="0" max="120" step="0.1" required><br>
<label for="gender">Gender</label>
<select id="gender">
<option value="female">Female</option>
<option value="male">Male</option>
</select><br>
<label for="comments">When did you first know you wanted to be a zoo-keeper?<em>*</em></label>
<textarea id="comments" oninput="validateComments(this)" required></textarea>
</fieldset>
<p><input type="submit" value="Submit Application"></p>
</form>
what am I doing wrong here?? I feel like an idiot. I keep going from getting the unidentified index error to where it prints out the format I want but it's just blank for all the values that should be getting plugged in.
First thing:
Change it to POST
<form id="zooKeeperForm" action="zoo.php" method="POST" onsubmit="return validateForm()">
// ^ POST not GET
Second. Name attributes is the one to be used not ids
<input id="name" placeholder="Jane Smith" autofocus required>
// NOT ID but name="name"
This must be:
<input name="telephone" placeholder="(xxx) xxx-xxxx" id="telephone" />
<input name="email" type="email" required id="email" />
<input name="birthDate" type="date" required id="birthDate" />
<select name="gender" id="gender">
<textarea name="comments" oninput="validateComments(this)" id="comments" required>
Third:
The simple thing here is that, always process form input the form is submitted. Not upon initial load.
Catch the submission with something like this:
<input type="submit" name="zoo_submit" value="Submit Application" />
Then in PHP:
// simple initialization
$name = $telephone = $email = $birthDate = $gender = $comments = '';
if(isset($_POST['zoo_submit'])) {
$name = isset($_POST['name']) ? $_POST['name'] : '';
$telephone = isset($_POST['telephone']) ? $_POST['telephone'] : '';
$email = isset($_POST['email']) ? $_POST['email'] : '';
$birthDate = isset($_POST["birthDate"]) ? $_POST['birthDate'] : '';
$gender = isset($_POST['gender']) ? $_POST['email'] : '';
$comments = isset($_POST['comments']) ? $_POST['comments'] : '';
}
?>
Thanks for submitting your application!<br>
The following is the information we received:<br>
<!-- now you have already set the variables above, use them, not the POST values again -->
Name: <?php echo $name; ?><br>
Telephone: <?php echo $telephone; ?><br>
E-Mail: <?php echo $email; ?><br>
Birthday: <?php echo $birthDate; ?><br>
Gender: <?php echo $gender; ?><br>
When you first wanted to be a zookeeper: <?php echo $comments; ?>
EDIT: The code seems to work if I place the PHP code in the same file at the HTML. I'll implement this method for now. Thank you for the help!
Whenever I try to echo the values in a PHP file from an input box the values appear to be empty.
Here is my HTML code
<form action="sendmail.php" method="post">
<label>Name:</label><br>
<input name="person" type="text" /><br>
<label>Email:</label><br>
<input name="email" type="email" /><br>
<label>Opportunity:</label><br>
<textarea name="message" rows="8"></textarea><br>
<input type="submit" value="Submit" class="button">
</form>
This is my sendmail.php file
$name = $_POST['person'];
$email = $_POST['email'];
$message = $_POST['message'];
echo $name;
echo $email;
echo $message;
You can get the value in Your current page itself
<?php
if(isset($_POST['person']))
{
$name = $_POST['person'];
$email = $_POST['email'];
$message = $_POST['message'];
echo "Name".$name;
echo "Email".$email;
echo "Message".$message;
}
?>
<form action="" method="post">
<label>Name:</label><br>
<input name="person" type="text" /><br>
<label>Email:</label><br>
<input name="email" type="email" /><br>
<label>Opportunity:</label><br>
<textarea name="message" rows="8"></textarea><br>
<input type="submit" value="Submit" class="button">
</form>
or if you want the data in another page
<form action="send.php" method="post">
<label>Name:</label><br>
<input name="person" type="text" /><br>
<label>Email:</label><br>
<input name="email" type="email" /><br>
<label>Opportunity:</label><br>
<textarea name="message" rows="8"></textarea><br>
<input type="submit" value="Submit" class="button">
send.php file
<?php
if(isset($_POST['person']))
{
$name = $_POST['person'];
$email = $_POST['email'];
$message = $_POST['message'];
echo "Name".$name;
echo "Email".$email;
echo "Message".$message;
}
?>
I tried this code and it worked fine, so whatever is wrong it is not with the code you have pasted here.
to make sure the post is successful, try this:
if(isset($_POST['person']))
echo "passed fine.";
check:
if (strtoupper($_SERVER['REQUEST_METHOD']) == 'POST'){
if(isset($_POST['person'])){
$name = $_POST['person'];
echo $name;
}
}
else{
echo"Your form submission is not correct";
}
try this code.
HTML
<form action="sendmail.php" method="post">
<label>Name:</label><br>
<input name="person" type="text" /><br>
<label>Email:</label><br>
<input name="email" type="email" /><br>
<label>Opportunity:</label><br>
<textarea name="message" rows="8"></textarea><br>
<input type="submit" value="Submit" class="button">
</form>
PHP
<?php
$name = $_POST['person'];
$email = $_POST['email'];
$message = $_POST['message'];
echo $name;
echo $email;
echo $message;
?>
<form action="456.php" method="post">
<label>Name:</label><br>
<input name="person" type="text" /><br>
<label>Email:</label><br>
<input name="email" type="email" /><br>
<label>Opportunity:</label><br>
<textarea name="message" rows="8"></textarea><br>
<input type="submit" value="Submit" class="button">
</form>
<?
print_r($_POST);
?>
For some reason, the options are not showing up in my email. I can get the email to send just fine. I can see the body and all its comments, but none of the entries that the user made. I know I am doing something wrong, but I cannot determine what it is.
Also, feel free to mock me if it looks horrible. :)
$ToEmail = 'dmandrade1978#gmail.com';
$EmailSubject = 'Message from web page!!';
$name = $_POST['name'];
$email = $_POST['email'];
$comment = $_POST['comment'];
$urphone = $_POST['urphone'];
$event = $_POST['event'];
$date = $_POST['date'];
$mail = $_POST['mail'];
$phone = $_POST['phone'];
$comment = $_POST['comment'];
$hearaboutus = $_POST['hearaboutus'];
$body = <<<EMAIL
Email: $email <br />
Name: $name <br />
Comment: $comment <br />
Phone: $urphone <br />
Date: $urdate <br />
Comment: $comment <br />
How did you hear?: $hearaboutus <br />
Mail optiom: $mail <br />
EMAIL;
$header = "Content-type: text/html\r\n";
mail("$ToEmail", "$EmailSubject", "$body", "$header");
echo ("Message Sent!");
?>
<td class = "form">
<form action="?" method="get" enctype="text/plain">
<p class = "form">Name:<br />
<input type="text" name="name" id="name" /></p>
<p class = "form">E-mail:<br />
<input type="text" name="email" id="email" /></p>
<p class = "form">Phone #:<br />
<input type="text" name="urphone" id="urphone" /></p>
<p class = "form">Event type:<br />
<input type="text" name="event" id="event" /></p>
<p class = "form">Date of event:<br />
<input type="text" name="date" id="date" /></p>
<p class = "form" >Prefered method of contact:<br />
<span class = "contact">
<input type="radio" name="phone" id="phone" /> Phone<br />
<input type="radio" name="mail" id="mail" /> E-mail<br />
</span></p>
<p class = "form">How did you hear about us?:<br />
<select name="hearaboutus" id="hearaboutus" />
<option value="internet">Internet</option>
<option value="word of mouth">Friend/Family</option>
<option value="magazine">Magazine</option>
<option value="other">Other</option>
</select></p>
<p class = "form">Message, questions, or availability:<br />
<textarea rows="10" cols="30" name="comment" id="comment">
</textarea></p>
<input type="submit" value="Send email to us" id="submit">
<input type="reset" value="Reset and start over">
</form>
Change method="get"
to
method="post"
and remove enctype . It's not required in this case.
Also, why is there a ? in your action? You can keep action blank as it is posting to the same page.
To make things even simpler for you, copy paste the below code and run the file again
if(isset($_POST['submit']))
{
$ToEmail = 'dmandrade1978#gmail.com';
$EmailSubject = 'Message from web page!!';
$name = $_POST['name'];
$email = $_POST['email'];
$comment = $_POST['comment'];
$urphone = $_POST['urphone'];
$event = $_POST['event'];
$date = $_POST['date'];
$mail = $_POST['mail'];
$phone = $_POST['phone'];
$comment = $_POST['comment'];
$hearaboutus = $_POST['hearaboutus'];
$body = <<<EMAIL
Email: $email <br />
Name: $name <br />
Comment: $comment <br />
Phone: $urphone <br />
Date: $urdate <br />
Comment: $comment <br />
How did you hear?: $hearaboutus <br />
Mail optiom: $mail <br />
EMAIL;
$header = "Content-type: text/html\r\n";
mail("$ToEmail", "$EmailSubject", "$body", "$header");
echo ("Message Sent!");
}
?>
<td class = "form">
<form action="" method="post">
<p class = "form">Name:<br />
<input type="text" name="name" id="name" /></p>
<p class = "form">E-mail:<br />
<input type="text" name="email" id="email" /></p>
<p class = "form">Phone #:<br />
<input type="text" name="urphone" id="urphone" /></p>
<p class = "form">Event type:<br />
<input type="text" name="event" id="event" /></p>
<p class = "form">Date of event:<br />
<input type="text" name="date" id="date" /></p>
<p class = "form" >Prefered method of contact:<br />
<span class = "contact">
<input type="radio" name="phone" id="phone" /> Phone<br />
<input type="radio" name="mail" id="mail" /> E-mail<br />
</span></p>
<p class = "form">How did you hear about us?:<br />
<select name="hearaboutus" id="hearaboutus" />
<option value="internet">Internet</option>
<option value="word of mouth">Friend/Family</option>
<option value="magazine">Magazine</option>
<option value="other">Other</option>
</select></p>
<p class = "form">Message, questions, or availability:<br />
<textarea rows="10" cols="30" name="comment" id="comment">
</textarea></p>
<input type="submit" name="submit" value="Send email to us" id="submit">
<input type="reset" value="Reset and start over">
</form>