This is a read-only archive of the old Scratch 1.x Forums.
Try searching the current Scratch discussion forums.

#1 2012-01-20 00:52:42

nathanprocks
Scratcher
Registered: 2011-04-14
Posts: 1000+

help with PHP and SQL

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:

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:

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?


http://carrot.cassiedragonandfriends.org/Scratch_Signature/randomsig.php
http://trinary.site40.net/images/scratchrank.php?username=nathanprocks&amp;display=small

Offline

 

#2 2012-01-20 01:38:50

nathanprocks
Scratcher
Registered: 2011-04-14
Posts: 1000+

Re: help with PHP and SQL

anyone?


http://carrot.cassiedragonandfriends.org/Scratch_Signature/randomsig.php
http://trinary.site40.net/images/scratchrank.php?username=nathanprocks&amp;display=small

Offline

 

#3 2012-01-20 01:46:45

TRocket
Scratcher
Registered: 2009-08-18
Posts: 1000+

Re: help with PHP and SQL

you need to pass mysql_query a a mysql connection( the result of running mysql_connect)


http://i.imgur.com/1QqnHxQ.png

Offline

 

#4 2012-01-20 01:51:26

nathanprocks
Scratcher
Registered: 2011-04-14
Posts: 1000+

Re: help with PHP and SQL

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

http://carrot.cassiedragonandfriends.org/Scratch_Signature/randomsig.php
http://trinary.site40.net/images/scratchrank.php?username=nathanprocks&amp;display=small

Offline

 

#5 2012-01-20 02:04:34

TRocket
Scratcher
Registered: 2009-08-18
Posts: 1000+

Re: help with PHP and SQL

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


http://i.imgur.com/1QqnHxQ.png

Offline

 

#6 2012-01-20 02:15:54

fg123
Scratcher
Registered: 2008-11-13
Posts: 1000+

Re: help with PHP and SQL

You also need to use sessions if you are working with multiple pages.


Hai.

Offline

 

#7 2012-01-20 03:14:40

nathanprocks
Scratcher
Registered: 2011-04-14
Posts: 1000+

Re: help with PHP and SQL

fg123 wrote:

You also need to use sessions if you are working with multiple pages.

i am lol


http://carrot.cassiedragonandfriends.org/Scratch_Signature/randomsig.php
http://trinary.site40.net/images/scratchrank.php?username=nathanprocks&amp;display=small

Offline

 

#8 2012-01-20 10:28:28

Magnie
Scratcher
Registered: 2007-12-12
Posts: 1000+

Re: help with PHP and SQL

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'];

Offline

 

#9 2012-01-20 18:49:30

nathanprocks
Scratcher
Registered: 2011-04-14
Posts: 1000+

Re: help with PHP and SQL

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  smile

EDIT: still does not work  sad ...

Code:

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)


http://carrot.cassiedragonandfriends.org/Scratch_Signature/randomsig.php
http://trinary.site40.net/images/scratchrank.php?username=nathanprocks&amp;display=small

Offline

 

#10 2012-01-20 19:10:56

Magnie
Scratcher
Registered: 2007-12-12
Posts: 1000+

Re: help with PHP and SQL

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  smile

EDIT: still does not work  sad ...

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).

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'];

Offline

 

#11 2012-01-20 19:14:13

nathanprocks
Scratcher
Registered: 2011-04-14
Posts: 1000+

Re: help with PHP and SQL

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  smile

EDIT: still does not work  sad ...

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).

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  big_smile


http://carrot.cassiedragonandfriends.org/Scratch_Signature/randomsig.php
http://trinary.site40.net/images/scratchrank.php?username=nathanprocks&amp;display=small

Offline

 

#12 2012-01-20 19:16:11

Magnie
Scratcher
Registered: 2007-12-12
Posts: 1000+

Re: help with PHP and SQL

nathanprocks wrote:

yay it works. thanks  big_smile

No problem.  smile

Offline

 

Board footer