PDA

View Full Version : Error Help/



Colin-Roberts
14-06-2008, 10:32 PM
I've looked over this and no idea why.
If i login using the correct info it say's loginning in but then goes back to the form instead of showing the links..

<?PHP



$connection = mysql_connect("",
"",
"");
mysql_select_db("", $connection);












$id = $_REQUEST['id'];
switch($id){
















default:
if($_SESSION['zetolic_user']){
$select = mysql_query("SELECT * FROM `users` WHERE `username`='$_SESSION[zetolic_user]'");
$fetch = mysql_fetch_array($select);
echo"<center><font face='verdana' size='1'>
<b>Welcome,<a href='?page=member&id=" . $_SESSION[zetolic_user] . "'> $_SESSION[zetolic_user]</b></a><br>
Current Zoints: <b>$fetch[coins]</b><br><br>
<a href='?page=function&id=trade'>Trade Zoints</a><br>
<a href='?page=function&id=profile'>Edit Profile</a><br>";
if($fetch[rank] == 3){
if($_SESSION[zetolic_admin]){
echo"<a href='?page=admin&id=list'>UserList</a><br>
<a href='?page=admin&id=search'>Search Users</a><br>
";
}
else {

















echo"<a href='?page=admin'>Admin Login</a><br>";
}
}
















echo"
<a href='?page=function&id=logout'>Logout</a>
</font></center>";
}
else {
echo"<center><font face='verdana' size='1'><form action='?page&id=login' method='POST'>
Username :<br><input name='zetolic_user'><br><br>
Password :<br><input type='password' name='zetolic_pass'><br>
<input type='Submit' value='Login'></form><br><br>
<a href='?page=register'>Register</a></font></center>";
















}
















break;
















case "login":
$user = $_POST['zetolic_user'];
$pass = md5($_POST['zetolic_pass']);
$select = mysql_query("SELECT * FROM `users` WHERE `username`='$user' AND `password`='$pass'");
$count = mysql_num_rows($select);
if($count == '0'){
echo"<meta http-equiv='REFRESH' content='0;url=?'>";
echo"<center><font face='verdana' size='1'>Invalid Username/Password</center></font>";
}
else {
echo"<meta http-equiv='REFRESH' content='0;url=?'>";
echo"<center><font face='verdana' size='1'>Loggining in</center></font>";
$_SESSION['zetolic_user'] = $user;
}
break;
































}

Dentafrice
17-06-2008, 02:31 PM
I'd be happy to help you, but that coding is just too awful.. not to mention messy.. <?PHP -> <?php first off :P

Try to clean it up a bit, and remove the 6 miles of whitespace.

Jahova
17-06-2008, 03:04 PM
Horrible PHP coding.
That is worse than mine and mine is pretty bad.
Man, try and clean up that, or no-one will help you.

Excellent
17-06-2008, 03:06 PM
<?php
$connection = mysql_connect("","","");
mysql_select_db("", $connection);
$id = $_REQUEST['id'];
switch($id){

default:
if($_SESSION['zetolic_user']){
$select = mysql_query("SELECT * FROM `users` WHERE `username`='$_SESSION[zetolic_user]'");
$fetch = mysql_fetch_array($select);
echo"<center><font face='verdana' size='1'>
<b>Welcome,<a href='?page=member&id=" . $_SESSION[zetolic_user] . "'> $_SESSION[zetolic_user]</b></a><br>
Current Zoints: <b>$fetch[coins]</b><br><br>
<a href='?page=function&id=trade'>Trade Zoints</a><br>
<a href='?page=function&id=profile'>Edit Profile</a><br>";
if($fetch[rank] == 3){
if($_SESSION[zetolic_admin]){
echo"<a href='?page=admin&id=list'>UserList</a><br>
<a href='?page=admin&id=search'>Search Users</a><br>";
}
else {

echo"<a href='?page=admin'>Admin Login</a><br>";

}
}

echo" <a href='?page=function&id=logout'>Logout</a>
</font></center>";
}
else {
echo"<center><font face='verdana' size='1'><form action='?page&id=login' method='POST'>
Username :<br><input name='zetolic_user'><br><br>
Password :<br><input type='password' name='zetolic_pass'><br>
<input type='Submit' value='Login'></form><br><br>
<a href='?page=register'>Register</a></font></center>";

}

break;
case "login":
$user = $_POST['zetolic_user'];
$pass = md5($_POST['zetolic_pass']);
$select = mysql_query("SELECT * FROM `users` WHERE `username`='$user' AND `password`='$pass'");
$count = mysql_num_rows($select);
if($count == '0'){
echo"<meta http-equiv='REFRESH' content='0;url=?'>";
echo"<center><font face='verdana' size='1'>Invalid Username/Password</center></font>";
}
else {
echo"<meta http-equiv='REFRESH' content='0;url=?'>";
echo"<center><font face='verdana' size='1'>Loggining in</center></font>";
$_SESSION['zetolic_user'] = $user;
}
break;
}

