/    Sign up×
Community /Pin to ProfileBookmark

getting notice message

“Notice: Undefined index: foo_x in C:wampwwwcoord.php on line 9
Notice: Undefined index: foo_y in C:wampwwwcoord.php on line 10″

here is my code :

<form action=” method=post>
<input type=”image” alt=’ Finding coordinates of an image’ src=”xy-coordinates.jpg”
name=”foo” style=cursor:crosshair;/>
</form>

<?Php

$foo_x=$_POST[‘foo_x’];
$foo_y=$_
POST[‘foo_y’];

$m = $foo_x;
$n = $foo_y;

echo “(X,Y)=($m,$n) “;

?>

when i run this code am getting the above notice.
how to define the foo_x and foo_y variable ?
am new to php.
please help me.
thanks in advance !

to post a comment
PHP

4 Comments(s)

Copy linkTweet thisAlerts:
@NoEffinWayFeb 03.2015 — Check to see if the variables are set and if not, assign an empty value. Something like:
[code=php]

if(isset($_POST['foo_x'])){
$foo_x=$_POST['foo_x'];
}else{
$foo_x="";
}
if(isset($_POST['foo_y'])){
$foo_y=$_POST['foo_y'];
}else{
$foo_y="";
}

$m = $foo_x;
$n = $foo_y;

echo "(X,Y)=($m,$n) ";

[/code]
Copy linkTweet thisAlerts:
@NogDogFeb 03.2015 — You also might want to output what's actually in $_POST to make sure you're receiving what you think you are from the form, e.g.:

[code=php]
// test only:
echo "<pre>".print_r($_POST, 1)."</pre>";
[/code]
Copy linkTweet thisAlerts:
@gjerichFeb 06.2015 — [code=php]//Dumps information about a variable
var_dump($var);[/code]

manual
Copy linkTweet thisAlerts:
@rootFeb 06.2015 — You shouldn't be using var_dump, the safer method is the one NogDog posted.

Refer to PHP.net as to why, they have the answers and reasons on their site.
×

Success!

Help @kishoreavails 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 5.17,
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: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

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

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...