View previous topic :: View next topic |
Author |
Message |
longbow
Joined: 18 Feb 2004 Posts: 12 Location: mass
|
Posted: Wed Feb 18, 2004 7:16 am Post subject: php / mysql problem |
|
|
hello im new to php and i was trying to make a script to have a log in to view certian files and other stuff but when i got doen tinkering around with my script i ended up with this:
<?PHP
$conn = mysql_connect("localhost","user_name","password");
mysql_select_db("test",$conn);
$log = "SELECT FROM list values ('',$_POST[user])";
if ( $log === true ){
$dirname = ".";
$dh = opendir($dirname) or die("couldn't open directory");
while (!(($file = readdir($dh)) === false)) {
if (is_dir("$dirname/$file")) {
print "<a href= (D) > </a>";
}
print "<a href= $file>$file</a><br>";
}
closedir($dh);
} else {
print "<a href= \"register\">Please register here to veiw the files</a>";
}
?>
the problem is that i cant get it to view a listing of the DIR all it does is skip over that and goes strait to the last print statement. i have a learn php / mysql / apache in 24 hours book by sams that i have been reading to learn php and i couldnt find anything in the book on why it would do this. if anyone has any ideas please post a reply
the link to the location of the orignal script is http://www.macssuck.biz/longbow/test/
thank you
longbow _________________ the best acceleration you can get on a mac is 9.8m/s. |
|
Back to top |
|
 |
