Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You're not sanitizing your input when you're inserting it into the database.</p> <p>The <code>'</code> in the first item, <code>Found Tiamat's Shadow</code>, breaks your SQL-query so it actually fails to insert; this is confirmed by your question's problem "it will skip the first value".</p> <p>With <a href="http://www.php.net/manual/en/book.mysqli.php" rel="nofollow">MySQLi</a>, you have two options to fix this.</p> <p>The first is you can escape your data using <a href="http://php.net/mysqli_real_escape_string" rel="nofollow"><code>mysqli_real_escape_string()</code></a>:</p> <pre><code>$con=mysqli_connect("localhost","user","password","master"); foreach($allcharacters as $alts) { $alts = mysqli_real_escape_string($con, $alts); $sql="INSERT INTO masterlist (charactername) VALUES ('" . $alts . "')"; ... </code></pre> <p>Using this function, any "unsafe" characters will automatically be escaped when inserting into your database.</p> <p>The second method is to use a <a href="http://www.php.net/manual/en/mysqli.prepare.php" rel="nofollow">prepared statement</a>. This will require a little more code, however, doing this will almost-always guarantee you don't forget to do it by accident. Here's a sample with a prepared statement:</p> <pre><code>$con=mysqli_connect("localhost","user","password","master"); foreach($allcharacters as $alts) { $stmt = mysqli_prepare($con, "INSERT INTO masterlist (charactername) VALUES ( ? )"); mysqli_stmt_bind_param($stmt, "s", $alts); mysqli_stmt_execute($stmt); mysqli_stmt_close($stmt); ... </code></pre> <p>This method is far-more robust than the previous as it will escape data based on the data-type of the column. It may be a bit more than what's needed for your specific use-case, but it never hurts to be in the habit of using prepared statements =]</p>
    singulars
    1. This table or related slice is empty.
    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