Jump to content

What am i doing wrong?


cry of war

Recommended Posts

i tried to get this code to load but it doesnt want to for some odd reason anyone know why?

 

<?php
$info = $_POST["info"];
$id = $_POST["id"];
if (!isset($_POST['submit'])) { // if page is not submitted to itself echo the form
?>
<html>
<head>
<title>Personal INFO</title>
</head>
<body>
<form action="<?php echo $PHP_SELF;?>" method="post">
PLEASE CLICK INSIDE OF THE SGW SPY LOG AREA AND PRESS CTRL+A THEN CTRL+C THEN CLICK IN THE TEXT AREA BELOW WHERE IT SAYS "INSERT HERE".
<textarea rows="20" cols="20" name="info" wrap="physical">INSERT HERE</textarea><br />
ENTER ID: <INPUT TYPE="TEXT" name="id" value="id">INPUT ID HERE</INPUT>
<input type="submit" value="submit" name="submit"><input>
</form>
<?PHP
} else {
$wordChunks = explode(" ", $info);
for($i = 0; $i < count($info); $i++){
echo "Piece $i = $wordChunks[$i] <br />";
}
}
?>
</body>
</html>

Link to comment
https://forums.phpfreaks.com/topic/61012-what-am-i-doing-wrong/
Share on other sites

You have some invalid HTML issues, input tags do not have closing tags. So removeclosing tags for inputs (</input>)

 

Also your for loop needs to be this:

for($i = 0; $i <= count($info); $i++){

Notice the equals sign added after the the less than sign. With the way you have it PHP will never get to the last item within loop, for example it will only loop 7 times if there was 8 items within the array.

 

Working code:

<?php
// if page is not submitted to itself echo the form
if (!isset($_POST['submit']))
{
?>
<html>
<head>
<title>Personal INFO</title>
</head>
<body>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
PLEASE CLICK INSIDE OF THE SGW SPY LOG AREA AND PRESS CTRL+A THEN CTRL+C THEN CLICK IN THE
TEXT AREA BELOW WHERE IT SAYS "INSERT HERE".
<textarea rows="20" cols="20" name="info" wrap="physical">INSERT HERE</textarea><br />
ENTER ID: <INPUT TYPE="TEXT" name="id" value="INPUT ID HERE" /><br />
<input type="submit" value="submit" name="submit" />
</form>
<?PHP
}
else
{
    $info = $_POST['info'];
    $id   = $_POST['id'];

    $wordChunks = explode(" ", $info);

<?php
// if page is not submitted to itself echo the form
if (!isset($_POST['submit']))
{
?>
<html>
<head>
<title>Personal INFO</title>
</head>
<body>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
PLEASE CLICK INSIDE OF THE SGW SPY LOG AREA AND PRESS CTRL+A THEN CTRL+C THEN CLICK IN THE
TEXT AREA BELOW WHERE IT SAYS "INSERT HERE".
<textarea rows="20" cols="20" name="info" wrap="physical">INSERT HERE</textarea><br />
ENTER ID: <INPUT TYPE="TEXT" name="id" value="INPUT ID HERE" /><br />
<input type="submit" value="submit" name="submit" />
</form>
<?PHP
}
else
{
    $info = $_POST['info'];
    $id   = $_POST['id'];

    $wordChunks = explode(" ", $info);

    for($i = 0; $i <= count($info); $i++)
    {
    echo "Piece $i = $wordChunks[$i] <br />";
    }
}
?>

Link to comment
https://forums.phpfreaks.com/topic/61012-what-am-i-doing-wrong/#findComment-303661
Share on other sites

Archived

This topic is now archived and is closed to further replies.

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