php 故意 未定义变量,PHP-注意:未定义变量发生两次

加载页面时出现以下两个错误:

Notice: Undefined variable: realtor in C:\Program Files\EasyPHP-5.3.9\www\cglst\images\addform.php on line 255

Notice: Undefined variable: phone in C:\Program Files\EasyPHP-5.3.9\www\cglst\images\addform.php on line 256

我确实定义了这两个变量,所以我不明白为什么会出现这些错误.这是我的代码:

function addListing() {//if data was provided, insert it into database and confirm

//this will allow everything to be sanitized properly

require_once "sanitize.php";

$submitted = false;

//Checking if values were passed

if (isset($_POST['area']) &&

isset($_POST['price']) &&

isset($_POST['address']) &&

isset($_POST['bedrooms']) &&

isset($_POST['fullbath']) &&

isset($_POST['halfbath']) &&

isset($_POST['sqft']))

//if passed, sanitize and set variables accordingly

{

$area = sanitizeOne(get_post('area'), 'plain');

$price = sanitizeOne(get_post('price'), 'int');

$address = sanitizeOne(get_post('address'), 'plain');

$bedrooms = sanitizeOne(get_post('bedrooms'), 'int');

$fullbath = sanitizeOne(get_post('fullbath'), 'int');

$halfbath = sanitizeOne(get_post('halfbath'), 'int');

$sqft = sanitizeOne(get_post('sqft'), 'int');

$submitted = true;

}

//optional fields

if (isset($_POST['remarks']))

{

$remarks = sanitizeOne(get_post('remarks'), 'plain');

}

else

{$remarks = ' ';}

if (isset($_POST['realtor']))

{

$remarks = sanitizeOne(get_post('realtor'), 'plain');

}

else

{$realtor = "Anne-Marie Pelletier";}

if (isset($_POST['phone']))

{

$remarks = sanitizeOne(get_post('phone'), 'plain');

}

else

{$phone = "201.710.5500";}

if ($submitted) {

$query = 'PREPARE statement FROM "INSERT INTO bix(area, price, address, bedrooms,

fullbath, halfbath, sqft, remarks, realtor, phone) VALUES(?,?,?,?,?,?,?,?,?,?)"';

mysql_query($query);

$query = 'SET

@area = "' . $area . '"' .

'@price = "' . $price . '"' .

'@address = "' . $address . '"' .

'@bedrooms = "' . $bedrooms . '"' .

'@fullbath = "' . $fullbath . '"' .

'@halfbath = "' . $halfbath . '"' .

'@sqft = "' . $sqft . '"' .

'@remarks = "' . $remarks . '"' .

'@realtor = "' . $realtor . '"' . //line 255

'@phone = "' . $phone . '"'; //line 256

mysql_query($query);

$query = 'EXECUTE statement USING @area,@price,@address,@bedrooms,@fullbath,@halfbath,@sqft,@remarks,@realtor,@phone';

mysql_query($query);

$query = 'DEALLOCATE PREPARE statement';

mysql_query($query);

return true;

}

}

function get_post($var)

{

return mysql_real_escape_string($_POST[$var]);

}

如果条目已提交,这只是在数据库中添加一个条目(页面向自身提交了一个表单来执行此操作)

解决方法:

您的问题在这里,是一个“剪切”粘贴错误;

if (isset($_POST['realtor']))

{

$remarks = sanitizeOne(get_post('realtor'), 'plain');

}

else

{$realtor = "Anne-Marie Pelletier";}

如果将realtor设置为post参数,则将post变量的值分配给$remarks而不是$realtor.

$phone有完全相同的问题.

标签:mysql,php

来源: https://codeday.me/bug/20191201/2081965.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值