在我的下面的代码中,它应该清除它所做的表格Banner,然后在其中插入一条消息,它不会 这是我的代码,谢谢
<?php
error_reporting(-1);
mysql_connect('localhost', 'username', 'password');
mysql_select_db("induadmi_db");
if($_POST['submit']){
$bannermsg = $_POST['newBanner'];
mysql_query("TRUNCATE `Banner`");
mysql_query("INSERT INTO `Banner` SET Message='$bannermsg'");
}
?>
<html>
<body>
<form method="post">
<input type="text" id="newBanner" name="newBanner' placeholder="Enter Message"/>
<input type="submit" id="submit" name="submit" value="Submit">
</form>
</body>
</html>
这是我顺便说一句的错误:
注意:未定义的索引:newBanner in 第5行/home/induadmi/public_html/por/newbanner.php
答案 0 :(得分:4)
这是您在HTML中的错误
<html>
<body>
<form method="post">
<input type="text" id="newBanner" name="newBanner" placeholder="Enter Message"/>
<input type="submit" id="submit" name="submit" value="Submit">
</form>
</body>
</html>
name="newBanner'
是错误name="newBanner"
答案 1 :(得分:1)
您的错误意味着$_POST['newBanner']
尚未定义。所以将$bannermsg = $_POST['newBanner'];
放在if($_POST['submit']){
条件
通过检查$_POST
exixts
<?php
error_reporting(-1);
mysql_connect('localhost', 'username', 'password');
mysql_select_db("induadmi_db");
if(isset($_POST['submit']))
{
$bannermsg = $_POST['newBanner'];
mysql_query("TRUNCATE `Banner`");
mysql_query("INSERT INTO `Banner` SET Message='$bannermsg'");
}
?>
答案 2 :(得分:1)
试试这个
<?php
error_reporting(-1);
mysql_connect('localhost', 'username', 'password');
mysql_select_db("induadmi_db");
if (isset($_POST['submit'])) {
$bannermsg = $_POST['newBanner'];
mysql_query("TRUNCATE `Banner`");
mysql_query("INSERT INTO `Banner` SET Message='$bannermsg'");
}
?>
<html>
<body>
<form method="post">
<input type="text" id="newBanner" name="newBanner" placeholder="Enter Message"/>
<input type="submit" id="submit" name="submit" value="Submit">
</form>
</body>
</html>
答案 3 :(得分:0)
您没有在<form>
..
name="newBanner' place
^----------
这就是您收到Undefined:index
通知的原因..始终使用isset
构造。
另外......您的TRUNCATE
语法错误..
应该是
mysql_query("TRUNCATE TABLE `Banner`");
<?php
if(isset($_POST['submit'])){
error_reporting(-1);
mysql_connect('localhost', 'induadmi_main', '$admiNiNd/U');
mysql_select_db("induadmi_db");
$bannermsg = $_POST['newBanner'];
mysql_query("TRUNCATE TABLE `Banner`");
mysql_query("INSERT INTO `Banner` SET Message='$bannermsg'");
}
?>
<html>
<body>
<form method="post" action="">
<input type="text" id="newBanner" name="newBanner" placeholder="Enter Message"/>
<input type="submit" id="submit" name="submit" value="Submit">
</form>
</body>
</html>
此mysql_*
)扩展程序自PHP 5.5.0
起已弃用,将来会被删除。相反,应使用MySQLi
或PDO_MySQL
扩展名的准备好的语句来抵御SQL注入攻击!
答案 4 :(得分:0)
你需要检查mysql_query的结果,看看调用是否成功,如果没有,检查mysql_error以查看错误是什么。