simple update

Anyone, how to make this work - no resuts evident.

[php]<?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\n”;
mysql_close($conn);
}
// else
// {
?> [/php]

What’s not working with it?

Thanks for the response Topcoder. As I posted, “no result evident”. Since I got no error I’m inclined to
think the problemis in my php syntax, which I’m not great at. I’m hoping someone can peruse it and say
“right here is your problem, this is how it shoul be coded.”
The code that supplies “taxrate” follows:

[code]

Set taxrate Select state/rate Al-4% Ak-no tax

[/code]

[php]<?php
if (!isset($_POST[‘submit’]))
{ // if page is not submitted to itself echo the form
if(isset($_POST[‘update’]))
{
$dbhost = ‘localhost’;
$dbuser = ‘root’;
$dbpass = ‘cookie’;
$conn = mysql_connect($dbhost, $dbuser, $dbpass);
if(! $conn ) { die('Could not connect: ’ . mysql_error()); }
else { 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()); }
else { echo “Updated data successfully\n”; mysql_close($conn); }
}
}
?> [/php]

</body></html>

First off, you are using obsolete MySQL calls. You need to use PdO or mysqli. Second, using PHP self will subject you to an XSS attack.

Finally, you are checking for a post update and it is never set anywhere so nothing happens.

Sponsor our Newsletter | Privacy Policy | Terms of Service