PHP:問題與MySQL和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);
如果我在輸入寫測試將在$ TMP [0]爲空
請幫助
$ tmp [0]永遠不會包含任何明智的東西。先閱讀'mysql_query()'手冊頁。和mysql_real_escape_string()頁面 – 2010-10-14 18:40:10