5
Contributors
4
Replies
36
Views
3 Years
Discussion Span
Last Post by mesh457
0

Hi,

You need a php code that updates db from a form like tis?

<?php
db_conect();
$action = isset( $_POST['action'] ) ? $_POST['action'] : "";
if($action == "update"){ 
$query = "update city
set 
name = '".$con->real_escape_string($_POST['name'])."',
state = '".$con->real_escape_string($_POST['state'])."',
population = '".$con->real_escape_string($_POST['population'])."',
zipcode  = '".$con->real_escape_string($_POST['zipcode'])."',
area  = '".$con->real_escape_string($_POST['area'])."',
phone  = '".$con->real_escape_string($_POST['phone'])."',
fax  = '".$con->real_escape_string($_POST['fax'])."'    
where id_city='".$con->real_escape_string($_REQUEST['id'])."'";
if( $con->query($query) ) {
echo '<div class="alert alert-success">City was updated!</div>.';
}else{
echo '<div class="alert alert-danger">Database Error: Unable to update record.</div>';
}
}
?>
0

Try this:
Update.php

<?php
$con=mysqli_connect("example.com","peter","abc123","my_db");
// Check connection
if (mysqli_connect_errno()) {
  echo "Failed to connect to MySQL: " . mysqli_connect_error();
}

mysqli_query($con,"UPDATE Persons SET Age=36
WHERE FirstName='Peter' AND LastName='Griffin'");

mysqli_close($con);
?>
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.