tags:

views:

5

answers:

1

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($_POST['hname'])))."'

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

+1  A: 

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;
Pekka
it still cant save value in db
Pratikg88
@Pratik you need to show your mySQL query.
Pekka
$insert = "INSERT INTO jobs (hname,discription,url,adddate)VALUES ('".(!empty($_POST['hname']) ? mysql_real_escape_string($_POST['hname']) : null)."','".nl2br(mysql_real_escape_string($_POST['discription']))."','".mysql_real_escape_string((isset($_POST['url'])))."','".mysql_real_escape_string($adddate)."')";$add_jobs = mysql_query($insert) or trigger_error(mysql_error().$insert);
Pratikg88
@Partik the finished SQL query.
Pekka
Pratikg88
@Pratik please show the finished SQL query with the values in it.
Pekka
id : 5hname: blankdiscription:Walk-in interview for php web developers in VISION....url:blankadddate:2010-08-13
Pratikg88
@Pratik the finished SQL query containing INSERT INTO.... the string you get when doing `echo $insert;`
Pekka
INSERT INTO jobs (hname,discription,url,adddate) VALUES ('','Walk-in interview for php web developers in VISION SOFT+.\r\nfor more detail visit our site.','','2010-08-13')
Pratikg88
@Pratik Sorry, I can't see anything wrong with that query! What is the exact error message?
Pekka
ya but main thing is that "discription" also one of the field on the form but its value save into db without any error
Pratikg88
thanks for your help
Pratikg88