我想从这个简单的html网格数据推入sql,但我不能这样做。在一开始,我得到了var var impressions没有索引的错误。我修正了这一点。当我只使用广告客户价值时,我可以将数据推送到MySQL,而使用第二个值时,我无法成功。你能解释我做错了什么吗? 在此先感谢如何将数据从html网格推送到mysql?
<?php
include_once 'con_ui.php';
if(isset($_POST['btn-save']))
{
$advertiser = $_POST["advertiser"];
$impressions = (isset($POST["impressions"])?
$_POST["impressions"]:'');
$sql_query = "INSERT INTO data(adv, imp) VALUES('$advertiser', '$impressions')";
mysql_query($sql_query);
// sql query for inserting data into database
}
?>
<html>
<head>
</head>
<body>
<form method="post">
<table id="myTable" align='center' cellspacing=0 cellpadding=5 border=1>
<tr>
<th>advertiser</th>
<th>impressions</th>
</tr>
<td>
<select name="advertiser" id="advertiser">
<option value="">Select advertiser</option>
<option value = "Brita ">Brita</option>
<option value = "Sammontana">Sammontana</option>
</select>
</td>
<td name= "impressions" id="impressions" >1000000</td>
<td>
<button type="submit" name="btn-save"><strong>SAVE</strong></button>
</td>
</form>
</body>
</html>
仅供参考,[你不应该在新代码中使用'mysql_ *'函数](http://stackoverflow.com/questions/12859942/)。他们不再被维护[并被正式弃用](https://wiki.php.net/rfc/mysql_deprecation)。看到[红盒](http://php.net/manual/en/function.mysql-connect.php)?学习[*准备的语句*](https://en.wikipedia.org/wiki/Prepared_statement),并使用[PDO](http://php.net/pdo)或[MySQLi](http:// php.net/mysqli) - [这篇文章](http://php.net/manual/en/mysqlinfo.api.choosing.php)将帮助你决定哪一个最适合你。 –
你的脚本存在[SQL注入攻击]的风险(http://stackoverflow.com/questions/60174/how-can-i-prevent-sql-injection-in-php)看看发生了什么事[Little鲍比表](http://bobby-tables.com/)即使[如果你逃避投入,它不安全!](http://stackoverflow.com/questions/5741187/sql-injection-that-gets-around -mysql-real-escape-string)使用[prepared parameterized statements](http://php.net/manual/en/mysqli.quickstart.prepared-statements.php)。 –
你不知道什么是错的,因为你不检查代码中的错误。永远不要假设代码总是完美无缺地工作。 –