0

I'm trying to update a table with the form values although it doesn't seem to be updating in the database and there are no errors either.

<?php

    session_start();

if(!isset($_SESSION["user"]) or !is_array($_SESSION["user"]) or empty($_SESSION["user"])) {
      // redirect to login page
}
$dbhost   = "localhost";
$dbname   = "***";
$dbuser   = "***";
$dbpass   = "***";

// database connection
$conn = new PDO("mysql:host=$dbhost;dbname=$dbname",$dbuser,$dbpass);
// new data
                    $date = date('Y-m-d') ."\n";
                    $now = time(); $utc_time = $now - intval(date('Z', $now));
                    $time = date('H:i:s', $now);
                    $pname = $_POST['pname'];
                    $pdetails = $_POST['pdetails'];
                    $pabout = $_POST['pabout'];
                    $pwebsite = $_POST['pwebsite'];
                    $pyoutube = $_POST['pyoutube'];
                    $pfacebook = $_POST['pfacebook'];
                    $uID = $_POST['uID'];
                    $id = $_POST['id'];
                    $seshID = $_SESSION['user']['id'];




            $conn->prepare($sql = "UPDATE pages SET pname='$pname', pdetails='$pdetails', pabout='$pabout', pwebsite='$pwebsite', pyoutube='$pyoutube', pfacebook='$pfacebook' WHERE id='$id' AND author_id='$seshID'");

?>
Jay Blanchard
  • 34,243
  • 16
  • 77
  • 119
Casper Round
  • 343
  • 2
  • 14
  • [Your script is at risk for SQL Injection Attacks.](http://stackoverflow.com/questions/60174/how-can-i-prevent-sql-injection-in-php) Learn about [prepared](http://en.wikipedia.org/wiki/Prepared_statement) statements for [PDO](http://php.net/manual/en/pdo.prepared-statements.php). – Jay Blanchard Sep 21 '15 at 16:49
  • 5
    You never *execute* your query, so it never does anything. – Jay Blanchard Sep 21 '15 at 16:52

1 Answers1

0

Make sure that you are getting all the data from POST method. For that you can echo all the variables... The basic reason for your script not working is that you are not sending the query to the database.. Use a script like this:

$stmt = $conn->prepare("UPDATE pages SET pname='$pname', pdetails='$pdetails', pabout='$pabout', pwebsite='$pwebsite', pyoutube='$pyoutube', pfacebook='$pfacebook' WHERE id='$id' AND author_id='$seshID'");

$stmt->execute();
Jay Blanchard
  • 34,243
  • 16
  • 77
  • 119
Husnain Abbas
  • 159
  • 1
  • 1
  • 10