Hi ya'll, I'm new to php and I'm trying to work on a flat file news system.
So far, I have this script. I used some of it from another source.
I want it to open and write to shownews.php once you submit the form, but when I visit the page it's just shows up blank.
What am I doing wrong? And... is there a way to improve it?
I'm sorry if this is a n00bie question.
So far, I have this script. I used some of it from another source.
| Code: |
| <?php
if (!$_POST['submit']) { echo("<h2>Enter a news item</h2> <form method='post' action='$_SERVER[PHP_SELF]'> User:<br> <input type='text' name='user' size='30'>Administrator</input><p> News item:<br> <textarea cols='70' rows='8' name='news'></textarea><p> <input type='submit' name='submit' value='Add News' /></form>"); exit; } else { $user = $_POST['user']; $news = $_POST['news']; $errors = array(); //array for errors if (empty($user)) { //if host is empty $errors[] = "You Must Enter A User Name!"; //lol } //end host check if (empty($news)) { //user check $errors[] = "You Must Enter A News Article!"; //you fail o_0// } //end user check if (count($errors) > 0) { //if theres more then 0 errors print "<h2>Errors Found!</h2> <p>"; //error header foreach ($errors as $err) { //foreach error print $err . ''; } //end loop print "</p>"; exit(); if (!$cerror && !$derror) { $conf_handle = fopen('shownews.php', 'w+'); $data = "<table width='100%'><tr><td>Posted by $user </td><td width='80%'> $news </a>"; $write = @fwrite($conf_handle, $data); if ($write) { print "<h2>Success</h2> <p> Your news was added. </p>"; } ?> |
I want it to open and write to shownews.php once you submit the form, but when I visit the page it's just shows up blank.
What am I doing wrong? And... is there a way to improve it?
I'm sorry if this is a n00bie question.
