Mysql help

Status
Not open for further replies.
Howdy y'all. I figure we have computer savvy people here who might know the issue.
I'm trying to do a simple login that checks a database. I've checked my variables 100 times so I know thats not the issue. Every time I run mysql-count-rows I just keep getting 0. If someone here knew what the issue was I'd appreciate it a ton.

PHP:
<?php
 
                $username = empty($_POST['username']) ? '' : $_POST['username'];
                $password = empty($_POST['password']) ? '' : $_POST['password'];
 
                $myhost = "my database host";
                $myuser = "my username";
                $mypsw = "my password";
                $mydb = "my database name";
                $dblink = mysql_connect($myhost, $myuser, $mypsw) or die("Error: cannot connect");
 
                $db_selected = mysql_select_db($mydb, $dblink) or die("Error: cannot select db");
                $query1 = "select S.sid from Sailors S where S.username = '".$username."' and S.password = '".$password."';";
 
                if (mysql_num_rows($query1, $dblink) != 0)
                {
                        setcookie('username', $username);
                        header("Location: main.php");
                }
?>
 
Have you tried running that SQL query against the database by hand? I usually have the page give me the finished query with variables inserted, then cut and paste that into a MySQL interface connected to the db, like phpmysql, and see what the results are.

I agree your code looks good, I suspect the query is munged in some small way.
 
Yeah...I'm an idiot. The query is fine. I just plugged it into the count rows. You know, instead of the result of running the query.

It does make me feel better that no one else caught it though. Thanks for your help.
 
Ok, one more if you're willing. How do I enter a date (not a datetime) into a table? I try the format '19980720' for July 20th 1998, but it doesnt work.
 
Ok, one more if you're willing. How do I enter a date (not a datetime) into a table? I try the format '19980720' for July 20th 1998, but it doesnt work.
Check out http://stackoverflow.com/questions/12120433/php-mysql-insert-date-format for a long version of the following:

Yes, what you're doing should work, but there are all sorts of minor problems with taking that shortcut. You might want to use a function to convert your dates into the right format explicitly, rather than having mysql convert it for you, that way you're catching php errors, rather than mysql errors, when the data is wrong.

PHP:
INSERT INTO user_date VALUES ('', '$name', STR_TO_DATE('$date', '%m/%d/%Y'))
 
Status
Not open for further replies.
Top