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!

Jason Aller
  • 3,541
  • 28
  • 38
  • 38
  • Are you connecting with mysqli?Also in your query shouldn't be `WHERE WEEK(DATE)=.... AND YEAR(DATE)=..`? – Mihai Jan 15 '14 at 20:40
  • @Mihai Yes I am. Ive been cpnnecting with the same script for a long time and never got any issue though. – Enric Grau-Luque Jan 15 '14 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. – dar7yl Jan 15 '14 at 22:51
  • $myrow['palce'] -- looks like a spelling misteak. – dar7yl Jan 15 '14 at 22:53
  • @dar7yl I know that the query works beacause I use it twice in this same script (the first one is exactly the same). That one doe the work fine. Indeed was a spelling mistake, thanks! – Enric Grau-Luque Jan 16 '14 at 01:11
  • The vast majority of code in this question is clearly not relevant to the problem. Can you narrow it down a bit please. – Lightness Races in Orbit Jan 16 '14 at 01:14
  • @LightnessRacesinOrbit Edited the question with the relevant part. Tried to narrow it as much as I could. Ill try to make a different approach though, any ideas? thanks! – Enric Grau-Luque Jan 16 '14 at 01:43
  • Try adding this :http://stackoverflow.com/questions/6575482/how-do-i-enable-error-reporting-in-php and see what it tells you, then. – rm-vanda Jan 16 '14 at 02:16
  • @rm-vanda Thank you very much! Very useful script that is! I get 3 errors that say that $week, $tour and $year are not defined. Wierd though because if I 'echo' them just before de 'if(isset($_POST['input2'].....' they print... – Enric Grau-Luque Jan 16 '14 at 02:32
  • Please narrow it down more, but constructing a [testcase](http://sscce.org). You'll likely find the process of doing this reveals the problem to you. – Lightness Races in Orbit Jan 16 '14 at 10:24
  • 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! – Enric Grau-Luque Jan 16 '14 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. – Lightness Races in Orbit Jan 16 '14 at 15:01

2 Answers2

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

... mysqli_close($db);

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

dar7yl
  • 3,727
  • 25
  • 20
  • 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). – dar7yl Jan 15 '14 at 22:47
  • 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 :( – Enric Grau-Luque Jan 16 '14 at 01:28
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!

Community
  • 1
  • 1