Jump to content

Recommended Posts

I have a form outputting to the following script:

newspost.php

<HTML>
<BODY>
<?php
$user = $_POST('user');
$title = $_POST('title');
$content = nl2br(htmlentities($_POST('content')));
$pass = md5($_POST('pass'));
echo "lookit! something works";
if ($user = 'no') {
        $fail = 1;
        echo "<BR>No User Selected";
}
if ($title = '') {
        $fail = 1;
        echo "<BR>No Title Given";
}
if ($content = '') {
        $fail = 1;
        echo "<BR>Nothing to Post";
}
if ($pass != '66e6422bfdd2afd36400fbb0d57f104a') {
        $fail = 1;
        echo "<BR>Incorrect Password";
}
if ($fail != 1) {
        $main = file_get_contents('main.html');
        list($before, $after) = explode('<B>Latest News:</B><P>', $main);
        if ($user = 'dax') {
                $username = 'Mordax Praetorian';
                $back = 'grey';
                $pic = 'dax.png';
        }
        if ($user = 'emsem') {
                $username = 'Emsem Danceaholic';
                $back = 'orange';
                $pic = 'emsem.png';
        }
        if ($user = 'abseh') {
                $username = 'Abseh<sup>TM</sup>';
                $back = 'purp';
                $pic = 'abseh.png';
        }
        if ($user = 'j') {
                $username = 'Jonathan';
                $back = 'cyan';
                $pic = 'j.jpg';
        }
        $almost = array($before, "<B>Latest News:</B><P>/n/r<TABLE WIDTH=100%><TR><TD BACKGROUND='images/", $back, ".png' WIDTH='100'><IMG SRC='images", $pic, "></TD><TD BACKGROUND='images/", $back, ".png' WIDTH=20%>", $username, "</TD><TD BACKGROUND='images/", $back, ".png'><B>", $title, "</B></TD><TD BACKGROUND='images/", $back, ".png' WIDTH=10%>", date(jS M Y), "</TD></TR></TABLE><BR>", $content, "<P>/n/r", $after);
        $there = implode("", $almost);
        $file = fopen('main.html',wt);
        fwrite($file, $there);
        fclose($file);
}
?>
</BODY>
</HTML>

 

The problem is that no matter what information is passed to the script through the form, it does nothing

 

I get a blank page, and main.html remains unaltered

 

What really gets me, is that even the first echo command doesn't work

 

whats wrong with my code?

Link to comment
https://forums.phpfreaks.com/topic/84212-solved-making-newsposts/
Share on other sites

it seems that your using the $_POST super globals the wrong way.

 

$user = $_POST('user');

$title = $_POST('title');

$content = nl2br(htmlentities($_POST('content')));

$pass = md5($_POST('pass'));

 

try changing all the $_post() to $_POST['var']

 

ex: $_POST['user'];

 

 

 

 

Ok, I started running the script in bits to see where the problem was

 

I got this far:

 

<HTML>
<BODY>
<?php
$user = $_POST['user'];
$title = $_POST['title'];
$content = nl2br(htmlentities($_POST['content']));
$pass = md5($_POST['pass']);
echo $user;
if ($user = "no") {
        $fail = 1;
        echo "<BR>No User Selected";
}
?>
</BODY>
</HTML>

 

The code does output, which is good, however the If command does not work

 

When I change which user is outputted by the form, the first echo command changes to match, however the contents of the IF command run weather the user is "no" or otherwise

 

what is going on?

 

 

thanks, that fixed that one

 

by process of elimination, I have determined that this line:

$almost = array($before, "<B>Latest News:</B><P>/n/r<TABLE WIDTH=100%><TR><TD BACKGROUND='images/", $back, ".png' WIDTH='100'><IMG SRC='images", $pic, "></TD><TD BACKGROUND='images/", $back, ".png' WIDTH=20%>", $username, "</TD><TD BACKGROUND='images/", $back, ".png'><B>", $title, "</B></TD><TD BACKGROUND='images/", $back, ".png' WIDTH=10%>", date(jS M Y), "</TD></TR></TABLE><BR>", $content, "<P>/n/r", $after);

 

Is the reason for the blank screen problem... should have seen that one comming really

 

Guess I'll read up on array functions and then go about this in a more convoluted method

HELL YES!!

 

I have a working programme

 

Thannkyou, all of you

 

The idea is to put all the peices of the webpage into an array and then implode() them all into a string

 

I know theres probably a function for linking strings together somewhere, but I have no clue how to do it

 

in any case, the programme works, and I will be giving these forums some serious credit when I get around to making that part of the site

 

thankyou again

To concatenate strings you use the "." operator.

 

In your case:

<?php
$almost = $before . "<B>Latest News:</B><P>\r\n<TABLE WIDTH=100%><TR><TD BACKGROUND='images/" . $back . ".png' WIDTH='100'><IMG SRC='images" . $pic . "></TD><TD BACKGROUND='images/" . $back . ".png' WIDTH=20%>" . $username, "</TD><TD BACKGROUND='images/" . $back . ".png'><B>" . $title . "</B></TD><TD BACKGROUND='images/" . $back . ".png' WIDTH=10%>" . date(jS M Y) . "</TD></TR></TABLE><BR>" . $content . "<P>\r\n" . $after;
?>

 

Ken

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.