1

I've got a few php variables that I'd like to insert into an oracle table, but I'm having a hard time with the escape quotes.

Here's what I have so far:

   <?php
     ......
     $number_passed=20;//this is calculated earlier in the code
     $number_total=100;//also calculated earlier in the code
     $date=date('m/d/y');
     $username=//username here
     $password=//password here
     $database=//database connection string here

     $connection=oci_connect($username,$password,$database);

     $sql="INSERT INTO TEST_TABLE (Date_Col,num_pass,num_total) 
               VALUES ('"$date"','"$number_passed"','"$number_total"')";

     $st= oci_parse($$connection, $sql);
     oci_execute($st);

    ?>

When I do this, I get the following error :Parse error: syntax error, unexpected T_VARIABLE on the line where I declare my sql statement. How do I insert the php variables into the database table correctly?

Also, I know I'm supposed to sanitize my php variables before inserting them into the database. Is there a function that does that for me?

Thank you!

3
  • 1
    Use parameterised queries rather than concatenation. Commented Dec 18, 2014 at 4:44
  • $st= oci_parse($$connection, $sql); to $st= oci_parse($connection, $sql); Commented Dec 18, 2014 at 4:48
  • Thanks for catching the error. Commented Dec 18, 2014 at 5:16

1 Answer 1

4

Simple string concatenation issue.

  VALUES ('${date}','${number_passed}','${number_total}')";

No need to even escape the interpreter.

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.