shage Posted September 26, 2008 Share Posted September 26, 2008 $handle = fopen("csv.txt", "r"); while ($line = fgetcsv($handle, 1000, ",")) { $title = $line[0]; $url = $line[1]; $image = $line[2]; $query = "INSERT INTO videos (`title`,`url`, `image`, `date`, `spon`, `cat`) VALUES ('$title','$url', '$image', '2008-09-25', 'NA', 'NM')"; $result = mysql_query($query); } fclose($handle); Some reason it only adds the first line of the csv, thank you Link to comment https://forums.phpfreaks.com/topic/125884-loop-not-working/ Share on other sites More sharing options...
redarrow Posted September 26, 2008 Share Posted September 26, 2008 Look like the loop...... have you tried it without ordering the array(); and why ant you useing mysql_real_escape_string($_POST['example_name']); Link to comment https://forums.phpfreaks.com/topic/125884-loop-not-working/#findComment-650930 Share on other sites More sharing options...
PFMaBiSmAd Posted September 26, 2008 Share Posted September 26, 2008 You are probably having a line-ending problem and the whole file is being read into the first line. Display the actual data to see what is being read from the file. Add the following inside of your loop - echo "<pre>"; print_r($line); echo "</pre>"; Link to comment https://forums.phpfreaks.com/topic/125884-loop-not-working/#findComment-650937 Share on other sites More sharing options...
shage Posted September 26, 2008 Author Share Posted September 26, 2008 Array ( [0] => First Bday [1] => 1a.wmv [2] => 1a.jpg ) Array ( [0] => First Bday [1] => 2a.wmv [2] => 2a.jpg ) Link to comment https://forums.phpfreaks.com/topic/125884-loop-not-working/#findComment-650943 Share on other sites More sharing options...
PFMaBiSmAd Posted September 26, 2008 Share Posted September 26, 2008 I'm going to guess that your table defines title as an index and the second query is failing due to a duplicate index error. All code must check for any possible error, how else will you know if it worked or not? At a minimum, change your mysql_query to get mysql/php to tell you if the query fails and why it failed - $result = mysql_query($query) or die("Query failed: $query<br />Mysql error: " . mysql_error()); Link to comment https://forums.phpfreaks.com/topic/125884-loop-not-working/#findComment-650947 Share on other sites More sharing options...
shage Posted September 26, 2008 Author Share Posted September 26, 2008 its erroring on the key which is the ID but some reason its not incrementing as its set for auto Link to comment https://forums.phpfreaks.com/topic/125884-loop-not-working/#findComment-650971 Share on other sites More sharing options...
PFMaBiSmAd Posted September 26, 2008 Share Posted September 26, 2008 You would need to post your table definition and the actual error message to get actual help with the problem. Link to comment https://forums.phpfreaks.com/topic/125884-loop-not-working/#findComment-650981 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.