0

I need some help I am trying to create a PHP form using sqlite3 and I keep on getting a "syntax error, unexpected T_CATCH in post.php on line 10". All I want to do from the php form is update an existing sqlite3 database in the table1 where the column type = p and the column id = 340 with the values from the form.

HTML Code:

   <html>
   <head>
   <title>Update Form</title>
   </head>
   <body style="font-size:12;font-family:verdana">
   <form action="post.php" method="post">
   <p>
   Slot1: <input type="text" name="slot1"><br>
   Slot2: <input type="text" name="slot2"><br>
   </p>

   <p>
   <input type="submit" name="update" value="update">
   </p>

   </form>
   </body>
   </html>

PHP Code: Post.php

<?php
$slot1 = sqlite_escape_string($_POST['slot1']);
$slot2 = sqlite_escape_string($_POST['slot2']);

try
{
$db = new PDO("sqlite:DefaultLibrary.db");
$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);   
catch(Exception $e)
{   
echo $e->getMessage();
}
}
if (!empty($slot1)) {
try
{   
    $stmt = $db->prepare("UPDATE tabel1 SET Slot1Pos = :slot1, Slot2Pos = :slot2 WHERE Type = P and ID = 340");
    $stmt->bindParam(':slot1', $slot1, PDO::PARAM_STR);
    $stmt->bindParam(':slot2', $slot2, PDO::PARAM_STR);
    $stmt->execute()
}
catch(Exception $e)
{
echo $e->getMessage();
}

echo "Form submitted successfully";

}

1 Answer 1

1

Looks like you're missing a brace:

try {
    $db = new PDO("sqlite:DefaultLibrary.db");
    $db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);   
} catch(Exception $e) {   
    echo $e->getMessage();
}
Sign up to request clarification or add additional context in comments.

1 Comment

yeah, i agree. indenting properly/consistently makes all the difference in the world sometimes.

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.