Chief Delphi

Chief Delphi (http://www.chiefdelphi.com/forums/index.php)
-   Programming (http://www.chiefdelphi.com/forums/forumdisplay.php?f=51)
-   -   php/forms/posting/I NEED HELP!!!!!!!!! (http://www.chiefdelphi.com/forums/showthread.php?t=45184)

Adam Richards 17-03-2006 17:57

Re: php/forms/posting/I NEED HELP!!!!!!!!!
 
Quote:

Originally Posted by chris31
This code isnt very portable. Say they do a site resign all the posts would have to be manually redone becuase you saved all html and not just the pure data. I think that my way is more portable. Ill scrap together some code soon.

Then you edit the page so it uses a really basic syntax, and calls some classes from a seperate CSS file.

chris31 17-03-2006 18:04

Re: php/forms/posting/I NEED HELP!!!!!!!!!
 
Quote:

Originally Posted by Adam Richards
Then you edit the page so it uses a really basic syntax, and calls some classes from a seperate CSS file.

He asked for a php driven shoutbox and i think he (and any who feels like using the code) should be able to do whatever with it. Not be forced to use CSS. Anyways, heres some quick code.

PHP Code:

<html>
<head>
</head>
<body>
<?
if($HTTP_POST_VARS['submit'])
{

        if(!
$HTTP_POST_VARS['name'])
        {
            echo 
"You must enter a name";
            exit;
        }
        if(!
$HTTP_POST_VARS['post'])
        {
            echo 
"You must enter a post";
            exit;
        }
        if(!
$HTTP_POST_VARS['team'])
        {
            echo 
"You must enter a team";
            exit;
        }
        if(
strstr($HTTP_POST_VARS['name'],"|"))
        {
            echo 
"Name cannot contain the pipe symbol - |";
            exit;
        }
        if(
strstr($HTTP_POST_VARS['team'],"|"))
        {
            echo 
"Team cannot contain the pipe symbol - |";
            exit;
        }
        if(
strstr($HTTP_POST_VARS['post'],"|"))
        {
            echo 
"Post cannot contain the pipe symbol - |";
            exit;
        }


        
$fp fopen('data.txt','a');
        if(!
$fp)
        {
            echo 
"Error opening file!";
            exit;
        }
        
$line $HTTP_POST_VARS['name'] . "|" $HTTP_POST_VARS['team'] . "|" $HTTP_POST_VARS['post'];
        
$line str_replace("\r\n","<BR>",$line);
        
$line .= "\r\n";
        
fwrite($fp$line);
        if(!
fclose($fp))
        {
            echo 
"Error closing file!";
            exit;
        }
}
?>


<FORM ACTION="<?=$PHP_SELF?>" METHOD="POST" NAME="register" type="text">

<table border="1" cellpadding="0" cellspacing="0" style="border-collapse: collapse" bordercolor="#859FA7" width="500" 
align="center" height="200" bgcolor="#F2F2F2">
<td width="100%" align="center">
<table border="0" cellpadding="0" cellspacing="0" width="100%">
Register
<br>
<br>
<tr>
<table border="0" cellpadding="0" cellspacing="2" width="95%">
<tr><td bgcolor="#FFFFFF">Name:</td><td bgcolor="#FFFFFF"><input type="text" name="name"></td></tr>
<tr><td bgcolor="#FFFFFF">Team:</td><td bgcolor="#FFFFFF"><input type="text" name="team"></td></tr>
<tr><td bgcolor="#FFFFFF">Post:</td><td bgcolor="#FFFFFF"><input type="text" name="post"></td></tr>
<tr><td></td><td><input type="submit" name="submit" value="Post"></td></tr>
</table>
</td>
</tr>
</table>
</form>

</body>
</html>

PHP Code:

<?
$data 
file('data.txt');
foreach(
$data as $stuff
{
    
$parts explode("|"$stuff);
    echo 
"Name: " $parts[0] . "<br>\n";
    echo 
"Team: " $parts[1] . "<br>\n";
    echo 
"Post: " $parts[2] . "<br>\n" "<br>\n";
}
?>


MattD 17-03-2006 18:08

Re: php/forms/posting/I NEED HELP!!!!!!!!!
 
Quote:

Originally Posted by chris31
This code isnt very portable. Say they do a site resign all the posts would have to be manually redone becuase you saved all html and not just the pure data. I think that my way is more portable. Ill scrap together some code soon.

I agree with you (for the most part, because the posts could actually be redone by writing a program to modify the file, or just change them to be CSS dependent as Adam recommended). However I have been having a hard time trying to come up with a good way to store the data in a text file. Using a character like "|" as a delimiter could work, but what if the user wants to enter a "|" into their message?

I think XML would be a good storage method.

Example:
Code:

<quotes>
    <entry>
          <name>Matt</name>
          <team>228</team>
          <quote>Some random quote..</quote>
    </entry>
</quotes>

The problem with this of course is that it would be a pain to parse out, at least as far as I know, because I have no experience with using PHP and XML together. I should go and check my books and see if they have anything about it. If not, there's always Google)

Another option, I suppose, would be to use an INI-style storage method... though that could become problematic when new line characters are entered.
This reminds me that in my previous code I failed to handle those by replacing them with <br /> .. along with doing a bunch of other cleaning that I would normally do, like check for JavaScript and deal with HTML entities. And that's where this whole thing can get much more complicated than it would normally need to be - security, user formatting features, ensuring HTML validation, etc..

This is what happens after using a database server like MySQL all the time. I'm having such a hard time trying to figure out a good, reliable storage method besides just dumping HTML into a file.

chris31 17-03-2006 18:14

Re: php/forms/posting/I NEED HELP!!!!!!!!!
 
Using XML would definatly open up more options but it means the data has to be parsed and i have only ever done a little XML and PHP together. As for the problem with using the "|" charcter there is a simple solution. The PHP explode function uses a string, just pick something nobody will ever uses suck as "a2ufjf94u". It might not look pretty in you data file but it will do the trick.

MattD 17-03-2006 18:32

Re: php/forms/posting/I NEED HELP!!!!!!!!!
 
Quote:

Originally Posted by chris31
Using XML would definatly open up more options but it means the data has to be parsed and i have only ever done a little XML and PHP together. As for the problem with using the "|" charcter there is a simple solution. The PHP explode function uses a string, just pick something nobody will ever uses suck as "a2ufjf94u". It might not look pretty in you data file but it will do the trick.

http://keithdevens.com/software/phpxml

Looks like using XML could actually work, but I haven't tried using this yet. If I'm not doing anything tommorow (and possibly later tonight) I think I may want to play around with that.

Yay for learning (kind of) how to do new things.

general 17-03-2006 20:08

Re: php/forms/posting/I NEED HELP!!!!!!!!!
 
The code from the last page works at http://www.khsfirst.com/insert.php , but it only records one message.

general 17-03-2006 20:16

Re: php/forms/posting/I NEED HELP!!!!!!!!!
 
and theres some extra stuufffffff at the bottom

MattD 17-03-2006 20:20

Re: php/forms/posting/I NEED HELP!!!!!!!!!
 
Quote:

Originally Posted by general
The code from the last page works at http://www.khsfirst.com/insert.php , but it only records one message.

Oops..

On this line in insert.php:
PHP Code:

$hfile fopen("quotes.dat""r+"

Change the "r+" to be "a"

I also noticed that there looks to be some RTF stuff in there.. did you create this file with Wordpad? You can probably just delete it, the script will recreate the file when a quote is submitted.

As much as I don't want to admit it.. I actually did a pretty sloppy job on this. I will work on improving it sometime during this weekend.

chris31 17-03-2006 20:49

Re: php/forms/posting/I NEED HELP!!!!!!!!!
 
Might want to fix this http://www.khsfirst.com/quotes.php. Its looks like a mess. Also, the .dat is still being overwritten.

general 17-03-2006 21:35

Re: php/forms/posting/I NEED HELP!!!!!!!!!
 
where do i put quotes(" ") in the code so that they will show up around the quote on quotes.php?

general 17-03-2006 21:50

Re: php/forms/posting/I NEED HELP!!!!!!!!!
 
and can i have a href in the part where it says "thanks, your quote has been submited", or have it automaticly rediect to the quotes.php page?

MattD 18-03-2006 00:00

Re: php/forms/posting/I NEED HELP!!!!!!!!!
 
Quote:

Originally Posted by general
where do i put quotes(" ") in the code so that they will show up around the quote on quotes.php?

In input.php before it writes the quote to the file, add in &quot; before and after $quote like this:
PHP Code:

$write "the HTML that is already there &quot;" $quote "&quot; the other HTML that is already there"

Quote:

Originally Posted by general
and can i have a href in the part where it says "thanks, your quote has been submited", or have it automaticly rediect to the quotes.php page?

In input.php, replace the line that says echo "Thanks.. blah blah" with this:
PHP Code:

?>
<script type="text/javascript">
<!--
window.location = "quotes.php";
//-->
</script>
Thanks, your quote has been submitted. <br />
<a href="quotes.php">Please click here if you are not redirected.</a>
<?php


general 18-03-2006 15:12

Re: php/forms/posting/I NEED HELP!!!!!!!!!
 
Every time a ( ' ) is used, like in I'm theres a slash to.

MattD 18-03-2006 20:26

Re: php/forms/posting/I NEED HELP!!!!!!!!!
 
Quote:

Originally Posted by general
Every time a ( ' ) is used, like in I'm theres a slash to.

Ah.. ok in quotes.php try changing this line
PHP Code:

echo $contents

to this:
PHP Code:

echo stripslashes($contents); 


general 20-03-2006 15:21

Re: php/forms/posting/I NEED HELP!!!!!!!!!
 
yup that code worked, only two questions is there any way of limiting the words, not the amount, but like not allowing "$@#$@#$@#$@#" to be posted?

And, is there any way to send me an email that says there was a post?


All times are GMT -5. The time now is 22:59.

Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi