Anyone, how to make this work. no results 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\n"; mysql_close($conn); } // else // { ?>
Use This <?php 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 = $_POST['id']; $taxrate = $_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); } ?> Code (markup):
1) would help if you used the CODE bbCode... 2) Not that it matters since you have no formatting (at least none that doing a quote showed) -- no sensible formatting == gibberish code and mistakes galore. 3) This is 2014, not 2006, you shouldn't be using the mysql_xxx functions 4) and here's why, you are wide open to sql injections as you are blindly dumping $_POST into your query... 5) your biggest problem is you don't actually connect to a database. IF you are going to use the buggy outdated outmoded insecure train-wreck known as mysql_ functions, you need to call mysql_select_db so it has some clue what database you are trying to use... (something built into the $DSN part of if you were using PDO like a good little doobie) To drag that kicking and screaming into THIS century: <?php error_reporting(E_ALL); if (isset($_POST['update'])) { try { $db = new PDO( 'mysql:host=localhost;dbname=database', 'root', 'cookie' ); $statement = $db->prepare(' UPDATE numbers SET taxrate = :taxrate WHERE id = :id '); $statement->execute([ ':taxrate' => $_POST['taxrate'], ':id' => $_POST['id'] ]); if ($statement->rowCount()) { echo 'Updated Data Successfully'; } else die('Could Not Update Data'); } catch (PDOException $e) { die('Connection failed ' . $e->getMessage()); } } ?> Code (markup):
How much debugging have you done? If you echo out the sql query and run it through phpMyAdmin what error messages do you get?