Jump to content

Recommended Posts

Ok im not sure wot i am doing wrong here, i can redirect a form to a differnt page, but for some reasson this isnt working correctly. I would like redirect my form to home.php instead of form.php, but if i take out form.php out the form action, it doesnt give any data to my database. here is all my code

 


THIS IS THE USERFORM.PHP

<?php


//db connection
require_once("includes/db_connection.php"); 
//end of db connection 
?>
<html>

<head> </heaD>
<body>
  
<form name="form" method="post" action="includes/form.php"> 
  <input type="hidden" name="redirect" value=""> 
  <table width="418" align="left" cellpadding="0" cellspacing="0">
    <tr>
      <td width="157"> Name:</td>
      <td width="259"><label for="name"></label>
      <input type="text" name="name" id="name"></td>
    </tr>
    <tr>
      <td>Email:</td>
      <td><label for="email"></label>
      <input type="text" name="email" id="email"></td>
    </tr>
    <tr>
      <td>WiFi Business Name:</td>
      <td><label for="buissnes_name"></label>
      <input type="text" name="buissnes_name" id="buissnes_name"></td>
    </tr>
    <tr>
      <td>WiFi Location;</td>
      <td><label for="textfield"></label>
      <input type="text" name="location" id="location"></td>
    </tr>
    <tr>
      <td>Free or Paid:</td>
      <td>Free<input type="radio" name="type" id="type" value="free">
      <label for="radio"></label>
      Paid<input type="radio" name="type" id="type" value="paid">
      <label for="radio2"></label></td>
    </tr>
    <tr>
      <td> </td>
      <td><label for="button"></label>
      <input type="submit" name="button" id="button" value="Submit">
      <label for="button2"></label>
      <input type="reset" name="button2" id="button2" value="Reset">       
      <label for="sub"></label></td>
    </tr>
  </table>
</form>

<?php


   
   // db table connection
  include("includes/form.php"); 
   //end of db table connection 


?>


</body>
</html>
<?php mysql_close($connect) ?> 

THIS IS FORM.PHP

<?php require_once('db_connection.php'); ?>
<?php

$sql="INSERT INTO tblbasicform (name, email, buissnes_name, location, type)
VALUES
('$_POST[name]','$_POST[email]','$_POST[buissnes_name]','$_POST[location]','$_POST[type]')";

if (!mysql_query($sql,$connect))
  {
  die('Error: ' . mysql_error());
  }
?>

Link to comment
https://forums.phpfreaks.com/topic/126829-form-re-directing/
Share on other sites

Got small problem with that, forgot to mention, the userform is already linked from another page before that. So i now get on, userform page

 

Warning: Cannot modify header information - headers already sent by (output started at C:\xampp\htdocs\Website\userform.php:2) in C:\xampp\htdocs\Website\includes\form.php on line 14

Link to comment
https://forums.phpfreaks.com/topic/126829-form-re-directing/#findComment-656023
Share on other sites

You can't ouput anything to html before PHP attempts to header redirect.

 

Ie.

 

You can not:

echo "hello"

header

 

you could:

$storeOutputText="hello" (etc.)

header (if needed)

echo $storeOutputText

 

etc.

 

They get funny on here about header questions, read the note at the top of the topics listings page which explains all.

Link to comment
https://forums.phpfreaks.com/topic/126829-form-re-directing/#findComment-656042
Share on other sites

It looks like you're including the form.php on the form page itself (userform.php) (without any values being entered yet!)

 

Why include form.php on userform.php if the form action is form.php?

 

If you take out that include, the page still goes to form.php, and you can use the header that was provided to you.

It has the error because you show the form before including form.php which tries to add that header call unsuccessfully (because you've already outputted to the page).

 

**

If you're going to do it that way, structure your page like this:

<?php
if(isset($_POST['button'])) {
  //db connection
require_once("includes/db_connection.php");

  //process form
  require("includes/form.php"); 

}// ^--post is set

?>
<html>

<head> </heaD>
<body>
...

 

That way you can still have the header call in form.php, because nothing will have been displayed yet.

 

also, change the action of the form

<form name="form" method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">

Link to comment
https://forums.phpfreaks.com/topic/126829-form-re-directing/#findComment-656050
Share on other sites

That got rid of the header problem on the userform page, but it doesnt direct to home.php

 

form.php has this

 

Warning: Cannot modify header information - headers already sent by (output started at C:\xampp\htdocs\Website\includes\form.php:1) in C:\xampp\htdocs\Website\includes\form.php on line 1

Link to comment
https://forums.phpfreaks.com/topic/126829-form-re-directing/#findComment-656058
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.