Jump to content

[SOLVED] mysql insert problem


Kingy

Recommended Posts

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

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;

<?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.')'); ?>

 

 

 

 

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;
?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.