rotten69 Posted May 9, 2011 Share Posted May 9, 2011 I'm using a simple shopping cart on my site and I want to implement functionality on the products page and details page (that contains details on the products basically) that reads the item information from an external file e.g. a txt file and I don't want to use any Database systems. So, for each item, I need to store: 1- the name 2- the image 3-the description 4-the price and I want the products page to generate a new row in the table for each item stored in the file. And, the details file should use the file to retrieve the info that should display. I think the best way of doing this is that implementing a function that reads the file into an array which can used by both the products page and details page. I'm just new to PHP and want some ideas on where to start really ... Cheers, Quote Link to comment https://forums.phpfreaks.com/topic/235896-need-help-with-io-file/ Share on other sites More sharing options...
sunfighter Posted May 9, 2011 Share Posted May 9, 2011 read this http://www.w3schools.com/php/php_ref_filesystem.asp Have a comma seperated file. Use fopen() - fgets() for single line input - explode to make array of single item - write HTML table code. Repeat till EOF. then fclose(). You should be able to write to a file, name the file copy delete and all kinds of good things to it. w3schools good to use. Quote Link to comment https://forums.phpfreaks.com/topic/235896-need-help-with-io-file/#findComment-1212670 Share on other sites More sharing options...
rotten69 Posted May 9, 2011 Author Share Posted May 9, 2011 Thanks for passing, buddy. I need an explanation on that if you can give one please. And, also what's a good idea to check if you have multiple usernames/ passwords in your log-in system? session_start(); $users = array("user1" =>"infs", "user2" =>"csse", "user3" =>"maths", "user4"=>"mmds", "user5"=>"csse"); $passwords = array("password1"=>"3202" "password2"=>"2002" "password3"=>"1061" "password4"=>"1400" "password5"=>"1001"); <-- my last idea and I don't know how I'm gonna use arrays .. If I was to use these arrays then How Would I make a username from $users correspond to a matching password in $passwords. if($_REQUEST['username'] == "guru" && $_REQUEST['password'] == "3202") || ($_REQUEST['username'] == "mad" && $_REQUEST['password'] == "2002") || ($_REQUEST['username'] == "lolo" && $_REQUEST['password'] == "1001") || ($_REQUEST['username'] == "chap" && $_REQUEST['password'] == "1061") || ($_REQUEST['username'] == "pal" && $_REQUEST['password'] == "1400"){ <<-- this is my first idea and for a username and password works, but for 5 sets of credentials doesn't work! $_SESSION['username'] = "guru" ; $_SESSION['password'] = "3202" ; $_SESSION['username'] = "mad" ; $_SESSION['password'] = "2002" ; $_SESSION['username'] = "lolo" ; $_SESSION['password'] = "1001" ; $_SESSION['username'] = "chap" ; $_SESSION['password'] = "1061" ; $_SESSION['username'] = "pal" ; $_SESSION['password'] = "1400" ; header("Location: home.php "); Your help is appreciated. Quote Link to comment https://forums.phpfreaks.com/topic/235896-need-help-with-io-file/#findComment-1212785 Share on other sites More sharing options...
sunfighter Posted May 10, 2011 Share Posted May 10, 2011 From above code it looks like your far more than a beginer. This may be too simple for you but here is an example of reading and displaying a cvs file with php: <?php $hd = fopen('personal.txt', 'r'); echo "<table border=\"1\" width=\"400px\""; for($i = 0; $i < 5; $i++) { $line = fgets($hd); $word = explode(',', $line); echo '<tr>'; echo '<td>'.$word[0].'</td>'; echo '<td>'.$word[1].'</td>'; echo '<td>'.$word[2].'</td>'; echo '<td>'.$word[3].'</td>'; echo '<br />'; echo '</tr>'; } fclose($hd); ?> Quote Link to comment https://forums.phpfreaks.com/topic/235896-need-help-with-io-file/#findComment-1213162 Share on other sites More sharing options...
rotten69 Posted May 10, 2011 Author Share Posted May 10, 2011 hahha.. Thanks mate. Well, Was that a complement? lol I modified the code you posted before and Here it is .. <?php $hd = fopen('content.txt', 'r'); $line = fgets($hd); $content = array(); while($line) { $word = explode(',', $line); $content [$word[0]] => array('img_path' => $word[1], 'description' => $word[2], 'price' => $word[3]); // the error message is indicating this line is broken!! Is it because of an equal sign missing? I tried putting an equal sign, but still it doesn't run. $line = fgets($hd); } fclose($hd); ?> This is a log-in system I'm trying to implement session_start(); $users = array("user1" =>"3202", "user2" =>"2002", "user3" =>"1061", "user4"=>"1400", "user5"=>"1001"); //So, inside the if statement .... Would that be $_REQUEST or GET or even isSet? if($_REQUEST['username'] == "user" && $_REQUEST['password'] == "3202"){ <-- This condition is NOT right.. and I don't really know how to re-set it up.. like how to check if the username is matching with its corresponding password $_SESSION['username'] = "user1" ; $_SESSION['password'] = "3202" ; $_SESSION['username'] = "user2" ; $_SESSION['password'] = "2002" ; $_SESSION['username'] = "user" ; $_SESSION['password'] = "1001" ; $_SESSION['username'] = "user3" ; $_SESSION['password'] = "1061" ; $_SESSION['username'] = "user4" ; $_SESSION['password'] = "1400" ; header("Location: home.php "); Cheers, Quote Link to comment https://forums.phpfreaks.com/topic/235896-need-help-with-io-file/#findComment-1213297 Share on other sites More sharing options...
rotten69 Posted May 11, 2011 Author Share Posted May 11, 2011 anyone can help me with this code PLEASE.. Quote Link to comment https://forums.phpfreaks.com/topic/235896-need-help-with-io-file/#findComment-1213578 Share on other sites More sharing options...
rotten69 Posted May 11, 2011 Author Share Posted May 11, 2011 I'm deadly desperate for the help.. Quote Link to comment https://forums.phpfreaks.com/topic/235896-need-help-with-io-file/#findComment-1213674 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.