Jump to content

Mysql update from form


ragrim

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";

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.