我是php编程的新手并且收到错误:
未定义的索引参数和数据未发送到数据库
请帮助
<?php require_once("navig.php");
$cool=$_SESSION['user_id'];
if(isset($_SESSION['user_id'])) {
?>
<form name="form" method="GET" action="<?php echo $_SERVER['PHP_SELF'] ?>">
<a href='http://www.amazon.in/?tag=rewardadda-21¶m=<?php echo $_SESSION['user_id'] ?>'><img src=images/a.png ></a>
</form>
<?php
require_once('connect.php');
$dbb = mysqli_connect(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME)
or die('Error communicating to MySQL server.');
$cool=$_GET['param'];
$querye = "INSERT INTO orderdata(user_id, store_used) ".
"VALUES ('$cool', 'amazon')";
mysqli_query ($dbb, $querye);
mysqli_close($dbb);
}
?>
答案 0 :(得分:0)
你没检查是$ cool = $ _ GET ['param'];有任何价值($ _GET ['param']在$ _GET数组存在)
尝试下一步:
if(isset($_SESSION['user_id'])) {
?>
<form name="form" method="GET" action="<?php echo $_SERVER['PHP_SELF'] ?>">
<a href='http://www.amazon.in/?tag=rewardadda-21¶m=<?php echo $_SESSION['user_id'] ?>'><img src=images/a.png ></a>
</form>
<?php
require_once('connect.php');
$dbb = mysqli_connect(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME) or die('Error communicating to MySQL server.');
if(isset($_GET['param'])){ // add this checking
$cool=$_GET['param'];
$querye = "INSERT INTO orderdata(user_id, store_used) ".
"VALUES ('$cool', 'amazon')";
mysqli_query ($dbb, $querye);
mysqli_close($dbb);
}
}
但这是不好的做法 - 以这种方式从字符串创建查询。阅读有关PDO和准备好的陈述
同时检查您是否通过了GET参数 - 您应该像
一样调用您的脚本/index.php?param=value1