...

View Full Version : New problem



sirborder
03-27-2007, 09:34 AM
OK,
New problem. I got the page to load and my form appears. I fill out the form and press submit. The page loads again and the form comes up again blank!? I am once again stumped.
Here is my code:


<?php include('header.php'); ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>SD Computerz - Register</title>
<style type="text/css">
<!--
.style1 {color: #000000}
body,td,th {
color: #FFFFFF;
}
body {
background-color: #000000;
}
-->
</style>

</head>
<body>
<span class="style1"></span>
<center><h1>SD Computerz</h1></center><br />
<?php include('menu.html') ?>
<hr />
<center>
<?php
$user="user";
$password="pass";
$database="database";
$host="host";
mysql_connect($host,$user,$password)or die("Could not connect to database");
mysql_select_db($database) or die( "Unable to select database");

$username=$_POST['username'];
$pass=$_POST['pass'];
$pass2=$_POST['confirm_pass'];
$email=$_POST['email'];
if($_SESSION['logged_in'] == 1)
{ echo('You are already logged in. Please <a href="http://www.sdcomutrez.com/logout.php">log out</a> or go to the <a href="http://www.sdcomputerz.com">homepage</a>');
}
else
{
if(isset($_POST['submit']))
{
if(!$username)
{
die('Alert: Userame field left blank!');
}
$q2 = mysql_query("SELECT * FROM `members` WHERE `username` = '".$username."'");
$q3 = mysql_fetch_object($q2);
if($q3->username == $username)
{
die('Alert: The username $username is already stored in our database. Please <a href="http://www.sdcomputerz.com/contact.php">contanct an administrator</a> if you feel there is a mistake');
}
if(!$pass)
{
die('Alert: Password field was left blank.');
}
if(!$pass2)
{
die('Alert: Verify Password field was left blank.');
}
if($pass != $pass2)
{
die('Alert: Password fields did not match.');
}
if(!$email)
{
die('Alert: Email field was left blank.');
}
$query= "INSERT INTO `members` (`id`, `username`, `password`, `email`) VALUES ('', '$username', '$pass', 'email'), ('', '', '', '')";
mysql_query($query);
echo('Thank you for signing up. You may now <a href="http://www.sdcomputerz.com/login.php">login</a>.');
mysql_close();
}
else
{
?>
<table>
<form name="register" action="<?php $_SERVER['PHP_SELF']; ?>" method="post">
<tr>
<td>
<p>*Indicates required field.</p>
</td>
</tr>
<tr>
<td>
<p>Username*</p>
</td>
<td>
<input type="text" name="username" />
</td>
</tr>
<tr>
<td>
<p>Password*</p>
</td>
<td>
<input type="password" name="pass" />
</td>
</tr>
<tr>
<td>
<p>Confirm Password*</p>
</td>
<td>
<input type="password" name="pass2" />
</td>
</tr>
<tr>
<td>
<p>Email*</p>
</td>
<td>
<input type="text" name="email" />
</td>
</tr>
<tr>
<td>
</td>
<td>
<input type="submit" value="Submit" />
</td>
</tr>
</form>
</table>
<?php
}
}
?>
</center>
</body>
</html>

Thanks again for you help and patience.

rafiki
03-27-2007, 01:19 PM
i did notice one thing

die('Alert: The username $username is already stored in our database. Please <a href="http://www.sdcomputerz.com/contact.php">contanct an administrator</a> if you feel there is a mistake');

shouldn't that be


die('Alert: The username' . $username . ' is already stored in our database. Please <a href="http://www.sdcomputerz.com/contact.php">contanct an administrator</a> if you feel there is a mistake');

mlseim
03-27-2007, 01:21 PM
I think I know what it is ...

See these lines ... Add a bracket (in blue) ... remove the bracket (in red)

else
{
if(isset($_POST['submit']))
{
if(!$username)
{
die('Alert: Userame field left blank!');
}
$q2 = mysql_query("SELECT * FROM `members` WHERE `username` = '".$username."'");
$q3 = mysql_fetch_object($q2);
if($q3->username == $username)
{
die('Alert: The username $username is already stored in our database. Please <a href="http://www.sdcomputerz.com/contact.php">contanct an administrator</a> if you feel there is a mistake');
}
if(!$pass)
{
die('Alert: Password field was left blank.');
}
if(!$pass2)
{
die('Alert: Verify Password field was left blank.');
}
if($pass != $pass2)
{
die('Alert: Password fields did not match.');
}
if(!$email)
{
die('Alert: Email field was left blank.');
}
$query= "INSERT INTO `members` (`id`, `username`, `password`, `email`) VALUES ('', '$username', '$pass', 'email'), ('', '', '', '')";
mysql_query($query);
echo('Thank you for signing up. You may now <a href="http://www.sdcomputerz.com/login.php">login</a>.');
mysql_close();
}
}
else
{
?>
<table>
<form name="register" action="<?php $_SERVER['PHP_SELF']; ?>" method="post">
<tr>
<td>
<p>*Indicates required field.</p>
</td>
</tr>
<tr>
<td>
<p>Username*</p>
</td>
<td>
<input type="text" name="username" />
</td>
</tr>
<tr>
<td>
<p>Password*</p>
</td>
<td>
<input type="password" name="pass" />
</td>
</tr>
<tr>
<td>
<p>Confirm Password*</p>
</td>
<td>
<input type="password" name="pass2" />
</td>
</tr>
<tr>
<td>
<p>Email*</p>
</td>
<td>
<input type="text" name="email" />
</td>
</tr>
<tr>
<td>
</td>
<td>
<input type="submit" value="Submit" />
</td>
</tr>
</form>
</table>
<?php
}
}
?>
</center>
</body>
</html>

