Jump to content
Larry Ullman's Book Forums

michaela

Members
  • Posts

    5
  • Joined

  • Last visited

michaela's Achievements

Newbie

Newbie (1/14)

1

Reputation

  1. hi everyone, In the last 4 weeks I've spent A LOT of time with Larry's book and Lynda.com videos (pertaining to PHP). I want to thank Larry for making such a clear and linear guide for PHP beginners. But anyways, I'm working on a small script and I want to list the contents of a directory, make them into hyperlinks, and then edit those hyperlinks to look pretty (I.e. not show an ugly super long path name), then limit the number files echoed back to the browser. I was thinking about using this: <?php $path = "/full/path/to/files"; if ($handle = opendir($path)) { while (false !== ($file = readdir($handle))) { if ($file != "." && $file != "..") { $files .= '<a href="'.$file.'">'.$file.'</a>'; } } closedir($handle); } ?> or this: <?php $sub = ($_GET['dir']); $path = 'enter/your/directory/here/'; $path = $path . "$sub"; $dh = opendir($path); $i=1; while (($file = readdir($dh)) !== false) { if($file != "." && $file != "..") { if (substr($file, -4, -3) =="."){ echo "$i. $file <br />"; }else{ echo "$i. <a href='?dir=$sub/$file'>$file</a><br />"; } $i++; } } closedir($dh); ?> But I dont want to list the files like this: C:/example/example2/Hello.pdf I want to edit the variable. Is that possible? To make it say something as simple as "Hello." I want to limit the amount of files listed as well. For example: only list the first 5 files, or last 5, etc. Is there a function or some kind of parameter for that? I appreciate any help or push in the right direction. Thanks
  2. I did it! I've been messing with it forever and I finally figured out (with everyone's help above) that these were wrong: <?php mysqli_connect ('localhost', 'webuser', 'BroWsIng', 'temp'); ?> I think when I started I created a user: webuser with password browsing but I had no database named temp. Is there a file where I can find this: DEFINE ('DB_USER', 'root'); DEFINE ('DB_PASSWORD', 'mypassword'); DEFINE ('DB_HOST', 'localhost'); DEFINE ('DB_NAME', 'forum2'); I'm still a little unclear on where this comes from. So if I'm the only person on this computer I don' have to create a password? Could someone comment a little more on security. I read in the appendix that users shouldn't be granted all privileges. Anyone have a real world example for this? Shouldn't one user have all capabilities? Thanks
  3. Thank you guys for replying, I really appreciate it. I got lost at page A12 in the bonus apprendix. I created a new user in PhpMyadmin. Then I went to test and got a warning stated above. I think my database name is 'user.' I'm not sure what this is for: DEFINE ('DB_USER', 'root'); DEFINE ('DB_PASSWORD', 'mypassword'); DEFINE ('DB_HOST', 'localhost'); DEFINE ('DB_NAME', 'forum2'); // Make the connection: $dbc = mysqli_connect (DB_HOST, DB_USER, DB_PASSWORD, DB_NAME) OR die ('Could not connect to MySQL: ' . mysqli_connect_error() ); Sorry, I'm new at this. Could anyone explain?
  4. Thank you for responding. I went into the config.inc file in the phpMyadmin files and I placed the password in this line: $cfg['Servers'][$i]['password'] = 'mypassword'; And I went into phpMyadmin and matched up the passwords. And I still get an error when I run: <?php mysqli_connect ('localhost', 'webuser', 'BroWsIng', 'temp'); ?>
  5. I keep getting this error: Warning: mysqli_connect() [function.mysqli-connect]: (28000/1045): Access denied for user 'webuser'@'localhost' (using password: YES) in C:\xampp\htdocs\Untitled-2.php on line 10 when I run this script: <?php mysqli_connect ('localhost', 'webuser', 'BroWsIng', 'temp'); ?> I'm following the directions from bonus appendix. I went into the php.in file and checked my extentions. Everything matches up to the text and I'm not sure what I'm missing. Could someone help me? I would appreciate it a lot.
×
×
  • Create New...