#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2012
    Posts
    2
    Rep Power
    0

    Add and subtract stock


    Hello. recently i'm creating this php file. But once i add a new function, which is for subtracting the element that had been released, it shows this error
    Parse error: syntax error, unexpected $end in C:\xampp\htdocs\mimin\updating.php on line 191

    and i dont have any idea how to solve it.

    This is my coding,

    PHP Code:
    ?><table id="mytable" cellspacing="0" width="700" border="1" align="center">
      <tr>
        <th width="10" scope="col" rowspan="2">Bil</th>
        <th width="150" scope="col" rowspan="2"><div align="center">Item</div></th>
        <th width="100" scope="col" colspan="2"><div align="center">Kuantiti</div></th>
        <th width="50" scope="col" rowspan="2"><div align="center">Padam</div></th>
        <th width="50" scope="col" rowspan="2"><div align="center">Update</div></th>
        <th width="50" scope="col" rowspan="2"><div align="center">Keluar</div></th>
         <tr><th width="50" scope="col"><div align="center">Masuk</div></th>
        <th width="50" scope="col"><div align="center">Keluar</div></th>
      </tr>

    <?php
    $dbhostname 
    "localhost";
    $dbusername "root";
    $dbpassword "";
    $databasename "try";

    $con1 mysql_connect("localhost","root","");
    $tablename "stok";
    if (!
    $con1)
        die (
    mysql_error()); 

    mysql_select_db("try"$con1);
    $query_string "SELECT * FROM $tablename";
    $rs1 mysql_query($query_string$con1) or die(mysql_error());

    while (
    $row_rsl mysql_fetch_assoc($rs1)){
        echo 
    '<tr>';
        echo 
    '<td>' $row_rsl['id'] . '</td>';
        echo 
    '<td>' $row_rsl['item'] . '</td>';
        echo 
    '<td>' $row_rsl['in_stock'] . '</td>';
        echo 
    '<td>' $row_rsl['out_stock']. '</td>';
        echo 
    '<td><a href="updating.php?act=padam&id=' $row_rsl['id'] . '">Padam</a></td>';
        echo 
    '<td><a href="updating.php?act=update&id=' $row_rsl['id'] . '">Tambah stok</a></td>';
        echo 
    '<td><a href="updating.php?act=out&id=' $row_rsl['id'] . '">Keluar stok</a></td>';    
        echo 
    '</tr>';
        }

    mysql_free_result($rs1);
    mysql_close($con1);
        
    ?>  
    </table> 

    <?php
    //fungsi untuk stok keluar
    if (isset($_POST['out'])) {
        
    $con1 mysql_connect($dbhostname$dbusername$dbpassword);
        if (!
    $con1)
            die (
    mysql_error()); 

        
    mysql_select_db($databasename$con1);
        
    $item_id = ($_POST['iddata']);
        
    $item_item stripslashes($_POST['item_baru']);
        
    $keluarstripslashes($_POST['kuantiti_baru_keluar']);
        
        
        
    $query_tambah "UPDATE $tablename SET item ='$item_item', out_stock = in_stock -'$keluar' WHERE id ='$item_id'";
        if (
    mysql_query($query_tambah$con1))
            echo 
    "<p>Data berjaya ditolak</p>";
        else
            echo 
    "<p>Data gagal ditolak: " . die(mysql_error()) . "</p>";
            
        
    mysql_close($con1);
        
    //refresh
        
    header ("Location:updating.php");
        }

    //fungsi2 url link
    if (isset ($_GET['act'])) {
        
        
    //fungsi untuk edit data
        
    if ($_GET['act'] == 'out') {

            
    $id_data $_GET['id'];
            
    $con1 mysql_connect($dbhostname$dbusername$dbpassword);
            if (!
    $con1)
                die (
    mysql_error()); 
            
            
    mysql_select_db($databasename$con1);
            
    $query_string "SELECT * FROM $tablename WHERE id ='$id_data'";
            
    $rs1 mysql_query($query_string$con1) or die(mysql_error());
            
    $row_rsl mysql_fetch_assoc($rs1);
            
    ?>
           
            <form id="form1" name="form1" method="post" action="updating.php">
              <table width="400" border="1" align="center">
                <tr><td width="101">Item</td>
                  <td width="283"><input name="item_baru" type="text" size="30" value="<?php echo $row_rsl['item'];?>"/></td></tr>
                <tr>
                  <td>Kuantiti</td>
                  <td><input name="kuantiti_baru" type="text" size="30" value =""/></td>
                </tr>
                <tr>
                  <td>&nbsp;</td>
                 <td><input type="submit" name="submit" id="submit" value="Update" />
                 <input type="hidden" name="iddata" value="<?php echo $row_rsl['id'];?>" /><input type="hidden" name="update" value="TRUE" /></td>
                </tr>
                  </table>
                            </form></p>    
    <?php
    //fungsi untuk tambah/edit data
    if(isset($_POST['update'])) {
        
    $con1 mysql_connect($dbhostname$dbusername$dbpassword);
        if (!
    $con1)
            die (
    mysql_error()); 

        
    mysql_select_db($databasename$con1);
        
    $item_id = ($_POST['iddata']);
        
    $item_item stripslashes($_POST['item_baru']);
        
    $masukstripslashes($_POST['kuantiti_baru']);
        
        
        
    $query_tambah "UPDATE $tablename SET item ='$item_item', in_stock = in_stock +'$masuk' WHERE id ='$item_id'";
        if (
    mysql_query($query_tambah$con1))
            echo 
    "<p>Data berjaya ditambah</p>";
        else
            echo 
    "<p>Data gagal ditambah: " . die(mysql_error()) . "</p>";
            
        
    mysql_close($con1);
        
    //refresh
        
    header ("Location:updating.php");
        }

    //fungsi2 url link
    if (isset ($_GET['act'])) {
        
        
    //fungsi untuk tambah data
        
    if ($_GET['act'] == 'update') {

            
    $id_data $_GET['id'];
            
    $con1 mysql_connect($dbhostname$dbusername$dbpassword);
            if (!
    $con1)
                die (
    mysql_error()); 
            
            
    mysql_select_db($databasename$con1);
            
    $query_string "SELECT * FROM $tablename WHERE id ='$id_data'";
            
    $rs1 mysql_query($query_string$con1) or die(mysql_error());
            
    $row_rsl mysql_fetch_assoc($rs1);
            
    ?>
           
            <form id="form1" name="form1" method="post" action="updating.php">
              <table width="400" border="1" align="center">
                <tr><td width="101">Item</td>
                  <td width="283"><input name="item_baru" type="text" size="30" value="<?php echo $row_rsl['item'];?>"/></td></tr>
                <tr>
                  <td>Kuantiti</td>
                  <td><input name="kuantiti_baru" type="text" size="30" value =""/></td>
                </tr>
                <tr>
                  <td>&nbsp;</td>
                 <td><input type="submit" name="submit" id="submit" value="Update" />
                 <input type="hidden" name="iddata" value="<?php echo $row_rsl['id'];?>" /><input type="hidden" name="update" value="TRUE" /></td>
                </tr>
                  </table>
                </form></p>
      

                
    <?php    
    mysql_close
    ($con1);
    }

    //fungsi untuk padam data
    if ($_GET['act'] == 'padam') {
            
    $con1 mysql_connect($dbhostname$dbusername$dbpassword);
            if (!
    $con1)
                die (
    mysql_error()); 

            
    mysql_select_db($databasename$con1);
        
            
    $id_komen $_GET['id'];
            
    $query_padam "DELETE FROM $tablename WHERE id = '$id_komen'";
            if (
    mysql_query($query_padam$con1))
                echo 
    "<p>Data berjaya padam</p>";
            else
                echo 
    "<p>Data gagal dipadam: " . die(mysql_error()) . "</p>";
            
    mysql_close($con1);
        
    //refresh
            
    header ("Location:updating.php");
        
            }
        }
    ?>


    <div align="center">
        <form action="inventoritest.php">
        <input type="submit" value="Borang inventori" />        
        </form>
    [[ please use php tags when posting PHP code --requinix ]]

    Hope someone can help me out. Thank you.
    Last edited by requinix; November 1st, 2012 at 05:06 AM.
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Jul 2003
    Posts
    3,621
    Rep Power
    595
    You probably have a misplaced or missing '}' somewhere. But without knowing which is line 191 is it hard to pinpoint the problem.
    There are 10 kinds of people in the world. Those that understand binary and those that don't.
  4. #3
  5. Sarcky
    Devshed Supreme Being (6500+ posts)

    Join Date
    Oct 2006
    Location
    Pennsylvania, USA
    Posts
    10,908
    Rep Power
    6352
    Until you're very well versed in PHP, be explicit and use { and } for every control structure, even one-line IF statements.

    Look at this one small section of your code:
    PHP Code:
    if ($_GET['act'] == 'padam') { 
            
    $con1 mysql_connect($dbhostname$dbusername$dbpassword); 
            if (!
    $con1
                die (
    mysql_error());  

            
    mysql_select_db($databasename$con1); 
         
            
    $id_komen $_GET['id']; 
            
    $query_padam "DELETE FROM $tablename WHERE id = '$id_komen'"
            if (
    mysql_query($query_padam$con1)) 
                echo 
    "<p>Data berjaya padam</p>"
            else 
                echo 
    "<p>Data gagal dipadam: " . die(mysql_error()) . "</p>"
            
    mysql_close($con1); 
        
    //refresh 
            
    header ("Location:updating.php"); 
         
            } 
        } 
    How many { characters are there? How many } characters? I count one opening and two closing characters in what LOOKS like a normal and well-ordered block of code.

    Get an editor with brace matching (like Eclipse PDT) and always use braces so you avoid this problem.

    The error you're getting means you have more { than }, but some of your blocks (like the one above) have more } than {. You just have to go through and verify all your own logic by hand, re-doing all your indentations and adding braces to every IF, ELSEIF, and ELSE.
    HEY! YOU! Read the New User Guide and Forum Rules

    "They that can give up essential liberty to obtain a little temporary safety deserve neither liberty nor safety." -Benjamin Franklin

    "The greatest tragedy of this changing society is that people who never knew what it was like before will simply assume that this is the way things are supposed to be." -2600 Magazine, Fall 2002

    Think we're being rude? Maybe you asked a bad question or you're a Help Vampire. Trying to argue intelligently? Please read this.
  6. #4
  7. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2012
    Posts
    2
    Rep Power
    0
    oh , okay. i'm still new in this field and really need a guide. thanks for correcting me. i will double check the use of { and }. its really make me stuck and confused.

IMN logo majestic logo threadwatch logo seochat tools logo