Jump to content

Archived

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

legohead6

Form sending with database

Recommended Posts

how do i stop a form heading to a database from sending untill the user clicks submit? right know it sends whenever they enter or refresh the page! heres the code
[code] <?php
$host = "localhost";
$user = "--";
$pass = "--";
$db = "--";

$first=$_POST['first'];
$last=$_POST['last'];
$gun=$_POST['gun'];
$age=$_POST['age'];
$saying=$_POST['saying'];
$email=$_POST['email'];
$phone=$_POST['phone'];
$users=$_POST['user'];
$passs=$_POST['pass'];

// open connection
$connection = mysql_connect($host, $user,'$pass') or die ("Unable to
connect!");

// select database
mysql_select_db($db) or die ("Unable to select database!");

$query = "INSERT INTO members VALUES ('$first','$last','$gun','$age','$saying','$email','$phone','$users','$passs')";
mysql_query($query);
?></p>

<p align="center">Player Info form!</p>
<form method="POST" name="membership" action="Membership.php">
<p align="center">First name <input type="text" name="first" size="20">
Last Name:<input type="text" name="last" size="24">
<br><br>
Phone#<input type="text" name="phone">(format= 000-0000)
<p align="center">
Gun type:<input type="text" name="gun" size="36"><br>
<br>
Age:<input type="text" name="age" size="3"><br>
<br>
Saying:<br>
<textarea rows="2" name="saying" cols="20"></textarea></p>
<p align="center">
Current email address:<input type="text" name="email" size="36">
</p>
<p align="center">
Desired Username:<input type="text" name="user" size="20">
</p>
<p align="center">
Desired pass:<input type="password" name="pass" size="20">
</p>
<p align="center"><input type="submit" value="Submit" name="B1"></p>
</form>
</body>

</html>

Share this post


Link to post
Share on other sites
[code] <?php

if(isset($_POST['submit']))
{
$host = "localhost";
$user = "--";
$pass = "--";
$db = "--";

$first=$_POST['first'];
$last=$_POST['last'];
$gun=$_POST['gun'];
$age=$_POST['age'];
$saying=$_POST['saying'];
$email=$_POST['email'];
$phone=$_POST['phone'];
$users=$_POST['user'];
$passs=$_POST['pass'];

// open connection
$connection = mysql_connect($host, $user,'$pass') or die ("Unable to
connect!");

// select database
mysql_select_db($db) or die ("Unable to select database!");

$query = "INSERT INTO members VALUES ('$first','$last','$gun','$age','$saying','$email','$phone','$users','$passs')";
mysql_query($query);
?></p>
}
else
{
?>
<p align="center">Player Info form!</p>
<form method="POST" name="membership" action="Membership.php">
<p align="center">First name <input type="text" name="first" size="20">
Last Name:<input type="text" name="last" size="24">
<br><br>
Phone#<input type="text" name="phone">(format= 000-0000)
<p align="center">
Gun type:<input type="text" name="gun" size="36"><br>
<br>
Age:<input type="text" name="age" size="3"><br>
<br>
Saying:<br>
<textarea rows="2" name="saying" cols="20"></textarea></p>
<p align="center">
Current email address:<input type="text" name="email" size="36">
</p>
<p align="center">
Desired Username:<input type="text" name="user" size="20">
</p>
<p align="center">
Desired pass:<input type="password" name="pass" size="20">
</p>
<p align="center"><input type="submit" value="Submit" name="B1"></p>
</form>
</body>

</html>
<?php
}
?>
[/code]

Share this post


Link to post
Share on other sites

×

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.