Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9006107
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T01:19:30+00:00 2026-06-16T01:19:30+00:00

I have a form with PHP that saves a variable to a MySQL database.

  • 0

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.

Here it works: http://www.zoekmachineoptimalisatie.us/test.php
and here (it’s the other VPS) it gives an error: http://www.onzebruidsfotograaf.nl/test.php

My form:

<?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);

?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
    <title>Untitled Document</title>
</head>
<body>
<?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->query($update) or die("Cannot update"); //update or error
}
?>


<?php
$bookid = 1;
$sql    = "SELECT * FROM test WHERE BookID = '" . $bookid . "'";
$result = $conn->query($sql) or die(mysql_error());
$query = getenv(QUERY_STRING);
parse_str($query);
?>

<h2>Update Record <?php echo $bookid;?></h2>

<form action="" method="post">
    <?php

    while ($row = $result->fetch_assoc()) {
        ?>

        <textarea name="updatetitle" cols="100" rows="30"><?php echo $row['Title']; ?></textarea>

        <table border="0" cellspacing="10">

            <tr>
                <td><INPUT TYPE="Submit" VALUE="Update the Record" NAME="Submit"></td>
            </tr>
        </table>
        <?php
    }
    ?>
</form>

<?php
if ($update) { //if the update worked

    echo "<b>Update successful!</b>";

}
?>
</body>
</html>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T01:19:31+00:00Added an answer on June 16, 2026 at 1:19 am

    An unescaped quote in your query will produce a syntax error. Instead of building the SQL fully your own, make use of SQL variables for your PHP variables with a Prepared Statement:

    if (isset($_POST['Submit'])) { //if the submit button is clicked
    
        $title  = $_POST['updatetitle'];
        $bookid = 1;
    
        $update = $conn->prepare('UPDATE test SET Title = ? WHERE BookID = ?;');
        $update->bind_param('sd', $title, $bookid);
        $update->execute();
    }
    

    One of your servers has Magic Quotes enabled and the other doesn’t. Magic Quotes is now considered undesirable and is deprecated, it automatically escapes input. You should turn off Magic Quotes and use a parameterised query/prepared statement instead – then there is no need to escape anything and it prevents SQL Injection.

    Paramterised queries are supported by the MySQLi and PDO APIs.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a php form that saves the info to my database and sends
I currently have a PHP form that uses AJAX to connect to MySQL and
I have an html/php form that updates entries on the database server. I need
I have a form (signup.php) that pops up in a nyroModal window when I
What I have so far: I have a form in PHP that contain the
I have a form page in PHP that reads a DBF, and conditionally converts
I have a php form that has a known number of columns (ex. top
I have a contact page (contact.php) that sends a form (formsend.php) when people fill
I have a form that looks like this. <form action=index.php method=post> <select name=dropdownOption> <option
I have one form in a PHP (5.2.9-1) application that causes IIS (Microsoft-IIS/6.0) to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.