ShopMAster Posted September 27, 2007 Share Posted September 27, 2007 My hosting company upgraded from 5.2.3 to 5.2.4 I'm getting the following errors now: PHP Notice: Undefined variable: submit in D:\domains\maddenwars.com\wwwroot\randomgamesshop3.php on line 20 PHP Notice: Undefined variable: delete in D:\domains\maddenwars.com\wwwroot\randomgamesshop3.php on line 55 PHP Notice: Undefined variable: id in D:\domains\maddenwars.com\wwwroot\randomgamesshop3.php on line 70 PHP Notice: Undefined variable: id in D:\domains\maddenwars.com\wwwroot\randomgamesshop3.php on line 96 PHP Notice: Undefined variable: random_wscore in D:\domains\maddenwars.com\wwwroot\randomgamesshop3.php on line 142 PHP Notice: Undefined variable: random_lscore in D:\domains\maddenwars.com\wwwroot\randomgamesshop3.php on line 155 PHP Notice: Undefined variable: random_comment in D:\domains\maddenwars.com\wwwroot\randomgamesshop3.php on line 159 Here is the code: <?php $db = mysql_connect("mysql.mydbserv.com", "*****", "*****"); mysql_select_db("DB_name",$db); if ($submit) { // here if no ID then adding else we're editing if ($id) { mysql_query("UPDATE random_games SET random_winner='$random_winner',random_wscore='$random_wscore',random_loser='$random_loser',random_lscore='$random_lscore',random_comment='$random_comment' WHERE id=$id"); mysql_query("UPDATE players SET player_win = player_win + 1 where player_name = '".$_POST['random_winner']."' "); mysql_query("UPDATE players SET player_loss = player_loss + 1 where player_name = '".$_POST['random_loser']."' "); mysql_query("UPDATE players SET player_lastw = '".$_POST['random_loser']."' where player_name = '".$_POST['random_winner']."' "); mysql_query("UPDATE players SET player_lastl = '".$_POST['random_winner']."' where player_name = '".$_POST['random_loser']."' "); mysql_query("UPDATE standings SET random = random + 1 where name = 'Shop'"); mysql_query("UPDATE standings SET total = total + 1 where name = 'Shop'"); } else { $sql = "INSERT INTO random_games (random_winner,random_wscore,random_loser,random_lscore,random_comment) VALUES ('$random_winner','$random_wscore','$random_loser','$random_lscore','$random_comment')"; mysql_query("UPDATE players SET player_win = player_win + 1 where player_name = '".$_POST['random_winner']."' "); mysql_query("UPDATE players SET player_loss = player_loss + 1 where player_name = '".$_POST['random_loser']."' "); mysql_query("UPDATE players SET player_lastw = '".$_POST['random_loser']."' where player_name = '".$_POST['random_winner']."' "); mysql_query("UPDATE players SET player_lastl = '".$_POST['random_winner']."' where player_name = '".$_POST['random_loser']."' "); mysql_query("UPDATE standings SET random = random + 1 where name = 'Shop'"); mysql_query("UPDATE standings SET total = total + 1 where name = 'Shop'"); } // run SQL against the DB $result = mysql_query($sql); echo "<font face=Verdana size=2>Record updated/edited! <a href=http://www.maddenwars.com/randomgamesshop3.php>Go Back to Random Stat Entry page!</a><p>"; } elseif ($delete) { // delete a record $sql = "DELETE FROM random_games WHERE random_gmid=$random_gmid"; $result = mysql_query($sql); echo "$sql Record deleted! <a href=http://www.maddenwars.com/randomgamesshop3.php>Go Back to List</a><p>"; } else { // this part happens if we don't press submit if (!$id) { // print the list if there is not editing $result = mysql_query("SELECT * FROM random_games ORDER BY random_gmid",$db); // while ($myrow = mysql_fetch_array($result)) { } } ?> <P> <!-- <form action="../mwleague/handle_game.php" method="post"> --> <form method="post" action="<?php echo $PHP_SELF?>"> <?php if ($id) { // editing so select a record $sql = "SELECT * FROM random_games WHERE id=$id"; $result = mysql_query($sql); $myrow = mysql_fetch_array($result); $id = $myrow["id"]; $random_winner = $myrow["random_winner"]; $random_loser = $myrow["random_loser"]; $random_wscore = $myrow["random_wscore"]; $random_lscore = $myrow["random_lscore"]; $random_comment = $myrow["random_comment"]; // print the id for editing ?> <input type=hidden name="random_gmid" value="<?php echo $random_gmid ?>"> <?php } ?></font><b><font face="Verdana" size="4" color="#0000FF">Random Game Entry</font></b><font face=Verdana size=2><br> <br> <font color="#000000">Winner: <select name="random_winner" size="1"> <?php $random_winner = mysql_query("SELECT * FROM players WHERE player_team = 'Shop' ORDER BY player_perc DESC",$db); while ($arr = mysql_fetch_assoc($random_winner)) { echo "<option value=\"".$arr['player_name']."\">".ucfirst($arr['player_name'])."</option>"; } ?> </select> </font> <input type="Text" name="random_wscore" value="<?php echo $random_wscore ?>" size="2">winning score<br><br> defeated<br> <br> <font color="#000000">Loser: <select name="random_loser" size="1"> <?php $random_loser = mysql_query("SELECT * FROM players WHERE player_team != 'Shop' ORDER BY player_name ASC",$db); while ($arr = mysql_fetch_assoc($random_loser)) { echo "<option value=\"".$arr['player_name']."\">".ucfirst($arr['player_name'])."</option>"; } ?> </select> </font><input type="Text" name="random_lscore" value="<?php echo $random_lscore ?>" size="2">losing score</font><p><font face=Verdana size=2><br> Comments:<br> <textarea rows="3" name="random_comment" cols="32" value="<?php echo $random_comment ?>"></textarea><br> <input type="Submit" name="submit" value="Enter information"> <br> (</font><font face="Verdana" size="1">press button once, takes time to process)</font> </p> </form> <font face=Verdana size=2> </font> <?php } ?> What do I need to change in order to fix those errors? Quote Link to comment https://forums.phpfreaks.com/topic/70833-php-notice-error-undefined-variable/ Share on other sites More sharing options...
marcus Posted September 27, 2007 Share Posted September 27, 2007 Do you have: extract($_POST); Anywheres? Quote Link to comment https://forums.phpfreaks.com/topic/70833-php-notice-error-undefined-variable/#findComment-356112 Share on other sites More sharing options...
d22552000 Posted September 27, 2007 Share Posted September 27, 2007 tey are not errors, ust stupid things that are ok its ok to ignroe them using: error_reporting(E_ALL ^ E_WARNING); at the start of your file. Quote Link to comment https://forums.phpfreaks.com/topic/70833-php-notice-error-undefined-variable/#findComment-356113 Share on other sites More sharing options...
ShopMAster Posted September 27, 2007 Author Share Posted September 27, 2007 Where do I add that and what is the correct syntax? Quote Link to comment https://forums.phpfreaks.com/topic/70833-php-notice-error-undefined-variable/#findComment-356114 Share on other sites More sharing options...
trq Posted September 27, 2007 Share Posted September 27, 2007 tey are not errors, ust stupid things that are ok its ok to ignroe them using: That is poor advice. Fix your code! eg; if ($submit) { should be.... if ($_POST['submit']) { These changes where made default in php4. Also, calling mysql_query() multiple times like that is very infificient, esecially when your queries can be combined into much fewer. Quote Link to comment https://forums.phpfreaks.com/topic/70833-php-notice-error-undefined-variable/#findComment-356116 Share on other sites More sharing options...
ShopMAster Posted September 27, 2007 Author Share Posted September 27, 2007 tey are not errors, ust stupid things that are ok its ok to ignroe them using: That is poor advice. Fix your code! eg; if ($submit) { should be.... if ($_POST['submit']) { These changes where made default in php4. Also, calling mysql_query() multiple times like that is very infificient, esecially when your queries can be combined into much fewer. I tried that and now I'm getting the following error: PHP Notice: Undefined index: submit in D:\domains\maddenwars.com\wwwroot\randomgamesshop3.php on line 10 PHP Notice: Undefined index: delete in D:\domains\maddenwars.com\wwwroot\randomgamesshop3.php on line 45 PHP Notice: Undefined index: id in D:\domains\maddenwars.com\wwwroot\randomgamesshop3.php on line 60 PHP Notice: Undefined index: id in D:\domains\maddenwars.com\wwwroot\randomgamesshop3.php on line 86 PHP Notice: Undefined index: random_wscore in D:\domains\maddenwars.com\wwwroot\randomgamesshop3.php on line 132 PHP Notice: Undefined index: random_lscore in D:\domains\maddenwars.com\wwwroot\randomgamesshop3.php on line 145 PHP Notice: Undefined index: random_comment in D:\domains\maddenwars.com\wwwroot\randomgamesshop3.php on line 149 Quote Link to comment https://forums.phpfreaks.com/topic/70833-php-notice-error-undefined-variable/#findComment-356127 Share on other sites More sharing options...
d22552000 Posted September 27, 2007 Share Posted September 27, 2007 you cannot use $<VAR>; when its from a form you must use $_POST['<VAR>']; Quote Link to comment https://forums.phpfreaks.com/topic/70833-php-notice-error-undefined-variable/#findComment-356128 Share on other sites More sharing options...
trq Posted September 27, 2007 Share Posted September 27, 2007 You need to make sure variable are actually set before attempting to use them. Use... if (isset($_POST['submit'])) { I should have posted that in the first place. Quote Link to comment https://forums.phpfreaks.com/topic/70833-php-notice-error-undefined-variable/#findComment-356131 Share on other sites More sharing options...
d22552000 Posted September 27, 2007 Share Posted September 27, 2007 better code practise is to do: if (!empty($_POST['submit'])) { instead of if (isset($_POST['submit'])) { Quote Link to comment https://forums.phpfreaks.com/topic/70833-php-notice-error-undefined-variable/#findComment-356132 Share on other sites More sharing options...
trq Posted September 27, 2007 Share Posted September 27, 2007 better code practise is to do: if (!empty($_POST['submit'])) { instead of if (isset($_POST['submit'])) { Not at all. $_POST['submit'] will always be empty because it has no value. Quote Link to comment https://forums.phpfreaks.com/topic/70833-php-notice-error-undefined-variable/#findComment-356137 Share on other sites More sharing options...
d22552000 Posted September 27, 2007 Share Posted September 27, 2007 lol then give submit a value under the form.... <input type="submit" name="submit" value="yes"> then you can tell if its really that script sending it values, pretty simple really. Quote Link to comment https://forums.phpfreaks.com/topic/70833-php-notice-error-undefined-variable/#findComment-356138 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.