Nightfire
03-27-2007, 01:31 PM
Nah, I think the problem is that there isn't enough brackets.

If you format the code properly, you can spot it



<?php include('header.php'); ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>SD Computerz - Register</title>
<style type="text/css">
<!--
.style1 {
color: #000000

}
body,td,th {
color: #FFFFFF;
}
body {
background-color: #000000;
}
-->
</style>

</head>
<body>
<span class="style1"></span>
<center><h1>SD Computerz</h1></center><br />
<?php include('menu.html') ?>
<hr />
<center>
<?php
$user="user";
$password="pass";
$database="database";
$host="host";
mysql_connect($host,$user,$password)or die("Could not connect to database");
mysql_select_db($database) or die( "Unable to select database");

$username=$_POST['username'];
$pass=$_POST['pass'];
$pass2=$_POST['confirm_pass'];
$email=$_POST['email'];
if($_SESSION['logged_in'] == 1){
echo('You are already logged in. Please <a href="http://www.sdcomutrez.com/logout.php">log out</a> or go to the <a href="http://www.sdcomputerz.com">homepage</a>');
}else{
if(isset($_POST['submit'])){
if(!$username){
die('Alert: Userame field left blank!');
}
$q2 = mysql_query("SELECT * FROM `members` WHERE `username` = '".$username."'");
$q3 = mysql_fetch_object($q2);
if($q3->username == $username){
die('Alert: The username $username is already stored in our database. Please <a href="http://www.sdcomputerz.com/contact.php">contanct an administrator</a> if you feel there is a mistake');
}
if(!$pass){
die('Alert: Password field was left blank.');
}
if(!$pass2){
die('Alert: Verify Password field was left blank.');
}
if($pass != $pass2){
die('Alert: Password fields did not match.');
}
if(!$email){
die('Alert: Email field was left blank.');
}
$query= "INSERT INTO `members` (`id`, `username`, `password`, `email`) VALUES ('', '$username', '$pass', 'email'), ('', '', '', '')";
mysql_query($query);
echo('Thank you for signing up. You may now <a href="http://www.sdcomputerz.com/login.php">login</a>.');
mysql_close();
}else{
?>
<table>
<form name="register" action="<?php $_SERVER['PHP_SELF']; ?>" method="post">
<tr>
<td><p>*Indicates required field.</p></td>
</tr>
<tr>
<td><p>Username*</p></td>
<td><input type="text" name="username" /></td>
</tr>
<tr>
<td><p>Password*</p></td>
<td><input type="password" name="pass" /></td>
</tr>
<tr>
<td><p>Confirm Password*</p></td>
<td><input type="password" name="pass2" /></td>
</tr>
<tr>
<td><p>Email*</p></td>
<td><input type="text" name="email" /></td>
</tr>
<tr>
<td></td>
<td><input type="submit" value="Submit" /></td>
</tr>
</form>
</table>
<?php
}
}
}
?>
</center>
</body>
</html>

mlseim
03-27-2007, 02:12 PM
Nightfire ...

you might be right ... I didn't try formatting it first,
but I know there's a problem with the brackets.

I tried counting them with my finger (the non-techie way) :)


For those newbies to PHP ... see how important it is to
properly format your code? It really helps with troubleshooting.

Nightfire
03-27-2007, 02:43 PM
Yeah I tried looking down the screen and counting lol Had some time so ended up sorting it properly

sirborder
03-27-2007, 08:18 PM
Well I appreciate the advice and all but... my form still won't work.
In order to see my problem, why don't you visit my form at this page (http://surfacehawaii.com/kylecaleb/currentproject/register.php).

Nightfire
03-27-2007, 08:20 PM
Give your submit button a name.

<input type="submit" value="Submit" name="submit" />

iLLin
03-27-2007, 09:46 PM
Form comes up blank eh? How bout you put in the values?



<input type="text" name="email" value="<?php echo stripslashes($_POST['email']); ?>" />

mlseim
03-28-2007, 03:32 AM
There's some really basic troubleshooting (programming 101)
things you can do ...

Use some echo statements to figure it out.

Insert them in various spots ....

echo "test1";

echo "test2";

see where your program is not executing.

comment-out various parts ...
To isolate sections.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum