Note that there are some explanatory texts on larger screens.

plurals
  1. POMass inserting into an MySQL database via PHP skips names
    primarykey
    data
    text
    <p>I'm currently working on a tracking program which tracks hundreds of users at once, but I've came across a somewhat annoying problem. The way I get the users to insert into the database is via an html textarea and then I send them as a parameter. There's always about 7 out of 60 people (it's always the same names, too) that are inserted into the database, but it doesn't insert the proper data. I've tried to just insert those users and it does it all fine, so could there be a problem inserting all of the people at once?</p> <p>Here's some of the code that I'm using:<br> <em>index.html</em>: </p> <pre><code>&lt;head&gt; &lt;title&gt;Test&lt;/title&gt; &lt;/head&gt; &lt;body&gt; &lt;form name="input" action="tracker.php" method="get"&gt; &lt;textarea name="names" rows="20" cols="20"&gt;&lt;/textarea&gt;&lt;br&gt; &lt;input type="submit" value="Submit" /&gt; &lt;/form&gt; &lt;/body&gt; </code></pre> <p></p> <p><em>tracker.php</em>: <pre><code>$database = mysql_connect("mysql.alwaysdata.com", "stacktest", "stackoverflow"); if (!$database) { die('Could not connect to database: ' . mysql_error()); } mysql_select_db("stacktest_1", $database); mysql_query("CREATE TABLE stats (username varchar(12), start text, UNIQUE (username))"); $names = explode("\n", $_GET['names']); if (isset($_GET['track'])) { for ($i = 0; $i &lt; count($names); $i++) { startTracker($names[$i]); } } displayData(); function startTracker($username) { $stats = getStats($username); mysql_query("INSERT IGNORE INTO stats (username, start) VALUES ('" . trim($username) . "', '$stats')"); } function grabStats($username) { $query = mysql_query("SELECT * FROM stats WHERE username LIKE '$username'"); while ($row = mysql_fetch_array($query)) { return $row['start']; } } function displayData() { global $names; for ($i = 0; $i &lt; count($names); $i++) { $stats = getStats($names[$i]); $starting = getStat(grabStats($names[$i]), 2, 0); $current = getStat($stats, 2, 0); $gained = $currentExperience - $startingExperience; echo "Stats for &lt;b&gt;" . $names[$i] . "&lt;/b&gt;:&lt;br&gt;"; echo "Starting experience: " . number_format($starting) . "&lt;br&gt;"; echo "Current experience: " . number_format($current) . "&lt;br&gt;"; echo "Gained experience: " . number_format($gained) . "&lt;br&gt;&lt;br&gt;"; } } function getStats($username) { $curl = curl_init("http://hiscore.runescape.com/index_lite.ws?player=" . $username); curl_setopt ($curl, CURLOPT_CONNECTTIMEOUT, $timeout); curl_setopt ($curl, CURLOPT_USERAGENT, sprintf("Mozilla/%d.0", rand(4, 5))); curl_setopt ($curl, CURLOPT_HEADER, (int) $header); curl_setopt ($curl, CURLOPT_RETURNTRANSFER, 1); curl_setopt ($curl, CURLOPT_SSL_VERIFYPEER, 0); curl_setopt ($curl, CURLOPT_VERBOSE, 1); $httpCode = curl_getinfo($curl, CURLINFO_HTTP_CODE); $output = curl_exec($curl); curl_close ($curl); if (strstr($output, "&lt;html&gt;&lt;head&gt;&lt;title&gt;")) { return false; } return $output; } function getStat($stats, $row, $skill) { $stats = explode("\n", $stats); $levels = explode(",", $stats[$skill]); return $levels[$row]; } mysql_close($database); </code></pre> <p>You'll notice inside the database that <em>funkymunky11</em> has no data, yet there's clearly data from the site that I read from, <a href="http://hiscore.runescape.com/index_lite.ws?player=funkymunky11" rel="nofollow">as you can see</a>.</p> <p>I've also created a database just so you can see what's happening: <a href="http://phpmyadmin.alwaysdata.com/" rel="nofollow">http://phpmyadmin.alwaysdata.com/</a></p> <p>Username: stacktest<br> Password: stackoverflow</p> <p>The follow are the names that I used to test (I put this inside the text area):</p> <blockquote> <p>aeterna<br> quuxx<br> funkymunky11<br> ts danne</p> </blockquote> <p>I'm sorry if there's some unneeded code, I went through and cleaned almost everything that I didn't think was needed.</p> <p>Thanks in advance, Ron</p>
    singulars
    1. This table or related slice is empty.
    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