SitePoint Sponsor |
|
User Tag List
Results 1 to 8 of 8
-
Mar 6, 2007, 08:33 #1
- Join Date
- Aug 2003
- Location
- Bristol, United Kingdom
- Posts
- 2,160
- Mentioned
- 46 Post(s)
- Tagged
- 0 Thread(s)
Simple Form Problem - Will not write to DB
I have this code that I'm using to write to either my buyer or seller database (depending on what option the user chooses, and I've hit a brick wall with getting it working. Here's the code in question:
PHP Code:<?php
if(isset($_POST['accounttype'])):
include("./db-connect.inc.php");
$accounttype = $_POST['accounttype'];
$username = $_POST['username'];
$password = $_POST['password'];
$email = $_POST['email'];
$firstname = $_POST['firstname'];
$surname = $_POST['surname'];
$dob = $_POST['dob'];
$address = $_POST['address'];
$city = $_POST['city'];
$postcode = $_POST['postcode'];
$country = $_POST['country'];
$tel = $_POST['tel'];
if($accounttype == "buyer")
{
$sql = "INSERT INTO `buyer` ( `username` , `password`, `email`, `firstname`, `surname`, `dob`, `address`, `city`, `postcode`, `country`, `tel` )
VALUES ('$username', '$password', '$email', '$firstname', '$surname', '$dob', '$address', '$city', '$postcode', '$country', '$tel');";
}
else
{
$sql = "INSERT INTO `seller` ( `username` , `password`, `email`, `firstname`, `surname`, `dob`, `address`, `city`, `postcode`, `country`, `tel` )
VALUES ('$username', '$password', '$email', '$firstname', '$surname', '$dob', '$address', '$city', '$postcode', '$country', '$tel');";
}
if(@mysql_query($sql))
{
echo '<p>Account Created!</p>';
}
else
{
echo '<p>Error:' . mysql_error() . '</p>';
}
?>
Extra information if it's needed: The Country field is a dropdown box, and the accounttype is from radio boxes.»» My Articles: Putting your users' trust in Facebook Connect, Why Email is not broken
-
Mar 6, 2007, 08:44 #2
At a glance it looks OK.. :S
Any error messages?
-
Mar 6, 2007, 08:51 #3
- Join Date
- Oct 2005
- Location
- London, UK
- Posts
- 148
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
That code doesn't even run properly...
Change:
Code:if(isset($_POST['accounttype'])):
Code:if(isset($_POST['accounttype'])) {
-
Mar 6, 2007, 08:53 #4
-
Mar 6, 2007, 09:16 #5
- Join Date
- Aug 2003
- Location
- Bristol, United Kingdom
- Posts
- 2,160
- Mentioned
- 46 Post(s)
- Tagged
- 0 Thread(s)
I was looking into changing it to that, but it kinda confuses me with the extra code. Here's all the code (with the form inputs taken out, they don't seem that inportant) I'm using.
PHP Code:<?php
if(isset($_POST['accounttype'])):
include("./db-connect.inc.php");
$accounttype = $_POST['accounttype'];
$username = $_POST['username'];
$password = $_POST['password'];
$email = $_POST['email'];
$firstname = $_POST['firstname'];
$surname = $_POST['surname'];
$dob = $_POST['dob'];
$address = $_POST['address'];
$city = $_POST['city'];
$postcode = $_POST['postcode'];
$country = $_POST['country'];
$tel = $_POST['tel'];
if($accounttype == "buyer")
{
$sql = "INSERT INTO `buyer` ( `username` , `password`, `email`, `firstname`, `surname`, `dob`, `address`, `city`, `postcode`, `country`, `tel` )
VALUES ('$username', '$password', '$email', '$firstname', '$surname', '$dob', '$address', '$city', '$postcode', '$country', '$tel');";
}
else
{
$sql = "INSERT INTO `seller` ( `username` , `password`, `email`, `firstname`, `surname`, `dob`, `address`, `city`, `postcode`, `country`, `tel` )
VALUES ('$username', '$password', '$email', '$firstname', '$surname', '$dob', '$address', '$city', '$postcode', '$country', '$tel');";
}
if(@mysql_query($sql))
{
echo '<p>Account Created!</p>';
}
else
{
echo '<p>Error:' . mysql_error() . '</p>';
}
?>
<?php else: ?>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" class="cmxform" method="get">
<fieldset>
<legend>Account Type</legend>
<ol>
<li>
<label for="type">Buyer</label>
<input type="radio" name="accounttype" value="buyer" />
<label for="type">Seller</label>
<input type="radio" name="accounttype" value="seller" />
</li>
</ol>
</fieldset>
<fieldset>
<legend>User Details</legend>
<ol>
<li>
<label for="username">Username:</label>
<input name="username"/>
</li>
<li>
<label for="password">Password:</label>
<input name="password" type="password" />
</li>
<li>
<label for="verifypassword">Verify Password:</label>
<input name="vpassword" type="password" />
</li>
<li>
<label for="email">Email:</label>
<input name="email" />
</li>
</ol>
</fieldset>
<fieldset>
<legend>Personal Information</legend>
<ol>
<li>
<label for="firstname">First Name:</label>
<input name="firstname" />
</li>
<li>
<label for="surname">Surname:</label>
<input name="surname" />
</li>
<li>
<label for="dob">Date of Birth:</label>
<input name="dob" />
</li>
<li>
<label for="address">Address 1:</label>
<input name="address" />
</li>
<li>
<label for="city">City:</label>
<input name="city" />
</li>
<li>
<label for="postcode">Postcode:</label>
<input name="postcode" />
</li>
<li>
<label for="country">Country:</label>
<select name="country">
<option value="uk">United Kingdom</option>
<option value="fr">France</option>
<option value="gr">Germany</option>
</select>
</li>
<li>
<label for="tel">Telephone No.</label>
<input name="tel" />
</li>
</ol>
</fieldset>
<input type="submit" value="Register!" />
</form>
<?php endif; ?>»» My Articles: Putting your users' trust in Facebook Connect, Why Email is not broken
-
Mar 6, 2007, 09:20 #6
Changed your form tag to:
Code:<form action="<?php echo $_SERVER['PHP_SELF']; ?>" class="cmxform" method="post">
Code:<?php if(isset($_POST['accounttype'])) : include("./db-connect.inc.php"); $accounttype = $_POST['accounttype']; $username = $_POST['username']; $password = $_POST['password']; $email = $_POST['email']; $firstname = $_POST['firstname']; $surname = $_POST['surname']; $dob = $_POST['dob']; $address = $_POST['address']; $city = $_POST['city']; $postcode = $_POST['postcode']; $country = $_POST['country']; $tel = $_POST['tel']; if($accounttype == "buyer") { $sql = "INSERT INTO `buyer` ( `username` , `password`, `email`, `firstname`, `surname`, `dob`, `address`, `city`, `postcode`, `country`, `tel` ) VALUES ('$username', '$password', '$email', '$firstname', '$surname', '$dob', '$address', '$city', '$postcode', '$country', '$tel');"; } else { $sql = "INSERT INTO `seller` ( `username` , `password`, `email`, `firstname`, `surname`, `dob`, `address`, `city`, `postcode`, `country`, `tel` ) VALUES ('$username', '$password', '$email', '$firstname', '$surname', '$dob', '$address', '$city', '$postcode', '$country', '$tel');"; } if(@mysql_query($sql)) { echo '<p>Account Created!</p>'; } else { echo '<p>Error:' . mysql_error() . '</p>'; } ?> <?php else: ?> <form action="<?php echo $_SERVER['PHP_SELF']; ?>" class="cmxform" method="post"> <fieldset> <legend>Account Type</legend> <ol> <li> <label for="type">Buyer</label> <input type="radio" name="accounttype" value="buyer" /> <label for="type">Seller</label> <input type="radio" name="accounttype" value="seller" /> </li> </ol> </fieldset> <fieldset> <legend>User Details</legend> <ol> <li> <label for="username">Username:</label> <input name="username"/> </li> <li> <label for="password">Password:</label> <input name="password" type="password" /> </li> <li> <label for="verifypassword">Verify Password:</label> <input name="vpassword" type="password" /> </li> <li> <label for="email">Email:</label> <input name="email" /> </li> </ol> </fieldset> <fieldset> <legend>Personal Information</legend> <ol> <li> <label for="firstname">First Name:</label> <input name="firstname" /> </li> <li> <label for="surname">Surname:</label> <input name="surname" /> </li> <li> <label for="dob">Date of Birth:</label> <input name="dob" /> </li> <li> <label for="address">Address 1:</label> <input name="address" /> </li> <li> <label for="city">City:</label> <input name="city" /> </li> <li> <label for="postcode">Postcode:</label> <input name="postcode" /> </li> <li> <label for="country">Country:</label> <select name="country"> <option value="uk">United Kingdom</option> <option value="fr">France</option> <option value="gr">Germany</option> </select> </li> <li> <label for="tel">Telephone No.</label> <input name="tel" /> </li> </ol> </fieldset> <input type="submit" value="Register!" /> </form> <?php endif; ?>
-
Mar 6, 2007, 12:05 #7
- Join Date
- Aug 2003
- Location
- Bristol, United Kingdom
- Posts
- 2,160
- Mentioned
- 46 Post(s)
- Tagged
- 0 Thread(s)
All works now. Thanks for the help Mase and Bill Palmer.
»» My Articles: Putting your users' trust in Facebook Connect, Why Email is not broken
-
Mar 6, 2007, 22:10 #8
- Join Date
- Oct 2005
- Location
- London, UK
- Posts
- 148
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
I had no idea you could do IF statements like that... the lack of the closing ENDIF in the first post threw me off.
I'll never use them, but nice to know.
Bookmarks