Cheat Engine Forum Index Cheat Engine
The Official Site of Cheat Engine
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 


forum-index.php Code help please

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming
View previous topic :: View next topic  
Author Message
deleted user 111213
Grandmaster Cheater
Reputation: 0

Joined: 09 Nov 2007
Posts: 714

PostPosted: Tue Nov 18, 2008 12:52 pm    Post subject: forum-index.php Code help please Reply with quote

i have a problem, when i go to the forum-index.php page when i'm logged in, it comes up with this error message
Code:
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'FROM `users` WHERE `id`='1'' at line 1


source code to forum-index.php

Code:
<?php
session_start();
include './global.php';
?>
<html>

   <head>
      <title>Noskiw's Forum</title>

   <style type="text/css">
      body{
         background-color:#EEE;
         color:#000;
         font-family:Arial, Helvetica, sans-serif;
         font-size:10pt;
      }

      #holder{
         width:90%;
         color:#000;
         font-family:Arial, Helvetica, sans-serif;
         border:1px solid #000;
         padding:10px;
         text-align:left;
      }
      
      #userInfo{
         color:000;
         font-family:Arial, Helvetica, sans-serif;
         border:1px solid #CCC;
         text-align:right;
         padding:3px;
      }
   </style>
   
   </head>

   <body>

      <center>

         <div id="holder">

            <div id="userInfo">
                   <?php
                  if($_SESSION['uid']){
                     $sql = "SELECT * FROM username FROM `users` WHERE `id`='" . $_SESSION['uid'] . "'";
                     $res = mysql_query($sql) or die(mysql_error());
                     
                     if(mysql_num_row($res) == 0){
                        session_destroy();
                        echo "<p>Please <a href=\"./login2.php\">Login</a> to you account, or <a href=\"./reg.php\">Register</a> a new account!</p>\n";
                     }else{
                        $row = mysql_fetch_assoc($res);
                        echo "<p>Welcome back <a href=\"./forum-index.php?act=profile&id=" . $row['id']."\">" . $row['username'] . "</a></p>";
                     }
                  }else{
                     echo "<p>Please <a href=\"./login2.php\">Login</a> to you account, or <a href=\"./reg.php\">Register</a> a new account!</p>\n";
                  }
               ?>
                </div>

            <?php



            ?>

         </div>

      </center>

   </body>

</html>


and login2.php

Code:
<?php
session_start();
include'./global.php';

echo "<title>Login</title>\n";

if($_SESSION['uid']){
echo "You are already logged in, if you wish to log out, please <a href=\"./logout.php\">click here<a>!\n";
}else {


if(!$_POST['submit']){
echo "<table border='0' cellspacing='0' cellpadding='3'>\n";
echo "<form method='post' action='login2.php'>\n";
echo "<tr><td>Username: </td><td><input type='text' name='username'></td></tr>\n";
echo "<tr><td>Password: </td><td><input type='password' name='password'></td></tr>\n";
echo "<tr><td colspan='2' align='right'><input type='submit' name='submit' value='login'></td></tr>\n";
}else{
$user = $_POST['username'];
$pass = $_POST['password'];

if($user && $pass){
$sql = "SELECT id FROM `users` WHERE `username`='".$user."'";
$res = mysql_query($sql) or die(mysql_error());
if(mysql_num_rows($res) > 0){
$sql2 = "SELECT id FROM `users` WHERE `username`='".$user."' AND `password`='".($pass)."'";
$res2 = mysql_query($sql2) or die(mysql_error());
if(mysql_num_rows($res2) > 0){
$row = mysql_fetch_assoc($res2);
$_SESSION['uid'] = $row['id'];

echo "You have successfully logged in as " . $user;
}else{
echo "Username and password do not match!\n";
}
}else{
echo "the username you supplied does not exist.\n";
}
}else{
echo "You must supply both the username and password field";
}
}
}
?>


if anyone would be willing to help me please do so.

i dont want to post global.php because it contains some information i dont want to share.
Back to top
View user's profile Send private message
sloppy
Expert Cheater
Reputation: 0

Joined: 17 Aug 2008
Posts: 123

PostPosted: Tue Nov 18, 2008 5:43 pm    Post subject: Reply with quote

Read some tutorials for a better understanding of sql. Here is your error (forum-index.php),

Code:
$sql = "SELECT * FROM username FROM `users` WHERE `id`='" . $_SESSION['uid'] . "'";


Replace with.. SELECT username (the column), FROM users (the table), WHERE id (the row) = 'your session id',

Code:
$sql = "SELECT username FROM users WHERE id = '" . $_SESSION['uid'] . "'";
Back to top
View user's profile Send private message
ElectroFusion
Grandmaster Cheater
Reputation: 0

Joined: 17 Dec 2006
Posts: 786

PostPosted: Tue Nov 18, 2008 11:16 pm    Post subject: Reply with quote

More of a break down.
$sql = "SELECT * FROM username FROM `users` WHERE `id`='" . $_SESSION['uid'] . "'";

$sql is the variable
= would be what the variable equals
" brackets that go around the code.
SELECT select something
* would mean ALL
FROM what table to select it from
USERNAME row, but idk why you put this as the table
USERS the table that you are selecting from
WHERE more like a if
ID the column your selecting it from
$_SESSION['uid'] the value of ID

_________________
qwerty147 wrote:

ghostonline wrote:

what world are you in?

bera

but i live in NZ
Back to top
View user's profile Send private message
deleted user 111213
Grandmaster Cheater
Reputation: 0

Joined: 09 Nov 2007
Posts: 714

PostPosted: Wed Nov 19, 2008 10:24 am    Post subject: Reply with quote

thankyou. i have not tested it but i am rewriting login2.php. thx. i am sure it will work as you guys here are smart.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group

CE Wiki   IRC (#CEF)   Twitter
Third party websites