?>Personal preference.

Jahova
17-06-2008, 03:11 PM
Much cleaner =D

Excellent
17-06-2008, 03:13 PM
Much cleaner =DIf the coding was better I would have spent more time cleaning it up.

Jackboy
17-06-2008, 03:36 PM
I think it looks neat with capitals..

I got some addiction now of doing Mysql_Fetch_Array(); etc

It looks smart i think? :S

but yeh anyway

And you have coded it weirdly imo

Invent
17-06-2008, 03:40 PM
That looks awful Jack :P

PreProcessor
17-06-2008, 03:44 PM
As said that has been coded terribly, I can't even help you because I cba going through thousands of blank lines. You should try recoding it.

Independent
17-06-2008, 03:53 PM
That looks awful Jack :P
Agreed.

I thought functions we're case sensitive :P

Jackboy
17-06-2008, 03:55 PM
Agreed.

I thought functions we're case sensitive :P
well no coz i use caps



That looks awful Jack :P
mehhhh

Dentafrice
17-06-2008, 03:56 PM
I think it looks neat with capitals..

I got some addiction now of doing Mysql_Fetch_Array(); etc

It looks smart i think? :S

but yeh anyway

And you have coded it weirdly imo

Not standards.. <?php looks more professional.

You mean mysql_fetch_array(), you don't need capitals.. it looks like crap :P

If you're going to play with capitals, use the camel method, $this->fetchArray, $this->mysqlQuery, $this->numRows

First word lowercase, second word uppercase.



<?php
$connection = mysql_connect("","","");
mysql_select_db("", $connection);
$id = $_REQUEST['id'];
switch($id){

default:
if($_SESSION['zetolic_user']){
$select = mysql_query("SELECT * FROM `users` WHERE `username`='$_SESSION[zetolic_user]'");
$fetch = mysql_fetch_array($select);
echo"<center><font face='verdana' size='1'>
<b>Welcome,<a href='?page=member&id=" . $_SESSION[zetolic_user] . "'> $_SESSION[zetolic_user]</b></a><br>
Current Zoints: <b>$fetch[coins]</b><br><br>
<a href='?page=function&id=trade'>Trade Zoints</a><br>
<a href='?page=function&id=profile'>Edit Profile</a><br>";
if($fetch[rank] == 3){
if($_SESSION[zetolic_admin]){
echo"<a href='?page=admin&id=list'>UserList</a><br>
<a href='?page=admin&id=search'>Search Users</a><br>";
}
else {

echo"<a href='?page=admin'>Admin Login</a><br>";

}
}

echo" <a href='?page=function&id=logout'>Logout</a>
</font></center>";
}
else {
echo"<center><font face='verdana' size='1'><form action='?page&id=login' method='POST'>
Username :<br><input name='zetolic_user'><br><br>
Password :<br><input type='password' name='zetolic_pass'><br>
<input type='Submit' value='Login'></form><br><br>
<a href='?page=register'>Register</a></font></center>";

}

break;
case "login":
$user = $_POST['zetolic_user'];
$pass = md5($_POST['zetolic_pass']);
$select = mysql_query("SELECT * FROM `users` WHERE `username`='$user' AND `password`='$pass'");
$count = mysql_num_rows($select);
if($count == '0'){
echo"<meta http-equiv='REFRESH' content='0;url=?'>";
echo"<center><font face='verdana' size='1'>Invalid Username/Password</center></font>";
}
else {
echo"<meta http-equiv='REFRESH' content='0;url=?'>";
echo"<center><font face='verdana' size='1'>Loggining in</center></font>";
$_SESSION['zetolic_user'] = $user;
}
break;
}

?>Personal preference.

Still looks awful, not aligned at all :P Looks like my pre-2006 coding.

Agnostic Bear
17-06-2008, 04:30 PM
I prefer
$this->db->runResults();

Dentafrice
17-06-2008, 04:31 PM
Well since most of my applications are centered around the database, I just usually extend my core from the database, that way I can manage it, but your way is just as easy.

Agnostic Bear
17-06-2008, 04:43 PM
Have some clean code.


