PHP文件:
<?php
if (isset($_POST[ name ])){
mysql_connect("localhost", "db", "test") or die(mysql_error());
mysql_select_db("db") or die(mysql_error());
$tmp = mysql_query("SELECT commercial FROM Channels WHERE name= .$_POST[name]. ");
echo $tmp[0];
}
else
{
?>
<form method="post" action="<?php echo $_SERVER[ PHP_SELF ];?>">
<input name="name" type="text">
<input type="submit" name="submit" value="submit" >
</form>
<?php
}
?>
MYSQL数据库:
CREATE TABLE IF NOT EXISTS `Channels` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`name` varchar(30) NOT NULL,
`commercial` tinyint(1) NOT NULL DEFAULT 0 ,
`usrid` int(11) NOT NULL DEFAULT 0 ,
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=3 ;
--
-- Daten für Tabelle `Channels`
--
INSERT INTO `Channels` (`id`, `name`, `commercial`, `usrid`) VALUES
(2, TEST , 0, 0);
如果我在输入中写入TEST,$tmp[0]中的为空
请帮忙