Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 12 of 12
  1. #1
    New Coder
    Join Date
    Jul 2006
    Posts
    30
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Update not working

    I have missed a closing statement somewhere and cannot figure it out.

    This page is simply listing data and inputting a quantity filed to update.

    The error is "Parse error: parse error, unexpected $ in /home/trailerr/public_html/UpdateQnty3.php on line 168"

    Line 168 is the closing html statement" </html>".


    PHP Code:
    <?php

        
    require_once('init.php'); 

        require_once(
    'settings.inc');

    if (isset(
    $_POST['Update'])){

        if (
    $_POST['Update']=="Home"header('Location: CustomerSearch.php');
         
        if (
    $_POST['Update']=="Save") {
        
    $link mysql_connect($hostname$login$password);
        if (!
    $link) {
            die(
    'Could not connect: ' mysql_error());
        }
             
        
    $cid=0;
        
    $type="TL";
        foreach (
    $_POST["Qnty"] as $value) {
        if (
    $cid>=$_POST["RN"]) $type="TT";

        
    mysql_select_db($dbname);
        if (
    $type=="TL") {
        
        
    $result mysql_query('
        SELECT * from trailertype WHERE ID='
    .$_POST["rid"][$cid]
        ) or die(
    "Query failed : " mysql_error());
        
        while (
    $row mysql_fetch_assoc($result)); 
        
        
    mysql_query("UPDATE trailertype 
            SET 
            Qnty='"
    .$_POST["Qnty"][$cid]."'
            WHERE ID="
    .$_POST["rid"][$cid]) 
            or die(
    "Query failed : " mysql_error());
        }

        else
        {
        
        
    $result mysql_query('
        SELECT * from tractortype WHERE ID='
    .$_POST["rid"][$cid]
        ) or die(
    "Query failed : " mysql_error());

        while (
    $row mysql_fetch_assoc($result)); 
        
        
    mysql_query("UPDATE tractortype 
            SET 
            Qnty='"
    .$_POST["Qnty"][$cid]."'
            WHERE ID="
    .$_POST["rid"][$cid]) 
            or die(
    "Query failed : " mysql_error());
        }

    ?>

    <html>
    <head>
    <meta http-equiv="content-type" content="text/html; charset=windows-1252">
    <link rel="stylesheet" href="griffin.css" type="text/css">
    <title>Update Quantity</title>
    </head>
    <body marginwidth=0 marginheight=0 leftmargin=0 topmargin=0>

    <?php
        
    include ('logo_header.php');
    ?>
        <table border=0 width=800><tr><td>
        <form name=UpdateQnty action="UpdateQnty.php" method=post>
        <a class=titler>Update Quantity </a> as of <?php echo date("F d, Y"); ?>
        </td></tr></table><br>
        
    <table border=0 width=800 align=center bgcolor=#000000 cellpadding=0 cellspacing=0><tr ><td>
    <table border=0 width=100% align=center cellpadding=3 cellspacing=1><tr bgcolor=cdcdcd align=center >    

        <td><b>Ref. No. </b></td>
        <td width=60><b> Available Date </b></td>
        <td><b> Year </b></td>
        <td><b> Equipment Type </b></td>
        <td><b> Qty Update</b></td>
        <td width= 100><b> Company </b></td>
        <td><b>Status Date</b></td></tr>



    <?php
        
        mysql_select_db
    ($dbname);

        
    $result mysql_query('
        SELECT * from trailertype tl, customerinfo c 
        WHERE tl.RefNo=c.RefNo and tl.status="Sell" '
    .$wh
        or die(
    "Query failed : " mysql_error());

        
    $TL=mysql_num_rows($result);
        
    $TLNum=$TL;
        
    $TLa=array($TLNum);    

        while (
    $row mysql_fetch_assoc($result)) 
            {

        
    $TLa[$row['ID']]=$row['SELL_STATUS'];    

        echo 
    "<tr bgcolor=white>
            <td> TL$row[ID] 
            <input type=hidden name=rid[] value=$row[ID]>
            <input type=hidden name=RN value=$TL>
            </td>
            <td>"
    .date("F",mktime(0,0,0,$row['aMonth'],1,2005))."&nbsp;".$row['aYear']."</td>
            <td> $row[Year] </td>
            <td> $row[TL] <input type=hidden name=EQ value=TL></td>
            <td> <input type=text name=Qnty[] size=1 value="
    .$row['Quantity']." class=TxtBut></td>
            <td> $row[Company] </td>
            <td>"
    .strftime("%m/%d/%y",strtotime("$row[Status_Date]"))." </td>
            </tr>"
    ;
            }

        
    $result mysql_query('
        SELECT * from tractortype tt, customerinfo c 
        WHERE tt.RefNo=c.RefNo and tt.status="Sell" '
    .$wh
        or die(
    "Query failed : " mysql_error());
        
        
    $TTNum=mysql_num_rows($result);
        
    $TTa=array($TTNum);
        while (
    $row mysql_fetch_assoc($result)) 
            {
        
    $TTa[$row['ID']]=$row['SELL_STATUS'];
        echo 
    "<tr bgcolor=white>
            <td> TT$row[ID] <input type=hidden name=rid[] value=$row[ID]></td>
            <td>"
    .date("F",mktime(0,0,0,$row['aMonth'],1,2005))."&nbsp;".$row['aYear']."</td>
            <td> $row[Year] </td>
            <td> $row[TT] <input type=hidden name=EQ value=TT></td>
            <td> <input type=text name=Qnty[] size=1 value="
    .$row['Quantity']." class=TxtBut></td>
            <td> $row[Company] </td>
            <td>"
    .strftime("%m/%d/%y",strtotime("$row[Status_Date]"))." </td>
            </tr>"
    ;
            }


    ?>


    </table>
    </td></tr></table>

        <center><br>
        <input type=button name="Update" value="Print" class=TxtBut onClick="window.print()">&nbsp;&nbsp;&nbsp;
        <input type=submit name="Update" value="Save" class=TxtBut>&nbsp;&nbsp;&nbsp;
        <input type=submit name="Update" value="Home" class=TxtBut>
        </form>
        <br></center>

    <?php   include ('logo_footer.php');?>

    </body>

    </html>
    I have narrowed it down to the following section but, can't figure it out.
    PHP Code:
    $cid=0;
        
    $type="TL";
        foreach (
    $_POST["Qnty"] as $value) {
        if (
    $cid>=$_POST["RN"]) $type="TT";

        
    mysql_select_db($dbname);
        if (
    $type=="TL") {
        
        
    $result mysql_query('
        SELECT * from trailertype WHERE ID='
    .$_POST["rid"][$cid]
        ) or die(
    "Query failed : " mysql_error());
        
        while (
    $row mysql_fetch_assoc($result)); 
        
        
    mysql_query("UPDATE trailertype 
            SET 
            Qnty='"
    .$_POST["Qnty"][$cid]."'
            WHERE ID="
    .$_POST["rid"][$cid]) 
            or die(
    "Query failed : " mysql_error());
        }

        else
        {
        
        
    $result mysql_query('
        SELECT * from tractortype WHERE ID='
    .$_POST["rid"][$cid]
        ) or die(
    "Query failed : " mysql_error());

        while (
    $row mysql_fetch_assoc($result)); 
        
        
    mysql_query("UPDATE tractortype 
            SET 
            Qnty='"
    .$_POST["Qnty"][$cid]."'
            WHERE ID="
    .$_POST["rid"][$cid]) 
            or die(
    "Query failed : " mysql_error());
        } 

  • #2
    Regular Coder
    Join Date
    Jan 2003
    Posts
    867
    Thanks
    4
    Thanked 8 Times in 8 Posts
    That error usually means you missed a '}'

    Do you ever close the very first if-statement?

    if (isset($_POST['Update'])){

  • #3
    Super Moderator guelphdad's Avatar
    Join Date
    Mar 2006
    Location
    St. Catharines, Ontario Canada
    Posts
    2,634
    Thanks
    4
    Thanked 148 Times in 139 Posts
    If you use a decent text editor then it should be relatively easy to find mis-matched { or }.

  • #4
    New Coder
    Join Date
    Jul 2006
    Posts
    30
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by guelphdad
    If you use a decent text editor then it should be relatively easy to find mis-matched { or }.
    Can you recommend one?

  • #5
    New Coder
    Join Date
    Jul 2006
    Posts
    30
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I have closed all the If statements and now no more error, but I get no updated information. I tried to echo $_POST[Qnty] in various locations but it never displays the information.

    My question is am I closing the IF statment too soon thus not inserting the new information into the table?

    PHP Code:
    <?php

        
    require_once('init.php'); 

        require_once(
    'settings.inc');

    if (isset(
    $_POST['Update'])){

        if (
    $_POST['Update']=="Home"header('Location: CustomerSearch.php');
        if (
    $_POST['Update']=="Save") {
        

        
    $link mysql_connect($hostname$login$password);
        if (!
    $link) {
            die(
    'Could not connect: ' mysql_error());
            }
        
    $cid=0;
        
    $type="TL";
        foreach (
    $_POST["Qnty"] as $value) {
        if (
    $cid>=$_POST["RN"]) $type="TT";
        
        
    mysql_select_db($dbname);
        if (
    $type=="TL") {
        
        
    $result mysql_query('
        SELECT * from trailertype WHERE ID='
    .$_POST["rid"][$cid]
        ) or die(
    "Query failed : " mysql_error());
        
        while (
    $row mysql_fetch_assoc($result)); 

        
    mysql_query("INSERT INTO trailertype
            (Quantity)
            VALUES
            ('$_POST[Qnty]')
            "
    )or die("Query failed : " mysql_error());
        }
        else
        {
        
        
    $result mysql_query('
        SELECT * from tractortype WHERE ID='
    .$_POST["rid"][$cid]
        ) or die(
    "Query failed : " mysql_error());

        while (
    $row mysql_fetch_assoc($result)); 
        
        
    mysql_query("INSERT INTO tractortype
            (Quantity)
            VALUES
            ('$_POST[Qnty]')
            "
    )or die("Query failed : " mysql_error());
        }
        }}}
        
    ?>

  • #6
    UE Antagonizer Fumigator's Avatar
    Join Date
    Dec 2005
    Location
    Utah, USA, Northwestern hemisphere, Earth, Solar System, Milky Way Galaxy, Alpha Quadrant
    Posts
    7,691
    Thanks
    42
    Thanked 637 Times in 625 Posts
    Can you recommend one?
    I like Crimson Editor. It's even free.

    Regarding your code... there are a few syntax problems you need to resolve.

    Your select queries are missing a closing single quote around id='<value>'.

    You are misusing the statement "while ($row = mysql_fetch_assoc($result));". There is no need to enclose the mysql_fetch_assoc() function inside a while loop that doesn't have anything inside its loop!

    I lose track of your foreach() loop, I'm not sure you've enclosed it properly, but it's hard to tell because you aren't properly indenting your code. It's a personal preference I know, but without proper indenting it makes life hell when you have multiple nested "if" statements and loops within those "if" statements.

  • #7
    UE Antagonizer Fumigator's Avatar
    Join Date
    Dec 2005
    Location
    Utah, USA, Northwestern hemisphere, Earth, Solar System, Milky Way Galaxy, Alpha Quadrant
    Posts
    7,691
    Thanks
    42
    Thanked 637 Times in 625 Posts
    On second glance I take back what I said about the id='<value>' stuff; as long as your ID column is an integer your code will work fine.

  • #8
    New Coder
    Join Date
    Jul 2006
    Posts
    30
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I have re-worked my code to only pass the information over for an indiviual record, but running into a problem submitting the changes.

    I think I have everything right as the out put works ok and I can change the amounts. Again the problem is submitting it does nothing!

    PHP Code:
    <?php

        
    require_once('init.php'); 

        require_once(
    'settings.inc');

    if (isset(
    $_GET['ID'])){

        
    $link mysql_connect($hostname$login$password);
        if (!
    $link) {
            die(
    'Could not connect: ' mysql_error());
        }

        
    mysql_select_db($dbname);

                
    $CustID=$_GET['ID'];
                
            if (
    $_GET['type']=="TT"
                {
                
    $Ttable="tractortype";
                }
                else 
                {
                
    $Ttable="trailertype";
                }
        
    $result2=mysql_query("SELECT * FROM ".$Ttable." WHERE ID=".$_GET['ID']) or die("Query failed : " mysql_error());

        while (
    $row mysql_fetch_array($result2)) 
            {
        
    $AY=$row['aYear'];
        
    $Y =$row['Year'];
        
    $Q =$row['Quantity'];
        
    $P =$row['SellingPrice'];
        
    $AM=$row['aMonth'];
        }
    }
    ?>

    <?php
    if (isset($_POST['Update'])){
             if (
    $_POST['Update']=="Back"header('Location: CustomerInfo.php');
             if (
    $_POST['Update']=="Save"
                {
                
    $link mysql_connect($hostname$login$password);
                    if (!
    $link) {
                        die(
    'Could not connect: ' mysql_error());
                    }
                    
    mysql_select_db($dbname);
                    
                    
    mysql_query("INSERT INTO ".$Ttable.
                        (Quantity, SELLING_PRICE)
                        VALUES
                        ('$Q','$P')"
    )
                         or die(
    "Query failed : " mysql_error());
                         }
             if (
    $_POST['Update']=="Save"header('Location: UpdateQnty.php');
                    }    


    ?>

    <html>
    <head>
    <meta http-equiv="content-type" content="text/html; charset=windows-1252">
    <link rel="stylesheet" href="griffin.css" type="text/css">
    <title>Equipment Update</title>
    </head>

    <body marginwidth=0 marginheight=0 leftmargin=0 topmargin=0>

    <?php
            
    include ('logo_header.php');
    ?>

    <?php
        
    if (isset($_GET['type'])) {
            if (
    $_GET['type']=="TL") {
        echo 
    "<td>&nbsp;&nbsp;<b>Year:</b>"
        echo 
    " ".$Y."";
        echo 
    "";
        echo 
    "&nbsp;&nbsp;<b>Quantity:</b> <input type=text name=TLqty size=10 class=TxtBut";
            if (isset(
    $Q)) echo " value=\"".$Q."\"";
        echo 
    "&nbsp;&nbsp;<b>Price:</b> <input type=text name=TLprice size=10 class=TxtBut";
            if (isset(
    $P)) echo " value=\"".$P."\" </td></tr>";
        echo 
    "<tr><td colspan=3>&nbsp;</td></tr>";
            }
        }

        if (!isset(
    $_GET['type'])) {

        echo 
    "<td>&nbsp;&nbsp;<b>Year:</b>";
        echo 
    "&nbsp;&nbsp;<b>Quantity:</b> <input type=text name=TLqty size=10 class=TxtBut";
        echo 
    "&nbsp;&nbsp;<b>Price:</b> <input type=text name=TLprice size=10 class=TxtBut";
        echo 
    "</td></tr>";
        echo 
    "<tr><td colspan=3>&nbsp;</td></tr>";
            }
    ?>
        
    <?php

        
    if (isset($_GET['type'])) {
            if (
    $_GET['type']=="TT") {
        echo 
    "<td>&nbsp;&nbsp;<b>Year:</b>" 
        echo 
    "&nbsp;&nbsp;<b>Quantity:</b> <input type=text name=TTqty size=10 class=TxtBut";
            if (isset(
    $Q)) echo " value=\"".$Q."\"";
        echo 
    "&nbsp;&nbsp;<b>Price:</b> <input type=text name=TTprice size=10 class=TxtBut";
            if (isset(
    $P)) echo " value=\"".$P."\" </td></tr>";
        echo 
    "<tr><td colspan=3>&nbsp;</td></tr>";
            }
        }

        if (!isset(
    $_GET['type'])) 
            {
        echo 
    "<td>&nbsp;&nbsp;<b>Year:</b>";
        echo 
    "&nbsp;&nbsp;<b>Quantity:</b> <input type=text name=TTqty size=10 class=TxtBut";
        echo 
    "&nbsp;&nbsp;<b>Price:</b> <input type=text name=TTprice size=10 class=TxtBut";
        echo 
    "</td></tr>";
        echo 
    "<tr><td colspan=3>&nbsp;</td></tr>";
            }
        echo 
    "</table>";

        
    ?>

        <center><br>
        <input type=hidden name=ID value="<?php echo $_GET['ID']; ?>">
        <input type=hidden name=q value="<?php echo $_GET['q']; ?>">
        <input type=hidden name=p value="<?php echo $_GET['p']; ?>">
        <input type=submit name="Update" value="Back" class=TxtBut>&nbsp;&nbsp;&nbsp;
        <input type=submit name="Update" value="Save" class=TxtBut>
        </form>
        <br></center>

    <?php   include ('logo_footer.php');?>

    </body>

    </html>

  • #9
    UE Antagonizer Fumigator's Avatar
    Join Date
    Dec 2005
    Location
    Utah, USA, Northwestern hemisphere, Earth, Solar System, Milky Way Galaxy, Alpha Quadrant
    Posts
    7,691
    Thanks
    42
    Thanked 637 Times in 625 Posts
    You have no <form> tag.

  • #10
    New Coder
    Join Date
    Jul 2006
    Posts
    30
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I hate that, you tend to miss the simple things... Ok now that it submits I am lacking in the update logic. I replace insert into with udate and having a small problem.

    The error "Query failed : You have an error in your SQL syntax. Check the manual that corresponds to your MySQL server version for the right syntax to use near 'SET Quantity='', SellingPrice='', WHERE I"

    I am testing over and over on mysql server but don't get the same results..

    Before
    PHP Code:
    mysql_select_db($dbname);
    mysql_query("INSERT INTO ".$Ttable.
                        (Quantity, SellingPrice)
                        VALUES
                        ('$Q','$P')"
    )
                         or die(
    "Query failed : " mysql_error()); 
    After using the Update command instead

    PHP Code:
    mysql_select_db($dbname);
                    
                    
    mysql_query("UPDATE ".$Ttable.
                                SET 
                                Quantity='"
    .$Q."',
                                SellingPrice='"
    .$P."',
                                WHERE ID="
    .$_GET["ID"] ) 
                            or die(
    "Query failed : " mysql_error()); 
    Last edited by smarlar; 08-16-2006 at 10:39 PM.

  • #11
    UE Antagonizer Fumigator's Avatar
    Join Date
    Dec 2005
    Location
    Utah, USA, Northwestern hemisphere, Earth, Solar System, Milky Way Galaxy, Alpha Quadrant
    Posts
    7,691
    Thanks
    42
    Thanked 637 Times in 625 Posts
    Whenever I have a SQL syntax error I echo out the query string and if I can't see anything wrong by doing that, I copy/paste it into an adhoc query engine (such as PHPMyAdmin) and tweak it there to see if I can find the problem.

    In your case you are putting the string directly into your mysql_query() function, so in order to debug you'll need to break the string out with a $query = "UPDATE blah blah blah"; statement and then a echo $query statement.

  • #12
    New Coder
    Join Date
    Jul 2006
    Posts
    30
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I trying to narrow it down and did not fully understand your comment of echoing It out. Are you reffering to the following?

    PHP Code:
    $query"UPDATE ".$Ttable.
                                SET 
                                Quantity='"
    .$Q."',
                                SellingPrice='"
    .$P."',
                                WHERE ID="
    .$_GET["ID"

    Echo 
    "$query" 
    I am wondering if the variables are correctly coded, the error makes be believe that its how I am setting them.

    PHP Code:
    Quantity='".$Q."',
                                
    SellingPrice='".$P."'
    Given that I am setting the constants below using inputs from the EquipmentUpd.php page.

    PHP Code:
    echo "&nbsp;&nbsp;<b>Quantity:</b> <input type=text name=TLqty size=10 class=TxtBut";
            if (isset(
    $Q)) echo " value=\"".$Q."\"";
        echo 
    "&nbsp;&nbsp;<b>Price:</b> <input type=text name=TLprice size=10 class=TxtBut";
            if (isset(
    $P)) echo " value=\"".$P."\" </td></tr>"
    It's a bit fuzzy for me, the code is'nt given me the problem just the results.


  •  

    Posting Permissions

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