Kingy Posted November 11, 2007 Share Posted November 11, 2007 This is a weird error that i have no idea how to fix. I have a php script that connects to an irc server gets the room list and i then have it inserting it into a mysql database. It works well and once it retrieves the roomlist it echo's every single room name. But when it inserts them into the database it only inserts half the rooms. eg: it will echo #Lobby, #Help, #Room1, #Room2, #Room3, #Room4 and it will only insert. #Lobby, #Help, #Room1 any ideas? Link to comment https://forums.phpfreaks.com/topic/76808-solved-mysql-insert-problem/ Share on other sites More sharing options...
darkfreaks Posted November 11, 2007 Share Posted November 11, 2007 code please? Link to comment https://forums.phpfreaks.com/topic/76808-solved-mysql-insert-problem/#findComment-388875 Share on other sites More sharing options...
Kingy Posted November 11, 2007 Author Share Posted November 11, 2007 case 322: $chan = explode(' ', $data, 7); $channel = $chan[3]; $users = $chan[4]; $topic = $chan[6]; echo "CHANNEL: $channel"; echo "USERS: $users"; echo "TOPIC $topic"; mysql_query("INSERT INTO rooms (channel, users, topic) VALUES ('$channel', '$users', '$topic')"); break; Link to comment https://forums.phpfreaks.com/topic/76808-solved-mysql-insert-problem/#findComment-388878 Share on other sites More sharing options...
darkfreaks Posted November 11, 2007 Share Posted November 11, 2007 <?php mysql_query("INSERT INTO rooms (channel, users, topic) VALUES ($channel, $users, $topic)"); ?> or <?php mysql_query('INSERT INTO rooms (channel, users, topic) VALUES ('.$channel.', '.$users.', '.$topic.')'); ?> Link to comment https://forums.phpfreaks.com/topic/76808-solved-mysql-insert-problem/#findComment-388879 Share on other sites More sharing options...
Kingy Posted November 11, 2007 Author Share Posted November 11, 2007 ok so i took the ' ' off the $channel, $users, $topic etc and now it doesnt insert anything at all? and same result for the '. .' - nothing Link to comment https://forums.phpfreaks.com/topic/76808-solved-mysql-insert-problem/#findComment-388880 Share on other sites More sharing options...
darkfreaks Posted November 11, 2007 Share Posted November 11, 2007 try the second method Link to comment https://forums.phpfreaks.com/topic/76808-solved-mysql-insert-problem/#findComment-388881 Share on other sites More sharing options...
Kingy Posted November 11, 2007 Author Share Posted November 11, 2007 lol we keep missing each others edits... that bit didnt work either Link to comment https://forums.phpfreaks.com/topic/76808-solved-mysql-insert-problem/#findComment-388882 Share on other sites More sharing options...
Daukan Posted November 11, 2007 Share Posted November 11, 2007 Try escaping the string it might contain a quote or other illegal character <?php case 322: $chan = explode(' ', $data, 7); $channel = mysql_real_escape_strng($chan[3]); $users = mysql_real_escape_strng($chan[4]); $topic = mysql_real_escape_strng($chan[6]); echo "CHANNEL: $channel"; echo "USERS: $users"; echo "TOPIC $topic"; mysql_query("INSERT INTO rooms (channel, users, topic) VALUES ('$channel', '$users', '$topic')"); break; ?> Link to comment https://forums.phpfreaks.com/topic/76808-solved-mysql-insert-problem/#findComment-388885 Share on other sites More sharing options...
Kingy Posted November 11, 2007 Author Share Posted November 11, 2007 good idea, but it still not working Link to comment https://forums.phpfreaks.com/topic/76808-solved-mysql-insert-problem/#findComment-388887 Share on other sites More sharing options...
Daukan Posted November 11, 2007 Share Posted November 11, 2007 is the field in your table big enough to hold all the data? Maybe use a tinytext or text field. Edit: I meant tinytext not smalltext. There is no such thing as smalltext fields Link to comment https://forums.phpfreaks.com/topic/76808-solved-mysql-insert-problem/#findComment-388888 Share on other sites More sharing options...
Kingy Posted November 11, 2007 Author Share Posted November 11, 2007 Daukan.. you are a legend lol. That was the problem. I had varchar(255) and some of the topics were very long lol. Changed it to a TEXT field. Thanks heaps. Link to comment https://forums.phpfreaks.com/topic/76808-solved-mysql-insert-problem/#findComment-388893 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.