0

I want to send post data to url and go to url... I use index.php for login and send post data to enter.php but I don't know how to use post data in enter.php? I use cURL.

index.php :

<?
$c = curl_init();
curl_setopt($c , CURLOPT_URL , 'http://localhost/enter.php');
curl_setopt($c , CURLOPT_POST , 1);
curl_setopt($c , CURLOPT_POSTFIELDS , 'name=Elmi&surname=Ehmedov');
curl_exec($c); curl_close($c);
?>

enter.php :

<?
$nm = $_POST['name'];
$snm = $_POST['surname'];
echo $nm , $snm;
?>

Thanks for advice.

5
  • not go to enter.php open enter.php inside index.php. Commented Jun 15, 2011 at 11:23
  • The code you have works properly..what do you need ot happen next? Commented Jun 15, 2011 at 11:26
  • not change url. when I run index.php use enter.php but not change url. Commented Jun 15, 2011 at 11:33
  • You want to load index.php but post data to enter.php but not show the user you are in fact posting to enter.php? Commented Jun 15, 2011 at 11:47
  • @Dan I want to load enter.php and use post data from index.php. firstly I run index.php. Commented Jun 15, 2011 at 11:50

2 Answers 2

1

I think if I am reading your question CORRECT then you need an AJAX call to complete your request to enter.php.

Since you are talking like you want to process your input-data which is in enter.php but user will see the form in index.php and when user submits the form it should post the data to enter.php.

Please use the following code snippet:

index.php

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js" language="javascript"></script>

<script language="javascript">
$("#submit_form").submit(function()
{
        //check the username exists or not from ajax
        $.post("enter.php",{ name:$('#name').val(),surname:$('#surname').val(),rand:Math.random() } ,function(data)
        {
          if(data) //if correct login detail
          {
                $("#submit_response").html(data);
          }
       });

       alert("Problem in connecting your server.");

       return false;//not to post the  form physically
});
</script>

<!-- Show Message for AJAX response -->
<div id="submit_response"></div>

<form id="submit_form" action="javascript:login()" method="post">
<input name="name" type="text" id="name" value=""/>
<input name="surname" type="text" id="surname" value=""/>
<input type="submit" name="Submit" value="Submit"/>
</form>

enter.php

<?php

$nm = $_POST['name'];
$snm = $_POST['surname'];
echo $nm.", ".$snm;

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

2 Comments

I want to send post data like <form action = "enter.php" method = "post"></form> but your code not go to enter.php use enter.php inside index.php. not change url.
@Elmi Ehmedov please see the updated answer. I hope that is what you want.
0

Put the code of enter.php into index.php

You need to check if the user send a post request before checking/showing the "enter.php stuff"

Comments

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.