PHP Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsProgramming LanguagesPHP Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old November 1st, 2012, 03:56 AM
niy_min niy_min is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2012
Posts: 2 niy_min User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 32 m 9 sec
Reputation 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 04:06 AM.

Reply With Quote
  #2  
Old November 1st, 2012, 07:57 AM
gw1500se gw1500se is online now
Contributing User
Dev Shed Frequenter (2500 - 2999 posts)
 
Join Date: Jul 2003
Posts: 2,879 gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level) 
Time spent in forums: 1 Year 2 Weeks 1 Day 1 h 52 m 38 sec
Reputation Power: 581
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.

Reply With Quote
  #3  
Old November 1st, 2012, 08:12 AM
ManiacDan's Avatar
ManiacDan ManiacDan is online now
Likely to be eaten by a grue.
Dev Shed God 10th Plane (9500 - 9999 posts)
 
Join Date: Oct 2006
Location: Pennsylvania, USA
Posts: 9,805 ManiacDan User rank is General 77th Grade (Above 100000 Reputation Level)ManiacDan User rank is General 77th Grade (Above 100000 Reputation Level)ManiacDan User rank is General 77th Grade (Above 100000 Reputation Level)ManiacDan User rank is General 77th Grade (Above 100000 Reputation Level)ManiacDan User rank is General 77th Grade (Above 100000 Reputation Level)ManiacDan User rank is General 77th Grade (Above 100000 Reputation Level)ManiacDan User rank is General 77th Grade (Above 100000 Reputation Level)ManiacDan User rank is General 77th Grade (Above 100000 Reputation Level)ManiacDan User rank is General 77th Grade (Above 100000 Reputation Level)ManiacDan User rank is General 77th Grade (Above 100000 Reputation Level)ManiacDan User rank is General 77th Grade (Above 100000 Reputation Level)ManiacDan User rank is General 77th Grade (Above 100000 Reputation Level)ManiacDan User rank is General 77th Grade (Above 100000 Reputation Level)ManiacDan User rank is General 77th Grade (Above 100000 Reputation Level)ManiacDan User rank is General 77th Grade (Above 100000 Reputation Level)ManiacDan User rank is General 77th Grade (Above 100000 Reputation Level)  Folding Points: 127430 Folding Title: Super Ultimate Folder - Level 1Folding Points: 127430 Folding Title: Super Ultimate Folder - Level 1Folding Points: 127430 Folding Title: Super Ultimate Folder - Level 1Folding Points: 127430 Folding Title: Super Ultimate Folder - Level 1Folding Points: 127430 Folding Title: Super Ultimate Folder - Level 1Folding Points: 127430 Folding Title: Super Ultimate Folder - Level 1
Time spent in forums: 2 Months 3 Weeks 17 h 42 m 42 sec
Reputation Power: 6112
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.

Reply With Quote
  #4  
Old November 1st, 2012, 08:26 AM
niy_min niy_min is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2012
Posts: 2 niy_min User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 32 m 9 sec
Reputation 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.

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesPHP Development > Add and subtract stock

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap