Jump to content

submit data to sql and navigate to newpage


Guest elthomo

Recommended Posts

Guest elthomo

Here is my code it submits the data ok but i cant get it to navigate to a new page with the same click too. I could really use some help and I'm sure its really simple but just cant see it.

 

Thanks in advance.

 

<?php

$db_host = "localhost";

$db_user = "****";

$db_pwd = "****";

$db_name = "****";

mysql_connect($db_host, $db_user, $db_pwd);

mysql_select_db($db_name);

?>

<html xmlns="http://www.w3.org/1999/xhtml">

<head>

<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />

<title>Untitled Document</title>

<style type="text/css">

<!--

body {

background-color: #FF9933;

}

.style1 {

font-family: Verdana, Arial, Helvetica, sans-serif;

font-size: 12px;

}

-->

</style></head>

 

<body>

<?php

if (!isset($_POST['submit'])) {

?>

<table width="100%">

  <tr>

    <td bgcolor="#FF9933"><img src="Images/header2.gif" width="476" height="74" /></td>

  </tr>

</table>

<table width="800" align="center">

  <tr>

    <td height="600

" bgcolor="#FFFFFF"><table width="500" align="center">

      <tr>

        <td><form action="index2.php" method="post">

          <span class="style1">Achternaam:</span>   

          <input type="text" name="achternaam" />

            <br />

<br />

            <span class="style1">Voorletters:</span>

          <input type="text" name="voorletters" />

          <br />

  <br />

          <span class="style1">Geboorte:</span>

          <input type="num" name="geboorte" />

 

          <br />

  <br />

          <span class="style1">Postcode:</span>

          <input type="string" name="postcode" />

          <br />

  <br />

          <span class="style1">Huisnummer:</span>

          <input type="num" name="huisnummer" />

          <br />

  <br />

          <span class="style1">E-mail adres:</span>

          <input type="string" name="email" />

          <br />

  <br />

          <span class="style1">Uw dossiernummer(zie onze brief):</span>

          <input type="string" name="dossiernummer" />

          <br />

  <br />

          <input type="submit" name="submit" value="Submit!" onClick="goTo('index2.php)" />

        </form></td>

      </tr>

  </table></td>

  </tr>

</table><table width="800" align="center">

  <tr>

    <td><img src="Images/adres2.gif" width="699" height="20" align="middle" /></td>

  </tr>

</table>

<?php

} else {

$achternaam = $_POST['achternaam'];

$voorletters = $_POST['voorletters'];

$geboorte = $_POST['geboorte'];

$huisnummer = $_POST['huisnummer'];

$email = $_POST['email'];

$postcode = $_POST['postcode'];

$dossiernummer = $_POST['dossiernummer'];

mysql_query("INSERT INTO `klanten` (achternaam, voorletters, geboorte, huisnummer, email, postcode, dossiernummer) VALUES ('$achternaam', '$voorletters', '$geboorte', '$huisnummer', '$email', '$postcode', '$dossiernummer')");

}

?>

 

</body>

</html>

After this line

 

mysql_query("INSERT INTO `klanten` (achternaam, voorletters, geboorte, huisnummer, email, postcode, dossiernummer) VALUES ('$achternaam', '$voorletters', '$geboorte', '$huisnummer', '$email', '$postcode', '$dossiernummer')");

 

Add this:

 

header("Location: www.your-url.com");

That's not going to work, because he has already outputted headers to the browser by that point.

 

OP: You need to move all your PHP form processing to the top of your script, BEFORE you output your <html > tag. Put all the processing script inside a similar condition to the one you have so that it looks like this:

 

if(isset($_POST['submit'])) {
// form processing script here
header("Location: www.your-url.com");
}
<html>
// continue the rest of your script here

 

Also, you need to post your code in [code ] tags when you post here. Its really hard to read as it is now.

Guest elthomo

When I add the header tag it redirects me to the root of the site. So  www.url.com/index.php goes to www.url.com

 

Things that may confuse the problem is that I am currently connecting to the IP not a URL.(not sure if that will make a difference at this stage)

 

 

Guest elthomo

I did try that but I get the error from the browser that says "The page isn't redirecting properly Firefox has detected that the server is redirecting the request for this address in a way that will never complete." The same happens with Safari.

 

Again thanks for the speedy reply :-)

 

 

Guest elthomo

Current code, also to note i have tried just the IP in the header too.

 

