0

我正在尝试在 MySQL 消息表中插入一个文本,但它似乎无法正常工作。我尝试了数百种可能性如何让它发挥作用,但我失败了

当你读到这句话

mysql_query("INSERT INTO rapoarte (emitator,rec....

下来我正在尝试整合一个表格,但我不知道为什么它在这部分不起作用

<td><a href='alianta_principal.php?catre=".$g['id']."'>Accepta invitatia</a></td>

或者这既不是

<td><a href='alianta_principal.php?catre=".$g['id']."'>Refuza invitatia</a></td>

MySQL表是:

DROP TABLE IF EXISTS `rapoarte`;
CREATE TABLE `rapoarte` (
  `id` int(11) NOT NULL auto_increment,
  `emitator` int(11) NOT NULL,
  `receptor` int(11) NOT NULL,
  `titlu` text NOT NULL,
  `descriere` longtext NOT NULL,
  PRIMARY KEY  (`id`),
  KEY `id` (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=5 DEFAULT CHARSET=utf8;

代码

$selectare = mysql_query("select * from membri where id !=".$citeste['id']);
 $g = mysql_fetch_array($selectare);

 $clan_nume = $klan_info['clan_nume'];
 $clan_id_test = $klan_info['clan_uid'];

if ($_GET['in']>0)
{

    mysql_query("INSERT INTO rapoarte (emitator,receptor,titlu,descriere)
            VALUES(".$citeste['id'].",'".$g['id']."','Invitatie','
            <table>
            <tr>
            <th>Aceasta este o invitatie a clanului $clan_nume</th>
            </tr>
            <tr>
            <td><a href='alianta_principal.php?catre=".$g['id']."'>Accepta invitatia</a></td>
            <td><a href='alianta_principal.php?catre=".$g['id']."'>Refuza invitatia</a></td>
            </tr>
            </table>')");

}
4

1 回答 1

0

如果您查看您要尝试的内容,INSERT您会发现您正在传递未转义的单引号:

INSERT INTO rapoarte (emitator,receptor,titlu,descriere)
        VALUES(,'','Invitatie','
        <table>
        <tr>
        <th>Aceasta este o invitatie a clanului </th>
        </tr>
        <tr>
        <td><a href='alianta_principal.php?catre='>Accepta invitatia</a></td>
        <td><a href='alianta_principal.php?catre='>Refuza invitatia</a></td>
        </tr>
        </table>')

您需要对它们进行转义,或者以最佳方式将绑定参数与准备好的语句一起使用。

mysql_query("INSERT INTO rapoarte (emitator,receptor,titlu,descriere)
        VALUES(".$citeste['id'].",'".$g['id']."','Invitatie','
        <table>
        <tr>
        <th>Aceasta este o invitatie a clanului $clan_nume</th>
        </tr>
        <tr>
        <td><a href=\'alianta_principal.php?catre=".$g['id']."\'>Accepta invitatia</a></td>
        <td><a href=\'alianta_principal.php?catre=".$g['id']."\'>Refuza invitatia</a></td>
        </tr>
        </table>')");
于 2013-04-01T20:47:11.990 回答