-3

I want the data to be posted into the datahouse.php which will now submit the data to the server and redirect to Index page without showing the datahouse.php file on page..

register.html

<form method="POST" action="DataHouse.php">
<input type="text" name="username" value="tempapilogin" /><br>
<input type="password" name="password" value="aF4YMjuQ" /><br>
<input type="text" required name="name" placeholder="Full Name" /><br>
<input type="email" required name="email" placeholder="EMail Address" /><br>
Gender:
    <fieldset data-role="controlgroup" data-mini="true" >
        <input type="radio" name="gender" id="radio-mini-1" value="MALE" />
        <label for="radio-mini-1">MALE</label>
    <input type="radio" name="gender" id="radio-mini-2" value="FEMALE" />
        <label for="radio-mini-2">FEMALE</label>
        </fieldset>     
Birthday: <input type="date" required name="birth_date" placeholder="dd/mm/yyyy" />
Phone Number: <input placeholder="02xxxxxxxx" type="tel" name="phone_number" />
Facebook ID: <input type="email" name="facebookid" />
<table>
<tr>
<td><input type="submit" name="submit" value="Submit"/></td>
</tr>
</table>
</form>

Below is the php file to post the data to the server and will then have to redirect to the index.html page.

datahouse.php

<?php
//Index.html page to redirect to-->
header("Location: c:\Users\Selorm\Desktop\Maxwell-Internship @ Nandimobile\connect\Index.html");

//create cURL connection
$curl_connection = curl_init();

//create array of data to be posted
array{$post_items[] = 'Username='.strip_tags($_POST['username']);
$post_items[] = 'Password='.strip_tags($_POST['password']);
$post_items[] = 'Email='.strip_tags($_POST['email']);
$post_items[] = 'Gender='.strip_tags($_POST['gender']);
$post_items[] = 'Birthday='.strip_tags($_POST['birth_date']);
$post_items[] = 'Phone Number='.strip_tags($_POST['phone_number']);
$post_items[] = 'Facebook ID='.strip_tags($_POST['facebookid']);}

$username = $_POST['username'];
$password = $_POST['password'];
$name = $_POST['name'];
$email = $_POST['email'];
$gender = $_POST['gender'];
$birth_date = $_POST['birth_date'];
$phone_number = $_POST['phone_number'];
$facebookid = $_POST['facebookid'];

//traverse array and prepare data for posting (key1=value1)
foreach ( $_POST as $key => $value) {
    $post_items[] = $key . '=' . $value;
}

//create the final string to be posted using implode()
$post_string = implode ('&', $post_items);

//set options and set data to be posted
curl_setopt_array($curl_connection, array(
 CURLOPT_CONNECTTIMEOUT => 30,
 CURLOPT_RETURNTRANSFER => true,
 CURLOPT_SSL_VERIFYPEER => false,
 CURLOPT_AUTOREFERER => true,
 CURLOPT_FOLLOWLOCATION => true,
 CURLOPT_POSTFIELDS => array(
 username => 'username',
 password => 'password',
 name => 'name',
 email => 'email',
 gender => 'gender',
 birth_date => 'birth_date',
 phone_number => 'phone_number',
 facebookid => 'facebookid' )
 ));

//perform our request
$result = curl_exec($curl_connection);
$result = json_decode($json);
foreach ($result as $key => $value)
{
 echo $key. ':' ;
}
print_r(curl_getinfo($curl_connection));

//show information regarding the request
print_r(curl_getinfo($curl_connection));
echo curl_errno($curl_connection) . '-' . 
curl_error($curl_connection);

//close the connection
curl_close($curl_connection);
exit;
?>
Parrotmaster
  • 647
  • 1
  • 7
  • 27
