Undefined variable: y in C:\wamp\www\gun.php on line 8

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Ruchi choudhary
    New Member
    • Nov 2012
    • 22

    Undefined variable: y in C:\wamp\www\gun.php on line 8

    I am getting an error that "y is undefined variable".
    I know this will gonna be so simple and basic problem but I am new to php so that's why I am facing this problem.
    please me its urgent for me.

    Code:
    <?php
    $Amtoffirstrelease=$_POST['Amtoffirstrelease'];
    $Amtofsecondrelease=$_POST['Amtofsecondrelease'];
    $head=$_POST['head'];
    $subhead=$_POST['subhead'];
    $Availableamt=$Amtoffirstrelease+$Amtofsecondrelease;
    $sanctionedamt=$_POST['sanctionedamt'];
    $progressivebal=$y+$sanctionedamt;
    $dbhost = "localhost";
    $dbuser = "root";
    $dbpass = "";
    $dbname = "purchase";
    mysql_connect($dbhost, $dbuser, $dbpass);
    mysql_select_db($dbname) or die(mysql_error());
    
    $x="SELECT MAX(progressivebal) FROM 'naipone'";
    $y= mysql_query("SELECT progressivebal FROM 'naipone' WHERE progressivebal=x") or die('error');
    $query="insert into naipone(Amtoffirstrelease, Amtofsecondrelease, head, subhead, 
    
    Availableamt,sanctionedamt,progressivebal) values 
    
    ('$Amtoffirstrelease','$Amtofsecondrelease','$head','$subhead','$Availableamt','$sanctionedamt','$progressiveba
    
    l')";
    mysql_query($query)or die('error');
    echo"database update with:" .$Amtoffirstrelease."" .$Amtofsecondrelease. "".$Availableamt."" .$head."".
    
    $subhead."";
    ?>
    Last edited by Rabbit; Feb 21 '13, 07:53 AM. Reason: Fixed code tags.
  • Rabbit
    Recognized Expert MVP
    • Jan 2007
    • 12517

    #2
    Line 8, you use a variable y without first assigning it a value.

    Comment

    • Ruchi choudhary
      New Member
      • Nov 2012
      • 22

      #3
      Now its solved but its show error1 which at 18 line.

      Comment

      • gvuksa
        New Member
        • Feb 2013
        • 7

        #4
        You should use mysql_error to know exactly what the error is.
        You should maybe lose empty lines or try something like this
        Code:
        $query="insert into naipone(Amtoffirstrelease, Amtofsecondrelease, head, subhead," .
         
        "Availableamt,sanctionedamt,progressivebal) values" .
         
        "('$Amtoffirstrelease','$Amtofsecondrelease','$head','$subhead','$Availableamt','$sanctionedamt','$progressiveba" .
         
        "l')";

        Comment

        • Ruchi choudhary
          New Member
          • Nov 2012
          • 22

          #5
          Thanks!
          It works.I solved that problem. But now the main problem is progressivebal values does not update as I want (like line 9 and 18).
          Thank you

          Comment

          • Rabbit
            Recognized Expert MVP
            • Jan 2007
            • 12517

            #6
            We only allow one question per thread on this forum. Please create a new thread for your question.

            Comment

            Working...