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
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

Link to comment
Share on other sites

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

 

Link to comment
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.