5

I am trying to use pdo to update a database, the code is not returning any errors but the code does not work. Logic is the user would enter in user id and then a new location hit submit and the location would be updated.

Here is the form code:

<html>
    <head>
        <title>Web Dev 1</title>
    </head>
    <body>
        <form method="post" action="update.php">
            Patient location by ID: <input type="text" id="Patid" name="Patid" /><br />
            Location: <input type="text" id="Location" name="Location" /><br />
            <input type="submit" name = 'action' value="update" />
</html>

This is update code:

<?php
    error_reporting(E_ALL);
    ini_set('display_errors',1);
    $host = "localhost";
    $user ="sbuser";
    $db = "mdb";
    $pass ="lamepassword";
    $conn = new PDO($dsn, $user, $password);
    $sqlInsert = 'UPDATE lobby set Location=:Location where Patid=:Patid';
    $preparedStatement = $conn->prepare($sqlInsert);
    $preparedStatement->execute(array(':Patid' => '$_POST[Patid]', ':Location' = $_POST[Location]' );
    }
?>
4
  • Where is the initialization of $dsn ? Commented Aug 2, 2015 at 8:56
  • 3
    On a side note, your closing </body> is missing in the code sample. Commented Aug 2, 2015 at 9:00
  • thanku for that note... @dakab Commented Aug 2, 2015 at 9:06
  • That also applies to the closing </form> as well as unmatched curly brackets in your PHP code. There's already an answer with further hints. Commented Aug 2, 2015 at 9:09

1 Answer 1

2

there is some error in your code

<?php
 $host = "localhost";
 $db = "mdb";
 $user ="sbuser";
 $pass ="";
 $Patid=$_POST['Patid'];
 $Location=$_POST['Location'];
 $conn = new PDO("mysql:host=$host;name=$name",$user,$pass);
    $sqlInsert = "UPDATE lobby SET Location=? WHERE Patid=?";
    $preparedStatement = $conn->prepare($sqlInsert);
    $preparedStatement->execute(array($Location, $Patid));
?>
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.