ok... i have made a login system for my page creator. (i haven't made the registration part yet.) i have a database. it has id, username, password and email. i also have 1 row where id=0, username=test, password=test and email=test@testthing.test. i have the code:
$id = mysql_query("SELECT id FROM $tbl_name WHERE username='$myusername'");
$email = mysql_query("SELECT email FROM $tbl_name WHERE username='$myusername'");... and i have the code:
<table style="font-size:18; margin:auto; color:yellow;"> <tr><td>User ID: </td><td><? echo $_SESSION["id"]; ?></td></tr> <tr><td>Email: </td><td><? echo $_SESSION["email"]; ?></td></tr> </table>
in another page... when i try to login, it goes to profile page and it says User ID: 0 and Email: 0... what i am doing wrong?
Offline
TRocket wrote:
you need to pass mysql_query a a mysql connection( the result of running mysql_connect)
you mean this?
mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");Offline
nathanprocks wrote:
TRocket wrote:
you need to pass mysql_query a a mysql connection( the result of running mysql_connect)
you mean this?
Code:
mysql_connect("$host", "$username", "$password")or die("cannot connect"); mysql_select_db("$db_name")or die("cannot select DB");
yes
Offline
fg123 wrote:
You also need to use sessions if you are working with multiple pages.
i am lol
Offline
You need to use mysql_fetch_array($array) like:
$result = mysql_query("SELECT id FROM $tbl_name WHERE username='$myusername'");
$row = mysql_fetch_result($result);
$id = $row['id'];
$result = mysql_query("SELECT email FROM $tbl_name WHERE username='$myusername'");
$row = mysql_fetch_result($result);
$email = $row['email'];or to simplify the process:
$result = mysql_query("SELECT * FROM $tbl_name WHERE username='$myusername'");
$row = mysql_fetch_result($result);
$id = $row['id'];
$email = $row['email'];Offline
Magnie wrote:
You need to use mysql_fetch_array($array) like:
Code:
$result = mysql_query("SELECT id FROM $tbl_name WHERE username='$myusername'"); $row = mysql_fetch_result($result); $id = $row['id']; $result = mysql_query("SELECT email FROM $tbl_name WHERE username='$myusername'"); $row = mysql_fetch_result($result); $email = $row['email'];or to simplify the process:
Code:
$result = mysql_query("SELECT * FROM $tbl_name WHERE username='$myusername'"); $row = mysql_fetch_result($result); $id = $row['id']; $email = $row['email'];
ok i will try that
EDIT: still does not work
...
Fatal error: Call to undefined function mysql_fetch_result() in /home/cassiedr/public_html/easypage/checklogin.php on line 25
Last edited by nathanprocks (2012-01-20 18:58:31)
Offline
nathanprocks wrote:
Magnie wrote:
You need to use mysql_fetch_array($array) like:
Code:
$result = mysql_query("SELECT id FROM $tbl_name WHERE username='$myusername'"); $row = mysql_fetch_result($result); $id = $row['id']; $result = mysql_query("SELECT email FROM $tbl_name WHERE username='$myusername'"); $row = mysql_fetch_result($result); $email = $row['email'];or to simplify the process:
Code:
$result = mysql_query("SELECT * FROM $tbl_name WHERE username='$myusername'"); $row = mysql_fetch_result($result); $id = $row['id']; $email = $row['email'];ok i will try that
![]()
EDIT: still does not work...
Code:
Fatal error: Call to undefined function mysql_fetch_result() in /home/cassiedr/public_html/easypage/checklogin.php on line 25
Whoops, I meant mysql_fetch_array($result).
$result = mysql_query("SELECT id FROM $tbl_name WHERE username='$myusername'");
$row = mysql_fetch_array($result);
$id = $row['id'];
$result = mysql_query("SELECT email FROM $tbl_name WHERE username='$myusername'");
$row = mysql_fetch_array($result);
$email = $row['email'];$result = mysql_query("SELECT * FROM $tbl_name WHERE username='$myusername'");
$row = mysql_fetch_array($result);
$id = $row['id'];
$email = $row['email'];Offline
Magnie wrote:
nathanprocks wrote:
Magnie wrote:
You need to use mysql_fetch_array($array) like:
Code:
$result = mysql_query("SELECT id FROM $tbl_name WHERE username='$myusername'"); $row = mysql_fetch_result($result); $id = $row['id']; $result = mysql_query("SELECT email FROM $tbl_name WHERE username='$myusername'"); $row = mysql_fetch_result($result); $email = $row['email'];or to simplify the process:
Code:
$result = mysql_query("SELECT * FROM $tbl_name WHERE username='$myusername'"); $row = mysql_fetch_result($result); $id = $row['id']; $email = $row['email'];ok i will try that
![]()
EDIT: still does not work...
Code:
Fatal error: Call to undefined function mysql_fetch_result() in /home/cassiedr/public_html/easypage/checklogin.php on line 25Whoops, I meant mysql_fetch_array($result).
Code:
$result = mysql_query("SELECT id FROM $tbl_name WHERE username='$myusername'"); $row = mysql_fetch_array($result); $id = $row['id']; $result = mysql_query("SELECT email FROM $tbl_name WHERE username='$myusername'"); $row = mysql_fetch_array($result); $email = $row['email'];Code:
$result = mysql_query("SELECT * FROM $tbl_name WHERE username='$myusername'"); $row = mysql_fetch_array($result); $id = $row['id']; $email = $row['email'];
yay it works. thanks
Offline
nathanprocks wrote:
yay it works. thanks
![]()
No problem.
Offline