PDA

View Full Version : php....again


goldfish
07-28-03, 12:55
Okay..... what up wid this...

My main file...

<?php
include("top.php");
include("db_connect.php")?>
allor <br>

<?php
$sql = 'SELECT * FROM `users`';
$result = mysql_db_query($dbname,$sql,$connection) or
die("Error in query");
// with a while loop
// this loop will iterate as many times as there are records
while($myrow = mysql_fetch_array($result))
{
$userrname = $myrow["usrname"];
$password = $myrow["pwd"];
echo "$username ... $password <br>";
}
mysql_free_result($result);
?>

<?php include("bottom.php"); ?>


right, my top file has all sorts of funky layout stuff, and so does the bottom file. the dbconnect has.....


<?php
function db_connect() {
$dbuser = "my user name ;)";
$dbpass = "no chance!";
$dbname = "wouldnt you like to know"
$dbhost = "localhost";

$connection = mysql_connect($dbuser, $dbpass, $dbname, $dbhost)

if(!$connection) {
echo( "Unable to connect to the database");
exit();
}

else {
$connected_to_db = "Connected to Database";
}

}
?>


right... the table does exist, and it has an entry in it. it dies (i.e. it echos "error in query" ) and i cant figure out why

Vlad902
07-28-03, 13:18
allor <br> I am guessing is something you put in there to make sure it proccesses after the includes?


$connection = mysql_connect($dbuser, $dbpass, $dbname, $dbhost)

Usually I do it...

$blah = mysql_connect("localhost", $luser, $passwd);

does mysql_select_db($dbname,$connection) or die("No DB found... f00l") Give you the error?

In $sql try having no `s' but instead just users

goldfish
07-28-03, 13:32
hmm, okay, i fout out why it wasnt getting the query (urr, yeah.... :o) but now nothing comes out of my query. its got somthing to do with my while loop i think...

while($myrow = mysql_fetch_array($result))
{
$username = $myrow["usrname"];
$password = $myrow["pwd"];
echo "$username ... $password <br>";
}

Vlad902
07-28-03, 13:38
Is it usrname and pwd and not username and passwd? Just making sure :)

goldfish
07-28-03, 13:42
yep, im quite sure i got the names right ;)
anything else you can see?

Vlad902
07-28-03, 13:51
try echo $username . "blah" . $password;

EDIT: What was the prob in the first place?

goldfish
07-28-03, 13:56
the prob is that it gets past the includes, and then stops, and i dont know why. you can look at it if you like....
http://cgi.nicholaslidster.plus.com/hypostasis/login.php

Vlad902
07-28-03, 14:05
The while statement may an infinite loop... maybe that's it? didn't seem to load slowly so weird, did you make any changes to the code in the first page or is it the same?

goldfish
07-28-03, 14:11
hang on... this is the latest version of the bit thats causing the problems...

its not the loop, i got rid of it same problem.. :(
<?php
db_connect();
$sql = 'SELECT * FROM users';
$result = mysql_db_query($dbname,$sql,$connection) or
die("Error in query");

$username = $myrow["usrname"];
$password = $myrow["pwd"];
echo $username . "blah" . $password;

mysql_free_result($result);
exit();

Vlad902
07-28-03, 14:16
Yeah and you forgot to add

$myrow = mysql_fetch_array($result)

;)

Still nothing I'm guessing :/ I really gotta start working with MySQL again...

goldfish
07-28-03, 14:56
hah, yo right.....

but yeah, still nuthin.. :(

Vlad902
07-28-03, 17:56
try mysql_list_tables($dbname,$connection);

What are the results?

goldfish
07-29-03, 09:24
ah, i cracked it ! http://cgi.nicholaslidster.plus.com/hypostasis/list_users_and_passwords.php
now im just having a problem with the login script :cry:

goldfish
07-29-03, 09:27
Ive pinned it down to this if branch... what might be going wrong?


$sql = mysql_query("SELECT * FROM users WHERE usrname = '$loginuser'") or die("There was a problem in the query!");
$numrows = mysql_num_rows($sql);
$fetch_em = mysql_fetch_array($sql)

//Here is the naughty one!!
if($numrows != "0" & md5($loginpwd) == $fetch_em["pwd"])
{
echo "valid";
}
else {
echo "not valid";
}

goldfish
07-29-03, 10:10
BTW that thing you told me to do, gives me this :

Resource id #5

goldfish
07-29-03, 10:19
/me laughs insanley


A SEMI COLON!!!!!!!!!!!!!

asdfasdfAsdFHFDAS/FSAF,HBSA/¬!!!!]#
runs around in circles..

carry on...

i dont get session variables....

session_register("username");
session_register("password");

That declares the session variables username and password, but how do you actually SET them to somthing?

Vlad902
07-29-03, 21:43
This solved since there is a new post or still going at it?

goldfish
07-29-03, 21:46
yes solved, i meant to say so but slipped mind.
uset cookies instead with the setcookie() function :) mmmm coo
kkies