Tutorials
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Codewalkers ForumsOtherTutorials

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
  #1  
Old April 30th, 2002, 06:41 AM
primetime primetime is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Posts: 11 primetime User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Send a message via ICQ to primetime Send a message via AIM to primetime
News Script Tutorial Questions

Hey Guys,

I was doing the tutorial here on the site about News Script using PHP (btw, it rocks)

And I was wondering why I can't have new lines/paragraphs in the <textarea> field.

Thanks.

Reply With Quote
  #2  
Old April 30th, 2002, 06:02 PM
Anonymous Anonymous is offline
Registered User
Codewalkers God 35th Plane (22000 - 22499 posts)
 
Join Date: Apr 2007
Posts: 22,309 Anonymous User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 24
RE: News Script Tutorial Questions

You should be able to have newlines in the textarea. If you type them in, it will convert them to breaking returns so that it will display properly on an html page.

Reply With Quote
  #3  
Old May 1st, 2002, 05:15 AM
primetime primetime is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Posts: 11 primetime User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Send a message via ICQ to primetime Send a message via AIM to primetime
RE: News Script Tutorial Questions

Oh yeah..

What I'm basically thinkin' is that when the script finds a match between the stuff in the .dat file and the username and password entered by the poster, it'll stop the foreach loop and go to print the news post on the news.txt file.

But I don't know how to get out of the foreach loop

Reply With Quote
  #4  
Old May 1st, 2002, 05:22 AM
Anonymous Anonymous is offline
Registered User
Codewalkers God 35th Plane (22000 - 22499 posts)
 
Join Date: Apr 2007
Posts: 22,309 Anonymous User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 24
RE: News Script Tutorial Questions

You can use the break statement to get out of the foreach loop....

Reply With Quote
  #5  
Old May 1st, 2002, 05:26 AM
Anonymous Anonymous is offline
Registered User
Codewalkers God 35th Plane (22000 - 22499 posts)
 
Join Date: Apr 2007
Posts: 22,309 Anonymous User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 24
RE: News Script Tutorial Questions

break statement?

Reply With Quote
  #6  
Old May 1st, 2002, 09:43 AM
primetime primetime is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Posts: 11 primetime User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Send a message via ICQ to primetime Send a message via AIM to primetime
RE: News Script Tutorial Questions

w00t!

I found out the problem!

check out the script here
You'll have to register first

http://members.lycos.co.uk/initialdrive/scripts/register.php
http://members.lycos.co.uk/initialdrive/scripts/postnews.php

Thanks to the tutorial on your site, I learned more about PHP!


Reply With Quote
  #7  
Old May 1st, 2002, 10:13 AM
Anonymous Anonymous is offline
Registered User
Codewalkers God 35th Plane (22000 - 22499 posts)
 
Join Date: Apr 2007
Posts: 22,309 Anonymous User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 24
RE: News Script Tutorial Questions

Hey guys, I found out how to use that break statement

But I still have a problem, when I enter the right values, it doesn't evalute it right.

Here's a sample of my code and I also put comments on each line to specifically tell you what it does.

php Code:
Original - php Code
  1. <?
  2. // This is a script to check registered users against a flat-file database
  3. // It is modified from Matt's tutorial of a
  4. // News Posting Script from http://www.codewalkers.com
  5.  
  6. // Check to see if the "Submit" button was set
  7. if(isset($submit)):
  8.    
  9.     // Put the password submitted by the user into an md5() Hash
  10.     $pass = md5($password);
  11.    
  12.     // Put the submitted values (name and password) into an array
  13.     $user_sub = array($name,$pass);
  14.  
  15.     // Load the userdatabase file into an array for processing
  16.     $check = file('userdata.dat');
  17.    
  18.     // Reverse the array to check the latest entries first
  19.     $data = array_reverse($check);
  20.    
  21.     // Evaluate each line of the user database array as a specific content
  22.     foreach($check as $element) {
  23.    
  24.         // Trim spaces from the contents
  25.             $element = trim($element);
  26.                
  27.         // Break apart the values in the userdatabase that are
  28.         // separated by the pipe symbol and load these into an array
  29.      $user_info = explode("|", $element);
  30.       
  31.         // Check if values of the userdatabase array and the
  32.         // user submitted array are the same
  33.         if($user_info == $user_sub):
  34.                
  35.             // Stop the foreach loop
  36.             break;
  37.                
  38.             // Print out the results
  39.             echo "<br>There is a match in the user database.";
  40.         else:
  41.             echo "You are not in the database.";
  42.                
  43.         // Finish checking the values of both arrays
  44.         endif;
  45.         }
  46. else:
  47. echo "Please enter your username and password<br>";
  48. endif;     
  49. ?>
  50. <form action="<?=$PHP_SELF?>" method="post" name="check">
  51. Name: <input type="text" size="20" name="name"><br>
  52. Password: <input type="password" size="20" name="password"><br>
  53. <input type="submit" name="submit" value="Submit">
  54. </form>


Basically, it doesn't print out either:
"There is a match in the user database."

or

"You are not in the database."

Even if I input the right values for the username and pass.

Reply With Quote
  #8  
Old May 1st, 2002, 10:14 AM
primetime primetime is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Posts: 11 primetime User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Send a message via ICQ to primetime Send a message via AIM to primetime
RE: News Script Tutorial Questions

Hey guys, I'm trying to modify some of the News Script tutorial to have users register first before posting news

What I basically did is make a register page for the user and the username and pass are entered into a .dat file

What I'm trying to do is to see if the username and password that the poster entered matches any of the username (with the corresponding password) before he/she is allowed to post.

But I'm stumped 'cause of the foreach function because it keeps looping for every line that's in the .dat file

Is there a better way to evaluate the username and pass to see if they match?

Here's some of the code that I've been workin' on.
php Code:
Original - php Code
  1.  
  2. <?
  3.     $name = "username";
  4.     $password = "password";
  5.     $pass = md5($password);
  6.     $user_sub = array($name,$pass);
  7.  
  8.     $check = file('userdata.dat');
  9.     $data = array_reverse($check);
  10.     foreach($check as $element) {
  11.             $element = trim($element);
  12.      $user_info = explode("|", $element);
  13.         // Check if values are the same
  14.         if($user_info = $user_sub):
  15.         }
  16.                 $fp = fopen('news.txt','a');
  17.                 if(!$fp) {
  18.                         echo "Error opening file!";
  19.                         exit;
  20.                 }
  21.                 $line = date("D F d, Y @ h:ia") . "|" . $name;
  22.                 $line .= "|" . $news;
  23.                 $line = str_replace("rn","<BR>",$line);
  24.                 $line .= "rn";
  25.                 fwrite($fp, $line);
  26.                 if(!fclose($fp)) {
  27.                         echo "Error closing file!";
  28.                         exit;
  29.             }
  30.             else:
  31.                 echo "You are not in the database.";
  32.             endif;     
  33. ?>


Reply With Quote
  #9  
Old June 9th, 2002, 05:13 PM
Anonymous Anonymous is offline
Registered User
Codewalkers God 35th Plane (22000 - 22499 posts)
 
Join Date: Apr 2007
Posts: 22,309 Anonymous User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 24
RE: News Script Tutorial Questions

Can you show me what the php-filke looks like now? What was the problemP

Reply With Quote
Reply

Viewing: Codewalkers ForumsOtherTutorials > News Script Tutorial Questions


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

 Free IT White Papers!