I am setting up an update profile page using php and a bit of laravel. I have an if check that checks if the form is submitted and I have an update query.
The update query only works outside of the if statement and I have no idea why. If I put in inside of the if statement it doesnt do anything. I have checked if all the names are the same as in my sql database and they are all correct.
<form class="form" id="registrationForm">
<div class="form-group">
<div class="col-xs-6">
<label for="first_name">
<h4>Voornaam</h4></label>
<input type="text" class="form-control" name="voornaam" id="first_name" placeholder="<?= $user->voornaam; ?>" title="enter your first name if any.">
</div>
</div>
<div class="form-group">
<div class="col-xs-6">
<label for="last_name">
<h4>Achternaam</h4></label>
<input type="text" class="form-control" name="achternaam" id="last_name" placeholder="<?= $user->achternaam; ?>" title="enter your last name if any.">
</div>
</div>
<div class="form-group">
<div class="col-xs-6">
<label for="phone">
<h4>Gebruikersnaam</h4></label>
<input type="text" class="form-control" name="gebruikersnaam" id="username" placeholder="<?= $user->gebruikersnaam; ?>" title="enter your phone number if any.">
</div>
</div>
<div class="form-group">
<div class="col-xs-6">
<label for="mobile">
<h4>Telefoon nummer</h4></label>
<input type="text" class="form-control" name="telefoonnummer" id="mobile" placeholder="<?= $user->telefoonnummer; ?>" title="enter your mobile number if any.">
</div>
</div>
<div class="form-group">
<div class="col-xs-12">
<label for="email">
<h4>Email</h4></label>
<input type="email" class="form-control" name="email" id="email" placeholder="<?= $user->email; ?>" title="enter your email.">
</div>
</div>
<div class="form-group">
<div class="col-xs-12">
<br>
<button class="btn btn-lg btn-success" type="submit" name="submit"><i class="glyphicon glyphicon-ok-sign"></i> Sla op</button>
<button class="btn btn-lg" type="reset" name="resetww"><i class="glyphicon glyphicon-repeat"></i> Verander wachtwoord</button>
</div>
</div>
</form>
<?php
if (isset($_POST['submit'])) {
$voornaam = $_POST['voornaam'];
$achternaam = $_POST['achternaam'];
$gebruikersnaam = $_POST['gebruikersnaam'];
$telefoonnummer = $_POST['telefoonnummer'];
$email = $_POST['email'];
App\User::where('klant_id', 1)->update(['gebruikersnaam' => $gebruikersnaam, 'voornaam' => $voornaam, 'achternaam' => $achternaam, 'email' => $email ,'telefoonnummer' => $telefoonnummer]);
}
?>
I want my database to be updated
Put the tag in your form, the PHP is trying to find de POST but you are not sending it.
method="POST"
First of all mention form method as below and use csrf token
#csrf
Why u can't use controller to complete this work
First of all use controller, Then make a method to update information
public function update_user(Request $request){
if ($request->isMethod('post')) {
$data = $request->all();
User = new User();
$voornaam = $_POST['voornaam'];
$achternaam = $data['achternaam'];
$gebruikersnaam = $data['gebruikersnaam'];
$telefoonnummer = $data['telefoonnummer'];
$email = $data['email'];enter code here
}
}
Related
Why a particular column gets updated with a null value? if I use
$firstName = $this->input->post('first_name'); //this has a value.
It works finely if I assign string values(Hardcoded).
$firstName = "First Name"
Profile Update function in Controller
$user_id = $this->session->userdata('user_auth')->id;
$firstName = $this->input->post('first_name');
$lastName = $this->input->post('last_name');
$email = $this->input->post('email');
$data = array(
'firstName' => $firstName,
'lastName' => $lastName,
'email' => $email,
);
$this->User_model->update_profile($user_id, $data);
DB Update in Model
$this->db->where('id', $user_id);
$this->db->update('user', $data);
if ($this->db->affected_rows()>0){
return true;
}else{
return false;
}
Form View
<form method="POST" enctype="multipart/form-data"
id="update_profile-form" class="update_profile-form"
action="<?php echo base_url(); ?>index.php/user/update_profile">
<div class="modal-body">
<div class="row">
<div class="col-md-6">
<div class="form-group">
<label for="first_name">First Name</label>
<input style="padding: 5px;" type="text" class="form-input"
name="first_name"
id="first_name"
value=<?= $user->firstName ?>
/>
</div>
</div>
<div class="col-md-6">
<div class="form-group">
<label for="last_name">Last Name</label>
<input style="padding: 5px;" type="text" class="form-input"
name="last_name"
id="last_name"
value="<?= $user->lastName ?>"/>
</div>
</div>
<div class="col-md-6">
<div class="form-group">
<label for="last_name">Email</label>
<input style="padding: 5px;" type="text" class="form-input"
name="email"
id="email" placeholder="Email"
value="<?= $user->email ?>"/>
<span
class="text-danger"><?php echo form_error('email'); ?></span>
</div>
</div>
</div>
</div>
<div class="modal-footer">
<!-- <button type="button" class="btn btn-secondary" data-dismiss="modal">Close-->
<!-- </button>-->
<input type="submit" value="Update" class="btn btn-primary"></input>
</div>
</form>
php form not submitting or doing any action from the form to my database despite following all the rules for connecting the form to mysql with php
the php code supposed to get the infor from the form using the name tags but no action nor any error occurs when the data is submitted
HTML Form
<form id="contactForm" method="post" action="register.php">
<div class="row">
<div class="col-md-6 wow fadeInLeft">
<div class="input-group">
<label class="sr-only" for="name">Name</label>
<span class="input-group-addon" id="basic-addon1"><i class="fa fa-user"></i></span>
<input id="name" name="name" type="text" class="form-control" required="" placeholder="Name">
</div>
</div>
<div class="col-md-6 wow fadeInRight">
<div class="input-group">
<label class="sr-only" for="email">Email address</label>
<span class="input-group-addon" id="basic-addon2"><i class="fa fa-envelope"></i></span>
<input id="email" name="email" type="email" class="form-control" required="" placeholder="Email">
</div>
</div>
</div>
<div class="row">
<div class="col-md-6 wow fadeInLeft">
<div class="input-group">
<label class="sr-only" for="phone">Phone</label>
<span class="input-group-addon" id="basic-addon3"><i class="fa fa-phone"></i></span>
<input id="phone" name="mobile" type="tel" class="form-control" placeholder="Phone">
</div>
</div>
<div class="col-md-6 wow fadeInRight">
<div class="input-group">
<label class="sr-only" for="subject">Location</label>
<span class="input-group-addon" id="basic-addon4"><i class="fa fa-file-text"></i></span>
<input id="subject" name="location" type="text" class="form-control" required="" placeholder="location">
</div>
</div>
</div>
<div class="row">
<div class="col-md-6 wow fadeInLeft">
<div class="input-group">
<label class="sr-only" for="phone">Username</label>
<span class="input-group-addon" id="basic-addon3"><i class="fa fa-phone"></i></span>
<input id="phone" name="username" type="text" class="form-control" required=""placeholder="username">
</div>
</div>
<div class="col-md-6 wow fadeInRight">
<div class="input-group">
<label class="sr-only" for="subject">Password</label>
<span class="input-group-addon" id="basic-addon4"><i class="fa fa-file-text"></i></span>
<input id="subject" name="password" type="text" class="form-control" required="" placeholder="password">
</div>
</div>
</div>
<div class="row">
<div class="col-md-12 wow fadeInRight">
<div class="input-group">
<label class="sr-only" for="subject">Interest</label>
<span class="input-group-addon" id="basic-addon4"><i class="fa fa-file-text"></i></span>
<input id="subject" name="interest" type="text" class="form-control" required="" placeholder="interest">
</div>
</div>
</div>
<input type="submit" class="btn btn-primary btn-lg btn-block" name="submit" value="Register">
</form>
PHP Form
if (isset($_POST['submit'])) {
$name = $_POST['name'];
$mobile = $_POST['mobile'];
$email = $_POST['email'];
$cusername = $_POST['username'];
$cpassword = $_POST['password'];
$location = $_POST['location'];
$interest = $_POST['interest'];
$sql = "INSERT INTO users(name,email,mobile,location,username,password,interest)
VALUES('$name','$email','$mobile','$location','$cusername','$cpassword','$interest')";
mysql_query($sql) or die(mysql_error());
session_start();
$_SESSION['username']=$cusername;
echo "<script type=\"text/javascript\">
alert(\"Registration Complete , you will be redirected shortly\");
window.location = \"profile.php\"
</script>";
}
please advice what seems to be the problem that i am missing or not seeing
try to connect with db first and pass the link into your query like this
$link = mysql_connect('localhost', 'mysql_user', 'mysql_password');
if (!$link) {
die('Could not connect: ' . mysql_error());
}
$sql = "INSERT INTO users(name,email,mobile,location,username,password,interest) VALUES('$name','$email','$mobile','$location','$cusername','$cpassword','$interest')";
// here put your LINK-CONNECTION
mysql_query($sql,$link) or die(mysql_error());
mysql_close($link);
and please filter the content you get from fields in your post, to avoid sql injection and other stuff.
first of all thank you all for your support , i simply missed the ID that the form had which was connected to a JS file for submitting the data and that was why the form was not seeing the php code
once removed everything was working fine
thank you all
I have to create a form where answers get sent to the database but when I fill in the form the database is not updating and I have getting the self made error :"something went wrong". Can anyone see anything wrong? Thanks.
Form:
<form id="contact-form" method="post" action="sentEnquiries.php" name="enquiries">
<div class="row">
<div class="col-md-6">
<div class="form-group">
<label for="name">
Name</label>
<div class="input-group">
<span class="input-group-addon"><span class="glyphicon glyphicon-user"></span>
</span>
<input type="text" class="form-control" id="name" name="name" placeholder="Enter name" required="required" /></div>
</div>
<div class="form-group">
<label for="email">
Email Address</label>
<div class="input-group">
<span class="input-group-addon"><span class="glyphicon glyphicon-envelope"></span>
</span>
<input type="email" class="form-control" id="email" name="email" placeholder="Enter email" required="required" /></div>
</div>
<div class="form-group">
<label for="phoneNumber">
Phone Number</label>
<div class="input-group">
<span class="input-group-addon"><span class="glyphicon glyphicon-earphone"></span>
</span>
<input type="tel" class="form-control" id="phoneNumber" name="phone" placeholder="Enter phone number" required="required" /></div>
</div>
<div class="form-group">
<label for="partySize">
Party Size</label>
<input type="number" min="1" max="6" class="form-control" id="partySize" name="partySize" required="required" />
</div>
</div>
<div class="col-md-6">
<div class="form-group">
<label for="arrivalDate">
Arrival Date</label>
<input type="date" class="form-control" id="arrivalDate" name="arrivalDate" />
</div>
<div class="form-group">
<label for="departureDate">
Departure Date</label>
<input type="date" class="form-control" id="departureDate" name="departureDate"/>
</div>
<div class="form-group">
<label for="name">
Message</label>
<textarea name="message" id="message" class="form-control" rows="9" cols="25" required="required"
placeholder="Message"></textarea>
</div>
</div>
<div class="col-md-12">
<button type="submit" class="btn btn-skin pull-right" id="btnContactUs">
Send enquiry</button>
</div>
</div>
</form>
Answers:
<?php
include("conn.php");
$sentName = $_POST['name'];
$sentEmail = $_POST['email'];
$sentPhone = $_POST['phone'];
$sentPartySize = $_POST['partySize'];
$sentArrivalDate = $_POST['arrivalDate'];
$sentDepartureDate = $_POST['departureDate'];
$sentMessage = $_POST['message'];
$insertQuery = "INSERT INTO Enquiries(enquiryID, name, email, phone, partySize, arrivalDate, departureDate, message) VALUES(NULL, '$sentName', '$sentEmail', '$sentPhone, '$sentPartySize', $sentArrivalDate, '$sentDepartureDate', '$sentMessage')";
?>
Further down answers doc:
<div class="descriptions">
<?php
if(mysqli_query($conn, $insertQuery)) {
echo "<p>Thank you for your enquiry.</p>";
mysqli_close($conn);
} else {
echo "<p>Something went wrong.</p>";
mysqli_close($conn);
}
?>
</div>
could you make sure as below :
enquiryID column, is this column is auto increment if not better you set the id become auto increment primary key
For debug purposes, can you echo first in $_POST['name'] then exit; to make sure that the post data from your html is work correctly.
if that not work, you should try to select first from database with simple query, so you will know the connection to database table is work correctly
Here is how i'd do it.
Change yours as required but here's my example:
PDO class:
class form
{
public function sendForm($name, $email, $phone, $party, $date, $depart, $message)
{
$stmt = $this->conn->prepare("INSERT INTO `enquiries` (`name`,`email`,`phone`,`partySize`,`arrivalDate`,`departureDate`,`message`) VALUES (:fname, :email, :phone, :party, :arrive, :depart, :msg)");
$stmt->bindParam(array(':fname' => $name, ':email' => $email, ':phone' => $phone, ':party' => $party, ':arrive' => $date, ':depart' => $depart, ':msg' => $message));
$stmt->execute();
}
}
Then within your form page:
$form = new form();
if (isset($_POST['sendIt']))
{
$form->sendForm($_POST['Fname'],$_POST['email'],$_POST['phone'],$_POST['size'],$_POST['date'],$_POST['depart'],$_POST['message']);
}
Then my basic form without the div tagging so you'll need to tweak slightly:
<form action="" method="post">
<input type="text" name="Fname">
<input type="email" name="email">
<input type="text" name="phone">
<input type="text" name="size">
<input type="text" name="date">
<input type="text" name="depart">
<textarea name="message" id="" cols="30" rows="10"></textarea>
<input type="submit" name="sendIt">
</form>
This is a very basic one with no thank you message or conditions but you can easily add conditions before running the query by doing
if (!empty($var)
{
// do something
} else {
echo "you didnt fill this in...";
I am trying to get a simple contact form to work with my wordpress site but cannot get it to work. I dont want to use any plugin, I just want to do it using PHP. So I put this file in root dir of my wordpress installation on my hostgator hosted site
www.example.com/sendmail.php
<?php
if(isset($_POST['submit'])){
$to = "myemail#yahoo.com";
$from= $_POST['email'];
$fname= $_POST['fname'];
$lname= $_POST['lname'];
$message= $_POST['message'];
$subject = "Request email";
$headers = "From:" .$from;
mail($to,$subject,$message,$headers);
}
?>
This is the contact-us form on www.example.com/contact-us
<form action="http://www.example.com/sendmail.php" method="post">
<fieldset>
<div class="form-group">
<div class="col-md-12">
<input id="fname" name="name" type="text" placeholder="First Name" class="form-control">
</div>
</div>
<div class="form-group">
<div class="col-md-12">
<input id="lname" name="name" type="text" placeholder="Last Name" class="form-control">
</div>
</div>
<div class="form-group">
<div class="col-md-12">
<input id="email" name="email" type="text" placeholder="Email Address" class="form-control">
</div>
</div>
<div class="form-group">
<div class="col-md-12">
<input id="phone" name="phone" type="text" placeholder="Phone" class="form-control">
</div>
</div>
<div class="form-group">
<div class="col-md-12">
<textarea class="form-control" id="message" name="message" placeholder="Enter your massage for us here. We will get back to you within 2 business days." rows="7"></textarea>
</div>
</div>
<div class="form-group">
<div class="col-md-12 text-center">
<!-- <button type="submit" class="btn btn-primary btn-lg">Submit</button>-->
<input type="submit" name="submit" class="btn btn-primary btn-lg" value="Submit">
</div>
</div>
</fieldset>
</form>
If i try to visit this page www.example.com/sendmail.php, it gives 200 success ok message. However if I try to fill the form and then it sends the email, i am not able to recieve it.
Is there anything I am missing or I need to check ?
You are getting these variables $fname= $_POST['fname']; $lname= $_POST['lname']; on sendmail.php
But your html form input fields does not have name for fname and lname .
So use the below one :
<div class="form-group">
<div class="col-md-12">
<input id="fname" name="fname" type="text" placeholder="First Name" class="form-control">
</div>
</div>
<div class="form-group">
<div class="col-md-12">
<input id="lname" name="lname" type="text" placeholder="Last Name" class="form-control">
</div>
</div>
Instead of :
<div class="form-group">
<div class="col-md-12">
<input id="fname" name="name" type="text" placeholder="First Name" class="form-control">
</div>
</div>
<div class="form-group">
<div class="col-md-12">
<input id="lname" name="name" type="text" placeholder="Last Name" class="form-control">
</div>
</div>
Hope it helps you.
I Have two forms on my site. One works fine and the other sends email with email_from: etc but doesn't capture any of the form data.
Wondering what it may be. I can post the form that is working along with it's html too if that would help debug. Very much a novice and built form using stack overflow/other sites.
Coffee
<div class="form-group">
<label class="col-sm-3 control-label">Quantity</label>
<div class="col-sm-4">
<input type="text" name="quantity" class="form-control" placeholder="Quantity : " required>
</div>
</div>
<div class="form-group">
<label class="col-sm-3 control-label">Name</label>
<div class="col-sm-6">
<input type="text" name="name" class="form-control" placeholder="Name : " required>
</div>
</div>
<div class="form-group">
<label class="col-sm-3 control-label">Email address</label>
<div class="col-sm-6">
<input type="email" name="email" class="form-control" placeholder="Email address : " required>
</div>
</div>
<div class="form-group">
<label class="col-sm-3 control-label">Shipping Address</label>
<div class="col-sm-6">
<textarea class="form-control" name="shipping_address" rows="8" placeholder="Shipping Address : " required></textarea>
</div>
</div>
<div class="form-group">
<label class="col-sm-3 control-label">Payment Method</label>
<div class="col-sm-6">
<select class="form-control" required>
<option value="Paypal">Paypal</option>
</select>
</div>
</div>
<div class="form-group">
<label class="col-sm-3 control-label">Notes</label>
<div class="col-sm-6">
<textarea class="form-control" name="notes" rows="8" placeholder="Notes : "></textarea>
</div>
</div>
<div class="form-group">
<div class="col-sm-offset-3 col-sm-10">
<button type="submit" class="btn btn-black">Order Now</button></a>
</div>
</div>
</form>
</div>
</div>
</div>
</div>
And here is the php
<?php
if(isset($_POST ['submit']))
{
$coffee = ($_POST['coffee']));
$quantity = ($_POST['quantity']));
$name = ($_POST['name']));
$email = ($_POST['email']));
$shipping_address = ($_POST['shipping_address']));
$notes = ($_POST['notes']));
}
$email_from ='paradigmcoffee#gmail.com';
$email_subject="New Order Submission";
$email_body ="You have received a new message from user $name.\n".
"Email_address:$email\n".
"Coffee: $coffee\n".
"Quantity: $quantity\n".
"Shipping_Address: $shipping_address\n".
"Notes: $notes\n".
$to ="paradigmcoffee#gmail.com";
$headers = "From: $email \r\n";
mail($to,$email_from,$email_subject,$email_body,$headers);
header("Location: http://www.paradigmcoffee.co/order_thanks.html");
?>
From what you have supplied, likely the reason you can not get data is because you are not sending anything called submit. Try naming your button:
<!-- name="submit" added -->
<button name="submit" type="submit" class="btn btn-black">Order Now</button>
You can do this or make a hidden field:
<input type="hidden" name="submit" value="1" />