<?php
$connection = mysql_connect( "", "", "" );
mysql_select_db( "", $connection );
$id = $_REQUEST[ 'id' ];
switch( $id )
{
default:
if( $_SESSION[ 'zetolic_user' ] )
{
$select = mysql_query( "SELECT * FROM `users` WHERE `username`='$_SESSION[zetolic_user]'" );
$fetch = mysql_fetch_array( $select );
echo "<center><font face='verdana' size='1'>
<b>Welcome,<a href='?page=member&id=" . $_SESSION[ zetolic_user ] . "'> $_SESSION[zetolic_user]</b></a><br>
Current Zoints: <b>$fetch[coins]</b><br><br>
<a href='?page=function&id=trade'>Trade Zoints</a><br>
<a href='?page=function&id=profile'>Edit Profile</a><br>";
if( $fetch[ rank ] == 3 )
{
if( $_SESSION[ zetolic_admin ] )
{
echo "<a href='?page=admin&id=list'>UserList</a><br>
<a href='?page=admin&id=search'>Search Users</a><br>";
}
else
{
echo "<a href='?page=admin'>Admin Login</a><br>";
}
}
echo " <a href='?page=function&id=logout'>Logout</a>
</font></center>";
}
else
{
echo "<center><font face='verdana' size='1'><form action='?page&id=login' method='POST'>
Username :<br><input name='zetolic_user'><br><br>
Password :<br><input type='password' name='zetolic_pass'><br>
<input type='Submit' value='Login'></form><br><br>
<a href='?page=register'>Register</a></font></center>";
}
break;
case "login":
$user = $_POST[ 'zetolic_user' ];
$pass = md5( $_POST[ 'zetolic_pass' ] );
$select = mysql_query( "SELECT * FROM `users` WHERE `username`='$user' AND `password`='$pass'" );
$count = mysql_num_rows( $select );
if( $count == '0' )
{
echo "<meta http-equiv='REFRESH' content='0;url=?'>";
echo "<center><font face='verdana' size='1'>Invalid Username/Password</center></font>";
}
else
{
echo "<meta http-equiv='REFRESH' content='0;url=?'>";
echo "<center><font face='verdana' size='1'>Loggining in</center></font>";
$_SESSION[ 'zetolic_user' ] = $user;
}
break;
}
?>

Excellent
17-06-2008, 04:45 PM
Still looks awful, not aligned at all :P Looks like my pre-2006 coding.As I said, I'm not willing to spend time cleaning up his code if it's crappy :P just got rid of the 6 miles of white spaces you quite rightly pointed out and cleaned up his connection and echo spacing.

@Jack - capitals doesn't look professional, looks like you're a shift abusing learner. As denta said if you want to use caps go to the scrappy method of using $this->

@Jew - please tell me you were bored.

Agnostic Bear
17-06-2008, 04:47 PM
As I said, I'm not willing to spend time cleaning up his code if it's crappy :P just got rid of the 6 miles of white spaces you quite rightly pointed out and cleaned up his connection and echo spacing.

@Jack - capitals doesn't look professional, looks like you're a shift abusing learner. As denta said if you want to use caps go to the scrappy method of using $this->

@Jew - please tell me you were bored.

I just right click then press format ;)

Excellent
17-06-2008, 04:55 PM
What program:P

Dentafrice
17-06-2008, 05:01 PM
I just right click then press format ;)
Get me a DL link to that version xx

Excellent
17-06-2008, 05:04 PM
Get me a DL link to that version xxI second that "xx"

Jackboy
17-06-2008, 05:06 PM
Tbhhh i gonna use caps because its not like im gonna sell what im coding atm. this is just the first time i am Abusing My Shift Key.

But stiill i might take what you said on board

Dentafrice
17-06-2008, 05:10 PM
Well if you want to learn, you should :)

Jackboy
17-06-2008, 05:17 PM
No i mean i can do php quite well, i learnt it doing in lowercase, but i am going to code my project with caps, and to be honest it is harder doing with caps so i may adapt your way.

Dentafrice
17-06-2008, 05:22 PM
Yeah, it is harder because you are pushing the shift button, tbh I don't see any benefits from using caps? It just makes it harder to read.. and when you start doing some actually 'advanced' things, when you need to go back and debug.. you will wish you would have made it readable.

Excellent
17-06-2008, 07:12 PM
Found the program jew uses, phpDesigner 2008 for eclipse :p

Dentafrice
17-06-2008, 07:13 PM
^_^ :rolleyes:

Colin-Roberts
18-06-2008, 06:02 PM
It's the code from Zetolic's one php coder. I didn't code it. He's been to busy lately to fix it. So I thought i'd post it here. Thanks for the cleaner code. any idea what's wrong?

Want to hide these adverts? Register an account for free!