Author Topic: Stupid, stupid syntax errors and memory leaks  (Read 1846 times)

reactosguy

  • Member
  • **
  • Posts: 269
  • Kudos: 2
    • Microsoft Sucks !!!
Stupid, stupid syntax errors and memory leaks
« on: 14 May 2011, 04:45 »
Code: [Select]
<?php
if (isset($_POST['Submit1']))
{
    
$i 1;
    while (
$i != $_POST['fieldnum'])
    {
        
$array[] = $_POST['favs[$i]'];
        
$i++;
    }
    
$arrayvars array_values($array);
    
$favnum $_POST['favnum'];
    
$ii 1;
    
$msg "List<br /><br />";
    for (
$ii 1;$ii != $_POST['fieldnum'];$ii++)
    {
        if(
$ii == $favnum)
        {
            
$msg .= "<b>{$ii}$array[$_POST['favs']]</b><br />";
        }
        else
        {
            
$msg .= "{$ii}$array[$_POST['favs']]<br />";
        }
    }
}
?>

<html>
<head>
<title>Your Favourite Things</title>
</head>
<body>
<form action="<?php echo htmlentities$_SERVER['PHP_SELF'] ); ?>" method="post">
<?php
$i 
1;
if ( 
$_POST['fieldnum'] < )
{
    echo 
"<label>Number of fields <input type='text' name='fieldnum' /></label><br /><input type='submit' name='Submit' value='Go Ahead' />";
}
else
{
    while (
$i != $_POST['fieldnum'])
    {
        echo 
"<input type='radio' name='favnum' value='$i' /><label>Favourite #$i <input type='text' name='favs[$i]' /></label><br />";
        
$i++;
    }
    echo 
"<input type='hidden' name='fieldnum' value='".$_POST['fieldnum']."' /><input type='submit' name='Submit1' value='Go Ahead' />";
}
?>

</form>
<?php echo $msg?>
</body>
</html>

I'm too <beep>ing tired to figure this out. I had memory leaks when may maximum memory limit was set at 256MB! I solved that but I have a new error that Google just doesn't bother to answer: syntax errors.

I'm trying to make a one-man script where you enter the number of fields, then that quantity pops up, then you arrange them into a list.

I input 5 in the number of fields box, then go to the next page and fill this in:

Hi
Hello
Hey (favourite)
Welcome

I expect:

1. Hi
2. Hello
3. Hey
4. Welcome

But I get this when successful:

1.
2.
3.
4.

In an attempt to fix it, I ended up screwing up the variables irreversibly. Are there any changes I could make to have the script perform the intended objective? This is super annoying and just plain pressuring.