how to resolve Undefined index error?
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;
精彩评论