Jump to content

ZombieToast

New Members
  • Posts

    9
  • Joined

  • Last visited

Profile Information

  • Gender
    Not Telling

ZombieToast's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. I doubt anyone cares, but I found the solution to my main issue. I thought the problem was with reading the array, but it was actually with writing it. On the array-writing page, I had this variable: $Notes = addslashes($_GET['notes']); Underneath it, I added this: $Notes = str_replace("\r\n", "<br />", $Notes); And now it does exactly what I need. When a return is entered, str_replace converts it to a line break. This was giving me so much trouble because instead of doing this, I was trying to make my script read the \r\n returns and interpret them as line breaks. How silly of me.
  2. Thank you for the great suggestion. I hadn't even thought of colspan! Doing it exactly like that didn't fix my table, but adjusting/customizing the colspan of each section helped me get a nice clean look. It doesn't look exactly how I would like it to, but it's much better and certainly good enough to keep. Thanks again. Now, if I can just figure out how stop the multi-line Notes from messing up my page, I'll be set. If anyone's interested, here's my updated script... $HouseArray = file("houselist.txt"); $HouseArray = array_unique($HouseArray); sort($HouseArray); for ($i=0; $i<count($HouseArray); ++$i) { $Row = explode("__", $HouseArray[$i]); echo "<table width='60%' border='1'>"; echo "<tr><td colspan='4'><strong>Price:</strong> " . stripslashes($Row[0]) . "</td></tr>"; echo "<tr><td colspan='4'><img src='pics/" . stripslashes($Row[1]) . ".jpg'></td></tr>"; echo "<tr><td colspan='1'><strong>Park Name:</strong><br />" . stripslashes($Row[2]) . "</td>"; echo "<td colspan='2'><strong>Address:</strong><br />" . stripslashes($Row[3]) . "</td>"; echo "<td colspan='1'><strong>Phone #:</strong><br />" . stripslashes($Row[4]) . "</td></tr>"; echo "<tr><td colspan='1'><strong>Built:</strong> " . stripslashes($Row[5]) . "</td>"; echo "<td colspan='3'><strong>MLS #:</strong> " . stripslashes($Row[6]) . "</td></tr>"; echo "<tr><td colspan='4'><strong>Monthly Dues:</strong> " . stripslashes($Row[7]) . "</td></tr>"; echo "<tr><td colspan='1'><strong>Bedrooms:</strong><br />" . stripslashes($Row[8]) . "</td>"; echo "<td colspan='1'><strong>Bathrooms:</strong><br />" . stripslashes($Row[9]) . "</td>"; echo "<td colspan='1'><strong>House Size:</strong><br />" . stripslashes($Row[10]) . " sq. ft.</td>"; echo "<td colspan='1'><strong>Lot Size:</strong><br />" . stripslashes($Row[11]) . " sq. ft.</td></tr>"; echo "<tr><td colspan='4'><strong>Notes:</strong><br />" . stripslashes($Row[12]) . "</td></tr>"; echo "<tr><td colspan='4'><strong>Link(s):</strong><br /><a href='" . stripslashes($Row[13]) . "'>" . stripslashes($Row[13]) . "</a><br /><a href='" . stripslashes($Row[14]) . "'>" . stripslashes($Row[14]) . "</a><br /><a href='" . stripslashes($Row[15]) . "'>" . stripslashes($Row[15]) . "</a></td></tr>"; echo "<tr><td colspan='4'><strong>Seen in person?</strong> " . stripslashes($Row[16]) . "</td></tr>"; echo "<tr><td colspan='4'><strong>Additional Notes:</strong><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /></td></tr>"; echo "</table><br /><br /><br /><hr /><br /><br /><br />"; }
  3. I'm really hoping someone can help me out here. My fiancé and I are looking for a house and I thought it would help make things a bit more convenient if I created a mini-site for us to keep track of properties that we want to consider. I could easily do this with HTML, but I wanted to put some of my [limited] PHP knowledge to use. At the moment, I have three pages: a form for entering house information, a php script to process the form (and add it to a text file on my server), and a page to display all entered houses. Most of it is actually working how I want it to, but I'm having a few minor problems. The main one is that I can't get my table to display properly. See here for an example. I want each row to extend to the full width. Is there a better way to build my table? Another big problem is that if I enter more than one line into my Notes textarea box, it screws everything up (take a look at my page to see what I mean). Is there a way to fix this without having to manually enter a line break when I type in the data? At the moment, those are the only issues I'm having. The main one I would like to fix is the display of my tables. Thankfully, the script itself works without any issues (other than the Notes textarea that I mentioned). Here is the script from my showhouses.php page... $HouseArray = file("houselist.txt"); $HouseArray = array_unique($HouseArray); sort($HouseArray); for ($i=0; $i<count($HouseArray); ++$i) { $Row = explode("__", $HouseArray[$i]); echo "<table width='80%' border='1'>"; echo "<tr><td><strong>Price:</strong> " . stripslashes($Row[0]) . "</td></tr>"; echo "<tr><td><img src='pics/" . stripslashes($Row[1]) . ".jpg'></td></tr>"; echo "<tr><td><strong>Park Name:</strong><br />" . stripslashes($Row[2]) . "</td>"; echo "<td><strong>Address:</strong><br />" . stripslashes($Row[3]) . "</td>"; echo "<td><strong>Phone #:</strong><br />" . stripslashes($Row[4]) . "</td></tr>"; echo "<tr><td><strong>Built:</strong> " . stripslashes($Row[5]) . "</td>"; echo "<td><strong>MLS #:</strong> " . stripslashes($Row[6]) . "</td></tr>"; echo "<tr><td><strong>Monthly Dues:</strong> " . stripslashes($Row[7]) . "</td></tr>"; echo "<tr><td><strong>Bedrooms:</strong><br />" . stripslashes($Row[8]) . "</td>"; echo "<td><strong>Bathrooms:</strong><br />" . stripslashes($Row[9]) . "</td>"; echo "<td><strong>House Size:</strong><br />" . stripslashes($Row[10]) . " sq. ft.</td>"; echo "<td><strong>Lot Size:</strong><br />" . stripslashes($Row[11]) . " sq. ft.</td></tr>"; echo "<tr><td><strong>Notes:</strong><br />" . stripslashes($Row[12]) . "</td></tr>"; echo "<tr><td><strong>Link(s):</strong><br /><a href='" . stripslashes($Row[13]) . "'>" . stripslashes($Row[13]) . "</a><br /><a href='" . stripslashes($Row[14]) . "'>" . stripslashes($Row[14]) . "</a><br /><a href='" . stripslashes($Row[15]) . "'>" . stripslashes($Row[15]) . "</a></td></tr>"; echo "<tr><td><strong>Seen in person?</strong> " . stripslashes($Row[16]) . "</td></tr>"; echo "<tr><td><strong>Additional Notes:</strong><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /></td></tr>"; echo "</table><br /><br /><br /><hr /><br /><br /><br />"; }
  4. Actually, nevermind. All it took was a simple for loop and now everything's working exactly how I want. Thanks a lot!
  5. Thanks a bunch for the help. I can't believe I didn't notice how I was separating the strings. I changed my fwrite so it would use tildes and now the script works just fine. When I tried using preg_match, it didn't change anything, but I'm not familiar with it, so I probably didn't do it right. As for regex...I was introduced to it in a JavaScript class, but that was awhile ago and we only touched on it briefly, so I'm not exactly well-versed on the matter. Anyway...the tildes make my script work, but when I display the entries on another page, they now show up as "LastName~FirstName~Email" when I use the following script... <?php $GuestBook = fopen("lab7guestbook.txt", "r"); if ($GuestBook) { while (!feof($GuestBook)) { $Visitor = fgets($GuestBook); $Visitor = stripslashes($Visitor); echo "<p>$Visitor</p>"; } echo "<p>Thank you!</p>"; } fclose($GuestBook); ?> I could just change the separators to commas instead of tildes and be done with the whole thing, but for my own personal knowledge, I'm wondering how I could modify the above code to get the strings to display in the "LastName, FirstName (Email)" format. These arrays are being a bit trickier than what I'm used to.
  6. Just for the heck of it, I tried print_r($CurMessage); and it displayed this... Array ( [0] => lname, fname (email) ) But if I understand correctly, it should be: Array ( [0] => lname [1] => fname [2] => email ) This gives me the impression that my field values aren't being read into the array properly because they're all being entered as one key instead of three. Of course, I don't know if I'm right and if I am, I'm not exactly sure how to fix this. Heh. If you have any input, I'd greatly appreciate it. For now, I must finally go to bed.
  7. Thanks for your comments; I'll update my code using your suggestion. If how the book has been going up until now is any indication, I'm sure more effective methods are on their way. Typically, it'll teach me all about a certain method and gradually introduce me to several other methods, each one more useful and effective than the last. This is basically just an introduction to reading from and writing to files in a database, as well as manipulating arrays. If I can't comprehend this fully, then I'm afraid I might have even more problems later on. The if statement that is giving me trouble is the file_exists (line 5). It isn't returning a value of TRUE when a field value (fname) already exists. I'm pretty sure the $_GET['fname'] (line 9) is related to the problem. If I replace it with $MessageArray[1], I get a value of TRUE. Of course, this will give me a value of TRUE no matter what is entered because it merely checks to see if a key exists in that position. I'm not sure if I'm making any sense with that. Basically, I think I'm either incorrectly loading the info into an array or I'm not exploding the array properly. But I'm really not sure because the concept is a bit unclear to me. What I need the script to do is check the values of $MessageArray[0] and $MessageArray[1]. Then if they contain the values of $_GET['lname'] and $_GET['fname'], $NameExists will become TRUE. I hope you get what I'm saying 'cause honestly, I'm starting to confuse myself. Ha.
  8. Thanks for taking a look. My script is relatively small; I just wanted to be cautious because I know some people can be pretty picky about rules. Heh. I'm still a beginner, so try to go easy on me if I've got this completely wrong and have blasphemed and spit in the face of all programmers... if (empty($_GET['fname']) || empty($_GET['lname']) || empty($_GET['email'])) echo "<p>You must fill out all fields! Click your browser's Back button to return to the form.</p>"; else { $NameExists = FALSE; if (file_exists("lab7guestbook.txt") && filesize("lab7guestbook.txt") > 0) { $MessageArray = file("lab7guestbook.txt"); for ($i=0; $i<count($MessageArray); ++$i) { $CurMessage = explode("~", $MessageArray[$i]); if (in_array($_GET['fname'], $CurMessage)) { $NameExists = TRUE; break; } } } if ($NameExists) echo "<p>You've already signed the guestbook!</p>"; else { $FirstName = addslashes($_GET['fname']); $LastName = addslashes($_GET['lname']); $Email = addslashes($_GET['email']); $GuestBook = fopen("lab7guestbook.txt", "a"); if (is_writable("lab7guestbook.txt")) { if (fwrite($GuestBook, $LastName . ", " . $FirstName . " (" . $Email . ")" . "\r\n")) echo "<p>Thank you for signing our guestbook!</p>"; else echo "<p>Cannot add your name to the guestbook.</p>"; } else echo "<p>Cannot write to the file.</p>"; fclose($GuestBook); } } The code starts off by checking verifying that the fname (first name), lname (last name), and email fields are all filled out. It then tries to check whether or not a name exists (I'm currently using $_GET['fname'] to try to test this). The last section then processes the data. This script is very similar to the one from the tutorial...of course, that could be what's messing me up. Thanks again to anyone willing to take a look at this. I've got to head over to my girlfriend's house, but I'll be working on this and checking back periodically while I'm there.
  9. I'm a beginner working with Don Gosselin's PHP Programming With MySQL and I was hoping someone could help me out a little with a certain case file (7-1 on page 361 for anyone who has the book). I've been catching onto all of this stuff without much trouble, but I seem to have caught a snag here. This particular case file wants me to create a guestbook that collects users' names and e-mail addresses, checks for existing names, removes duplicate entries, and displays the information in alphabetical order. That sounds pretty simple, but it's just not working out for me. My problem is that I can't get the script to check for existing names and alert the user if the name already exists. Right now, I have a $NameExists variable set to a value of FALSE. An if statements checks to make sure the .txt file exists, and if it does, it loads the file into an array (theoretically at least). Then I'm trying to make a for loop check the array for any instances of the user-entered name. When found, it changes $NameExists to TRUE. Another if statements checks to see if $NameExists is true, and if so, it displays an error message. Otherwise, the script executes normally and lets the information submit. While going through a similar exercise in the chapter, it worked out just fine. However, when I try it out on my own, it doesn't work at all. It would appear that the first if statement isn't working and $NameExists is maintaining its FALSE value because when I manually change it to TRUE, the script works. Any suggestions? The posting guidelines said to refrain from posting codes/scripts, so I'll obide to that unless anyone wants to see what I have. I'm still learning this stuff, so I don't know if I'm completely off-track or if I'm using improper syntax or what. Anyway, any help/suggestions would be appreciated.
×
×
  • 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.