Weird problem
Moderator: General Moderators
Weird problem
Database chat_users
Warning: mysql_list_tables(): supplied argument is not a valid MySQL-Link resource in /home/jonas/public_html/chat/list.php on line 24
Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/jonas/public_html/chat/list.php on line 26
Any idea why its telling me those are not valid MySQL-Link resources? I am running.. (checks)
mysql Ver 11.15 Distrib 3.23.45, for pc-linux-gnu (i686)
All I am trying to do is list ALL usernames in that database.. *sigh* Can anyone show me a working way to LIST all data in that database and one for searching and displaying just specific data? (we'll use 'username' as an example) because Im getting this error and I dont know why!
Warning: mysql_list_tables(): supplied argument is not a valid MySQL-Link resource in /home/jonas/public_html/chat/list.php on line 24
Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/jonas/public_html/chat/list.php on line 26
Any idea why its telling me those are not valid MySQL-Link resources? I am running.. (checks)
mysql Ver 11.15 Distrib 3.23.45, for pc-linux-gnu (i686)
All I am trying to do is list ALL usernames in that database.. *sigh* Can anyone show me a working way to LIST all data in that database and one for searching and displaying just specific data? (we'll use 'username' as an example) because Im getting this error and I dont know why!
first try to find the error yourself by adding "or die(mysql_error())"s to your script
i.e.
i.e.
Code: Select all
$dbConn = mysql_connect(...) or die(mysql_error());
mysql_select_db($dbName, $dbConn) or die(mysql_error());
$result = mysql_query($query, $dbConn) or die(mysql_error());Yeah I fixed it, I had a small typo..
Another problem though.
I have an apply function and a login function in my ONE php file (yeah Im only using one), anywho both those functions are HTML output with forms, how can I make apply post to user_reg() and login post to user_login()
I've tried almost everything, I know it is EASY if I use multiple files, but that isnt an option at this time.
Another problem though.
I have an apply function and a login function in my ONE php file (yeah Im only using one), anywho both those functions are HTML output with forms, how can I make apply post to user_reg() and login post to user_login()
I've tried almost everything, I know it is EASY if I use multiple files, but that isnt an option at this time.
not quite sure, I got the point butyou get the same values as with type="hidden" or "text" but only the data from the submit-button that has been activated, so the script can decide what to do.
Code: Select all
<input type="submit" name="mode" value="register" /> <br/>
<input type="submit" name="mode" value="login" />Ok I'm using case's and having login html called with ?id=login, and reg ?=apply (those both go to html forms)volka wrote:not quite sure, I got the point butyou get the same values as with type="hidden" or "text" but only the data from the submit-button that has been activated, so the script can decide what to do.Code: Select all
<input type="submit" name="mode" value="register" /> <br/> <input type="submit" name="mode" value="login" />
Now I need those forms to be able to be submitted (to the same php file they are being called from) and load up the proper functions, for example login form might call user_login function, and registration form might call user_registration, now I cant seem to get it to work properly.
Code: Select all
<html><body>
<?php
if (!isset($_POSTї'mode']) || !isset($_POSTї'uname']))
{ ?>
<form method="post">
user name: <input type="text" name="uname"/><br/>
<input type="submit" name="mode" value="login"/>
<input type="submit" name="mode" value="register"/><br/>
</form>
<?php
}
else
{
switch($_POSTї'mode'])
{
case 'login':
print('login procedure for '.$_POSTї'uname']);
break;
case 'register':
print('registration procedure for '.$_POSTї'uname']);
break;
default:
print('malformed request');
break;
}
}
?>
</body></html>Thanks vodka, works, but I get an error when trying to send to proper fucntion Im using:
user_login('.$_POST['username']','.$_POST['password']');
I get the error:
Parse error: parse error, unexpected T_STRING in /home/canadian/public_html/csys/csys.php on line 20
Not certain how I should pass it to user_login(); which requires username and password. I've tried a few ways now.
user_login('.$_POST['username']','.$_POST['password']');
I get the error:
Parse error: parse error, unexpected T_STRING in /home/canadian/public_html/csys/csys.php on line 20
Not certain how I should pass it to user_login(); which requires username and password. I've tried a few ways now.
should be
you don't need the quotes; the variables already represent strings.
Code: Select all
user_login($_POSTї'username'], $_POSTї'password']);first the simple answer:
user_login($_POST['username'], $_POST['password']);
---
a string literal starts with either " or ' and ends with the same character
"valid" 'valid' "invalid' 'invalid"
if unquoted the start-stop-sign within the literal marks the end of it
"this is unvalid because " is within the literal"
The parser finds ", parses this is invalid because as literal (ending with ") and than finds is which has no meaning at this location -> error (unexpected T_STRING).
if starting the string with " you may use ' freely within i.e. "I'm happy to be valid
" and ' "me" too '
"this is valid because \" is quoted within the literal"
\ turns off the special meaning of some characters.
The operator . concatenates two strings
$a = "b" . "c" -> $a == "ab"
$a = "b" . "c" . "d" -> "b" . ("c" . "d") -> "b" . ("cd") -> "b" . "cd" == "bcd"
if a literal is marked with " (instead of ') the contents is parsed and all variables (starting with $) are replaced by their values.
$var = 'test';
$a = "this is a $var" -> a$ == "this is a test"
If the contents of an array field shall be replaced the array must be marked for the parser with {} (i.e. "posted username is {$_POST['username']}")
There's no need for something like $a="$variable" or $a="{$_POST['username']}" since you may directly assign a value to variable i.e. $a=$variable; or $a=$_POST['username'];
Same goes with functions:
doFunc("$variable", "{$_POST['username']}"); -> doFunc($variable, $_POST['username']);
The only reason I can image why someone uses doFunc("$variable") is to assure the parameter will be a string and not empty (maybe of length 0 but not NULL)
user_login($_POST['username'], $_POST['password']);
---
a string literal starts with either " or ' and ends with the same character
"valid" 'valid' "invalid' 'invalid"
if unquoted the start-stop-sign within the literal marks the end of it
"this is unvalid because " is within the literal"
The parser finds ", parses this is invalid because as literal (ending with ") and than finds is which has no meaning at this location -> error (unexpected T_STRING).
if starting the string with " you may use ' freely within i.e. "I'm happy to be valid
"this is valid because \" is quoted within the literal"
\ turns off the special meaning of some characters.
The operator . concatenates two strings
$a = "b" . "c" -> $a == "ab"
$a = "b" . "c" . "d" -> "b" . ("c" . "d") -> "b" . ("cd") -> "b" . "cd" == "bcd"
if a literal is marked with " (instead of ') the contents is parsed and all variables (starting with $) are replaced by their values.
$var = 'test';
$a = "this is a $var" -> a$ == "this is a test"
If the contents of an array field shall be replaced the array must be marked for the parser with {} (i.e. "posted username is {$_POST['username']}")
There's no need for something like $a="$variable" or $a="{$_POST['username']}" since you may directly assign a value to variable i.e. $a=$variable; or $a=$_POST['username'];
Same goes with functions:
doFunc("$variable", "{$_POST['username']}"); -> doFunc($variable, $_POST['username']);
The only reason I can image why someone uses doFunc("$variable") is to assure the parameter will be a string and not empty (maybe of length 0 but not NULL)
Main code:
Any idea why main_menu doesnt seem to be getting called? this all functioned fine when I had it in seperate files, which is not an option for the admin so they are all in one file. Thanks in advance.
Now the actual login procedure is:if (isset($_POST['mode']) || isset($_POST['username'])) {
switch($_POST['mode'])
{
case 'login':
user_login($_POST['username'], $_POST['password']);
break;
case 'register':
print('registration procedure not updated '.$_POST['username']);
break;
default:
break;
}
} else {
/* put all the register stuff and login stuff into their own function */
$id = $_GET['id'];
switch($id){
case "login":
login();
break;
case "apply":
if (!CSYS_APPLY) { echo '<b>Sorry, we are not currently Accepting appli$
} else { apply(); }
break;
default:
login();
}
}
I know it authenticates properly.. I tested it, but it wont send the user to the main menu, which it did before i combined them. What I get with this, is if a user tries to login, wether the login/password are correct or not it takes them to a blank page. Man I wish the admin really wanted this all in seperate files, I would have been done already without all these headaches.. and I hate bugging you guysfunction user_login($username,$password) {
global $feedback;
if (!$username || !$password) {
$feedback .= ' ERROR - Missing user name or password ';
return false;
} else {
$username=strtolower($username);
$password=strtolower($password);
$sql="SELECT * FROM csys_users WHERE username='$username' AND password='$password';
$result=db_query($sql);
if (!$result || db_numrows($result) < 1){
$feedback .= ' ERROR - User not found or password incorect';
return false;
} else {
if (db_result($result,0,'is_active') == '1') {
$feedback .= '1';
main_menu($username,$password);
} else {
$feedback .= '0';
return false;
}
}
}
}
- RandomEngy
- Forum Contributor
- Posts: 173
- Joined: Wed Jun 26, 2002 3:24 pm
- Contact:
Change this:
To this:
I don't know if that's your only problem, since I have only worked with mysql databases.
Code: Select all
$sql="SELECT * FROM csys_users WHERE username='$username' AND password='$password';Code: Select all
$sql="SELECT * FROM csys_users WHERE username='$username' AND password='$password'";Thanks for the reply, noticed it right before I ran out the door for work and fixed it, sorry I didnt have time to post that I resolved the issue
*runs from you* hehe
Thanks a lot for all your help.. I've never made a PHP Script of this magnitude and kept it ALL in one file (aside from templates.php, database.php and config.php).
It's quite a different angle on PHP this way, learning new stuff, always a great sign 
*runs from you* hehe
Thanks a lot for all your help.. I've never made a PHP Script of this magnitude and kept it ALL in one file (aside from templates.php, database.php and config.php).