1

Ok, so i tried multiple of solutions but nothing seems to work for me, (or i'm just too stupid to get it).

I have such jquery code:

Jquery:

var current_id = $(this).attr("id");
var dataString = {"id" : current_id};
$.post("popup.php" , {"id" : $(this).attr("id")}, function(msg) { alert(msg);} );

I know few lines are useless here but i tried all options,

PHP:

$tmp = $_POST['id'];
if($tmp == "kontakt"){
echo '<p>UDANE PRZESŁANIE</p>';}
else{
echo '<p>NIEUDANE PRZESŁANIE</p>';
}

When i click on id=kontakt php returns error :

 Notice: Undefined index: id in D:\***\popup.php on line 2

but alert sends back

<p>UDANE PRZESŁANIE</p>

Edit:

Ok, Maybe i haven't make my question clear. I don't care if php error is shown or not, I just want to know why it shows up in the first place.

8
  • 4
    What is this in your JavaScript Snipplet? Commented May 21, 2012 at 22:13
  • notice !=error so it actually still works. Commented May 21, 2012 at 22:13
  • I wonder why do you first assign a dataString, but then essentially throw it away - and calculate the data again? Why is {"id": $(this).attr("id")} code used twice? Commented May 21, 2012 at 22:15
  • 1
    @raina77ow: I think these are relicts from what the asker has tried... Commented May 21, 2012 at 22:20
  • 1
    But why try this instead of just logging the current_id value, I wonder? With console.log(current_id) or something like that. ) Commented May 21, 2012 at 22:21

2 Answers 2

1

It's just a PHP warning - it's basically saying that $_POST has no index called 'id'.

You can get rid of it in several ways...

  1. A shorted version of Austin Allover's answer:

    if(!isset($_POST['id')) $tmp = '';

  2. Turn of warnings in your script or your php config file, see: http://php.net/manual/en/function.error-reporting.php (Look for E_WARNING)

  3. You might also want try $.post("popup.php" , {"id" : "BLAHBLAHBLAH"}, function(msg) { alert(msg);} ); - just in case $(this).attr("id") doesn't contain anything...

Sign up to request clarification or add additional context in comments.

Comments

0

Declare $tmp var this way:

$tmp = (isset($_POST['id'])) ? $_POST['id'] : "";

Or ...

if(isset($_POST['id'])) { $tmp = $_POST['id']; } else { $tmp = ""; }

If you don't understand what this code does...

if post id is set, then declare $tmp as the post id, else set $tmp as "". This will take away the PHP notice.

1 Comment

Ok, I got rid of the error but the echo still returns $tmp="" i don't know why the $_POST['id'] isn't working

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.