Jump to content

Joe Sai

Members
  • Posts

    34
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

Joe Sai's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. Ok, I'm an idiot. One big problem was relabeling everything, which I've done here: <?php $lines = file('telephonedirectory.txt'); foreach ($lines as $line_num => $line) { echo "Line #<b>{$line_num}</b> : " . htmlspecialchars($line) . "<br />\n"; $lines = explode(', ', $line); echo $line[0]; } ?> Now my problem is still getting just the last name, first name, and phone number to appear. I have line[0] on there, but it still displays everything instead of just one part. It's kind of confusing me. This is what shows up when I run the directory with made up entries: I don't know where the S, J, and C came from, and I still can't get it just to display the names and phone numbers. :/
  2. Like this? <?php $lines = file('telephonedirectory.txt'); foreach ($lines as $line_num => $line) { echo $item[0]; echo "Line #<b>{$line_num}</b> : " . htmlspecialchars($line) . "<br />\n"; $item = explode(', ', $line); } ?> It's giving me a lot of problems. I made up entries for the directory, and it's duplicating them and going all crazy! This is what happens when I open it: Line 15 is echo $item[0];
  3. Thank you soooo much! I've spent like 20 hours on this, if not more, and it's making me want to pull my hair out, I really am having a hard time, especially since this is my first php class and I know nothing about it. Ok, so the code worked for the most part, but I guess I'm not putting the echo in the right place. I put it after my other echo, but should I have two echos? I keep getting an error that says undefined variable, I'm probably putting it in the wrong place. This is what I did <?php $lines = file('telephonedirectory.txt'); foreach ($lines as $line_num => $line) { echo "Line #<b>{$line_num}</b> : " . htmlspecialchars($line) . "<br />\n"; echo $item[0]; $item = explode(', ', $line); } ?>
  4. Is there anyone that can help me with that?
  5. Thanks so much for your help! I really had a hard time understanding it, but it's making more sense now. I do, however, have another question. You said that I could make $item[0] the Last Name, but how? If I just put $item[0], it won't know that I'm talking about the last name, and I'm not sure how to tell it.
  6. Ok, so I asked for help last week and am grateful for what I did get, but I still couldn't figure it out, and this assignment is a few days late. I'm trying to get it done today so I can work on my new assignment tomorrow, and I'd really, really appreciate the help. I think the problem I had was that I tried to make the file open into a table without reading it as an array first, so after researching some guides, I was able to do much better. So here is what I have so far: Telephone Directory HTML Form: <body> <h2>Enter your information into our telephone directory!</h2> <form method="get" action="../TelephoneDirectory.php"> <p>Last Name <input type="text" name="last_name" /></p> <p>First Name <input type="text" name="first_name" /></p> <p>Street Address <input type="text" name="street_address" /></p> <p>City <input type="text" name="city" /></p> <p>State <input type="text" name="state" /></p> <p>Zip <input type="text" name="zip" /></p> <p>Area Code <input type="text" name="area_code" /></p> <p>Phone Number <input type="text" name="phone_number" /></p> <p><input type="submit" value=" Submit" /></p> </form> <p><a href="../ShowData.php">Show Data</a></p> <p><a href="../ShowDirectory.php">Show Directory</a></p> </body> </html> Telephone Directory PHP: <body> <?php if (empty($_GET['first_name']) || empty($_GET['last_name']) || empty($_GET['street_address']) || empty($_GET['city']) || empty($_GET['state']) || empty($_GET['zip']) || empty($_GET['area_code']) || empty($_GET['phone_number'])) echo "<p>You must enter all information! Click your browser's Back button to return to the Telephone Directory form.</p>"; else { $FirstName = addslashes($_GET['first_name']); $LastName = addslashes($_GET['last_name']); $StreetAddress = addslashes($_GET['street_address']); $City = addslashes($_GET['city']); $State = addslashes($_GET['state']); $Zip = addslashes($_GET['zip']); $AreaCode = addslashes($_GET['area_code']); $PhoneNumber = addslashes($_GET['phone_number']); $TelephoneDirectory = fopen("telephonedirectory.txt", "a"); if (is_writable("telephonedirectory.txt")) { if (fwrite($TelephoneDirectory, $LastName . "," . $FirstName . "," . $StreetAddress . "," . $City . "," . $State . "," . $Zip . "," . $AreaCode . "-" . $PhoneNumber . "\n")) echo "<p>Thank you for signing our Telephone Directory!</p>"; else echo "<p>Cannot add your entry to the directory.</p>"; } else echo "<p>Cannot write to the file.</p>"; fclose($TelephoneDirectory); } ?> </body> </html> And finally, the part I need help with, opening the information from the form: <body> <?php $lines = file('telephonedirectory.txt'); foreach ($lines as $line_num => $line) { echo "Line #<b>{$line_num}</b> : " . htmlspecialchars($line) . "<br />\n"; } ?> </body> </html> So far so good with it opening it into an array; however, I can't get it to do some other things. It's displaying all of the information from the form, but I only want it to show the last name, first name, and phone number. Also, I need it to be alphabetical as well, according to last name, and the hardest part is that I also need all this information to be displayed into a two column table instead of just listed. I'm still looking up guides, and I think I have a good start, but I'm really having some trouble, and i would greatly appreciate some help, even if just a little. Thank you so much.
  7. Thanks for responding. I used one of their guides to help me with the table, which I posted above, but it's giving me those errors and I don't understand why.
  8. Ok, well I'm about to leave for work, I hope someone can help me before I get back. I am really stumped. :/
  9. Thank you for your response, but I'm not sure how to do that. Like I said, I'm new to PHP, so I need some more specifics. So in the errors I posted before, do I need to type in "explode" instead of HTML_Table that it was not reading? I'm sorry, but I don't understand what you're saying, I need things babied down a bit I guess. I'm trying my best here, so please try to be patient with me. I really appreciate your help.
  10. Any comments at all? I feel like I'm being ignored here and I am very confused, I really, really need some help please.
  11. Anybody have any idea what's wrong? I'm confused and I desperately need help, it's 2AM and I have work in the morning, I really need help. :/
  12. Ok, I've worked on the table a little to get it to display, and now I'm getting a little bit of problems. Here is my code: <?php require_once 'telephonedirectory.txt'; $attrs = array('width' => '600'); $table = new HTML_Table($attrs); $table->setAutoGrow(true); $table->setAutoFill('n/a'); for ($nr = 0; $nr < count($data); $nr++) { $table->setHeaderContents($nr+1, 0, (string)$nr); for ($i = 0; $i < 4; $i++) { if ('' != $data[$nr][$i]) { $table->setCellContents($nr+1, $i+1, $data[$nr][$i]); } } } $altRow = array('bgcolor' => 'red'); $table->altRowAttributes(1, null, $altRow); $table->setHeaderContents(0, 0, ''); $table->setHeaderContents(0, 1, 'Name'); $table->setHeaderContents(0, 2, 'Phone Number'); $hrAttrs = array('bgcolor' => 'silver'); $table->setRowAttributes(0, $hrAttrs, true); $table->setColAttributes(0, $hrAttrs); ?> I found this from a php help site regarding tables. When I put this in I got an error on line 13 saying: I tried changing it to 'telephonedirectory.txt' and then got this message: This is really throwing me for a loop. Oh, and abaz, I'm not exactly sure how to do all that, I'm really new at this.
  13. Ok guys, back yet again, sorry for bothering you. Anyway, I want to thank you all soooo much for helping me last week with my telephone directory project. Everything worked out perfectly once you pointed out my errors. Now I'm working with arrays. These are the directions for what I have to do from here: Ok, so some of this I've already got down with no problems, it's just some others I need help with. This is my Telephone Directory PHP code: <body> <?php if (empty($_GET['first_name']) || empty($_GET['last_name']) || empty($_GET['street_address']) || empty($_GET['city']) || empty($_GET['state']) || empty($_GET['zip']) || empty($_GET['area_code']) || empty($_GET['phone_number'])) echo "<p>You must enter all information! Click your browser's Back button to return to the Telephone Directory form.</p>"; else { $FirstName = addslashes($_GET['first_name']); $LastName = addslashes($_GET['last_name']); $StreetAddress = addslashes($_GET['street_address']); $City = addslashes($_GET['city']); $State = addslashes($_GET['state']); $Zip = addslashes($_GET['zip']); $AreaCode = addslashes($_GET['area_code']); $PhoneNumber = addslashes($_GET['phone_number']); $TelephoneDirectory = fopen("telephonedirectory.txt", "a"); if (is_writable("telephonedirectory.txt")) { if (fwrite($TelephoneDirectory, $LastName . "," . $FirstName . "," . $StreetAddress . "," . $City . "," . $State . "," . $Zip . "," . $AreaCode . "-" . $PhoneNumber . "\n")) echo "<p>Thank you for signing our Telephone Directory!</p>"; else echo "<p>Cannot add your entry to the directory.</p>"; } else echo "<p>Cannot write to the file.</p>"; fclose($TelephoneDirectory); } ?> </body> </html> And this is the html code for my telephone directory: <body> <h2>Enter your information into our telephone directory!</h2> <form method="get" action="../TelephoneDirectory.php"> <p>Last Name <input type="text" name="last_name" /></p> <p>First Name <input type="text" name="first_name" /></p> <p>Street Address <input type="text" name="street_address" /></p> <p>City <input type="text" name="city" /></p> <p>State <input type="text" name="state" /></p> <p>Zip <input type="text" name="zip" /></p> <p>Area Code <input type="text" name="area_code" /></p> <p>Phone Number <input type="text" name="phone_number" /></p> <p><input type="submit" value=" Submit" /></p> </form> <p><a href="../ShowData.php">Show Data</a></p> <p><a href="../ShowDirectory.php">Show Directory</a></p> </body> </html> Notice how I have "Show Data" and "Show Directory" on the bottom, which really isn't necessary to have both, but I'm doing it incase my professor wanted one without the array and one with. Anyway, I'm working on the PHP file for displaying the information in the directory, and I have this: <body> <?php if (is_writable("telephonedirectory.txt")) { echo "<p>The following visitors have entered our Telephone Directory:</p><pre>"; readfile("telephonedirectory.txt"); echo "</pre>"; } else echo "<p>Cannot write to the file.</p>"; ?> </body> </html> So at this point, it displays everything, and I only need it to display the last name, first name, and phone number. Moreover, I also need to make an html file as well to display the information in, but I'm not sure how to do that. I did one form for the genera directory where you input the information, but how would I go about making that form just to display the information in the two columns? I know this is probably something really easy and I'm being an idiot, but please bear with me, I'm trying really hard over here. Thanks for your help!
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.