Jump to content

Need help


Rosst

Recommended Posts

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:
[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;
}
?>[/code]
Link to comment
Share on other sites

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.

[code]
<?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
?>
[/code]

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?
Link to comment
Share on other sites

[!--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) [snapback]380885[/snapback][/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.
Link to comment
Share on other sites

somthink wrong here dont know what theo

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


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

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



[code]

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");

[/code]
Link to comment
Share on other sites

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:
[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;
}
?>[/code]
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.