michael92
  • 61
  • 1
  • 1
  • 10
  • 3
    So what is your question? Put your header to php file and it will redirect! – Sergei Beregov Jul 26 '13 at 13:12
  • 2
    Whats the problem here? – Jonathan Römer Jul 26 '13 at 13:12
  • Better you can use Ajax POST. – Sarvap Praharanayuthan Jul 26 '13 at 13:12
  • @SuryaS There is no "better", since a PHP script will do just as fine. Only use AJAX POST if you really don't want to use PHP. – Parrotmaster Jul 26 '13 at 13:16
  • @SergeiBeregov it is already there but doesn't seem to be working. – michael92 Jul 26 '13 at 13:19
  • @Parrotmaster : You can send an ajax request to a PHP page, it does the same job, but without two useless redirects – Pascamel Jul 26 '13 at 13:20
  • 1
    @michael92 Your "header("Location: c:\Users\Selorm\Desktop\Maxwell-Internship @ Nandimobile\connect\Index.html");" sends the user to another page BEFORE performing all the code. You need to put it at the END, otherwise it sends the user away before doing all the other PHP. – Parrotmaster Jul 26 '13 at 13:20
  • @JonathanRomer the problem is i have a register page and the input fields on the register page should be posted to a php file which will submit the data into the server and then redirect to a different html page based on the fact that the data is posted into the server. – michael92 Jul 26 '13 at 13:21
  • @Parrotmaster it was at the end before but when i submit it only shows a blank page with datahouse.php in the address bar not knowing whether the data is been posted or not – michael92 Jul 26 '13 at 13:23
  • @Pascamel: Ajax doesn't work when Javascript is disabled or otherwise unavailable. Hard as it may be to believe, certain types of browsers don't even support Javascript. Don't lose sight of usability. – Herbert Jul 26 '13 at 13:25
  • @Herbert, OP tagged the question under jQuery, so I'm assuming he can use JS ;) – Pascamel Jul 26 '13 at 13:31
  • @Pascamel what will be the codes in that case...im new to everything im doing now anyways.. – michael92 Jul 26 '13 at 13:34
  • @michael92 Try using the simpler echo '' That I posted. You can use the same URL. – Parrotmaster Jul 26 '13 at 13:49
  • @Parrotmaster is that in any way going to check whether the data is posted before it redirects to the address in the URL.. – michael92 Jul 26 '13 at 14:01
  • @Herbert im asking if you could go through the whole code and verify if that's what it is supposed to be? – michael92 Jul 26 '13 at 14:03
  • @michael92 No, it's just a standard redirect. I don't know how to tell you this but.....I'm afraid you're gonna have to actually do something yourself :( – Parrotmaster Jul 26 '13 at 14:07
  • @Parrotmaster..i appreciate the help you're giving me but i really need all your comments, corrections and suggestions – michael92 Jul 26 '13 at 14:09
  • 2
    I made an edit to remove the JQuery tag, since the question is not related to JQuery. – Parrotmaster Jul 26 '13 at 14:30
  • @Parrotmaster...i have pasted thw whole link at http://pastebin.com/iD0TJAhJ would like you to look at the whole code and then help from there... – michael92 Jul 26 '13 at 14:49
  • [edit] your question to tell us what problem your having. Is it not redirecting, is it not posting the data. What exactly is the problem you need help with? – Herbert Jul 26 '13 at 14:56
  • @herbert..it is not redirecting neither is it posting the data – michael92 Jul 26 '13 at 15:54

2 Answers2

2

I'm guessing the problem is that the page relocates, but doesn't post anything.

datahouse.php redirects as soon as it encounters

header("Location: c:\Users\Selorm\Desktop\Maxwell-Internship @ Nandimobile\connect\Index.html");

Move that to the end and DO NOT OUTPUT ANYTHING BEFORE IT. If you echo anything, you'll get an error telling you that headers have already been sent.

Herbert
  • 5,698
  • 2
  • 26
  • 34
  • 1
    This is actually the correct answer. I would've posted this same answer if the person asking the question would've been clearer about what he wanted. – Parrotmaster Jul 26 '13 at 13:22
  • @Herbert...that is what i beleive is going on...so i want you to figure out if the php file code is correct.... – michael92 Jul 26 '13 at 13:27
  • @Parrotmaster ,i want to post the data on the register.html page but first the datahouse.php file should take the data and now post it into the server and upon the response from the server...if successful it should now redirect to the index.html page – michael92 Jul 26 '13 at 13:29
  • @Parrotmaster: Spend enough time on SO and you get a knack for guessing what the question _actually_ is. Sometimes it's just a shot in the dark. – Herbert Jul 26 '13 at 13:33
  • 1
    There's an `echo` statement in one of your loops. The page won't redirect if you output anything before the header. You're getting a blank page because you don't have error reporting turned on. Also `header("Location: index.html");` _should_ be sufficient even on localhost. – Herbert Jul 26 '13 at 13:44
  • @Herbert...how would i turn on error reporting ...?can u help me out based on the submitted code.. – michael92 Jul 26 '13 at 13:50
  • [How do I turn on error reporting to find the source of problems?](http://stackoverflow.com/a/1824352/911182) – Herbert Jul 26 '13 at 13:55
  • @Herbert the "How do i turn on error reporting to find the source of problems?"...i didn't really understand what it is doing – michael92 Jul 26 '13 at 14:05
  • Try [PHP Error Reporting](http://php.about.com/od/troubleshooting/qt/php_error_reporting.htm). Add the two lines of code to the beginning of your PHP script. – Herbert Jul 26 '13 at 14:43
  • Remember. You can't output _anything_ from the datahouse.php page if you want it to redirect. That includes echo, print_r, var_dump, print, or anything else that displays something on the page. After your data is sent via cURL, your code is showing the results. That's fine for testing the code to make sure it works, but the page won't redirect as long as that stuff is in there. – Herbert Jul 26 '13 at 14:52
  • @Herbert,so what do you suggest i do – michael92 Jul 30 '13 at 15:34
1

You need to send a redirect to a URL visible on some web server.

You cannot redirect the client to an arbitrary filepath on the server's hard disk.

SLaks
  • 868,454
  • 176
  • 1,908
  • 1,964
  • @Slaks..im using an arbitrary filepath the server's harddisk because it's not yet online.... – michael92 Jul 26 '13 at 13:14
  • 1
    @michael92 In that case a redirect would still work. If you're using a local PHP server your URL would look like so: "http://localhost/yourwebsite/page.html" or "http://127.0.0.1/yourwebsite/page.html" – Parrotmaster Jul 26 '13 at 13:16
  • @Parrotmaster i have the credentials to connect to the server into which i will post the data into..i have to now decipher whether the posted data is really posted into the server and if it is posted then i should now be redirected to the index.html page im talking about – michael92 Jul 26 '13 at 13:25
  • guys help me fix this stuff im not done yet...@Parrotmaster,@herbert – michael92 Jul 30 '13 at 15:34
  • @michael92: What do you see in the dev tools? – SLaks Jul 30 '13 at 21:13
  • @SLaks ...what dev tools are you talking about? – michael92 Jul 31 '13 at 13:54
  • @michael92: Chrome Developer Tools (F12) or Firebug. Look in the console and network tabs. – SLaks Aug 04 '13 at 23:37