<?php
$db_host = "localhost";
$db_user = "****";
$db_pwd = "****";
$db_name = "****";
mysql_connect($db_host, $db_user, $db_pwd);
mysql_select_db($db_name);
?>
<?php
if (!isset($_POST['submit'])) {
header("Location: http://192.168.2.108/index.php");
?>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
<title>Untitled Document</title>
<style type="text/css">
<!--
body {
background-color: #FF9933;
}
.style1 {
font-family: Verdana, Arial, Helvetica, sans-serif;
font-size: 12px;
}
-->
</style></head>

<body>
<table width="100%">
  <tr>
    <td bgcolor="#FF9933"><img src="Images/header2.gif" width="476" height="74" /></td>
  </tr>
</table>
<table width="800" align="center">
  <tr>
    <td height="600
" bgcolor="#FFFFFF"><table width="500" align="center">
      <tr>
        <td><form action="index2.php" method="post">
          <span class="style1">Achternaam:</span>    
          <input type="text" name="achternaam" />
            <br />
		<br />
            <span class="style1">Voorletters:</span>
          <input type="text" name="voorletters" />
          <br />
	  <br />
          <span class="style1">Geboorte:</span>
          <input type="num" name="geboorte" />

          <br />
	  <br />
          <span class="style1">Postcode:</span>
          <input type="string" name="postcode" />
          <br />
	  <br />
          <span class="style1">Huisnummer:</span>
          <input type="num" name="huisnummer" />
          <br />
	  <br />
          <span class="style1">E-mail adres:</span>
          <input type="string" name="email" />
          <br />
	  <br />
          <span class="style1">Uw dossiernummer(zie onze brief):</span>
          <input type="string" name="dossiernummer" />
          <br />
	  <br />
          <input type="submit" name="submit" value="Submit!" onClick="goTo('index2.php)" />
        </form></td>
      </tr>
   </table></td>
  </tr>
</table><table width="800" align="center">
  <tr>
    <td><img src="Images/adres2.gif" width="699" height="20" align="middle" /></td>
  </tr>
</table>
<?php
} else {
$achternaam = $_POST['achternaam'];
$voorletters = $_POST['voorletters'];
$geboorte = $_POST['geboorte'];
$huisnummer = $_POST['huisnummer'];
$email = $_POST['email'];
$postcode = $_POST['postcode'];
$dossiernummer = $_POST['dossiernummer'];
mysql_query("INSERT INTO `klanten` (achternaam, voorletters, geboorte, huisnummer, email, postcode, dossiernummer) VALUES ('$achternaam', '$voorletters', '$geboorte', '$huisnummer', '$email', '$postcode', '$dossiernummer')");
}
?>

i suggest you to use anchor element insted of radio button in that case elimenate the javascript below and just give

<a href="http://someplace.com">someplace</a>

 

as suggested by haku

 

if(isset($_POST['submit'])) {
// form processing script here
header("Location: www.your-url.com");
}
<html>
// continue the rest of your script here

but insted of

header("Location: www.your-url.com");

give the radio buttons with the onclick event handler as

window.location="http://someplace.com";

Guest elthomo

It sounds like the page you are trying to forward the user to is forwarding the user back, and getting stuck in a loop. If the page didn't exist, you would get a 404 message. But the message you posted makes it sound like a loop problem.

 

Yes it is whats happening as fas as I can tell. If I just give the base url of the site as the header it just sits at the site index(not the index.php)

 

Guest elthomo

i suggest you to use anchor element insted of radio button in that case elimenate the javascript below and just give

<a href="http://someplace.com">someplace</a>

 

as suggested by haku

 

if(isset($_POST['submit'])) {
// form processing script here
header("Location: www.your-url.com");
}
<html>
// continue the rest of your script here

but insted of

header("Location: www.your-url.com");

give the radio buttons with the onclick event handler as

window.location="http://someplace.com";

 

 

Thanks for that I will try it but because this is also a learning exercise for me I would like to workout how to do it with the submit button first.

Guest elthomo

Ok I have been looking and thinking a little more and I think the header tag maybe a bit of a "red herring" because I don't want to do a page redirect. What I want to do is a nav to a new page when I click the submit button, that currently submits the form data to the mysql database.

 

I hope this helps you PHP gurus

Then set the address of the page in your form tag:

 

<form action="path/to/file.php" method="post">

 

(replace path/to/file.php with the actual address of the page that processes the form information)

I think the person Only replaced that so people don't bug their test server.
Guest elthomo

Then set the address of the page in your form tag:

 

<form action="path/to/file.php" method="post">

 

(replace path/to/file.php with the actual address of the page that processes the form information)

 

Thanks for that we have progress! but.....

 

If I do this I am able navigate to the new page but it no longer enters the data into my mysql database

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.