Note that there are some explanatory texts on larger screens.

plurals
  1. POError when saving to MySQL when field contains ' character
    primarykey
    data
    text
    <p>I have a form with PHP that saves a variable to a MySQL database. That form worked on a VPS, but when trying it on another VPS it gives an error when trying to write to the database when the field contains a ' character. So the same PHP code works on 1 VPS when the field contains a ' character, but not on the other VPS.</p> <p>Here it works: <a href="http://www.zoekmachineoptimalisatie.us/test.php" rel="nofollow">http://www.zoekmachineoptimalisatie.us/test.php</a> and here (it's the other VPS) it gives an error: <a href="http://www.onzebruidsfotograaf.nl/test.php" rel="nofollow">http://www.onzebruidsfotograaf.nl/test.php</a></p> <p>My form:</p> <pre><code>&lt;?php $hostname = "localhost"; //host name $dbname = "xxxxxxxx"; //database name $username = "xxxxxxxx"; //username you use to login to php my admin $password = "xxxxxxxx"; //password you use to login $conn = new MySQLi($hostname, $username, $password, $dbname); ?&gt; &lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt; &lt;html xmlns="http://www.w3.org/1999/xhtml"&gt; &lt;head&gt; &lt;meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/&gt; &lt;title&gt;Untitled Document&lt;/title&gt; &lt;/head&gt; &lt;body&gt; &lt;?php if (isset($_POST['Submit'])) { //if the submit button is clicked $title = $_POST['updatetitle']; $bookid = 1; $update = "UPDATE test SET Title='$title' WHERE BookID = " . $bookid; $conn-&gt;query($update) or die("Cannot update"); //update or error } ?&gt; &lt;?php $bookid = 1; $sql = "SELECT * FROM test WHERE BookID = '" . $bookid . "'"; $result = $conn-&gt;query($sql) or die(mysql_error()); $query = getenv(QUERY_STRING); parse_str($query); ?&gt; &lt;h2&gt;Update Record &lt;?php echo $bookid;?&gt;&lt;/h2&gt; &lt;form action="" method="post"&gt; &lt;?php while ($row = $result-&gt;fetch_assoc()) { ?&gt; &lt;textarea name="updatetitle" cols="100" rows="30"&gt;&lt;?php echo $row['Title']; ?&gt;&lt;/textarea&gt; &lt;table border="0" cellspacing="10"&gt; &lt;tr&gt; &lt;td&gt;&lt;INPUT TYPE="Submit" VALUE="Update the Record" NAME="Submit"&gt;&lt;/td&gt; &lt;/tr&gt; &lt;/table&gt; &lt;?php } ?&gt; &lt;/form&gt; &lt;?php if ($update) { //if the update worked echo "&lt;b&gt;Update successful!&lt;/b&gt;"; } ?&gt; &lt;/body&gt; &lt;/html&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload