0

I am trying to integrate a PHP plugin with my web app, but I am stuck with storing the values that I receive from an XML file to a table in my database.

This is what I have so far, but when I run the PHP script it does not save to the database. I have created a table in my database with one column (type=text, name=test)

    global $mysqli;

    $str = serialize($Items);
    printF($str);
    $result = $mysqli->query("INSERT INTO nepremicnine (test) VALUES ('$str');");
2
  • Have you checked your error logs? You're making an assumption the query is working. Commented May 4, 2016 at 18:20
  • You do have an extra semicolon toward the end of your result statement. Logs would show this. ('$str');"); Commented May 4, 2016 at 19:03

1 Answer 1

2

$Items probably contains some strings with single quotes, and this is causing a syntax error when you substitute it into the INSERT query. Use a prepared statement to avoid problems with special characters.

$stmt = $mysqli->prepare("INSERT INTO nepremicnine (test) VALUES (?);");
$stmt->bind_param("s", $str);
$result = $stmt->execute();
Sign up to request clarification or add additional context in comments.

1 Comment

This was correct, sorry for the late approval, but your solution helped me out :)

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.