Jump to content

PHP Notice error: Undefined Variable


ShopMAster

Recommended Posts

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?

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.