SitePoint Sponsor

User Tag List

Results 1 to 12 of 12
  1. #1
    SitePoint Zealot
    Join Date
    Jan 2013
    Posts
    110
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    ERROR that cant be found.HELP

    i have these code below,keep goes to "else" condition no matter what number i put whether it is the same or not, I really don't know why, Please help me to figure it out. Thanks!

    PHP Code:
    <script type="text/javascript">
        function update()
        {
        var msg = "DATA SUCCESSFULLY UPDATED!";
        alert(msg);
        window.history.back();
        }
    </script>

    <script type="text/javascript">
        function no_update()
        {
        var msg = "NO DATA UPDATED!";
        alert(msg);
        window.history.back();
        }
    </script>

    <?php


    $z 
    $_POST['original'] ;
    $x $_POST['brand'];
    $w $_POST['copy'] ;

    echo 
    $_POST['original'];
    echo 
    $_POST['copy'];
    echo 
    $_POST['brand'];

    /*
    switch ($z)

    {
        case $x:
        echo '<script type="text/javascript"> no_update(); </script>';

            
        default:
        echo '<script type="text/javascript"> update(); </script>';
    }
    */

    if ($z == $w)
        {    
            echo 
    '<script type="text/javascript"> no_update(); </script>';
            
        }
    else
        {    
            
            echo 
    $_POST['original'];
            echo 
    $_POST['copy'];
            echo 
    $_POST['brand'];
            
    $con mysql_connect("localhost","root","880702");
            if (!
    $con)
              {
              die(
    'Could not connect: ' mysql_error());
              }

            
    mysql_select_db("SPAREPART2"$con);


            
    mysql_query("UPDATE list2 SET Qty = '".$z."' WHERE Brand = '".$x."'"); /* no error */

            
    echo '<script type="text/javascript"> update(); </script>';

            
        }

    mysql_close($con);
    ?>
    p/s: The value of $z and $w is an integer number (ex = 32,33.55,44).

  2. #2
    Avid Logophile silver trophy
    ParkinT's Avatar
    Join Date
    May 2006
    Location
    Central Florida
    Posts
    2,337
    Mentioned
    192 Post(s)
    Tagged
    4 Thread(s)
    How are you testing (calling) this code? What does the submit form look like?
    What have you done to confirm that the inputs *ARE* integers (BTW: 33.55 is not an integer. Perhaps the dot was a mis-typed comma)
    Don't be yourself. Be someone a little nicer. -Mignon McLaughlin, journalist and author (1913-1983)


    Git is for EVERYONE
    Literally, the best app for readers.
    Make Your P@ssw0rd Secure
    Leveraging SubDomains

  3. #3
    SitePoint Evangelist captainccs's Avatar
    Join Date
    Mar 2004
    Location
    Caracas, Venezuela
    Posts
    516
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Before the
    PHP Code:
    if ($z == $w) { 
    add
    PHP Code:
    echo "Z= {$Z}<br>W= {$W}<br>"
    That should tell you.
    Denny Schlesinger
    web services

  4. #4
    SitePoint Mentor bronze trophy
    John_Betong's Avatar
    Join Date
    Aug 2005
    Location
    City of Angels
    Posts
    1,840
    Mentioned
    73 Post(s)
    Tagged
    6 Thread(s)
    $z and $w are strings.

    Before the if statement var_dump($z) and var_dump($w) to see the exact values.
    Learn how to be ready for The New Move to Discourse

    How to make Make Money Now with a *NEW* look

    Be sure to congratulate Patche on earning Member of the Month for July 2014

  5. #5
    SitePoint Zealot
    Join Date
    Jan 2013
    Posts
    110
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by ParkinT View Post
    How are you testing (calling) this code? What does the submit form look like?
    What have you done to confirm that the inputs *ARE* integers (BTW: 33.55 is not an integer. Perhaps the dot was a mis-typed comma)
    ive tested it by echo-ing it before tried to use it if you notice in the code i posted. actually its 33,55. mistyped. the submit form looks like this

    <form name="lol" action="the_code_i_posted_just_now.php" method="post">
    <label> Brand</label>
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;:
    <input id="brand" name="brand" type="text" class = "lol" readonly="readonly" value= "<?php echo $c; ?>"/>
    &nbsp;&nbsp;&nbsp;&nbsp;</p>

    <input name="original" type="text" class = "quantity" value= "<?php echo $l; ?> " />
    <input name="copy" type="text" class = "quantity" value= "<?php echo $l; ?>" style="visibility: hidden" />

    </form>
    p/s: $c and $l is an integer value.

  6. #6
    SitePoint Zealot
    Join Date
    Jan 2013
    Posts
    110
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by captainccs View Post
    Before the
    PHP Code:
    if ($z == $w) { 
    add
    PHP Code:
    echo "Z= {$Z}<br>W= {$W}<br>"
    That should tell you.
    i've already did that in "else" condition if you notice it in the code.

  7. #7
    SitePoint Zealot
    Join Date
    Jan 2013
    Posts
    110
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by John_Betong View Post
    $z and $w are strings.

    Before the if statement var_dump($z) and var_dump($w) to see the exact values.
    i've already "echo" it before use and it echo the correct value. is it different by using var_dump?

  8. #8
    SitePoint Zealot
    Join Date
    Jan 2013
    Posts
    110
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by John_Betong View Post
    $z and $w are strings.

    Before the if statement var_dump($z) and var_dump($w) to see the exact values.
    FOUND IT. Thanks to John Betong. After using var_dump(), i got string(3) "23" for $z and string(2) "23" for $w. Why the string is not the same but the value is the same? can somebody explain?

  9. #9
    From space with love silver trophy
    SpacePhoenix's Avatar
    Join Date
    May 2007
    Location
    Poole, UK
    Posts
    5,033
    Mentioned
    103 Post(s)
    Tagged
    0 Thread(s)
    You might have accidentally got a space when typing in the value, trim() can be used to eliminate blank spaces at the start and end of strings
    Community Team Advisor
    Forum Guidelines: Posting FAQ Signatures FAQ Self Promotion FAQ
    Help the Mods: What's Fluff? Report Fluff/Spam to a Moderator

  10. #10
    SitePoint Zealot
    Join Date
    Jan 2013
    Posts
    110
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by SpacePhoenix View Post
    You might have accidentally got a space when typing in the value, trim() can be used to eliminate blank spaces at the start and end of strings
    how can i use the trim()? just simply put trim($z); before using it?

  11. #11
    SitePoint Zealot
    Join Date
    Jan 2013
    Posts
    110
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by SpacePhoenix View Post
    You might have accidentally got a space when typing in the value, trim() can be used to eliminate blank spaces at the start and end of strings
    FIXED! THANK YOU SO MUCH FOR YOUR HELP ESPECIALLY JOHN BETUNG AND SPACEPHOENIX.^^

  12. #12
    SitePoint Mentor bronze trophy
    John_Betong's Avatar
    Join Date
    Aug 2005
    Location
    City of Angels
    Posts
    1,840
    Mentioned
    73 Post(s)
    Tagged
    6 Thread(s)
    Quote Originally Posted by Marvin_G View Post
    FIXED! THANK YOU SO MUCH FOR YOUR HELP ESPECIALLY JOHN_BETONG AND SPACEPHOENIX.^^
    'glad you managed to find why your script was not doing what you wanted it to do

    PHP's automatic type conversion still trips me up and frequently Google "php manual type_juggling"

    "http://php.net/manual/en/language.types.type-juggling.php"

    Please note that $_POST is an array of strings and useful tests are:

    PHP Code:

    # check for $_POST and if set then show all string values 
    if( count$_POST) > )
    {
      
    # PRE required for formatting with line-feeds
      
    echo '<pre>';  
        
    print_r($_POST);
      echo 
    '</pre>';

      
    # convert to integers OR set a default value
      
    $z = isset( $_POST['original'] ) ? intval$_POST['original'] ) : 0;
      
    $x = isset( $_POST['brand']    ) ? intval$_POST['brand']   ) : 0;;
      
    $w = isset( $_POST['copy']     ) ? intval$_POST['copy']    ) : 0;    
    }
    else
    {
       echo 
    'Yes we have no $_POST today';

    Last edited by John_Betong; Mar 3, 2013 at 23:09. Reason: spelling: not my fortay
    Learn how to be ready for The New Move to Discourse

    How to make Make Money Now with a *NEW* look

    Be sure to congratulate Patche on earning Member of the Month for July 2014


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •