| View previous topic :: View next topic |
| Author |
Message |
deleted user 111213 Grandmaster Cheater
Reputation: 0
Joined: 09 Nov 2007 Posts: 714
|
Posted: Tue Nov 18, 2008 12:52 pm Post subject: forum-index.php Code help please |
|
|
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 |
|
 |
sloppy Expert Cheater
Reputation: 0
Joined: 17 Aug 2008 Posts: 123
|
Posted: Tue Nov 18, 2008 5:43 pm Post subject: |
|
|
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 |
|
 |
ElectroFusion Grandmaster Cheater
Reputation: 0
Joined: 17 Dec 2006 Posts: 786
|
Posted: Tue Nov 18, 2008 11:16 pm Post subject: |
|
|
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 |
|
 |
deleted user 111213 Grandmaster Cheater
Reputation: 0
Joined: 09 Nov 2007 Posts: 714
|
Posted: Wed Nov 19, 2008 10:24 am Post subject: |
|
|
| 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 |
|
 |
|