Board index   FAQ   Search  
Register  Login
Board index php forum :: Database mySQL & php coding

mySQL isn't working

Codes here !

Moderators: macek, egami, gesf

mySQL isn't working

Postby Quilevian » Mon Dec 23, 2013 5:32 pm

Code: Select all
<?php

   if (session_status() == PHP_SESSION_NONE) {
      session_start();
   }

   $con=mysqli_connect("localhost","root","","xdb");
   if (mysqli_connect_errno($con)) {
      echo "Failed to connect to Database : " . mysqli_connect_error();
   } else {
      $tc = $_SESSION['code'];
      $ntd = $_POST['details'];
      echo "code (tc) : " . $tc . "<br/>";
      echo "details (ntd) : " . $ntd . "<br/>";
      echo "html spec char ntd : " . htmlspecialchars($ntd) . "<br/>";
      $td = mysqli_real_escape_string($con, (string) $_POST['details']);      
      echo "td : " . $td . "<br/>";

      if (mysqli_ping($con)) {
         echo 'Connected';
      }
      echo "-----------------<br/>";

      $stmt = $con->prepare("UPDATE `xtable` SET `details`=? WHERE `code`=? ");

        $stmt->bind_param('ss', $ntd, $tc);
        if($stmt->execute() === TRUE){
         $stmt->close();
            echo "Database successfully updated";
        } else {
            echo "There was a problem updating the database.";
        }
      
      mysqli_close($con);
   }
?>


Somehow when I run it, I get database successfully updated but there wasn't any updates going in the db itself.
I tried to put all the echos to test the value before the statement n all gives the right value, but either using prepare or straight with the update query it just doesn't work.
I'd also checked on the connection using ping and it shows connected.

Just wonder where the wrong part is.

I'd appreciate if anyone can share a light on this matter, as it's getting confusing without any error messages (so far all the echos and all are working, but just the sql isn't, but the sql itself was tested directly using mySQL workbench n working, with or without the `) :(


Thanks in advance,
Quilevian
New php-forum User
New php-forum User
 
Posts: 2
Joined: Mon Dec 23, 2013 5:12 pm

Return to mySQL & php coding

Who is online

Users browsing this forum: No registered users and 1 guest

Sponsored by Sitebuilder Web hosting and Traduzioni Italiano Rumeno and antispam for cPanel.

cron