blank page after editing

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

thefreebielife
Forum Contributor
Posts: 126
Joined: Thu Apr 26, 2007 2:59 pm

blank page after editing

Post by thefreebielife »

i added some stuff to this php code, and now the page doesnt load. did i put in something extra/need to add something? i added all the stuff about "uID's"

Code: Select all

 <? 
$username = $_SESSION['username'];


if (isset($_GET["form"]) && $_GET['form'] == "password") { 
$e = "none";
$p1 = $_POST['pass1'];
$p2 = $_POST['pass2'];

//validate password
if (!username_field($p1) or $p1 == "") {
$e = "password";
}
//make sure the same
if ($p1 != $p2) {
$e = "match";
}

if ($e == "none") {
$pass = md5($p1);
$query="UPDATE users SET password='$pass' WHERE username='$username'";
mysql_query($query) or die("Could not insert data because ".mysql_error());
echo '<div align=center><font color=red>Password Changed<font></div>';
echo '<meta http-equiv="refresh" content="3;url=main.php">';
}


if (isset($_GET["form"]) && $_GET['form'] == "uid") { 
$e = "none";
$uid1 = $_POST['uid1'];
$uid2 = $_POST['uid2'];

//validate uid
if (!username_field($uid) or $uid == "") {
$e = "uid";
}
//make sure the same
if ($uid1 != $uid2) {
$e = "match";
}

if ($e == "none") {
$uid = md5($uid);
$query="UPDATE users SET uid='$uid' WHERE username='$username'";
mysql_query($query) or die("Could not insert data because ".mysql_error());
echo '<div align=center><font color=red>Password Changed<font></div>';
echo '<meta http-equiv="refresh" content="3;url=main.php">';

//validate form
//get vars
if (isset($_GET["form"]) && $_GET['form'] == "submit") { 
$Email = $_POST['email']; 
$fname = $_POST['fname'];
$address = $_POST['address'];
$city = $_POST['city'];
$zip = $_POST['zip'];
$error = "none";
$pass = md5($password);

//validate

//validate zip
if (!zip_field($zip)  or $zip == "") {
$error = "zip";
}
//validate city
if (!other_fields($city) or $city == "") {
$error = "city";
}
//validate address
if (!other_fields($address) or $address == "") {
$error = "address";
}
//valiudate fname
if (!name_fields($fname) or $fname == "") {
$error = "firstname";
}

//validate email
if (!check_email($Email)) {
$error = "Email"; 
}


//check to see if email is used
$sql = 'SELECT * FROM `users` WHERE `email` = "'.$Email.'"';
$query = mysql_query ($sql);
$data = mysql_query("SELECT * FROM users WHERE username='$username'")
or die(mysql_error()); 
$info = mysql_fetch_array($data);
$email = $info['email'];

if (mysql_num_rows($query) !=0  && $Email != $email) {
$error = "doubleemail";
} 

//if not insert data
if ($error == "none") { 
$query="UPDATE users SET fname='$fname', email='$Email', address='$address', city='$city', zip='$zip' WHERE username='$username'";
mysql_query($query) or die("Could not insert data because ".mysql_error());
echo '<div align=center><font color=red>Account Updated<font></div>';
echo '<meta http-equiv="refresh" content="3;url=main.php">';
}
}

?>
 
<? 
$data = mysql_query("SELECT * FROM users WHERE username='$username'")
or die(mysql_error()); 
$info = mysql_fetch_array($data);
$email = $info['email'];
$name = $info['fname'];
$address = $info['address'];
$city = $info['city'];
$state = $info['state'];
$zip = $info['zip'];
$country = $info['country'];

?>
		
		 <form action="editaccount.php?form=submit" method="post" name="edit">
           <p>&nbsp;</p>
           <table width="300" border="0" align="center"  class="table" style="border: 1px dashed red; padding: 4px 4px 4px 4px; ">
 <tr>
    <td colspan="2"><div align="center"><? 
if ($error == "firstname") { echo "<font color=red><center>Your First Name is Incorrect</center></font>"; }
if ($error == "address") { echo "<font color=red><center>Your Address is Incorrect</center></font>"; }
if ($error == "city") { echo "<font color=red><center>Your City is Incorrect</center></font>"; }
if ($error == "state") { echo "<font color=red><center>Your State is Incorrect</center></font>"; }
if ($error == "zip") { echo "<font color=red><center>Your Zip Code is Incorrect</center></font>"; }
if ($error == "Email") { echo "<font color=red><center>Your Email is Incorrect</center></font>"; }
if ($error == "doubleemail") {echo '<center><font color="#ff0000">This Email is already in use.  <br>Please Try Again'; }

?></div></td>
	</tr>

 <tr>
    <td colspan="2" style="border-bottom:1px dashed red "><div align="left"><strong>Your Account </strong></div></td>
	</tr>
	 <tr>
    <td colspan="2"><div align="center"><strong>Account Information </strong></div></td>
	</tr>
  <tr>
    <td width="141">Username:</td>
    <td width="320"><? echo "$username" ?></td>
  </tr>
  <tr>
    <td>Email:</td>
    <td><input name="email" type="text" id="email" size="20" value="<? echo "$email"; ?>"  /></td>
  </tr>
  <tr>
    <td colspan="2"><div align="center"><strong>Shipping Information </strong></div></td>
  </tr>
  <tr>
    <td height="26">Full Name: </td>
    <td><input name="fname" type="text" id="fname" size="20" value="<? echo "$name"; ?>"  /></td>
  </tr>
  <tr>
    <td>Address:</td>
    <td><input name="address" type="text" id="address" size="20" value="<? echo "$address"; ?>"  /></td>
  </tr>
  <tr>
    <td>City:</td>
    <td><input name="city" type="text" id="city" size="20" value="<? echo "$city"; ?>"  /></td>
  </tr>
  <tr>
    <td>State:</td>
    <td><? echo "$state"; ?>
    </td>
  </tr>
  <tr>
    <td>Zip:</td>
    <td><input name="zip" type="text" id="zip" size="20" value="<? echo "$zip"; ?>" /></td>
  </tr>
  <tr>
    <td>Country:</td>
    <td><? echo "$country"; ?></td>
  </tr>
     <tr>
  </tr>
   <tr>
    <td colspan="2">
      <div align="center">
        <input type="submit" name="Submit" value="Submit" class="button" />
        </div></td>
  </tr>
     <tr>
    <td colspan="2"></td>
  </tr>
</table>
</form>
		
		 <form action="editaccount.php?form=password" method="post" name="edit">
	<table width="300" border="0" align="center"  class="table" style="border: 1px dashed red; padding: 4px 4px 4px 4px; ">
 <tr>
    <td colspan="2"><div align="center"><? 
if ($e == "match") { echo "<font color=red><center>The Passwords Do Not Match</center></font>"; }
if ($e == "password") { echo "<font color=red><center>Your Password is Invalid</center></font>"; }


?></div></td>
	</tr>
	<tr>
	<Td colspan="2" style="border-bottom:1px dashed red "><strong>
	Change Password
	</strong></Td> 
	</tr>
	<tr>
	<td>
	Password
	</td>
	<td>
	<input name="pass1" type="password" id="pass1">
	</td>
	</tr>
		<tr>
	<td>
	Retype Password
	</td>
	<td>
	<input name="pass2" type="password" id="pass2">
	</td>
	</tr>
   <tr>
    <td colspan="2">
      <div align="center">
        <input type="submit" name="Submit" value="Change" class="button" />
        </div></td>
  </tr>
     <tr>
    <td colspan="2"></td>
  </tr>
</table>
</form>
</td>

<form action="editaccount.php?form=uid" method="post" name="edit">
	<table width="300" border="0" align="center"  class="table" style="border: 1px dashed red; padding: 4px 4px 4px 4px; ">
 <tr>
    <td colspan="2"><div align="center"><? 
if ($e == "match") { echo "<font color=red><center>The ID's Do Not Match</center></font>"; }
if ($e == "uid") { echo "<font color=red><center>Your ID is Invalid</center></font>"; }


?></div></td>
	</tr>
	<tr>
	<Td colspan="2" style="border-bottom:1px dashed red "><strong>
	Change Referral ID
	</strong></Td> 
	</tr>
	<tr>
	<td>
	Password
	</td>
	<td>
	<input name="uid1" type="password" id="uid1">
	</td>
	</tr>
		<tr>
	<td>
	Retype Referral ID
	</td>
	<td>
	<input name="uid2" type="uid" id="uid2">
	</td>
	</tr>
   <tr>
    <td colspan="2">
      <div align="center">
        <input type="submit" name="Submit" value="Change" class="button" />
        </div></td>
  </tr>
     <tr>
    <td colspan="2"></td>
  </tr>
</table>
</form>
	
		
	  </td>
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

You definitely need an editor that helps you formatting your code.
What OS do you use? (windows, linux, ....)
thefreebielife
Forum Contributor
Posts: 126
Joined: Thu Apr 26, 2007 2:59 pm

Post by thefreebielife »

windows
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

You could try http://notepad-plus.sourceforge.net
It has syntax highlighting and code folding for php scripts. And though TextFX->TextFX Edit->Reindent C++ code will not produce perfectly formatted code it's still a beginning.
thefreebielife
Forum Contributor
Posts: 126
Joined: Thu Apr 26, 2007 2:59 pm

Post by thefreebielife »

by using that command i got this, which still doesnt work:

Code: Select all

<?
$username = $_SESSION['username'];


if (isset($_GET["form"]) && $_GET['form'] == "password") {
	$e = "none";
	$p1 = $_POST['pass1'];
	$p2 = $_POST['pass2'];

	//validate password
	if (!username_field($p1) or $p1 == "") {
		$e = "password";
	}
	//make sure the same
	if ($p1 != $p2) {
		$e = "match";
	}

	if ($e == "none") {
		$pass = md5($p1);
		$query="UPDATE users SET password='$pass' WHERE username='$username'";
		mysql_query($query) or die("Could not insert data because ".mysql_error());
		echo '<div align=center><font color=red>Password Changed<font></div>';
		echo '<meta http-equiv="refresh" content="3;url=main.php">';
	}


	if (isset($_GET["form"]) && $_GET['form'] == "uid") {
		$e = "none";
		$uid1 = $_POST['uid1'];
		$uid2 = $_POST['uid2'];

		//validate uid
		if (!username_field($uid) or $uid == "") {
			$e = "uid";
		}
		//make sure the same
		if ($uid1 != $uid2) {
			$e = "match";
		}

		if ($e == "none") {
			$uid = md5($uid);
			$query="UPDATE users SET uid='$uid' WHERE username='$username'";
			mysql_query($query) or die("Could not insert data because ".mysql_error());
			echo '<div align=center><font color=red>Password Changed<font></div>';
			echo '<meta http-equiv="refresh" content="3;url=main.php">';

			//validate form
			//get vars
			if (isset($_GET["form"]) && $_GET['form'] == "submit") {
				$Email = $_POST['email'];
				$fname = $_POST['fname'];
				$address = $_POST['address'];
				$city = $_POST['city'];
				$zip = $_POST['zip'];
				$error = "none";
				$pass = md5($password);

				//validate

				//validate zip
				if (!zip_field($zip)  or $zip == "") {
					$error = "zip";
				}
				//validate city
				if (!other_fields($city) or $city == "") {
					$error = "city";
				}
				//validate address
				if (!other_fields($address) or $address == "") {
					$error = "address";
				}
				//valiudate fname
				if (!name_fields($fname) or $fname == "") {
					$error = "firstname";
				}

				//validate email
				if (!check_email($Email)) {
					$error = "Email";
				}


				//check to see if email is used
				$sql = 'SELECT * FROM `users` WHERE `email` = "'.$Email.'"';
				$query = mysql_query ($sql);
				$data = mysql_query("SELECT * FROM users WHERE username='$username'")
				or die(mysql_error());
				$info = mysql_fetch_array($data);
				$email = $info['email'];

				if (mysql_num_rows($query) !=0  && $Email != $email) {
					$error = "doubleemail";
				}

				//if not insert data
				if ($error == "none") {
					$query="UPDATE users SET fname='$fname', email='$Email', address='$address', city='$city', zip='$zip' WHERE username='$username'";
					mysql_query($query) or die("Could not insert data because ".mysql_error());
					echo '<div align=center><font color=red>Account Updated<font></div>';
					echo '<meta http-equiv="refresh" content="3;url=main.php">';
				}
			}

			?>

			<?
			$data = mysql_query("SELECT * FROM users WHERE username='$username'")
			or die(mysql_error());
			$info = mysql_fetch_array($data);
			$email = $info['email'];
			$name = $info['fname'];
			$address = $info['address'];
			$city = $info['city'];
			$state = $info['state'];
			$zip = $info['zip'];
			$country = $info['country'];

			?>
			
			<form action="editaccount.php?form=submit" method="post" name="edit">
			<p>&nbsp;</p>
			<table width="300" border="0" align="center"  class="table" style="border: 1px dashed red; padding: 4px 4px 4px 4px; ">
			<tr>
			<td colspan="2"><div align="center"><?
			if ($error == "firstname") { echo "<font color=red><center>Your First Name is Incorrect</center></font>"; }
			if ($error == "address") { echo "<font color=red><center>Your Address is Incorrect</center></font>"; }
			if ($error == "city") { echo "<font color=red><center>Your City is Incorrect</center></font>"; }
			if ($error == "state") { echo "<font color=red><center>Your State is Incorrect</center></font>"; }
			if ($error == "zip") { echo "<font color=red><center>Your Zip Code is Incorrect</center></font>"; }
			if ($error == "Email") { echo "<font color=red><center>Your Email is Incorrect</center></font>"; }
			if ($error == "doubleemail") {echo '<center><font color="#ff0000">This Email is already in use.  <br>Please Try Again'; }

			?></div></td>
			</tr>

			<tr>
			<td colspan="2" style="border-bottom:1px dashed red "><div align="left"><strong>Your Account </strong></div></td>
			</tr>
			<tr>
			<td colspan="2"><div align="center"><strong>Account Information </strong></div></td>
			</tr>
			<tr>
			<td width="141">Username:</td>
			<td width="320"><? echo "$username" ?></td>
			</tr>
			<tr>
			<td>Email:</td>
			<td><input name="email" type="text" id="email" size="20" value="<? echo "$email"; ?>"  /></td>
			</tr>
			<tr>
			<td colspan="2"><div align="center"><strong>Shipping Information </strong></div></td>
			</tr>
			<tr>
			<td height="26">Full Name: </td>
			<td><input name="fname" type="text" id="fname" size="20" value="<? echo "$name"; ?>"  /></td>
			</tr>
			<tr>
			<td>Address:</td>
			<td><input name="address" type="text" id="address" size="20" value="<? echo "$address"; ?>"  /></td>
			</tr>
			<tr>
			<td>City:</td>
			<td><input name="city" type="text" id="city" size="20" value="<? echo "$city"; ?>"  /></td>
			</tr>
			<tr>
			<td>State:</td>
			<td><? echo "$state"; ?>
			</td>
			</tr>
			<tr>
			<td>Zip:</td>
			<td><input name="zip" type="text" id="zip" size="20" value="<? echo "$zip"; ?>" /></td>
			</tr>
			<tr>
			<td>Country:</td>
			<td><? echo "$country"; ?></td>
			</tr>
			<tr>
			</tr>
			<tr>
			<td colspan="2">
			<div align="center">
			<input type="submit" name="Submit" value="Submit" class="button" />
			</div></td>
			</tr>
			<tr>
			<td colspan="2"></td>
			</tr>
			</table>
			</form>
			
			<form action="editaccount.php?form=password" method="post" name="edit">
			<table width="300" border="0" align="center"  class="table" style="border: 1px dashed red; padding: 4px 4px 4px 4px; ">
			<tr>
			<td colspan="2"><div align="center"><?
			if ($e == "match") { echo "<font color=red><center>The Passwords Do Not Match</center></font>"; }
			if ($e == "password") { echo "<font color=red><center>Your Password is Invalid</center></font>"; }


			?></div></td>
			</tr>
			<tr>
			<Td colspan="2" style="border-bottom:1px dashed red "><strong>
			Change Password
			</strong></Td>
			</tr>
			<tr>
			<td>
			Password
			</td>
			<td>
			<input name="pass1" type="password" id="pass1">
			</td>
			</tr>
			<tr>
			<td>
			Retype Password
			</td>
			<td>
			<input name="pass2" type="password" id="pass2">
			</td>
			</tr>
			<tr>
			<td colspan="2">
			<div align="center">
			<input type="submit" name="Submit" value="Change" class="button" />
			</div></td>
			</tr>
			<tr>
			<td colspan="2"></td>
			</tr>
			</table>
			</form>
			</td>

			<form action="editaccount.php?form=uid" method="post" name="edit">
			<table width="300" border="0" align="center"  class="table" style="border: 1px dashed red; padding: 4px 4px 4px 4px; ">
			<tr>
			<td colspan="2"><div align="center"><?
			if ($e == "match") { echo "<font color=red><center>The ID's Do Not Match</center></font>"; }
			if ($e == "uid") { echo "<font color=red><center>Your ID is Invalid</center></font>"; }


			?></div></td>
			</tr>
			<tr>
			<Td colspan="2" style="border-bottom:1px dashed red "><strong>
			Change Referral ID
			</strong></Td>
			</tr>
			<tr>
			<td>
			Password
			</td>
			<td>
			<input name="uid1" type="password" id="uid1">
			</td>
			</tr>
			<tr>
			<td>
			Retype Referral ID
			</td>
			<td>
			<input name="uid2" type="uid" id="uid2">
			</td>
			</tr>
			<tr>
			<td colspan="2">
			<div align="center">
			<input type="submit" name="Submit" value="Change" class="button" />
			</div></td>
			</tr>
			<tr>
			<td colspan="2"></td>
			</tr>
			</table>
			</form>
			
			
			</td
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

It's not supposed to understand and fix your code. Only the formatting.

Image
note the gray line that connects the if ... { in line 19 with its corresponding closing brace on line 25

and now compare it to
Image
it's the end of your script but still there are two "open/unfinished" gray lines. What does this tell you?
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

The formatting of the code wasn't wen't to solve the issue, it was to make it readable. As you can see, the number of opening curly brackets does not equal the number of closing curly brackets.
thefreebielife
Forum Contributor
Posts: 126
Joined: Thu Apr 26, 2007 2:59 pm

Post by thefreebielife »

i fixed the curly brackets so i dont think that was the problem, or maybe some of it. is there something wrong with the actual coding?
User avatar
infolock
DevNet Resident
Posts: 1708
Joined: Wed Sep 25, 2002 7:47 pm

Post by infolock »

It's times like these i wish people followed MVC
User avatar
guitarlvr
Forum Contributor
Posts: 245
Joined: Wed Mar 21, 2007 10:35 pm

Post by guitarlvr »

Code: Select all

//validate uid
                if (!username_field($uid) or $uid == "") {
                        $e = "uid";
                }
the or should be replaced with '||'

EDIT: I stand corrected. I did not know 'or' worked. forget what i said! :) but the statement should probably look like this:

Code: Select all

if ((!username_field($uid)) or ($uid == "")) {
Wayne
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

Wrong again Wayne, it is perfectly valid. :wink:
thefreebielife
Forum Contributor
Posts: 126
Joined: Thu Apr 26, 2007 2:59 pm

Post by thefreebielife »

thanks for help so far.

i just cant figure out whats wrong with this :?
User avatar
guitarlvr
Forum Contributor
Posts: 245
Joined: Wed Mar 21, 2007 10:35 pm

Post by guitarlvr »

Jcart wrote:Wrong again Wayne, it is perfectly valid. :wink:
yeah i realized that after more testing. to ashamed to hit the edit button again. :(

Wayne
thefreebielife
Forum Contributor
Posts: 126
Joined: Thu Apr 26, 2007 2:59 pm

Post by thefreebielife »

does it work okay for you?
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

Check your error logs. A blank page is almost a sure sign of a parse error. In this case, given what volka discovered, I would suspect unmatched braces. But there is no one in their right mind that is going to sift through that code for you when you can just look in your error logs to find the error.
Post Reply