stevem
Joined: 15 Mar 2003 Posts: 369
|
Posted: Wed Feb 18, 2004 2:52 pm Post subject: |
|
|
Try removing the extra = sign so === becomes == in the line
Code: | while (!(($file = readdir($dh)) === false)) { |
|
|
Back to top |
|
 |
longbow
Joined: 18 Feb 2004 Posts: 12 Location: mass
|
Posted: Wed Feb 18, 2004 7:00 pm Post subject: |
|
|
still no result
i forgot to add that the temp user name for this page i am building is "longbow" without the quotes _________________ the best acceleration you can get on a mac is 9.8m/s. |
|
Back to top |
|
 |
stevem
Joined: 15 Mar 2003 Posts: 369
|
Posted: Thu Feb 19, 2004 7:37 pm Post subject: |
|
|
Just realised that there is another === which could be the cause in the line Code: | if ( $log === true ){ | Again replace === by ==
The if condition would always be false using === so the program will go to the print after else. |
|
Back to top |
|
 |
Guest
|
Posted: Fri Feb 20, 2004 12:05 am Post subject: |
|
|
now it only shows the dir list
with this
Code: | if ( $log == true ){ |
|
|
Back to top |
|
 |
longbow
Joined: 18 Feb 2004 Posts: 12 Location: mass
|
Posted: Fri Feb 20, 2004 12:06 am Post subject: |
|
|
opps for got to log in
Anonymous wrote: | now it only shows the dir list
with this
Code: | if ( $log == true ){ |
|
_________________ the best acceleration you can get on a mac is 9.8m/s. |
|
Back to top |
|
 |
stevem
Joined: 15 Mar 2003 Posts: 369
|
Posted: Fri Feb 20, 2004 12:27 am Post subject: |
|
|
That must mean an error in Code: | $log = "SELECT FROM list values ('',$_POST[user])"; | as $log is always true.
If $_post[user] has the value longbow then the line says
Code: | $log = "SELECT FROM list values (",longbow)"; |
which doesn't make much sense to me. It has a comma and 3 quotes which can't be correct. You may mean:
Code: | $log = "SELECT FROM list values(".$_POST[user].")"; |
which becomes
Code: | $log = "SELECT FROM list values(longbow)"; |
though without seeing your table it is hard to tell.
If you could export the table (removing any sensitive data) and copy it here it may be possible to see what you are trying to SELECT. |
|
Back to top |
|
 |
longbow
Joined: 18 Feb 2004 Posts: 12 Location: mass
|
Posted: Fri Feb 20, 2004 6:11 am Post subject: |
|
|
and how would i go about and export the tables?
ive only been doing PHP and SQL for about 5 months _________________ the best acceleration you can get on a mac is 9.8m/s. |
|
Back to top |
|
 |
stevem
Joined: 15 Mar 2003 Posts: 369
|
Posted: Fri Feb 20, 2004 11:06 am Post subject: |
|
|
Use phpMyAdmin. You may already have it in the Control Panel for your server, but if not, you can download it from http://www.phpmyadmin.net
It will give you a view of your databases and will allow you to make manual changes, export tables and lots and lots of other facilities.
Exporting will give you something like this (taken from the demo at http://www.phpmyadmin.net/phpMyAdmin/ . Select the table and press Export then Go):
Quote: | #
# Table structure for table `PMA_bookmark`
#
CREATE TABLE `PMA_bookmark` (
`id` int(11) NOT NULL auto_increment,
`dbase` varchar(255) NOT NULL default '',
`user` varchar(255) NOT NULL default '',
`label` varchar(255) NOT NULL default '',
`test` text NOT NULL,
PRIMARY KEY (`id`,`label`),
FULLTEXT KEY `test` (`test`)
) TYPE=MyISAM COMMENT='Bookmarks' AUTO_INCREMENT=4 ;
#
# Dumping data for table `PMA_bookmark`
#
INSERT INTO `PMA_bookmark` VALUES (1, '日本語', '', '', '');
INSERT INTO `PMA_bookmark` VALUES (2, 'good', 'jake', 'great', 'first now is the time for all good men to come to the aid of their country');
INSERT INTO `PMA_bookmark` VALUES (3, '[email protected]', '', '', ''); |
This will show how the table is made up and help decide what the SELECT statement should be.
Evene better, in the table in phpMyAdmin, if you press SQL you can try out Code: | SELECT FROM list values(longbow) | in the box. If the code is correct you will get the record(s) you want, if not it will give the wrong records or an error message. This will be a great help in getting the code correct. |
|
Back to top |
|
 |
Guest
|
|
Back to top |
|
 |
longbow
Joined: 18 Feb 2004 Posts: 12 Location: mass
|
Posted: Mon Feb 23, 2004 12:27 am Post subject: |
|
|
_________________ the best acceleration you can get on a mac is 9.8m/s. |
|
Back to top |
|
 |
stevem
Joined: 15 Mar 2003 Posts: 369
|
Posted: Mon Feb 23, 2004 6:49 pm Post subject: |
|
|
Difficult to see what is going on, except that you have a field called list in a table called list which is confusing.
I presume you have a list of passwords and you want to check that password is in the list field.
You need something like Code: | $log = "SELECT list FROM list WHERE list=='longbow'"; | then you look at the number of rows in $log to see if it is at least 1. So then you say Code: | if (mysql_num_rows($log)>0) { |
I can't be sure this is correct since I am not sure what is in the table, but if correct you can then replace 'longbow' by $_POST[user] |
|
Back to top |
|
 |
longbow
Joined: 18 Feb 2004 Posts: 12 Location: mass
|
Posted: Mon Feb 23, 2004 9:17 pm Post subject: |
|
|
i get this error
Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in c:\program files\apache group\apache\htdocs\longbow\test\login.php on line 5 _________________ the best acceleration you can get on a mac is 9.8m/s. |
|
Back to top |
|
 |
stevem
Joined: 15 Mar 2003 Posts: 369
|
Posted: Mon Feb 23, 2004 9:48 pm Post subject: |
|
|
Whoops, forgot to actually do the query
Code: | $log = "SELECT * FROM list WHERE list=='longbow'";
$result = mysql_query($sql);
if (mysql_num_rows($result)>0) { |
But I don't guarantee anything as I am a bit in the dark with the content of the table.
[Edited: should have had * instead of list in the select statement]
Last edited by stevem on Mon Feb 23, 2004 10:30 pm; edited 2 times in total |
|
Back to top |
|
 |
longbow
Joined: 18 Feb 2004 Posts: 12 Location: mass
|
Posted: Mon Feb 23, 2004 9:54 pm Post subject: |
|
|
ok im going to install phpmyadmin 2.5.4
i just need a little help with configuring the config.php file
it still isnt working im still getting that error message _________________ the best acceleration you can get on a mac is 9.8m/s. |
|
Back to top |
|
 |
|