1

BIG EDIT: I've trimmed the code as much as possible while getting the same notice. So I'm trying to use the variable $tour which is defined in the first if(isset.... This if creates a second submit that when pressed should print the value $tour but I get the following output:

Notice: Undefined variable: torneo in /home/user/public_html/edit/file.php on line 19
1
before loop

Notice: Undefined variable: torneo in /home/user/public_html/edit/file.php on line 21

The trimmed code is:

<form method="POST">
TORNEO: <select name="torneo">
            <option value="DSHN ADULTO">DSHN ADULTO</option>
            <option value="NFL">NFL</option>
        </select>
<br />
<input type="submit" value="ELEGIR" name="input1"/>
<br />
<?php
ini_set('display_errors',1);
ini_set('display_startup_errors',1);
error_reporting(-1);
if(isset($_POST['input1'])){
    $torneo = $_POST['torneo'];
    echo $torneo;
    echo "<br><input type='submit' name='input2' value='CREAR'/>";
}     
if(isset($_POST['input2'])){
    echo $torneo."1";
    echo "<br>before loop<br>";
    while ($torneo){
        echo "Updated! ".$torneo."<br>";        
    }
}  
?>
</form>

Thanks for the help!

12
  • Are you connecting with mysqli?Also in your query shouldn't be WHERE WEEK(DATE)=.... AND YEAR(DATE)=..? Commented Jan 15, 2014 at 20:40
  • @Mihai Yes I am. Ive been cpnnecting with the same script for a long time and never got any issue though. Commented Jan 15, 2014 at 20:46
  • 1
    Check to see if your query actually returned some rows. Run the query directly on the database (ie, command line, MySql Workbench). Print out $query to be sure it's the proper format. Commented Jan 15, 2014 at 22:51
  • 1
    @LightnessRacesinOrbit thank you for the advice. Now I did trim the code desently (I believe). So its not about the connection. I just cant get the variable through the second submit... Thanks! Commented Jan 16, 2014 at 13:57
  • 1
    @EnricTomás: Yes! Woohoo!! This is now a perfect testcase. :D Excellent work. Hopefully you can now see the extreme value in doing this. Commented Jan 16, 2014 at 15:01

2 Answers 2

1
echo "</form>";
mysqli_close($db);

... mysqli_close($db);

You have an extraneous close, before the second part of your script.

Sign up to request clarification or add additional context in comments.

2 Comments

I see you open the database again.. Why not keep it open and close it at the end (you can test if it is opened).
I tried keeping it open from the very beginning and closing it at the end and still no loop. Tried different combinatios and the nothind :(
1

The answer to my problem is here:

Why do I keep losing variable values when submitting a second form on the same page

Thanks everyone who helped, Im really very thankful to all!

1 Comment

You may also benefit from switching your while() loop to a foreach() loop --

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.