0

I tried to INSERT values into an sql database via php. There is no need to check "database.php" as it works. It shows

Error: unexpected '$myquery' (T_STRING).

I'm using xampp 3.2.1 as a localhost. NEED HELP FAST.THANKS!!!

 <?php 

  require 'database.php';

  $for= $_GET ["for"];
  $approved= $_GET ["approved"];
  $before= $_GET ["before"]

  $myquery="INSERT INTO request('request date', 'request for', 'approved by') VALUES (NOW(),'$for','$approved')";
  $query = mysql_query($myquery);
   ?>
6
  • Wrap off quotes from table and column name instead use backtick. Commented May 4, 2016 at 13:52
  • and sorry, I forget to tell that I closed the php tag like ?> this. Commented May 4, 2016 at 13:54
  • 1
    You get the error because you forgot a semicolon. Adding the semicolon however won't fix the entire script. Commented May 4, 2016 at 13:55
  • Sorry to tell Dann it still doesn't work Commented May 4, 2016 at 14:01
  • 1
    Never use raw data from the client in sql queries, otherwise you risk bobby drop tables - xkcd.com/327 Commented May 25, 2016 at 7:20

1 Answer 1

2

Just like Daan said, you forgot a semicolon. You'll need to make this edit:

$before = $_GET["before"];
// note the semicolon at the end of the line

Also, you should use back ticks to quote your field names like so:

$myquery = "INSERT INTO request(`request date`, `request for`, `approved by`) VALUES (NOW(),'$for','$approved')";

One final suggestion, you should move away from using the mysql_* functions to using either their mysqli_* functions or PDO.

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.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.