Hello all, I have this one record database file used to hold several last used values, I’ve confirmed validity of the record. I don’t get an error so …? Will someone take look at this feeble attempt and advise?
thanks in advance!
<?php
// error_reporting(0);
error_reporting(E_ALL ^ E_NOTICE);
mysql_connect("localhost","root","");
mysql_select_db("numbersdb") or die( "Unable to select database");
if(!empty($_POST["submit"]))
{
$taxrate = $_POST['taxrate'];
$query="SELECT * FROM numbdata Where id='$id'";
$result=mysql_query($query);
if(mysql_num_rows($result))
{
}else{echo "No listing for taxrate $taxrate .<br />Select another? .<br />";}
}
if(!empty($_POST["update"]))
{
$sql = "UPDATE numbdata SET
taxrate = '" .mysql_real_escape_string($_POST['taxrate']) . "',
WHERE taxrate='".$_POST['taxrate']."'";
mysql_query($sql) or die(mysql_error());
echo "Record for taxrate ".$_POST["taxrate"]." has been updated";
}
?>
if(!empty($_POST["submit"]))
{
$taxrate = $_POST['taxrate'];
$query="SELECT * FROM numbdata Where id='$id'";
$result=mysql_query($query);
if(mysql_num_rows($result))
{
}else{echo "No listing for taxrate $taxrate .<br />Select another? .<br />";}
}
In this part I think you have an error in your query. You are checking for id = ‘$id’, and I think what you want is check for taxrate = ‘$taxrate’
if(!empty($_POST["update"]))
{
$sql = "UPDATE numbdata SET
taxrate = '" .mysql_real_escape_string($_POST['taxrate']) . "',
WHERE taxrate='".$_POST['taxrate']."'";
mysql_query($sql) or die(mysql_error());
echo "Record for taxrate ".$_POST["taxrate"]." has been updated";
}
In this query you update the taxrate value of the rows that already have that taxrate value. So you won’t see any difference in the end, even if there are any rows to be updated. I think here you should check for id = ‘$id’.
In both cases, in your code you don’t have anything that sets the $id value.
And you should always sanitize all user input before using it in a query. And you should not use mysql_ (it’s deprecated) but study mysqli_ and/or PDO instead.
thanks for the response, the submit is for one option & there is one record in the database table ?
I understand that. Did you understand the explanations I gave you?