/    Sign up×
Community /Pin to ProfileBookmark

Notice: Undefined index: name in C:xampphtdocs

Hello experts,
I am running with an app and i have some notice error while inserting records.
My form code is pasted below:

[code=html]
<form action=”add_bk_insert.php”>

Name <input type=”text” name=”name”/><br />
E-mail <input type=”text” name=”email” /><br />
Contact <input type=”text” name=”contact” /><br />
Requirement <input type=”text” name=”requirement” /><br />

<input type=”submit” value=”Submit” />

</form>
[/code]

and my add_bk_insert.php code is as shown below:

[code=php]
<?php

mysql_connect(“localhost”,”root”,””);

mysql_select_db(“test”);

$order = “INSERT INTO sal2

(name,email_id, contact,requirement)

VALUES

(‘$_POST[name]’,’$_POST[email_id]’,’$_POST[contact]’,’$_POST[requirement]’)”;

$result = mysql_query($order);

if($result){

echo “Inserted”;
//include_once(“testimonials.php”);
} else{

echo(“<br>Input data is fail”);

}

?>
[/code]

when i run the above code it shows a notice error as below:

[code=html]

Notice: Undefined index: name

Notice: Undefined index: email_id

Notice: Undefined index: contact

Notice: Undefined index: requirement

[/code]

So i dont know what exactly i am missing. Please some one can help me out with this.
I am really stuck. ?

to post a comment
PHP

5 Comments(s)

Copy linkTweet thisAlerts:
@ginerjmJan 06.2014 — Over 100 views and nobody wanted to give you this info.

First - horrible coding. Once again - NEVER ACCEPT INPUT FROM THE CLIENT THAT IS NOT ESCAPED BEFORE YOU PUT IT INTO YOUR DATABASE. You are just BEGGING to be hacked.

That said -

Go look at your PHP reference manual/book/resource and read up on how to write an array reference. Or try to think like the PHP interpreter. If I'm the interpreter I'm looking at this:

$_POST[email_id]

and saying to myself:

ok - this guy wants a value from my $_POST array. Got it. But what is this email_id thingy? I don't know any PHP variable by that name. What to do with this thing? ok - I'll put out a warning message saying "I don't know what this index you've given me is". Which is exactly what PHP has done.

Now go educate yourself with a little reading.
Copy linkTweet thisAlerts:
@NogDogJan 06.2014 — Well, the root cause of your specific problem is not having [B][FONT=Courier New]method="post"[/FONT][/B] in your [FONT=Courier New][B]form[/B][/FONT] tag. Even after fixing that, you should still use isset() or empty() to verify the $_POST values you need are actually there before you try to use them.

As alluded to above, though, there are issues with using unsanitized inputs directly in your SQL. At the very least, look into [url=http://php.net/mysql_real_escape_string]mysql_real_escape_string()[/url]. Better yet would be to use PDO or MySQL[B]i[/B] extensions and make use of prepared statements with bound parameters.

http://xkcd.com/327/
Copy linkTweet thisAlerts:
@GettingSmartJan 08.2014 — the error you get is saying there is no value assigned to that variable. As said above.

If you encounter this error later on you might want to consider putting an @ in front of your $_POST['variable name'].

Doing this will prevent it from giving an error like this. (in the current situation you should really prevent your script from inserting empty rows)
Copy linkTweet thisAlerts:
@NogDogJan 09.2014 — the error you get is saying there is no value assigned to that variable. As said above.

If you encounter this error later on you might want to consider putting an @ in front of your $_POST['variable name'].

Doing this will prevent it from giving an error like this. (in the current situation you should really prevent your script from inserting empty rows)[/QUOTE]


I'm not a fan of using the "@" error suppression operator, as that's just sweeping your garbage under the rug instead of really getting rid of it (the garbage, not the rug). I prefer to develop with all error/warning/info messages enabled; then code, test, add defensive code, test some more, etc., until there are no errors/warnings. ?

With experience you learn the common places where such things happen, and start putting in that defensive coding from the beginning.
Copy linkTweet thisAlerts:
@Lucifer0000Apr 19.2020 — @ginerjm#1305873 sunn meri bt it's his choice ar hn teri maa chodd dunga agar fir itni aakad mein bola to bhosdike. Help maangi usne to help kr gyaan na chod apne baap ke saamne. Ghar aake maa behn ek krke bund maarunga dalle ki aulaad madarchod.
×

Success!

Help @priyankagound spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.2,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,
)...