peter11 Posted June 5, 2010 Share Posted June 5, 2010 I have the following code: Getting the Random text file: $getfile = file("sentences/" .strval(rand ( 1 ,2 )).".txt"); Assigning vairables to each line: $lines = $getfile; $i=1; foreach($lines as $line ){ $var["line" . $i] = $line; $i++; } extract($var); I am then echo'ing them: echo ($line1)."<input type='text' size='4' name='q1' />".($line2); i am then storing the date: $message = ($line1).($q1).($line2); I am then sending this data to facebook: $facebook->api_client->stream_publish($message, $target_id); However the problem is the Sentence from the file it takes and shows me (answering questions too) Is not always the same as the one it posts to facebook. I think it must be running this Random file twice however i dont think it should be. I cant understand why its different each time it should only call the random file once. Right? Anyone know a way around this? Please help Quote Link to comment Share on other sites More sharing options...
kenrbnsn Posted June 5, 2010 Share Posted June 5, 2010 Please post your whole file as in one area. When it's broken up like you did, it's hard to follow the flow. Can you show us an example of the contents of file you're reading? Ken Quote Link to comment Share on other sites More sharing options...
peter11 Posted June 5, 2010 Author Share Posted June 5, 2010 Its in that order in the code. Quote Link to comment Share on other sites More sharing options...
kenrbnsn Posted June 5, 2010 Share Posted June 5, 2010 Let's simplify your code a little: <?php $lines = array_map('trim',file("sentences/" . rand(1 ,2) . ".txt")); echo $lines[0] . "<input type='text' size='4' name='q1' />" . $lines[1]; ?> Can you post the rest of your code, since you're obviously generating a form, but I don't see the <form> statement, so I don't know how your assigning the variable $q1. Ken Quote Link to comment Share on other sites More sharing options...
peter11 Posted June 5, 2010 Author Share Posted June 5, 2010 There is a lot of code. Yes the form stuff is at the bottom. if it helps. echo "<form method='post'>"; echo ($line1)."<input type='text' size='4' name='q1' />".($line2); echo "<p><input class='submitbox' type='submit' value='Answer and Publish'></form>"; echo "</table>"; Quote Link to comment Share on other sites More sharing options...
kenrbnsn Posted June 5, 2010 Share Posted June 5, 2010 If you're not using the variable $message in more than one place, you can do <?php $facebook->api_client->stream_publish($lines[0] . $_POST['q1'] . $lines[1]), $target_id); ?> Also, you really should put an action attribute in the <form> tag: <?php echo "<form method='post' action=''>"; ?> Ken Quote Link to comment Share on other sites More sharing options...
peter11 Posted June 5, 2010 Author Share Posted June 5, 2010 I have done what you said however you put a ) in yours thats not ment to be there. It is working however again it gives the same problem. Its not always posting the same file as its showing :S Quote Link to comment Share on other sites More sharing options...
kenrbnsn Posted June 5, 2010 Share Posted June 5, 2010 I've done all I can do with the code you've shown. There could be incorrect logic in the code you haven't shown that is causing the problem. Ken Quote Link to comment Share on other sites More sharing options...
peter11 Posted June 5, 2010 Author Share Posted June 5, 2010 I have given you all the related code. I cant post all of it there is too much. Quote Link to comment Share on other sites More sharing options...
peter11 Posted June 6, 2010 Author Share Posted June 6, 2010 Can anyone help on this ? Quote Link to comment Share on other sites More sharing options...
peter11 Posted June 6, 2010 Author Share Posted June 6, 2010 Here is the code related in order: <?php $getfile = file("sentences/" .strval(rand ( 1 ,2 )).".txt"); $lines = $getfile; $i=1; foreach($lines as $line ){ $var["line" . $i] = $line; $i++; } extract($var); echo "<form method='post' action=''>"; echo ($line1)."<input type='text' size='4' name='q1' />".($line2); echo "<p><input class='submitbox' type='submit' value='Answer and Publish'></form>"; $q1 = $_POST["q1"]; // Post MSG on users profile if ($q1 == ""){ echo "<p></p><div class='error1'>ENTER SOMETHING !!</div>"; } else $facebook->api_client->stream_publish($lines[0] . $_POST['q1'] . $lines[1]. $target_id); ?> If anyone knows they this is posting the random question to the profile different to the one it asks you please help Quote Link to comment Share on other sites More sharing options...
peter11 Posted June 6, 2010 Author Share Posted June 6, 2010 I have noticed when doing this If you answer the question it will then load the page again with random question again when u click submit it always seems to give the next question as the one it posts not the one you clicked submit too. So therefor i need to make sure the code has ended and starts again when clicking "submit and post" I have tryed doing this was sessions however that dont work. Anyone know how to do this? Quote Link to comment Share on other sites More sharing options...
kenrbnsn Posted June 7, 2010 Share Posted June 7, 2010 This is why we need to see more of your code, not just the parts you think are relevant. For instance, how do you handle when someone submits the form... Ken Quote Link to comment Share on other sites More sharing options...
peter11 Posted June 7, 2010 Author Share Posted June 7, 2010 I havent got anything in the code for that Quote Link to comment Share on other sites More sharing options...
peter11 Posted June 7, 2010 Author Share Posted June 7, 2010 I have re-done the code but put this in switches. Again it is doing the same. Posting the next question it asks you and not the one you answered Therefor it is a problem with <?php $facebook->api_client->stream_publish($part1 . $_POST['q1'] . $part2).($target_id); ?> It needs to run this with the $part1 and $part2 as the one it asks you and not the next one when you click submit. In the code submit is below this line of code. The form look like the following: <?php echo "<form method='post' action='http://apps.facebook.com/missingwords/'>"; echo ($part1)."<input type='text' size='4' name='q1' />".($part2); echo "<p><input class='submitbox' type='submit' value='Answer and Publish'></form>"; ?> Anyone have any idea how to do this? HELPPPP Quote Link to comment Share on other sites More sharing options...
peter11 Posted June 8, 2010 Author Share Posted June 8, 2010 I have tried using $facebook->api_client->stream_publish($message); AND Facebook.streamPublish(message,attachment,action_links); Both work fine however have the same problem. I am pulling up a random file also tried with a random switch and i want to post that random switch or file. This does work however it posts the wrong one. I.e If the switch was "whats your name" and you answered it and clicked publish it would then load the page again and maybe ask you "whats your age" it would have posted the whats you name answer you gave with whats your age. Does anyone know a way around this? Im out of ideas please help Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.