Anyone, how to make this work - no resuts evident
<?php
error_reporting(E_ALL ^ E_NOTICE);
// error_reporting(0);
if(isset($_POST['update']))
{
$dbhost = 'localhost';
$dbuser = 'root';
$dbpass = 'cookie';
$conn = mysql_connect($dbhost, $dbuser, $dbpass);
if(! $conn ) { die('Could not connect: ' . mysql_error()); }
$id = $_POST['id'];
$taxrate = $_POST['taxrate'];
$sql = "UPDATE numbers ".
"SET taxrate = $taxrate ".
"WHERE id = $id" ;
mysql_select_db('homedb');
$retval = mysql_query( $sql, $conn );
if(! $retval ) { die('Could not update data: ' . mysql_error()); }
echo "Updated data successfully\
";
mysql_close($conn);
}
// else
// {
?>
$id = mysql_real_escape_string($_POST['id']);
$taxrate = mysql_real_escape_string($_POST['taxrate']);
$sql = "UPDATE numbers
SET taxrate = '$taxrate'
WHERE id = '$id'";
Note: Might need to move select_db up before calling real_escape_string
<?php
error_reporting(E_ALL ^ E_NOTICE);
// error_reporting(0);
if(isset($_POST['update']))
{
$dbhost = 'localhost';
$dbuser = 'root';
$dbpass = 'cookie';
$conn = mysql_connect($dbhost, $dbuser, $dbpass);
if(! $conn ) { die('Could not connect: ' . mysql_error()); }
mysql_select_db('homedb');
$id = mysql_real_escape_string($_POST['id']);
$taxrate = mysql_real_escape_string($_POST['taxrate']);
$sql = "UPDATE numbers
SET taxrate = '$taxrate'
WHERE id = '$id'";
$retval = mysql_query( $sql, $conn );
if(! $retval ) { die('Could not update data: ' . mysql_error()); }
echo "Updated data successfully\
";
mysql_close($conn);
}
?>
I though you were switching to PDO?
Here’s a basic PDO version.
<?php
error_reporting(E_ALL ^ E_NOTICE);
// error_reporting(0);
if(isset($_POST['update']))
{
$dbhost = 'localhost';
$dbuser = 'root';
$dbpass = 'cookie';
$dbname = "homedb";
try {
$conn = new PDO("mysql:host=$dbhost;dbname=$dbname", "$dbuser", "$dbpass");
} catch (PDOException $e) {
// print "Error!: " . $e->getMessage() . "<br/>";
print "an error occurred";
die();
}
$id = trim($_POST['id']);
$taxrate = trim($_POST['taxrate']);
try {
$sql = "UPDATE numbers
SET taxrate = :taxrate
WHERE id = :id";
$query = $conn->prepare($sql);
$query->bindParam(":taxrate", $taxrate);
$query->bindParam(":id", $id);
$status = $query->execute();
if($status){
echo "Updated data successfully\
";
}else{
echo "Could not update data";
}
} catch (Exception $e) {
die("There's an error in the query!");
}
}
?>