Note that there are some explanatory texts on larger screens.

plurals
  1. POMySQL query failing due to reserved keyword?
    primarykey
    data
    text
    <p><strong>Edit: If you're coming here from Google, this issue is a result of the word <code>int</code> being a reserved keyword in PHP.</strong> See the end of the accepted answer.</p> <p>I'm still learning PHP/MySQL and for the life of me I can't figure out what's wrong with my code.</p> <p>I'm trying to take some data from an html page and add it to a table in my database. I'm passing the data with a <code>GET</code> request, then retrieving it with PHP's <code>$_GET</code>.</p> <p>I've tested this and the variables are passed correctly to the PHP script but they don't appear in the database. The script dies on this line: <code>mysql_query($query) or die('data entry failed');</code></p> <pre><code>$database='a9293297_blog'; $con = mysql_connect('mysql2.000webhost.com','my_username','my_password'); mysql_select_db($database,$con) or die('failed to connect to database'); $username = $_GET['username']; $password = $_GET['password']; $charName = $_GET['charName']; $sex = $_GET['sex']; $class = $_GET['class']; $race = $_GET['race']; $str = $_GET['str']; $sta = $_GET['sta']; $dex = $_GET['dex']; $int = $_GET['int']; $cha = $_GET['cha']; $query = "INSERT INTO Players (username, password, charName, sex, class, race, str, sta, dex, int, cha) VALUES ('" . $username . "', '" . $password . "', '" . $charName . "', '" . $sex . "', '" . $class . "', '" . $race . "', '" . $str . "', '" . $sta ."', '" . $dex . "', '" . $int . "', '". $cha . "')"; mysql_query($query) or die('data entry failed'); // Fails here mysql_close($con); </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.
    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