Jump to content

Need help with a simple webform


brigadechief

Recommended Posts

Hey

 

I have made a simple form for contact. I provide you guys with the script so you may help me ::)

 

<?php

$username="*********";

$password="*********";

$database="*********";

 

$fnavn=$_POST['fnavn'];

$enavn=$_POST['enavn'];

$telefon=$_POST['telefon'];

$email=$_POST['email'];

 

mysql_connect(localhost,$username,$password);

@mysql_select_db($database) or die( "Unable to select database");

 

$query = "INSERT INTO kontakter VALUES ('','$fnavn','$enavn','$telefon','$email')";

mysql_query($query);

mysql_close();

 

echo "Takk for at du ønsker mer informasjon. Vi vil ta så fort som mulig.";

?>

 

this is the script I called insert.php and the actual form is:

 

      <form action="insert.php" method="post">

      <table width="600" border="0">

        <tr>

          <th class="formHeader" scope="row">Fornavn:</th>

          <td><input type="text" name="fnavn"></td>

        </tr>

        <tr>

          <th class="formHeader" scope="row">Etternavn:</th>

          <td><input type="text" name="enavn"></td>

        </tr>

        <tr>

          <th class="formHeader" scope="row">Telefon:</th>

          <td><input type="text" name="telefon"></td>

        </tr>

        <tr>

          <th class="formHeader" scope="row">E-mail:</th>

          <td><input type="text" name="email"></td>

        </tr>

        <tr>

          <th class="formHeader" scope="row"> </th>

          <td><input type="Submit"></td>

        </tr>

      </table>

    </form>

 

I want this!!

 

When a user enter the details and hit the "submit-button" he will just get a message that says "Thanks for letting us know, we will take contact as soon as possible" in the same window and then the page refresh's automatically and the user can keep reading or whatever he's/she's doing.

 

If somebody got any ideas how this can be done or other ideas I would like to hear from you.

 

Thanks,

Andreas

Link to comment
https://forums.phpfreaks.com/topic/95810-need-help-with-a-simple-webform/
Share on other sites

Change your echo statement to this:

 

<?php
echo "Takk for at du ønsker mer informasjon. Vi vil ta så fort som mulig.
<script type="text/javascript">
   setTimeout("window.location='wherever.php';",5000); // wil redirect to wherever.php in 5 seconds
</script>
";
?>

 

Let me know if that works

What you want to do is check to make sure the insert query has run and then echo out the message

 

change the code to this

<?php
$username="*********";
$password="*********";
$database="*********";

$fnavn=$_POST['fnavn'];
$enavn=$_POST['enavn'];
$telefon=$_POST['telefon'];
$email=$_POST['email'];

mysql_connect(localhost,$username,$password);
@mysql_select_db($database) or die( "Unable to select database");

$query = "INSERT INTO kontakter VALUES ('','$fnavn','$enavn','$telefon','$email')";
$result = @mysql_query($query);
if($result){
// change the link(xxxxx.xxx) to the page you would like to return them to
<META HTTP-EQUIV="Refresh" content="4;url=xxxxxx.xxx">
echo "Takk for at du ønsker mer informasjon. Vi vil ta så fort som mulig.";
} else {
// Put a message saying the query did not work
die("Could not send message".mysql_error());
}
mysql_close();
?>

 

Ray

 

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.