php - mysql 插入问题

标签 php mysql

我正在构建一个网站来学习编码,并尝试构建“声明您的业务”类型的应用程序。因此,在 Claim.php 上,我们进行搜索并列出所有企业,每个企业都有一个指向 addclaimedbiz.php?id=$example_business_id 的链接。然后在 addclaimedbiz.php 上我使用以下代码:

<?

$biz_id = mysql_real_escape_string($_GET['id']);
error_reporting(E_ALL);
$auth = $_COOKIE["auth"];
if ($auth != "1"){
    header("Location: ./signin.php");
}
$firstname = $_COOKIE['firstname'];
$id = $_COOKIE['id'];
$fname = ucwords($_COOKIE['firstname']);
$lname = ucwords($_COOKIE['lastname']);
$email = $_COOKIE['email'];
$city = ucwords($_COOKIE['city']);
$biz = ucwords($_COOKIE['biz']); // This is Line 14



if (!empty($biz)){
    header("Location: ./claim.php?alreadyclaimed=1");
}
else{
    include("./config.php");
    $result = mysql_query("INSERT INTO users (biz) VALUES ('$biz_id')") or die(mysql_error());
    setcookie("biz", "", time()-3600); // This is Line 24
    setcookie("biz", $biz_id, time()+60*60*24*30); // This is Line 25
    header("Location: ./biz.php"); // This is Line 26
}

?>

基本上,它所做的就是获取从claim.php传递给它的业务ID,(然后所有cookie都是为了确保没有未经授权的人访问该页面,但我认为它与问题,但我将其保留在那里以防万一),然后将 id 添加到表中的 biz 字段,users。然后在最后它重定向到 biz.php。

不幸的是,当我运行此代码时,出现错误:

Notice: Undefined index: biz in addclaimedbiz.php on line 14

Warning: Cannot modify header information - headers already sent by (output started at addclaimedbiz.php:14) in addclaimedbiz.php on line 24

Warning: Cannot modify header information - headers already sent by (output started at addclaimedbiz.php:14) in addclaimedbiz.php on line 25

Warning: Cannot modify header information - headers already sent by (output started at addclaimedbiz.php:14) in addclaimedbiz.php on line 26

上面的代码中包含有错误的行的行号。

我的代码出了什么问题?

感谢您的帮助!

最佳答案

将第 14 行更改为: $biz = $biz_id;

编辑:抱歉,我从来没有注意到你正在学习 PHP。

关于php - mysql 插入问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11837127/

相关文章:

PHP - 使用迭代器的原因?

php - Eloquent laravel : How to get a row count from a ->get()

PHP 包含 : Long Path Issue

CentOS 6.5 上的 PHP MSSQL 5.5.8-1?

php - 如何从 mysql 回显日期(数字)

mysql - Node.js sequelize 死锁问题

php - SQL查询如何从多行返回数据

mysql - MariaDB 存储过程生成不清楚的错误,出了什么问题?

php - 我可以同时使用 Ajax、JS、HTML、PHP 和 MySQL 吗?

mysql - MySQL INSERT 时检查表中两个字段没有重复