Jump to content


Photo

Need help


  • Please log in to reply
6 replies to this topic

#1 Rosst

Rosst
  • Members
  • PipPip
  • Member
  • 29 posts

Posted 06 June 2006 - 11:09 PM

I was working on my site and I made a mistake in the log in section, the only section in my index.php other than the query stings, and now nothing is showing, I don't know why, please help me, this is my code:
<?php 
switch ($_GET['id']) { 
default: 
echo "Welcome to Vexxon.net, <a href='index.php?id=reg'>register now</a> to get access to the members area!!"; 
break; 

case 'reg': 
require("includes/register.php"); 
break; 

case 'log': 
include("config.php"); 
if (!$logged[username]) 
{ 
if (!$_POST[login]) 
{ 
echo(" 
<center><form method=\"POST\"> 
<table> 
<tr> 
<td align=\"center\"> 
Username: <input type=\"text\" size=\"15\" maxlength=\"25\" name=\"username\"> 
</td> 
</tr> 
<tr> 
<td align=\"center\"> 
Password: <input type=\"password\" size=\"15\" maxlength=\"25\" name=\"password\"> 
</td></tr><tr> 
<td align=\"center\"> 
<input type=\"submit\" name=\"login\" value=\"Login\"> 
</td></tr><tr> 
<td align=\"center\"> 
<a href=\"index.php?id=reg\">Register Here</a> 
</td></tr></table></form></center>"); 
} 
elseif ($_POST[login]) { 
// the form has been submitted. We continue... 
$username=$_POST['username']; 
$password = md5($_POST[password]); 
// the above lines set variables with the submitted information. 
$info = mysql_query("SELECT * FROM users WHERE username = '$username'") or die(mysql_error()); 
$data = mysql_fetch_array($info); 
if ($data[password] != $password || $data[username] != $username) { 
echo "Your password/username is wrong"; 
exit(); 
} 
setcookie("id", $data[id], time()+(60*60*24*5), "/", ""); 
setcookie("pword", $data[pass], time()+(60*60*24*5), "/", "");  
header("Location: login.php"); 
else { 
Echo "You are logged in!"; 
setcookie("uname", $data[id], time()+(60*60*24*5), "/", ""); 
setcookie("pword", $data[pass], time()+(60*60*24*5), "/", "");  
header("Location: index.php?id=log"); 
} 
} 
} 
else 
{ 

// we now display the user controls. 
$new = mysql_query("select * from pmessages where unread = 'unread' and touser = '$logged[username]'"); 
$new = mysql_num_rows($new); 
echo ("<center>Welcome <b>$logged[username]</b><br /></center> 
- <a href=\"index.php?id=editpro\">Edit Profile</a><br /> 
- <a href=\"index.php?id=memb\">Member List</a><br /> 
- <a href=\"index.php?id=pms\">Private Message Center ($new new)</a><br /> 
- <a href=\"index.php?id=logo\">Logout</a>"); 
} 
break; 

case 'memb': 
require("includes/members.php"); 
break; 

case 'on': 
require("includes/online.php"); 
break; 

case 'pms': 
require("includes/messages.php"); 
break; 

case 'logo': 
require("includes/logout.php"); 
break; 

case 'newad': 
require("includes/news_admin.php"); 
break; 

case 'editpro': 
require("includes/editprofile.php"); 
break; 

case 'news': 
require("includes/news.php"); 
break; 

case 'adm': 
require("includes/admin.php"); 
break; 

case 'newscom': 
require("includes/news_comments.php"); 
break; 
} 
?>


#2 Ferenc

Ferenc
  • Members
  • PipPipPip
  • Advanced Member
  • 94 posts

Posted 07 June 2006 - 05:47 AM

place this at the top of your code
<?php
error_reporting(E_ALL);
switch ($_GET['id']) {.........

Everything you want to know is here.

#3 .josh

.josh
  • Staff Alumni
  • .josh
  • 14,871 posts

Posted 07 June 2006 - 06:44 AM

first and foremost, I have to strongly scold you for your lack of indenting. debugging is a hell of a lot easier if you properly indent your code! that aside...

2nd, what do you mean by "nothing" is showing? do you get a blank page? certain variable(s) not showing?
Did I help you? Feeling generous? Buy me lunch! 
Please, take the time and do some research and find out how much it would have cost you to get your help from a decent paid-for source. A "roll-of-the-dice" freelancer will charge you $5-$15/hr. A decent entry level freelancer will charge you around $15-30/hr. A professional will charge you anywhere from $50-$100/hr. An agency will charge anywhere from $100-$250/hr. Think about all this when soliciting for help here. Think about how much money you are making from the work you are asking for help on. No, we do not expect you to pay for the help given here, but donating a few bucks is a fraction of the cost of what you would have paid, shows your appreciation, helps motivate people to keep offering help without the pricetag, and helps make this a higher quality free-help community :)

#4 .josh

.josh
  • Staff Alumni
  • .josh
  • 14,871 posts

Posted 07 June 2006 - 06:58 AM

here, i took the trouble to indent your code for you, and labeled your {}'s. see how much easier it is to follow the logic (it will look a lot better when you c/p it into your editor)? you can thank me by writing your code this way from now on.

<?php
switch ($_GET['id']) {// 1 -start switch
   default:
        echo "Welcome to Vexxon.net, <a href='index.php?id=reg'>register now</a> to get access to the members area!!";
        break;

     case 'reg':
        require("includes/register.php");
        break;

     case 'log':
        include("config.php");
        if (!$logged[username]) { //2 -start if not $logged
         if (!$_POST[login]) {//3 -start if not $_POST
            echo("
            <center><form method=\"POST\">
                         <table>
                            <tr>
                               <td align=\"center\">
                                  Username: <input type=\"text\" size=\"15\" maxlength=\"25\" name=\"username\">
                               </td>
                            </tr>
                            <tr>
                               <td align=\"center\">
                                   Password: <input type=\"password\" size=\"15\" maxlength=\"25\" name=\"password\">
                              </td></tr>
                           <tr>
                               <td align=\"center\">
                                  <input type=\"submit\" name=\"login\" value=\"Login\">
                               </td>
                           </tr>
                             <tr>
                               <td align=\"center\">
                                  <a href=\"index.php?id=reg\">Register Here</a>
                               </td>
                             </tr>
                    </table>
            </form></center>");
               }//3 -end if not $_POST 
                   elseif ($_POST[login]) {//4 -start if $_POST
              // the form has been submitted. We continue...
                  $username=$_POST['username'];
                  $password = md5($_POST[password]);
                  // the above lines set variables with the submitted information.
                  $info = mysql_query("SELECT * FROM users WHERE username = '$username'") or die(mysql_error());
                  $data = mysql_fetch_array($info);
                  if ($data[password] != $password || $data[username] != $username) {//5-start if not username or pw
                     echo "Your password/username is wrong";
                       exit();
            }//5 -end if not username or pw
                setcookie("id", $data[id], time()+(60*60*24*5), "/", "");
                setcookie("pword", $data[pass], time()+(60*60*24*5), "/", "");  
                header("Location: login.php");
                else {//6-start else (assumes username and pw match)
                     Echo "You are logged in!";
                     setcookie("uname", $data[id], time()+(60*60*24*5), "/", "");
                     setcookie("pword", $data[pass], time()+(60*60*24*5), "/", "");  
                     header("Location: index.php?id=log");
                }//6 - end else
        }//4 - end if $_POST
     }//2 - end if not $logged 
           else {//7 - start else (assumes that there is a $logged)
        // we now display the user controls.
          $new = mysql_query("select * from pmessages where unread = 'unread' and touser = '$logged[username]'");
          $new = mysql_num_rows($new);
          echo ("<center>Welcome <b>$logged[username]</b><br /></center>
          - <a href=\"index.php?id=editpro\">Edit Profile</a><br />
          - <a href=\"index.php?id=memb\">Member List</a><br />
          - <a href=\"index.php?id=pms\">Private Message Center ($new new)</a><br />
          - <a href=\"index.php?id=logo\">Logout</a>");
      }//7 - end else
      break;

   case 'memb':
      require("includes/members.php");
      break;

   case 'on':
      require("includes/online.php");
            break;

   case 'pms':
          require("includes/messages.php");
            break;

   case 'logo':
        require("includes/logout.php");
          break;

   case 'newad':
        require("includes/news_admin.php");
          break;

   case 'editpro':
        require("includes/editprofile.php");
            break;

   case 'news':
        require("includes/news.php");
            break;

   case 'adm':
      require("includes/admin.php");
      break;

   case 'newscom':
      require("includes/news_comments.php");
      break;
}//1 - end switch
?>

where are you setting $logged[username] ? i see you setting some cookies and then never using them. did you mean to check for the cookies?
Did I help you? Feeling generous? Buy me lunch! 
Please, take the time and do some research and find out how much it would have cost you to get your help from a decent paid-for source. A "roll-of-the-dice" freelancer will charge you $5-$15/hr. A decent entry level freelancer will charge you around $15-30/hr. A professional will charge you anywhere from $50-$100/hr. An agency will charge anywhere from $100-$250/hr. Think about all this when soliciting for help here. Think about how much money you are making from the work you are asking for help on. No, we do not expect you to pay for the help given here, but donating a few bucks is a fraction of the cost of what you would have paid, shows your appreciation, helps motivate people to keep offering help without the pricetag, and helps make this a higher quality free-help community :)

#5 Rosst

Rosst
  • Members
  • PipPip
  • Member
  • 29 posts

Posted 07 June 2006 - 03:29 PM

[!--quoteo(post=380885:date=Jun 7 2006, 02:44 AM:name=Crayon Violent)--][div class=\'quotetop\']QUOTE(Crayon Violent @ Jun 7 2006, 02:44 AM) View Post[/div][div class=\'quotemain\'][!--quotec--]
first and foremost, I have to strongly scold you for your lack of indenting. debugging is a hell of a lot easier if you properly indent your code! that aside...

2nd, what do you mean by "nothing" is showing? do you get a blank page? certain variable(s) not showing?
[/quote]
Yes I get a blank page, I don't see why though.

#6 redarrow

redarrow
  • Members
  • PipPipPip
  • Advanced Member
  • 7,308 posts
  • Locationlondon

Posted 07 June 2006 - 03:43 PM

somthink wrong here dont know what theo

is the cookie syntex wrong
setcookie("uname", $data[id], time()+(60*60*24*5), "/", "");


i thort it was this way but i am only learning.

setcookie(["uname"], "'.$data[id].'", time()+(60*60*24*5), "/", "");




 setcookie("id", $data[id], time()+(60*60*24*5), "/", "");
                setcookie("pword", $data[pass], time()+(60*60*24*5), "/", "");  
                header("Location: login.php");
                else {//6-start else (assumes username and pw match)
                     Echo "You are logged in!";
                     setcookie("uname", $data[id], time()+(60*60*24*5), "/", "");
                     setcookie("pword", $data[pass], time()+(60*60*24*5), "/", "");  
                     header("Location: index.php?id=log");


Wish i new all about php DAM i will have to learn
((EMAIL CODE THAT WORKS))
http://simpleforum.ath.cx/mail2.inc
((PAYPAL INTEGRATION THAT WORKS))
http://simpleforum.a...aypal1_info.inc

#7 Rosst

Rosst
  • Members
  • PipPip
  • Member
  • 29 posts

Posted 08 June 2006 - 03:45 AM

Hey everyone, I changed some stuff and now my outputing works, I mean I see the content, but it seems the cookies aren't being set, here is my new code:
<?php
ob_start();
include("config.php");
switch ($_GET['id']) {
default:
echo "Welcome to Vexxon.net, <a href='index.php?id=reg'>register now</a> to get access to the members area!!";
break;

case 'reg':
require("includes/register.php");
break;

case 'log':
if (!$logged[username])
{
if (!$_POST[login])
{
echo("
<center><form method=\"POST\" name=\"login\">
<table>
<tr>
<td align=\"center\">
Username: <input type=\"text\" size=\"15\" maxlength=\"25\" name=\"username\">
</td>
</tr>
<tr>
<td align=\"center\">
Password: <input type=\"password\" size=\"15\" maxlength=\"25\" name=\"password\">
</td></tr><tr>
<td align=\"center\">
<input type=\"submit\" name=\"login\" value=\"Login\">
</td></tr><tr>
<td align=\"center\">
<a href=\"index.php?id=reg\">Register Here</a>
</td></tr></table></form></center>");
}
elseif ($_POST[login]) {
// the form has been submitted. We continue...
$username=$_POST['username'];
$password = md5($_POST[password]);
// the above lines set variables with the submitted information.
$info = mysql_query("SELECT * FROM users WHERE username = '$username' AND password = '$password'") or die(mysql_error());
$data = mysql_fetch_array($info);
if ($data[password] != $password || $data[username] != $username) {
echo "Your password/username is wrong";
echo '</div>
</div>
<div class="footer">
<div align="center">©2005, vexxon productions</div>
</div>
</body>
</html>';
exit();
}
else {
setcookie("id", $data[id], time()+(60*60*24*5), "/", "");
setcookie("pword", $data[password], time()+(60*60*24*5), "/", "");  
Echo "You are logged in!";
header("Location: index.php?id=log");
}
}
}
else
{

// we now display the user controls.
$new = mysql_query("select * from pmessages where unread = 'unread' and touser = '$logged[username]'");
$new = mysql_num_rows($new);
echo ("<center>Welcome <b>$logged[username]</b><br /></center>
- <a href=\"index.php?id=editpro\">Edit Profile</a><br />
- <a href=\"index.php?id=memb\">Member List</a><br />
- <a href=\"index.php?id=pms\">Private Message Center ($new new)</a><br />
- <a href=\"index.php?id=logo\">Logout</a>");
}
break;

case 'memb':
require("includes/members.php");
break;

case 'on':
require("includes/online.php");
break;

case 'pms':
require("includes/messages.php");
break;

case 'logo':
require("includes/logout.php");
break;

case 'newad':
require("includes/news_admin.php");
break;

case 'editpro':
require("includes/editprofile.php");
break;

case 'news':
require("includes/news.php");
break;

case 'adm':
require("includes/admin.php");
break;

case 'newscom':
require("includes/news_comments.php");
break;
}
?>





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users