Jump to content

Recommended Posts

Hi,

 

Im trying to update a record from a form but im having some troubles using the variables ans such, i use $_POST to get the info from the field of the form, store it as a variable and try to use the variable in the query like i do with insert and select queries, but i just cant seem to get it to work with update.

 

<?php
$fname = $_POST["firstname"];
$lname = $_POST["lastname"];
$address = $_POST["address"];
$suburb = $_POST["suburb"];
$postcode = $_POST["postcode"];
$phone1 = $_POST["phone1"];
$phone2 = $_POST["phone2"];
$email1 = $_POST["email1"];
$email2 = $_POST["email2"];
$billingemail = $_POST["billingemail"];


$host=""; // Host name 
$username=""; // Mysql username 
$password=""; // Mysql password 
$db_name=""; // Database name 


// Connect to server and select database. 
mysql_connect("$host", "$username", "$password")or die("cannot connect server "); 
mysql_select_db("$db_name")or die("cannot select DB"); 


$query = 'UPDATE `invoicing`.`customers` SET `billingemail` = '$fname' WHERE `customers`.`id` = 13;'; 
?>

 

Any help would be muchly appreciated.

Link to comment
https://forums.phpfreaks.com/topic/137148-mysql-update-from-form/
Share on other sites

$query = 'UPDATE `invoicing`.`customers` SET `billingemail` = '$fname' WHERE `customers`.`id` = 13;';

You closed the statement when you added = '$fname, because you are enclosing it in ' from the beginning.  Also, you don't need the table prefixes if you're updating the same table..

 

$query = "UPDATE customers SET billingemail = '$fname' WHERE id = 13";

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.