texmansru47 Posted June 3, 2008 Share Posted June 3, 2008 Im trying to develop a PHP form that allows the user to input a value on the form, then the $_POST value will be subtracted from a QTY value that I get from searching the INV database for the Product Number selected in the same php form as the subtracting amount. Everything works if I eliminate the subtraction (the query pulls the proper database value, and the history table is updated with the proper value minus the new QTY on Hand). Here is the code I have for the php portion: <?php // Connect to mysql database $con = mysql_connect("localhost","user","password") or die(`Connection: ` . mysql_error());; mysql_select_db("logdata", $con) or die(`Database: ` . mysql_error()); mysql_select_db("logdata", $con); $consumed=$_POST['consumed']; $ProdNum=$_POST['ProdNum']; $copy = mysql_fetch_array(mysql_query("SELECT * FROM `SNAInv` WHERE `ProdNum`= `$ProdNum`")) or die(mysql_error()); $subtract = $copy[`QtyOnHand`] - $consumed; $sql = mysql_query("UPDATE `SNAInv` SET `QtyOnHand` = '$subtract' WHERE `ProdNum` = '$ProdNum'"); $sqlrun=mysql_query($sql) or die(mysql_error()); $hist = @mysql_query("INSERT INTO `SNAInvHist` (`ProdNum`, `ProdDesc`, `QtyOnHand`, `Consumed`, `RecvDate`, `ConSumDate`) VALUES (`" . $copy[`ProdNum`] . "`, `" . $copy[`ProdDesc`] . "`, $subtract, `". $_POST[Consumed] ."`, `". $copy[RecvDate] ."`, Now())") or die(mysql_error()); echo "Inventory For Part Number:\n" .$copy[`ProdNum`] ." has been modified and a Transaction has been recorded "; echo "new Quantity is:\n $subtract; mysql_close($sqlrun,$con); ?> Here is the code for the form: <html> <head> <title>Card Inventory</title> </head> <body bgcolor="#C0C0C0"> <b><img border="0" src="logo1.jpg" width="78" height="77"> <font face="Arial" color="#000080">SNA Inventory - Managing Inventory Input</font></b><font face="Arial" color="#000080"> <P> <form method="POST" name="Recv" action="queryme.php"> <table width="550" border="0" cellspacing="2" cellpadding="3"> <tr> <td colspan="2" bgcolor="#000000"><span class="style1">Managing Inventory Control</span></td> </tr> <tr> <td bgcolor="#FFCC66">Part Number: </td> <td bgcolor="#CCCCCC"><input name="ProdNum" type="text" id="ProdNum"></td> </tr> <tr> <td width="159" bgcolor="#FFCC66">Part Description:</td> <td width="373" bgcolor="#CCCCCC"><input name="ProdDesc" type="text" id="ProdDesc"></td> </tr> <tr> <td bgcolor="#FFCC66">Amount Consumed: </td> <td bgcolor="#CCCCCC"><input name="Consumed" type="text" id="Consumed"></td> </tr> <tr> <td> </td> <td><input type="submit" value="Submit Modifications" /></td> </tr> </table> </form> </body> </html> I get the following error: Parse error: parse error in /var/www/htdocs/sna/queryme.php on line 26 Which is the last line of the php code - the ?> value... I know I have som wrong syntax, but for the life of me I cannot find it... I was hoping someone out there could see it and let me know where I screwed up. Thanks in advance, Texman Quote Link to comment https://forums.phpfreaks.com/topic/108481-solved-trying-to-subtract-getting-a-parse-error-on-the-last-line-the-gt-line/ Share on other sites More sharing options...
jonsjava Posted June 3, 2008 Share Posted June 3, 2008 you forgot a quote at the bottom <?php // Connect to mysql database $con = mysql_connect("localhost","user","password") or die(`Connection: ` . mysql_error());; mysql_select_db("logdata", $con) or die(`Database: ` . mysql_error()); mysql_select_db("logdata", $con); $consumed=$_POST['consumed']; $ProdNum=$_POST['ProdNum']; $copy = mysql_fetch_array(mysql_query("SELECT * FROM `SNAInv` WHERE `ProdNum`= `$ProdNum`")) or die(mysql_error()); $subtract = $copy[`QtyOnHand`] - $consumed; $sql = mysql_query("UPDATE `SNAInv` SET `QtyOnHand` = '$subtract' WHERE `ProdNum` = '$ProdNum'"); $sqlrun=mysql_query($sql) or die(mysql_error()); $hist = @mysql_query("INSERT INTO `SNAInvHist` (`ProdNum`, `ProdDesc`, `QtyOnHand`, `Consumed`, `RecvDate`, `ConSumDate`) VALUES (`" . $copy[`ProdNum`] . "`, `" . $copy[`ProdDesc`] . "`, $subtract, `". $_POST[Consumed] ."`, `". $copy[RecvDate] ."`, Now())") or die(mysql_error()); echo "Inventory For Part Number:\n" .$copy[`ProdNum`] ." has been modified and a Transaction has been recorded "; echo "new Quantity is:\n". $subtract; mysql_close($sqlrun,$con); ?> Quote Link to comment https://forums.phpfreaks.com/topic/108481-solved-trying-to-subtract-getting-a-parse-error-on-the-last-line-the-gt-line/#findComment-556217 Share on other sites More sharing options...
texmansru47 Posted June 3, 2008 Author Share Posted June 3, 2008 I believe you are talking about this following: echo "new Quantity is:\n". $subtract; If so, I added it and I get the same error. Now the php code takes my QtyOnHand to "0" for the ProdNum I select... fun, huh? If you can offer any assistance I would be grateful... Trying to learn this stuff as fast as possible... after 20 years in infrastructure and executive management this is more fun, but a real booger to figure out without manuals and training. I take my hat off to you all. Texman Quote Link to comment https://forums.phpfreaks.com/topic/108481-solved-trying-to-subtract-getting-a-parse-error-on-the-last-line-the-gt-line/#findComment-556962 Share on other sites More sharing options...
LooieENG Posted June 3, 2008 Share Posted June 3, 2008 <?php // Connect to mysql database $con = mysql_connect("localhost","user","password") or die(`Connection: ` . mysql_error());; mysql_select_db("logdata", $con) or die(`Database: ` . mysql_error()); mysql_select_db("logdata", $con); $consumed=$_POST['consumed']; $ProdNum=$_POST['ProdNum']; $copy = mysql_fetch_array(mysql_query("SELECT * FROM `SNAInv` WHERE `ProdNum`= `$ProdNum`")) or die(mysql_error()); $subtract = $copy[`QtyOnHand`] - $consumed; $sql = mysql_query("UPDATE `SNAInv` SET `QtyOnHand` = '$subtract' WHERE `ProdNum` = '$ProdNum'"); $sqlrun=mysql_query($sql) or die(mysql_error()); $hist = @mysql_query("INSERT INTO `SNAInvHist` (`ProdNum`, `ProdDesc`, `QtyOnHand`, `Consumed`, `RecvDate`, `ConSumDate`) VALUES (`$copy[ProdNum]`, `$copy[ProdDesc]`, `$subtract`, `$_POST[Consumed]`, `$copy[RecvDate]`, `Now()`)") or die(mysql_error()); echo "Inventory For Part Number:\n" .$copy[`ProdNum`] ." has been modified and a Transaction has been recorded "; echo "new Quantity is:\n" . $subtract; mysql_close($sqlrun,$con); ?> Does that work? Quote Link to comment https://forums.phpfreaks.com/topic/108481-solved-trying-to-subtract-getting-a-parse-error-on-the-last-line-the-gt-line/#findComment-556979 Share on other sites More sharing options...
texmansru47 Posted June 4, 2008 Author Share Posted June 4, 2008 No. I got an syntax error then I made this change per the error message: $copy = mysql_fetch_array(mysql_query("SELECT * FROM `SNAInv` WHERE `ProdNum` = `$_POST[ProdNum]`")) or die(mysql_error()); Now I get the following error: Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /var/www/htdocs/sna/invtest.php on line 10 Unknown column '2002228' in 'where clause' the '2002228' is the $_POST[ProdNum] from the html form. Any ideas? Quote Link to comment https://forums.phpfreaks.com/topic/108481-solved-trying-to-subtract-getting-a-parse-error-on-the-last-line-the-gt-line/#findComment-557139 Share on other sites More sharing options...
texmansru47 Posted June 4, 2008 Author Share Posted June 4, 2008 The code I changed was: $copy = mysql_fetch_array(mysql_query("SELECT * FROM `SNAInv` WHERE `ProdNum` = `$_POST[ProdNum]`")) or die(mysql_error()); For some reason it is not showing. Quote Link to comment https://forums.phpfreaks.com/topic/108481-solved-trying-to-subtract-getting-a-parse-error-on-the-last-line-the-gt-line/#findComment-557141 Share on other sites More sharing options...
LooieENG Posted June 4, 2008 Share Posted June 4, 2008 Okay, try this <?php // Connect to mysql database $con = mysql_connect('localhost', 'user', 'password') or die('Connection: ' . mysql_error()); mysql_select_db('logdata', $con) or die('Database: ' . mysql_error()); $consumed = $_POST['consumed']; $ProdNum = $_POST['ProdNum']; $result = mysql_query("SELECT * FROM SNAInv WHERE ProdNum = '$ProdNum'"); $copy = mysql_fetch_array($result) or die(mysql_error()); $subtract = ( $copy['QtyOnHand'] - $consumed ); $sqlrun = mysql_query("UPDATE SNAInv SET QtyOnHand = '$subtract' WHERE ProdNum = '$ProdNum'") or die(mysql_error()); $hist = mysql_query("INSERT INTO SNAInvHist ('ProdNum', 'ProdDesc', 'QtyOnHand', 'Consumed', 'RecvDate', 'ConSumDate') VALUES (`$copy[ProdNum]', '$copy[ProdDesc]', '$subtract', '$_POST[Consumed]', '$copy[RecvDate]', 'Now()')") or die(mysql_error()); echo 'Inventory For Part Number: ' . $copy['ProdNum'] . ' has been modified and a Transaction has been recorded. New Quantity is: ' . $subtract; mysql_close($con); ?> Quote Link to comment https://forums.phpfreaks.com/topic/108481-solved-trying-to-subtract-getting-a-parse-error-on-the-last-line-the-gt-line/#findComment-557792 Share on other sites More sharing options...
revraz Posted June 4, 2008 Share Posted June 4, 2008 Dont put backticks around your SQL data variables. No. I got an syntax error then I made this change per the error message: $copy = mysql_fetch_array(mysql_query("SELECT * FROM `SNAInv` WHERE `ProdNum` = `$_POST[ProdNum]`")) or die(mysql_error()); Now I get the following error: Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /var/www/htdocs/sna/invtest.php on line 10 Unknown column '2002228' in 'where clause' the '2002228' is the $_POST[ProdNum] from the html form. Any ideas? Quote Link to comment https://forums.phpfreaks.com/topic/108481-solved-trying-to-subtract-getting-a-parse-error-on-the-last-line-the-gt-line/#findComment-557797 Share on other sites More sharing options...
Zane Posted June 5, 2008 Share Posted June 5, 2008 most always....well everytime it's happened to me when you get an error at the very end of your script...it's because you're missing a curly brace or you have one to many...which is pretty much the same as missing one Quote Link to comment https://forums.phpfreaks.com/topic/108481-solved-trying-to-subtract-getting-a-parse-error-on-the-last-line-the-gt-line/#findComment-557998 Share on other sites More sharing options...
texmansru47 Posted June 5, 2008 Author Share Posted June 5, 2008 Dont put backticks around your SQL data variables. Do you mena remove the outer ticks such as: $_POST[ProdNum] Is that what you mean? Quote Link to comment https://forums.phpfreaks.com/topic/108481-solved-trying-to-subtract-getting-a-parse-error-on-the-last-line-the-gt-line/#findComment-558002 Share on other sites More sharing options...
texmansru47 Posted June 5, 2008 Author Share Posted June 5, 2008 most always....well everytime it's happened to me when you get an error at the very end of your script...it's because you're missing a curly brace or you have one to many...which is pretty much the same as missing one I have ran into that TOO many times myself. I will start to count them. Thanks, Texman Quote Link to comment https://forums.phpfreaks.com/topic/108481-solved-trying-to-subtract-getting-a-parse-error-on-the-last-line-the-gt-line/#findComment-558003 Share on other sites More sharing options...
texmansru47 Posted June 5, 2008 Author Share Posted June 5, 2008 Well, I got it to run but a new problem as arisen. For some reason I get a negative value of the data inputted into the form by the user. So for example, I have a Qty On Hand of 8000 units... I run the form and say I'm consuming 450 units. The results are I will have a Qty on Hand of -450. To me it appears that this code: $sql = "SELECT * FROM `SNAInv` WHERE `ProdNum`= '$_POST[ProdNum]'"; $result = mysql_query($sql) or die('Query Error: ' . mysql_error()); $copy = mysql_fetch_array($result); Is not working... i.e. is not pulling the proper data required from the table in question. OR my subtract statement of: $newquant = $sql[QtyOnHand] - $_POST[Consumed]; is telling my QtyOnHand pulled from the initial query to hit the road jake and it over writes the QtyOn Hand as "0" or ignores it. I cannot really tell... but from the initial query (listed in the first code string) is working since the secondary table I try to populate is collecting that data from that query and is inserting it... the only thing not working is the subtraction part... again. Any ideas? Texman Quote Link to comment https://forums.phpfreaks.com/topic/108481-solved-trying-to-subtract-getting-a-parse-error-on-the-last-line-the-gt-line/#findComment-558004 Share on other sites More sharing options...
digitalgod Posted June 5, 2008 Share Posted June 5, 2008 you need to do $newquant = $copy['QtyOnHand'] - $_POST[Consumed]; since your results are store in the array $copy hence mysql_fetch_array Quote Link to comment https://forums.phpfreaks.com/topic/108481-solved-trying-to-subtract-getting-a-parse-error-on-the-last-line-the-gt-line/#findComment-558010 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.