开发者

how to resolve Undefined index error?

开发者 https://www.devze.com 2023-01-11 11:27 出处:网络
hey guys i got following error Undefined index: hname in C:\\Temp\\5Aug2010\\job.php on line 38 this error occur in insert command

hey guys i got following error Undefined index: hname in C:\Temp\5Aug2010\job.php on line 38

this error occur in insert command i use

'".mysql_real_escape_string($_POST['hname'])."'

where hname is a textbox field on form

if i use

'".mysql_real_escape_string((isset($_PO开发者_StackOverflow中文版ST['hname'])))."'

then error will gone but in database it show empty field.


If you need to stay inside that string you quote, use

 ".(!empty($_POST['hname']) ? mysql_real_escape_string($_POST['hname']) : null)."

but for readability's sake, it would be nicer to do before outputting the string:

 if (!empty($_POST['hname']))
  $hname = mysql_real_escape_string($_POST['hname']);
 else
  $hname = null;
0

精彩评论

暂无评论...
验证码 换一张
取 消