Jump to content

[SOLVED] $_POST help


thefredelement

Recommended Posts

Hi, I think I have a simple question but I'm not sure what's going on..

 

I have a login form on a page:

 

<form action="action.php" method="post" name="form1" id="form1">
  <p>
    <input name="twitter_username" type="text" id="twitter_username" />
  </p>
  <p>
    <input name="twitter_psw" type="password" id="twitter_psw" />
  </p>
  <p>
    <label>
      <input type="submit" name="button" id="button" value="Submit" />
    </label>
  </p>
</form>

 

There's a script on the action.php page:

$twitter_username	= 'username';
$twitter_psw		= 'password';

 

I'd like to not hardcode the username and passwrod variables, I want to use the ones set in the login.php file and form above, so I tried several variations like this:

 $twitter_username	= $_POST['twitter_username'];
$twitter_psw		= $_POST['twitter_psw'];

 

I've tried to name the variables something different (in the $_POST part) but can't seem to get the script to login.

 

I echo the posted form variables later in the page and I see them, so I know it's posting, I just don't know the right syntax to get them to be recognized by the script in action.php.

 

Any help would be greatly appreciated and thank you for looking!

 

Link to comment
Share on other sites

Thanks for looking, here is all the code if that helps...

 

(login.php)

 

<body>
<form action="insertTwitterMsg.php" method="post" name="form1" id="form1">
  <p>
    <input name="tuser" type="text" id="tuser" />
  </p>
  <p>
    <input name="tpass" type="password" id="tpass" />
  </p>
  <p>
    <label>
      <input type="submit" name="button" id="button" value="Submit" />
    </label>
  </p>
</form>
</body>

 

(insertTwitterMsg.php)

 

<?php
/* ---------------------------------------- */
// Change these parameters with your Twitter 
// user name and Twitter password.
/* ---------------------------------------- */
$twitter_username	= $_POST['tuser'];
$twitter_psw		= $_POST['tpass'];
/* ---------------------------------------- */

/* Don't change the code belove
/* ---------------------------------------- */
require('twitterAPI.php');
if(isset($_POST['twitter_msg'])){
$twitter_message=$_POST['twitter_msg'];
if(strlen($twitter_message)<1){
$error=1;
} else {
$twitter_status=postToTwitter($twitter_username, $twitter_psw, $twitter_message);
}
}
/* ---------------------------------------- */
?>
<body>
<h2>Post a message on Twitter</h2>
<p>This page use  Twitter API to send an message with postToTwitter() function.</p>
<!-- This is the form that you can reuse in your site -->
<?php if(isset($_POST['twitter_msg']) && !isset($error)){?>
<div class="msg"><?php echo $twitter_status ?></div>
<?php } else if(isset($error)){?>
<div class="msg">Error: please insert a message!</div>
<?php }?>
<p><strong>What are you doing?</strong></p>
<form action="insertTwitterMsg.php" method="post">
<input name="twitter_msg" type="text" id="twitter_msg" size="40" maxlength="140" />
<input type="submit" name="button" id="button" value="post" />
</form>
<!-- END -->

<script language="javascript">
function showDetails(){
details=document.getElementById('details')
if(details.style.display=='none'){
document.getElementById('details').style.display="block";
} else {
document.getElementById('details').style.display="none";
}
}
</script>
<p><?php echo $twitter_username; echo $twitter_psw; ?></p>

<p><a href="#" onclick="javascript:showDetails();">Show details</a></p>
<div id="details" style="display:none">
<p><strong>Step 1.</strong> Edit this page and change the parameter <strong>$twitter_username</strong> and <strong>$twitter_psw</strong>.</p>
<div class="code"> <?php<br />
/* ---------------------------------------- */<br />
// Change these parameters with your Twitter <br />
// user name and Twitter password.<br />
/* ---------------------------------------- */<br />
<strong>$twitter_username	='yourTwitterUserName';<br />
$twitter_psw		='yourTwitterPassword';<br /></strong>
/* ---------------------------------------- */  <br />
/* Don't change the code belove<br />
/* ---------------------------------------- */<br />
require('twitterAPI.php');<br />
if(isset($_POST['twitter_msg'])){<br />
$twitter_message=$_POST['twitter_msg'];<br />
if(strlen($twitter_message)<1){<br />
$error=1;<br />
} else {<br />
$twitter_status=postToTwitter($twitter_username, $twitter_psw, $twitter_message);<br />
}<br />
}<br />
/* ---------------------------------------- */</div>
</div>

<div class="footer">
For info please visit <a href="http://woork.blogspot.com">woork.blogspot.com</a> or send me an e-mail to <a href="mailto:antonio.lupetti@gmail.com">antonio.lupetti@gmail.com</a>
<br />
</div>

</body>

 

(twitterAPI.php)

<?php

// A simple function using Curl to post (GET) to Twitter
// Kosso : March 14 2007

function postToTwitter($username,$password,$message){

    $host = "http://twitter.com/statuses/update.xml?status=".urlencode(stripslashes(urldecode($message)));

    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $host);
    curl_setopt($ch, CURLOPT_VERBOSE, 1);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_USERPWD, "$username:$password");
    curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
    curl_setopt($ch, CURLOPT_POST, 1);

    $result = curl_exec($ch);
    // Look at the returned header
    $resultArray = curl_getinfo($ch);

    curl_close($ch);

    if($resultArray['http_code'] == "200"){
         $twitter_status='Your message has been sended! <a href="http://twitter.com/'.$username.'">See your profile</a>';
    } else {
         $twitter_status="Error posting to Twitter. Retry";
    }
return $twitter_status;
}
?>

 

Again, this is very much appreciated and thank you for looking.

Link to comment
Share on other sites

That form is in the "insertTwitterMsg.php" file, the file the login.php file posts to, then the insertTwitterMsg.php file does another posts.

 

The post to Twitter works fine when I hardcode the username & password values, I'm just trying to get the values pushed via the login form so other people can use it too.

Link to comment
Share on other sites

Every page request is completely separate from every other page request. $_POST data from one form is only directly available on the page that is the target of the action="..." parameter. You must deliberately do something to cause any data present on one page to be passed through to another page. You would either need to use one single form for everything, use a hidden field in the second form to carry data from the first form, or use session variables.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.