1

I'm in a bit of a pickle using the submit button in php. Here's the code I want to run (it's for a website where you rate things, if that helps any):

<form method="POST">
<input type="radio" name="person" value="1" />
<input type="radio" name="person" value="2" />
<input type="submit" name="submit" />
</form> 

<?php;
    $_variable1 = 1400
    function ratePerson($person)
     {
         $_variable1+1
         echo $_variable1
     }


     if (isset($_POST['submit']));
     {    
         $person = $_post['person'];
         echo $person;

         ratePerson($person)
     }


echo $_variable1     
?>

So, when I run this the submit button and both radio buttons appear and I can click one of them and hit submit, it's just that when I hit a button and hit submit, nothing happens, there is no printed value (echo), I dont know if the +1 is working, it's a mess. I haven't done a lot in php, so please excuse my ignorance.

I got this piece of code from a friend, so if you want to suggest your own solution, go right ahead.

Thanks for all the help!

SamtheMan
  • 111
  • 3

3 Answers3

0

You code is missing semicolons to end commands. And some other things wrong like incrementing.

<?php
$_variable1 = 1400; // note the added semicolon

// pass $_variable1 by reference so incrementation is stored to the variable
function ratePerson(&$_variable1) {
    $_variable1 += 1; // increment correctly
}

 if (isset($_POST['submit'])) { // no semicolon necessary
     $person = $_POST['person']; // _POST instead of _post
     echo $person; // missing semicolon
     ratePerson($_variable1); // missing semicolon
     echo $_variable1; // missing semicolon
 }
echo $_variable1; // missing semicolon
?>
Yolo
  • 1,569
  • 1
  • 11
  • 16
0

You have a couple of errors in your script:

    <form method="POST">
    <input type="radio" name="person" value="1" />
    <input type="radio" name="person" value="2" />
    <input type="submit" name="submit" />
    </form> 

    <?php;
        $_variable1 = 1400
        function ratePerson($person)
         {
            global $_variable1; // global variable precision

             $_variable1++; // increment or $_variable1 +=1; 
             echo $_variable1;
         }


         if (isset($_POST['submit']))
         {    
             $person = $_post['person'];
             echo $person;
         ratePerson($person)
     }
      echo $_variable1     
   ?>

Note: I don't get why you provided $person as an argument to your function because it's not used by the ratePerson($person) Hope it helps

kourouma_coder
  • 1,078
  • 2
  • 13
  • 24
0

I am not sure what you are trying to accomplish, but this code will at least provide some output upon form submission:

<form method="POST">
1: <input type="radio" name="person" value="1" /><br />
2: <input type="radio" name="person" value="2" /><br />
<input name="submit" type="submit" value="Submit">
</form> 

<?php
    function ratePerson($person) {
     $_variable1 = 1400;
     $_variable1+=1;
     return($_variable1);
     }

    if (isset($_POST['submit'])) {    
        $person = $_POST['person'];
        echo "Person: " . $person . "<br />";
        $_variable1 = ratePerson($person);
        echo "Variable1: " . $_variable1 . "<br />";
    }
?>
Wolf
  • 1
  • 1