[PHP] List problem again...
In my HTML5/PHP form I have this two rows.. trtd align=left valign=top0082/tdtd align=left valign=topExan E/tdtd align=left valign=topLEXE25NO/tdtd align=left valign=top200/td td align=center valign=topinput type=hidden name=leverandor value=Oricainput type=hidden name=valgt_lager value=Svilandinput type=hidden name=un_nr value=0082input type=hidden name=varenavn value=Exan Einput type=hidden name=varenr[] value=LEXE25NO input type=hidden name=adr_vekt_kg[] value=200input type=checkbox name=varenr_inn_pa_lager[] value=LEXE25NO/td/trtr td align=left valign=top0081/tdtd align=left valign=topDynamit - papirpatron - 22x180/tdtd align=left valign=topEDY22X180K/tdtd align=left valign=top100/td td align=center valign=topinput type=hidden name=leverandor value=input type=hidden name=valgt_lager value=Svilandinput type=hidden name=un_nr value=0081 input type=hidden name=varenavn value=Dynamit - papirpatron - 22x180input type=hidden name=varenr[] value=EDY22X180K input type=hidden name=adr_vekt_kg[] value=100input type=checkbox name=varenr_inn_pa_lager[] value=EDY22X180K/td/tr Then I have this in PHP source to handle it... $antall_varenr = count($varenr_inn_pa_lager); $i = 0; if($i $antall_varenr){ foreach($varenr_inn_pa_lager as $vnr){ echo $vnrbr /; } } ++$i; This source code get the serialnumber ($varenr_inn_pa_lager). The problem I struggling with is that it is two different products. The product with serialnumber LEXE25NO is named Exan and the other product with serialnumber EDY22X180K is Dynamite. I need a way to extract products and put them into their own table. The database have one table for Exan and another table for Dynamite, and I recive products for both at the same time. I do not know where to start for put product in their own table knowing by their own serialnumber. I think this is a list problem but need some help to understand this stuff. Thank you very much. I am very thankful for all your help. Karl
[PHP] Ambiguous?
1) query foreach($varenr_inn_pa_lager as $vnr){ include('../../tilkobling.php'); $sql = SELECT * FROM exan,dynamit WHERE varenr = '$vnr' LIMIT 1; $resultat = mysql_query($sql, $tilkobling) or die(mysql_error()); 2) Result: Column 'varenr' in where clause is ambiguous 3) Tables in MySQL database mysql SELECT * FROM exan; ++-+---+--+--+-+ | leverandor | valgt_lager | un_nr | varenavn | varenr | kg_pa_lager | ++-+---+--+--+-+ mysql SELECT * FROM dynamit; ++-+---++---+-++-+ | leverandor | valgt_lager | type | dim_mm | un_nr | varenavn| varenr | kg_pa_lager | ++-+---++---+-++-+ 4) My question: What means with ambiguous here? Thanks. Karl
[PHP] Operand error...
$oppdater_lager_med_antall_kg = $kg_pa_lager + $kg_fra_transportdokument_inn_pa_valgt_lager; result: *Fatal error*: Unsupported operand types in * /Users/karl/Sites/kasen/io/kp/index.php* on line *2970 *I have also tried this: $kg_pa_lager += $kg_fra_transportdokument_inn_pa_valgt_lager; Both of them return this Fatal error. I am using Dreamweaver CS6 and the syntax check in my software say: No syntax error What am I doing wrong this time? Thanks for your good advice! Karl
Re: [PHP] Re: Operand error...
2013/8/8 Jim Giner jim.gi...@albanyhandball.com On 8/8/2013 1:32 PM, Karl-Arne Gjersøyen wrote: $oppdater_lager_med_antall_kg = $kg_pa_lager + $kg_fra_transportdokument_inn_**pa_valgt_lager; result: *Fatal error*: Unsupported operand types in * /Users/karl/Sites/kasen/io/kp/**index.php* on line *2970 *I have also tried this: $kg_pa_lager += $kg_fra_transportdokument_inn_**pa_valgt_lager; Both of them return this Fatal error. I am using Dreamweaver CS6 and the syntax check in my software say: No syntax error What am I doing wrong this time? Thanks for your good advice! Karl You do a var_dump on each variable to see what type they were defined as. NULL array(2) { [0]= string(3) 100 [1]= string(3) 340 }
Re: [PHP] Re: Operand error...
2013/8/8 Jim Giner jim.gi...@albanyhandball.com On 8/8/2013 1:43 PM, Karl-Arne Gjersøyen wrote: 2013/8/8 Jim Giner jim.gi...@albanyhandball.com On 8/8/2013 1:32 PM, Karl-Arne Gjersøyen wrote: $oppdater_lager_med_antall_kg = $kg_pa_lager + $kg_fra_transportdokument_inn_pa_valgt_lager; result: *Fatal error*: Unsupported operand types in * /Users/karl/Sites/kasen/io/kp/index.php* on line *2970 *I have also tried this: $kg_pa_lager += $kg_fra_transportdokument_inn_pa_valgt_lager; Both of them return this Fatal error. I am using Dreamweaver CS6 and the syntax check in my software say: No syntax error What am I doing wrong this time? Thanks for your good advice! Karl You do a var_dump on each variable to see what type they were defined as. NULL array(2) { [0]= string(3) 100 [1]= string(3) 340 } That is one var. What is the other var? Thank you very much! Now I know the error.. One of those variables are NULL! When I fix it I think it work! Karl
Re: [PHP] Re: Operand error...
2013/8/8 Jim Giner jim.gi...@albanyhandball.com On 8/8/2013 1:56 PM, Karl-Arne Gjersøyen wrote: 2013/8/8 Jim Giner jim.gi...@albanyhandball.com On 8/8/2013 1:43 PM, Karl-Arne Gjersøyen wrote: 2013/8/8 Jim Giner jim.gi...@albanyhandball.com On 8/8/2013 1:32 PM, Karl-Arne Gjersøyen wrote: $oppdater_lager_med_antall_kg = $kg_pa_lager + $kg_fra_transportdokument_inn_**pa_valgt_lager; result: *Fatal error*: Unsupported operand types in * /Users/karl/Sites/kasen/io/kp/**index.php* on line *2970 *I have also tried this: $kg_pa_lager += $kg_fra_transportdokument_inn_**pa_valgt_lager; Both of them return this Fatal error. I am using Dreamweaver CS6 and the syntax check in my software say: No syntax error What am I doing wrong this time? Thanks for your good advice! Karl You do a var_dump on each variable to see what type they were defined as. NULL array(2) { [0]= string(3) 100 [1]= string(3) 340 } That is one var. What is the other var? Thank you very much! Now I know the error.. One of those variables are NULL! When I fix it I think it work! Karl actually, the null is ok I think. The array is wrong - you can't 'add' an array to a scalar variable, which an integer or null is. Yes, it is me and arrays again :D $resultat = mysql_query($sql, $tilkobling) or die(mysql_error()); $antall = mysql_num_rows($resultat); for($i = 0; $i $antall; $i++){ $rad = mysql_fetch_array($resultat, MYSQL_ASSOC); and write it tis way can perhaps make someting more correct? For example $variable[$i] ? Karl
[PHP] How to delete 3 months old records in my database?
Hello again, folks! I wish to delete records in my database that is older than 3 months. $todays_date = date('Y-m-d'); $old_records_to_delete = ??? if($old_records_to_delete){ include(connect.php); $sql = DELETE FROM table WHERE date = '$old_records_to_delete'; mysql_query($sql, $connect_db) or die(mysql_error()); } Thank you very much for your help to understand also this question :) Karl
Re: [PHP] How to delete 3 months old records in my database?
2013/8/2 Dušan Novaković ndu...@gmail.com $query = DELECT FROM `__table_name__` WHERE `__date__` BETWEEN NOW() - INTERVAL 3 MONTH AND NOW() This delete everything from now and 3months backwards. I want to store 3 months from now and delete OLDER than 3 months old records. Karl
[PHP] From 24/7/2013 to 2013-07-24
Below is something I try that ofcourse not work because of rsosort. Here is my code: --- $lagret_dato = $_POST['lagret_dato']; foreach($lagret_dato as $dag){ $dag = explode(/, $dag); rsort($dag); $dag = implode(-, $dag); var_dump($dag); What I want is a way to rewrite contents of a variable like this: From 24/7/2013 to 2013-07-24 Is there a way in PHP to do this? Thank you very much. Karl
Re: [PHP] From 24/7/2013 to 2013-07-24
2013/7/26 Davi Marcondes Moreira davi.marcondes.more...@gmail.com Hi! I suggest you to try this: $foo = DateTime::createFromFormat('d/m/Y'); $newDate = $foo-format('Y-m-d'); Thank you veyr much. With a small modification this work perfec! Karl Em 26/07/2013 09:19, Karl-Arne Gjersøyen karlar...@gmail.com escreveu: Below is something I try that ofcourse not work because of rsosort. Here is my code: --- $lagret_dato = $_POST['lagret_dato']; foreach($lagret_dato as $dag){ $dag = explode(/, $dag); rsort($dag); $dag = implode(-, $dag); var_dump($dag); What I want is a way to rewrite contents of a variable like this: From 24/7/2013 to 2013-07-24 Is there a way in PHP to do this? Thank you very much. Karl
[PHP] What wrong am I doing now?
mysql SELECT DATE_FORMAT(dato, '%e-%c-%Y') FROM transportdokument WHERE dato = '2013-07-20' AND dato = '2013-07-24' GROUP BY dato DESC; +---+ | DATE_FORMAT(dato, '%e-%c-%Y') | +---+ | 24-7-2013 | | 23-7-2013 | +---+ 2 rows in set (0.00 sec) mysql // My PHP code looks like this. // - $sql = SELECT DATE_FORMAT(dato, '%e-%c-%Y') FROM transportdokument WHERE dato = '2013-07-20' AND dato = '2013-07-24' GROUP BY dato DESC; $resultat = mysql_query($sql, $tilkobling) or die(mysql_error()); while($rad = mysql_fetch_array($resultat)){ $dato = $rad['dato']; var_dump($dato); I gott NULL,NULL here and believe it is something with my PHP Source that is wrong when using DATE_FORMAT. As you see above it work in terminal. I hope this not is off-topic for the list. If so, I am sorry for it and hope you can give me advice about a good MySQL list for newbie's. Thanks again for your help! Karl
[PHP] Fwd: What wrong am I doing now?
http://www.php.net/manual/en/datetime.format.php have the solution. Sorry for asking before I look at php.net!!! Karl -- Forwarded message -- From: Karl-Arne Gjersøyen karlar...@gmail.com Date: 2013/7/24 Subject: What wrong am I doing now? To: PHP Mailinglist php-general@lists.php.net mysql SELECT DATE_FORMAT(dato, '%e-%c-%Y') FROM transportdokument WHERE dato = '2013-07-20' AND dato = '2013-07-24' GROUP BY dato DESC; +---+ | DATE_FORMAT(dato, '%e-%c-%Y') | +---+ | 24-7-2013 | | 23-7-2013 | +---+ 2 rows in set (0.00 sec) mysql // My PHP code looks like this. // - $sql = SELECT DATE_FORMAT(dato, '%e-%c-%Y') FROM transportdokument WHERE dato = '2013-07-20' AND dato = '2013-07-24' GROUP BY dato DESC; $resultat = mysql_query($sql, $tilkobling) or die(mysql_error()); while($rad = mysql_fetch_array($resultat)){ $dato = $rad['dato']; var_dump($dato); I gott NULL,NULL here and believe it is something with my PHP Source that is wrong when using DATE_FORMAT. As you see above it work in terminal. I hope this not is off-topic for the list. If so, I am sorry for it and hope you can give me advice about a good MySQL list for newbie's. Thanks again for your help! Karl
Re: [PHP] Foreach and mydql_query problem
It works now and it was a php thing.When I combine a for and while loop together with Limit in my query it works. Karl mandag 22. juli 2013 skrev Liam følgende: Shouldn't $_POST['number_of_itemsi'] be $_POST['number_of_items'] Kind Regards, Liam. 3Sharp Ltd. T: 0845 6018370 F: 0845 6018369 -Original Message- From: Karl-Arne Gjersøyen [mailto:karlar...@gmail.com javascript:;] Sent: 22 July 2013 12:39 To: PHP Mailinglist Subject: Re: [PHP] Foreach and mydql_query problem 2013/7/22 Tamara Temple tamouse.li...@gmail.com javascript:; On Jul 22, 2013, at 1:19 AM, Karl-Arne Gjersøyen karlar...@gmail.comjavascript:; wrote: Hello again. I have this this source code that not work as I want... THe PHP/HTHML form fields is generated by a while loop and looks like this: input type=number name=number_of_items[] size=6 value=?hp echo $item; ? required=required the php source code look like this: ?php if(!empty($_POST['number_of_itemsi'])){ include('../../connect.php'); foreach($number_of_items as $itemi){ echo $itemibr; $sql = UPDATE item_table SET number_item = '$item' WHERE date = '$todays_date' AND sign = '$username'; mysql_query($sql,$connect) or die(mysql_error()); } } ? The problem is: Foreach list every items as expected in PHP doc and I thought that $sql and mysql_query should be run five times when I have five items. But the problem is that only the very last number_of_items is written when update the form.. I believe this is becayse number_of_items = '$item in $sqk override every earlier result. So my querstion is. How to to update the database in this case? Thanks again for your good advice and time to help me. Karl' Either the code you posted isn't the actual code, or if it is, the errors should be rather obvious. Post *actual* code. // The acutual source code is below: // == if(!empty($_POST['antall_kolli'])){ include('../../tilkobling.php'); foreach($antall_kolli as $kolli){ echo $kollibr; //echo $kolli. br; $sql = UPDATE transportdokument SET antall_kolli_stk = '$kolli' WHERE dato = '$dagens_dato' AND signatur = '$brukernavn'; mysql_query($sql,$tilkobling) or die(mysql_error()); } } // THE PHP/HTML Form below: include('../../tilkobling.php'); $sql = SELECT * FROM transportdokument WHERE dato = '$dagens_dato' AND signatur = '$brukernavn'; $resultat = mysql_query($sql, $tilkobling) or die(mysql_error()); while($rad = mysql_fetch_array($resultat, MYSQL_ASSOC)){ $valgt_lager = $rad['valgt_lager']; $un_nr = $rad['un_nr']; $sprengstofftype = $rad['sprengstofftype']; $varenavn = $rad['varenavn']; $varenr = $rad['varenr']; $antall_kolli = $rad['antall_kolli_stk']; $adr_vekt_kg = $rad['adr_vekt_kg']; $varenavn = $rad['varenavn']; $emb = $rad['emb']; ? tr td align=left valign=top?php echo $un_nr; ?/td td align=left valign=topstrongSprengstoff/strong,?php echo $sprengstofftype; ?/td td align=left valign=top?php echo $varenavn; ?/td td align=left valign=topstrong1.1D/strong/td td align=left valign=topnbsp;/td td align=left valign=top?php echo $emb; ?/td td align=left valign=top input type=hidden name=varenr[] value=?php echo $varenr; ? input type=number name=antall_kolli[] size=6 value=?php echo $antall_kolli; ? required=required /td td align=left valign=topinput type=text name=exan_kg_ut[] size=6 value=?php echo $adr_vekt_kg; ? required=required/td /tr ?php $total_mengde_kg_adr += $rad['adr_vekt_kg']; $total_antall_kolli += $rad['antall_kolli_stk']; } ? include('../../tilkobling.php'); $sql = SELECT * FROM transportdokument WHERE dato = '$dagens_dato' AND signatur = '$brukernavn'; $resultat = mysql_query($sql, $tilkobling) or die(mysql_error()); while($rad = mysql_fetch_array($resultat, MYSQL_ASSOC)){ $valgt_lager = $rad['valgt_lager']; $un_nr = $rad['un_nr']; $sprengstofftype = $rad['sprengstofftype']; $varenavn = $rad['varenavn']; $varenr = $rad['varenr']; $antall_kolli = $rad['antall_kolli_stk']; $adr_vekt_kg = $rad['adr_vekt_kg']; $varenavn = $rad['varenavn']; $emb = $rad['emb']; ? tr td align=left valign=top?php echo $un_nr; ?/td td align=left valign=topstrongSprengstoff/strong,?php echo $sprengstofftype; ?/td td align=left valign=top?php echo $varenavn; ?/td td align=left valign=topstrong1.1D/strong/td td align=left valign=topnbsp;/td td align=left valign=top?php echo $emb; ?/td td align=left valign=top input type=hidden name=varenr[] value=?php echo $varenr
[PHP] Foreach and mydql_query problem
Hello again. I have this this source code that not work as I want... THe PHP/HTHML form fields is generated by a while loop and looks like this: input type=number name=number_of_items[] size=6 value=?hp echo $item; ? required=required the php source code look like this: ?php if(!empty($_POST['number_of_itemsi'])){ include('../../connect.php'); foreach($number_of_items as $itemi){ echo $itemibr; $sql = UPDATE item_table SET number_item = '$item' WHERE date = '$todays_date' AND sign = '$username'; mysql_query($sql,$connect) or die(mysql_error()); } } ? The problem is: Foreach list every items as expected in PHP doc and I thought that $sql and mysql_query should be run five times when I have five items. But the problem is that only the very last number_of_items is written when update the form.. I believe this is becayse number_of_items = '$item in $sqk override every earlier result. So my querstion is. How to to update the database in this case? Thanks again for your good advice and time to help me. Karl'
Re: [PHP] Foreach and mydql_query problem
2013/7/22 Tamara Temple tamouse.li...@gmail.com On Jul 22, 2013, at 1:19 AM, Karl-Arne Gjersøyen karlar...@gmail.com wrote: Hello again. I have this this source code that not work as I want... THe PHP/HTHML form fields is generated by a while loop and looks like this: input type=number name=number_of_items[] size=6 value=?hp echo $item; ? required=required the php source code look like this: ?php if(!empty($_POST['number_of_itemsi'])){ include('../../connect.php'); foreach($number_of_items as $itemi){ echo $itemibr; $sql = UPDATE item_table SET number_item = '$item' WHERE date = '$todays_date' AND sign = '$username'; mysql_query($sql,$connect) or die(mysql_error()); } } ? The problem is: Foreach list every items as expected in PHP doc and I thought that $sql and mysql_query should be run five times when I have five items. But the problem is that only the very last number_of_items is written when update the form.. I believe this is becayse number_of_items = '$item in $sqk override every earlier result. So my querstion is. How to to update the database in this case? Thanks again for your good advice and time to help me. Karl' Either the code you posted isn't the actual code, or if it is, the errors should be rather obvious. Post *actual* code. // The acutual source code is below: // == if(!empty($_POST['antall_kolli'])){ include('../../tilkobling.php'); foreach($antall_kolli as $kolli){ echo $kollibr; //echo $kolli. br; $sql = UPDATE transportdokument SET antall_kolli_stk = '$kolli' WHERE dato = '$dagens_dato' AND signatur = '$brukernavn'; mysql_query($sql,$tilkobling) or die(mysql_error()); } } // THE PHP/HTML Form below: include('../../tilkobling.php'); $sql = SELECT * FROM transportdokument WHERE dato = '$dagens_dato' AND signatur = '$brukernavn'; $resultat = mysql_query($sql, $tilkobling) or die(mysql_error()); while($rad = mysql_fetch_array($resultat, MYSQL_ASSOC)){ $valgt_lager = $rad['valgt_lager']; $un_nr = $rad['un_nr']; $sprengstofftype = $rad['sprengstofftype']; $varenavn = $rad['varenavn']; $varenr = $rad['varenr']; $antall_kolli = $rad['antall_kolli_stk']; $adr_vekt_kg = $rad['adr_vekt_kg']; $varenavn = $rad['varenavn']; $emb = $rad['emb']; ? tr td align=left valign=top?php echo $un_nr; ?/td td align=left valign=topstrongSprengstoff/strong,?php echo $sprengstofftype; ?/td td align=left valign=top?php echo $varenavn; ?/td td align=left valign=topstrong1.1D/strong/td td align=left valign=topnbsp;/td td align=left valign=top?php echo $emb; ?/td td align=left valign=top input type=hidden name=varenr[] value=?php echo $varenr; ? input type=number name=antall_kolli[] size=6 value=?php echo $antall_kolli; ? required=required /td td align=left valign=topinput type=text name=exan_kg_ut[] size=6 value=?php echo $adr_vekt_kg; ? required=required/td /tr ?php $total_mengde_kg_adr += $rad['adr_vekt_kg']; $total_antall_kolli += $rad['antall_kolli_stk']; } ? include('../../tilkobling.php'); $sql = SELECT * FROM transportdokument WHERE dato = '$dagens_dato' AND signatur = '$brukernavn'; $resultat = mysql_query($sql, $tilkobling) or die(mysql_error()); while($rad = mysql_fetch_array($resultat, MYSQL_ASSOC)){ $valgt_lager = $rad['valgt_lager']; $un_nr = $rad['un_nr']; $sprengstofftype = $rad['sprengstofftype']; $varenavn = $rad['varenavn']; $varenr = $rad['varenr']; $antall_kolli = $rad['antall_kolli_stk']; $adr_vekt_kg = $rad['adr_vekt_kg']; $varenavn = $rad['varenavn']; $emb = $rad['emb']; ? tr td align=left valign=top?php echo $un_nr; ?/td td align=left valign=topstrongSprengstoff/strong,?php echo $sprengstofftype; ?/td td align=left valign=top?php echo $varenavn; ?/td td align=left valign=topstrong1.1D/strong/td td align=left valign=topnbsp;/td td align=left valign=top?php echo $emb; ?/td td align=left valign=top input type=hidden name=varenr[] value=?php echo $varenr; ? input type=number name=antall_kolli[] size=6 value=?php echo $antall_kolli; ? required=required /td td align=left valign=topinput type=text name=exan_kg_ut[] size=6 value=?php echo $adr_vekt_kg; ? required=required/td /tr ?php $total_mengde_kg_adr += $rad['adr_vekt_kg']; $total_antall_kolli += $rad['antall_kolli_stk']; } ?
Re: [PHP] Foreach and mydql_query problem
2013/7/22 Stuart Dallas stu...@3ft9.com On 22 Jul 2013, at 08:04, Tamara Temple tamouse.li...@gmail.com wrote: On Jul 22, 2013, at 1:19 AM, Karl-Arne Gjersøyen karlar...@gmail.com wrote: Hello again. I have this this source code that not work as I want... THe PHP/HTHML form fields is generated by a while loop and looks like this: input type=number name=number_of_items[] size=6 value=?hp echo $item; ? required=required the php source code look like this: ?php if(!empty($_POST['number_of_itemsi'])){ include('../../connect.php'); foreach($number_of_items as $itemi){ echo $itemibr; $sql = UPDATE item_table SET number_item = '$item' WHERE date = '$todays_date' AND sign = '$username'; mysql_query($sql,$connect) or die(mysql_error()); } } ? The problem is: Foreach list every items as expected in PHP doc and I thought that $sql and mysql_query should be run five times when I have five items. But the problem is that only the very last number_of_items is written when update the form.. I believe this is becayse number_of_items = '$item in $sqk override every earlier result. So my querstion is. How to to update the database in this case? Thanks again for your good advice and time to help me. Karl' Either the code you posted isn't the actual code, or if it is, the errors should be rather obvious. Post *actual* code. The error is rather obvious: it loops around an array running an update statement that will modify a single row in the table, so it's not surprising that it appears like only the last entry in the array has been stored. Yes, i know that only one a singe row is updated and that is the problem. What can I do to update several rows at the same time? Thank you very much for all your good adivce. Karl
[PHP] Re: Foreach and mydql_query problem
2013/7/22 Tim Streater t...@clothears.org.uk On 22 Jul 2013 at 12:56, Karl-Arne Gjersøyen karlar...@gmail.com wrote: Yes, i know that only one a singe row is updated and that is the problem. What can I do to update several rows at the same time? Which several rows? The row that will be updated is that (or those) that match your WHERE clause. Seems to me you should make sure your WHERE is correct. Thanks, Tim. Yes the form is generated in a while loop and have input type=number name=number_of_items[] size=6 value=?php echo $item; ?. This field is in several product rows and when I update the form the foreach loop write all (5) products correct. But the other way: Update actual rows in the database did not work. Only the latest row is updated.. Karl
Re: [PHP] Foreach and mydql_query problem
2013/7/22 Stuart Dallas stu...@3ft9.com On 22 Jul 2013, at 12:56, Karl-Arne Gjersøyen karlar...@gmail.com wrote: 2013/7/22 Stuart Dallas stu...@3ft9.com On 22 Jul 2013, at 08:04, Tamara Temple tamouse.li...@gmail.com wrote: On Jul 22, 2013, at 1:19 AM, Karl-Arne Gjersøyen karlar...@gmail.com wrote: Hello again. I have this this source code that not work as I want... THe PHP/HTHML form fields is generated by a while loop and looks like this: input type=number name=number_of_items[] size=6 value=?hp echo $item; ? required=required the php source code look like this: ?php if(!empty($_POST['number_of_itemsi'])){ include('../../connect.php'); foreach($number_of_items as $itemi){ echo $itemibr; $sql = UPDATE item_table SET number_item = '$item' WHERE date = '$todays_date' AND sign = '$username'; mysql_query($sql,$connect) or die(mysql_error()); } } ? The problem is: Foreach list every items as expected in PHP doc and I thought that $sql and mysql_query should be run five times when I have five items. But the problem is that only the very last number_of_items is written when update the form.. I believe this is becayse number_of_items = '$item in $sqk override every earlier result. So my querstion is. How to to update the database in this case? Thanks again for your good advice and time to help me. Karl' Either the code you posted isn't the actual code, or if it is, the errors should be rather obvious. Post *actual* code. The error is rather obvious: it loops around an array running an update statement that will modify a single row in the table, so it's not surprising that it appears like only the last entry in the array has been stored. Yes, i know that only one a singe row is updated and that is the problem. What can I do to update several rows at the same time? Thank you very much for all your good advice. Are you sure you want to update several rows, or do you actually want to insert several rows? This is pretty basic database stuff, and is off-topic for this list. OK. Sorry. I thought it was a PHP question for a way to update several mysql rows by PHP code. Karl
[PHP] Split/Group date together.
Hello again. In my program I have this: mysql SELECT * FROM transportdokument WHERE dato = '16/7/2013' AND dato = '18/7/2013'; This list all reccrds for 3 days. I need a way to split it up for every day even when the requst is as above and don't know in what way I can do it. I like to have all records for day 16 in one table in PHP/HTML and all records for day 17 in another table. i.e, Day 16 have 5 rows and day 17th and 18th have 7 and 8 rows. I hope for your help and advice to do also this correct. Thank you for your time and effort! Karl
[PHP] Hmmm.. I think I need your advice here to get in correct direction...
I am almost ready with my learning project in PHP/MySQL. I can register new product in stock. Add and increase the number and weight. I can move products between different storehouses I can also transfer products from store and onto a truck document but that's it and here I need some advice. I like to register new products and the amount in number (for example 4) and weight in kg. I like to write it in this way: Dynamite - package 4 - Weight 200 kg Lunt - Package 10
[PHP] Fwd: Hmmm.. I think I need your advice here to get in correct direction...
Sorry, the first mail in this subject run out for me. This is an updated one. I am almost ready with my learning project in PHP/MySQL. I can register new product in stock. Add and increase the number and weight. I can move products between different storehouses I can also transfer products from store and onto a truck document but that's it and here I need some advice. I like to register new products and the amount in number (for example 4) and weight in kg. I like to write it in this way: Dynamite - package 4 - Weight 200 kg Lunt - Package 10 - Weight 10kg Then I like to 4+10 = 14 and 200+10 = 210. It shall looks like this: == Dynamite | 4 | 200 Lunt | 10 | 10 -- TOTAL| 14 | 210 It is easy to register this product by product on their own row. but in what way can I multiply them? ned products be stored in arrays? I think it will be similar to shopping cart in online store but i have no clue about how to do this. If you have links to pages were i can learn am i Happy for it. If you can help me here is even better. Thanks for your time and effort to learn me programming. Karl -- Hjemmeside: http://www.karl-arne.name/
Re: [PHP] Re: Fwd: Hmmm.. I think I need your advice here to get in correct direction...
2013/7/10 Jim Giner jim.gi...@albanyhandball.com On 7/10/2013 8:37 AM, Karl-Arne Gjersøyen wrote: Sorry, the first mail in this subject run out for me. This is an updated one. I am almost ready with my learning project in PHP/MySQL. I can register new product in stock. Add and increase the number and weight. I can move products between different storehouses I can also transfer products from store and onto a truck document but that's it and here I need some advice. I like to register new products and the amount in number (for example 4) and weight in kg. I like to write it in this way: Dynamite - package 4 - Weight 200 kg Lunt - Package 10 - Weight 10kg Then I like to 4+10 = 14 and 200+10 = 210. It shall looks like this: ==** Dynamite | 4 | 200 Lunt | 10 | 10 --**--**-- TOTAL| 14 | 210 It is easy to register this product by product on their own row. but in what way can I multiply them? ned products be stored in arrays? I think it will be similar to shopping cart in online store but i have no clue about how to do this. If you have links to pages were i can learn am i Happy for it. If you can help me here is even better. Thanks for your time and effort to learn me programming. Karl Ahhh. So - you should run a query that selects the products and information that you want. Then you start by creating an html table header and then loop through your query results and echo a table row for each result row. // start the table echo table border=1; echo trthProduct/thth**Amount/th/tr; // loop thru each item found while ($results = $qrslts-fetch(PDO::FETCH_**ASSOC)) { echo trtd.$results['product_**name']./tdtd.$results['** product_amt']./td/tr; } // finish the table html echo /table; Yes that part is OK. I do have problem to add total weight and package at bottom of the table like this: Product_one 40kg Product_two 60kg - Total: 100kg === Because sometimes it is only a few products and other times many products. I then need to summing them at bottom. One timer only 3 rows, other times 20 rows. The program need a way to add every singel product and see if it's a few or many, Karl
Re: [PHP] Re: Fwd: Hmmm.. I think I need your advice here to get in correct direction...
2013/7/10 Lester Caine les...@lsces.co.uk Karl-Arne Gjersøyen wrote: // start the table $total = 0; echo table border=1; echo trthProduct/ththAmount/th/tr; // loop thru each item found while ($results = $qrslts-fetch(PDO::FETCH_ASSOC)) { echo trtd.$results['product_name']./tdtd.$results[' product_amt']./td/tr; $total += $results['product_amt'] } echo trtdTotal:/tdtd.$**total./td/tr; // finish the table html echo /table; Yes that part is OK. I do have problem to add total weight and package at bottom of the table like this: Product_one 40kg Product_two 60kg - Total: 100kg === Thank you very Much, Both of you Jim and Lester! You are amazing, folks! Karl
[PHP] Can this work?
Hello. I have a form in HTML/PHP with for loops that generate a selected list like this: for($i = 1; $i 25;$i++ ){ option value=?php echo $i; ??php echo $i; ?/option } The lists look like this: form action=index.php view-source:http://localhost/%7Ekarl/kasen/io/kp/index.php method=postselect name=valgt_dynamit_polse_1-25kgoption value=1-25 selected=selected1-25/optionoption value=11/optionoption value=22/optionoption value=33/optionoption value=44/optionoption value=55/optionoption value=66/optionoption value=77/optionoption value=88/optionoption value=99/optionoption value=1010/optionoption value=/optionoption value=1212/optionoption value=1313/optionoption value=1414/optionoption value=1515/optionoption value=1616/optionoption value=1717/optionoption value=1818/optionoption value=1919/optionoption value=2020/optionoption value=2121/optionoption value=/optionoption value=2323/optionoption value=2424/optionoption value=2525/option/select Kgnbsp;select name=valgt_dynamit_polse_26-50kgoption value=26-50 selected=selected26-50/optionoption value=2626/optionoption value=2727/optionoption value=2828/optionoption value=2929/optionoption value=3030/optionoption value=3131/optionoption value=3232/optionoption value=/optionoption value=3434/optionoption value=3535/optionoption value=3636/optionoption value=3737/optionoption value=3838/optionoption value=3939/optionoption value=4040/optionoption value=4141/optionoption value=4242/optionoption value=4343/optionoption value=/optionoption value=4545/optionoption value=4646/optionoption value=4747/optionoption value=4848/optionoption value=4949/optionoption value=5050/option/select Kgnbsp; What I try to do with it is to register the selected value and do something with it. The lists is weight in KG. I hope to select only one value between 1-25kg OR 26-50kg. I don't know if this is possible? What do you think? Thanks. Karl
Re: [PHP] Can this work?
2013/7/5 Stuart Dallas stu...@3ft9.com On 5 Jul 2013, at 14:56, Karl-Arne Gjersøyen karlar...@gmail.com wrote: Hello. I have a form in HTML/PHP with for loops that generate a selected list like this: for($i = 1; $i 25;$i++ ){ option value=?php echo $i; ??php echo $i; ?/option } The lists look like this: form action=index.php view-source:http://localhost/%7Ekarl/kasen/io/kp/index.php method=postselect name=valgt_dynamit_polse_1-25kgoption value=1-25 selected=selected1-25/optionoption value=11/optionoption value=22/optionoption value=33/optionoption value=44/optionoption value=55/optionoption value=66/optionoption value=77/optionoption value=88/optionoption value=99/optionoption value=1010/optionoption value=/optionoption value=1212/optionoption value=1313/optionoption value=1414/optionoption value=1515/optionoption value=1616/optionoption value=1717/optionoption value=1818/optionoption value=1919/optionoption value=2020/optionoption value=2121/optionoption value=/optionoption value=2323/optionoption value=2424/optionoption value=2525/option/select Kgnbsp;select name=valgt_dynamit_polse_26-50kgoption value=26-50 selected=selected26-50/optionoption value=2626/optionoption value=2727/optionoption value=2828/optionoption value=2929/optionoption value=3030/optionoption value=3131/optionoption value=3232/optionoption value=/optionoption value=3434/optionoption value=3535/optionoption value=3636/optionoption value=3737/optionoption value=3838/optionoption value=3939/optionoption value=4040/optionoption value=4141/optionoption value=4242/optionoption value=4343/optionoption value=/optionoption value=4545/optionoption value=4646/optionoption value=4747/optionoption value=4848/optionoption value=4949/optionoption value=5050/option/select Kgnbsp; What I try to do with it is to register the selected value and do something with it. The lists is weight in KG. I hope to select only one value between 1-25kg OR 26-50kg. I don't know if this is possible? What do you think? If the range of acceptable values is 1-50, why do you have two select fields instead of one? The select list has values between 1 and 200. Therefore I split it up for every 25th value. Karl
Re: [PHP] Can this work?
2013/7/5 Tedd Sperling tedd.sperl...@gmail.com On Jul 5, 2013, at 9:56 AM, Karl-Arne Gjersøyen karlar...@gmail.com wrote: The lists look like this: form action=index.php view-source:http://localhost/%7Ekarl/kasen/io/kp/index.php method=postselect name=valgt_dynamit_polse_1-25kgoption value=1-25 selected=selected1-25/optionoption value=11/optionoption value=22/optionoption Review this: http://sperling.com/php/select/ Also, omit 'multiple' in the select statement. Other than that, the demo shows how to gather the information you want. Cheers, tedd _ tedd.sperl...@gmail.com http://sperling.com Thank you very much! http://www.karl-arne.name/
Re: [PHP] Can this work?
2013/7/5 Stuart Dallas stu...@3ft9.com On 5 Jul 2013, at 15:05, Karl-Arne Gjersøyen karlar...@gmail.com wrote: 2013/7/5 Stuart Dallas stu...@3ft9.com On 5 Jul 2013, at 14:56, Karl-Arne Gjersøyen karlar...@gmail.com wrote: Hello. I have a form in HTML/PHP with for loops that generate a selected list like this: for($i = 1; $i 25;$i++ ){ option value=?php echo $i; ??php echo $i; ?/option } The lists look like this: form action=index.php view-source:http://localhost/%7Ekarl/kasen/io/kp/index.php method=postselect name=valgt_dynamit_polse_1-25kgoption value=1-25 selected=selected1-25/optionoption value=11/optionoption value=22/optionoption value=33/optionoption value=44/optionoption value=55/optionoption value=66/optionoption value=77/optionoption value=88/optionoption value=99/optionoption value=1010/optionoption value=/optionoption value=1212/optionoption value=1313/optionoption value=1414/optionoption value=1515/optionoption value=1616/optionoption value=1717/optionoption value=1818/optionoption value=1919/optionoption value=2020/optionoption value=2121/optionoption value=/optionoption value=2323/optionoption value=2424/optionoption value=2525/option/select Kgnbsp;select name=valgt_dynamit_polse_26-50kgoption value=26-50 selected=selected26-50/optionoption value=2626/optionoption value=2727/optionoption value=2828/optionoption value=2929/optionoption value=3030/optionoption value=3131/optionoption value=3232/optionoption value=/optionoption value=3434/optionoption value=3535/optionoption value=3636/optionoption value=3737/optionoption value=3838/optionoption value=3939/optionoption value=4040/optionoption value=4141/optionoption value=4242/optionoption value=4343/optionoption value=/optionoption value=4545/optionoption value=4646/optionoption value=4747/optionoption value=4848/optionoption value=4949/optionoption value=5050/option/select Kgnbsp; What I try to do with it is to register the selected value and do something with it. The lists is weight in KG. I hope to select only one value between 1-25kg OR 26-50kg. I don't know if this is possible? What do you think? If the range of acceptable values is 1-50, why do you have two select fields instead of one? The select list has values between 1 and 200. Therefore I split it up for every 25th value. Ok, but why? I will use my application on iPad and find it more easy to use multiple select lists than one big list with all 200 values at once. Karl
[PHP] Hmm.. I got NULL here. Why?
My PHP Source = ?php include('../../tilkobling.php'); $sql = SELECT kg_pa_lager FROM dynamit WHERE valgt_lager = '$valgt_lager' AND varenr = '$varenr'; $resultat = mysql_query($sql, $tilkobling) or die(mysql_error()); while($rad = mysql_fetch_array($resultat)){ $kg_pa_lager = $rad['kg_pa_lager']; echo $kg_pa_lager; } var_dump($sql); echo br /; var_dump($kg_pa_lager); ? My var_dump() value; == string(84) SELECT kg_pa_lager FROM dynamit WHERE valgt_lager = 'Tengs' AND varenr = 'EDY22X180' NULL My Database table: === mysql SELECT * FROM dynamit; ++-+---++---+--++-+ | leverandor | valgt_lager | type | dim_mm | un_nr | varenavn | varenr | kg_pa_lager | ++-+---++---+--++-+ | Orica | Tengs | Papirpatroner | 22x180 | 0081 | Dynamit | EDY22X180K | 100 | | Orica | Tengs | Papirpatroner | 25x180 | 0081 | Dynamit | EDY25X180 | 100 | | Orica | Tengs | Plastpølse | 45x540 | 0081 | Dynamit | EDY45X540 | 100 | ++-+---++---+--++-+ 3 rows in set (0.00 sec) mysql The Problem: == If I do this: $sql = SELECT kg_pa_lager FROM dynamit WHERE valgt_lager = '$valgt_lager'; I got 100100100 for kg_pa_lager But if I do this: $sql = SELECT kg_pa_lager FROM dynamit WHERE valgt_lager = '$valgt_lager' AND varenr = '$varenr'; I got NULL. Look at varenr = EDY22X180 in the select where and that it is in the table under varenr. But why is kg_pa_lager NULL? This is strange to me but I guess you know why? Thanks for your advice. Karl
[PHP] Fwd: Hmm.. I got NULL here. Why?
My PHP Source = ?php include('../../tilkobling.php'); $sql = SELECT kg_pa_lager FROM dynamit WHERE valgt_lager = '$valgt_lager' AND varenr = '$varenr'; $resultat = mysql_query($sql, $tilkobling) or die(mysql_error()); while($rad = mysql_fetch_array($resultat)){ $kg_pa_lager = $rad['kg_pa_lager']; echo $kg_pa_lager; } var_dump($sql); echo br /; var_dump($kg_pa_lager); ? My var_dump() value; == string(84) SELECT kg_pa_lager FROM dynamit WHERE valgt_lager = 'Tengs' AND varenr = 'EDY22X180' NULL My Database table: === mysql SELECT * FROM dynamit; ++-+---++---+--++-+ | leverandor | valgt_lager | type | dim_mm | un_nr | varenavn | varenr | kg_pa_lager | ++-+---++---+--++-+ | Orica | Tengs | Papirpatroner | 22x180 | 0081 | Dynamit | EDY22X180K | 100 | | Orica | Tengs | Papirpatroner | 25x180 | 0081 | Dynamit | EDY25X180 | 100 | | Orica | Tengs | Plastpølse | 45x540 | 0081 | Dynamit | EDY45X540 | 100 | ++-+---++---+--++-+ 3 rows in set (0.00 sec) mysql The Problem: == If I do this: $sql = SELECT kg_pa_lager FROM dynamit WHERE valgt_lager = '$valgt_lager'; I got 100100100 for kg_pa_lager But if I do this: $sql = SELECT kg_pa_lager FROM dynamit WHERE valgt_lager = '$valgt_lager' AND varenr = '$varenr'; I got NULL. Look at varenr = EDY22X180 in the select where and that it is in the table under varenr. But why is kg_pa_lager NULL? This is strange to me but I guess you know why? Thanks for your advice. Karl I got the solution. I had forget to write K at end of the serial number. Now it is OK. Karl
[PHP] Hello again. new newbie querstion
I have done as you explain for me an it works very vell in the halft part of my application. But below is my snippet of my source code where the number of items and weight not will update itself. This code do as what number I write in the oppdater_stk_nonel_tenner[] field is written as result, instead of the calculated result. I am also using var_dump() to check my viariables but there is something here I have missed. I hope it is ok to post my norwegian search code as an exaple. If this source code is to difficult because of my long norwegian name (Description of the meaning of varable) i will re-write it all in English as I appricate your good advice and help! Tanks. // My form with array's input type=hidden name=varenr[] value=?php echo $varenr; ? input type=hidden name=stk_pa_lager[] value=?php echo $stk_pa_lager; ? input type=hidden name=kg_pa_lager[] value=?php echo $kg_pa_lager; ? input type=number name=oppdater_stk_nonel_tenner[] size=6 input type=hidden name=valgt_lager value=?php echo $valgt_lager; ? input class=submitKnapp type=submit name=oppdater_nonel_tennere value=Neste if(isset($_POST['oppdater_nonel_tennere'])){ $valgt_lager = $_POST['valgt_lager']; $varenr = $_POST['varenr']; $kg_pa_lager = $_POST['kg_pa_lager']; $stk_pa_lager = $_POST['stk_pa_lager']; $oppdater_stk_nonel_tenner = $_POST['oppdater_stk_nonel_tenner']; include('../../tilkobling.php'); // count how many serialnumber it is the the array for use later in for loop. $antall_varenr = count($varenr); // Run for loop as long as $i is less than or equal to $antall_varenr. for($i=0;$i$antall_varenr;$i++){ // update amont in stock. Adding value of $oppdater_stk_nonel_tenner[$i] to $stk_pa_lager $stk_pa_lager[$i] += $oppdater_stk_nonel_tenner[$i]; // Get new weight in kg in stock $kg_pa_lager = $stk_pa_lager[$i] * 0.001; // Update the database table $sql = UPDATE nonel_tennere SET stk_pa_lager = '$stk_pa_lager[$i]', kg_pa_lager = '$kg_pa_lager' WHERE varenr = '$varenr[$i]' LIMIT 1; mysql_query($sql,$tilkobling) or die(mysql_error()); var_dump($sql); } echo pstrongDatabasen er oppdatert/strong/p; ? form action=index.php method=post input type=hidden name=valgt_lager value=?php echo $valgt_lager; ? input type=hidden name=admin_oppgave value=vis_status input class=submitKnapp type=submit name=velg_lager value=Neste /form ?php } ? I can't figure out why $stk_pa_lager[$i]; is the same as written in $oppdater_stk_nonel_tennere[$i] as long I have us this += operator in $stk_pa_lager[$i] += $oppdater_stk_nonel_tenner[$i]; I have just copy and past it from a working example above and chance the table name and $oppdater_stk_nonel_tenner[$i] variable. Thanks for your time. Karl
[PHP] Re: One more newbie question. About foreach..
WOW! Thank you very, very much! This is so good! Thanks to all of you for spending time to learning me programming! Karl 2013/6/23 Maciek Sokolewicz maciek.sokolew...@gmail.com On 23-6-2013 17:11, Karl-Arne Gjersøyen wrote: Hello again. I Got the solution for my last mention problem. Now I can update several rows at once by one single submit action. [...] I have tried to search in google and on PHP.net but can't fine anything that explain my problem. I like to have new $sql = SELECT queries for every given serialnumber ($snr) Thanks for your help. Karl Ok, Karl, I've seen quite a few messages from you to this list with various questions; from all these questions it becomes clear that you're trying to work with lists in a single form without understanding the basics of a form in the first place. You also seem to not understand what an array is exactly, or how to process it. So let's answer all these questions at once; I will attempt to explain (in short) how to do all this, using a custom form here. I don't speak Norwegian, and I find your variable names to be horribly long and complex, so let's not use them :) Say you want a simple form online which gives you a product name and asks you to update the amount of it in stock. form action=... method=post input type=text name=number_in_stock value=0 input type=submit name=submit value=store /form When you submit this simple form, the PHP script defined in the action property is called, and the $_POST array looks like: $_POST = array( 'number_in_stock' = '0' ); You can then run your simple query mysql_query(UPDATE some_table SET stock=' . $_POST['number_in_stock']); // note: you should always sanitize these values; i.e. make sure it is EXACTLY what you expect, and CAN NOT possibly be anything else. So if you expect it to be a number, check if it IS a number before running this query!!! Now, you said you wanted to update multiple items. Imagine you have a form showing multiple items: form action=... method=post Item A: input type=text name=number_in_stock value=8 Item B: input type=text name=number_in_stock value=2 Item C: input type=text name=number_in_stock value=258 input type=submit name=submit value=store /form If you do this, PHP will have no idea what is what, and it will just keep overwriting the number_in_stock value until it reaches the last one. So you would end up with a $_POST array looking like this: $_POST = array( 'number_in_stock' = '258' ); Obviously, you don't want that. The solution would be to tell PHP to turn all recieved values into an array. This can be done by manually specifying the key for each array item; or letting PHP do it automatically. This automatic way was suggested earlier, like so: form action=... method=post Item A: input type=text name=number_in_stock[] value=8 Item B: input type=text name=number_in_stock[] value=2 Item C: input type=text name=number_in_stock[] value=258 input type=submit name=submit value=store /form This then results in a $_POST array like this: $_POST = array( 'number_in_stock' = array( 0 = '8', 1 = '2', 2 = '258' ) ); So now, do you have any idea what is what? No. You don't. Why? because you don't supply a link between the value and the meaning. Instead, you could decide to supply a certain unique key per item, like so: form action=... method=post Item A: input type=text name=number_in_stock['ItemA']** value=8 Item B: input type=text name=number_in_stock['ItemB']** value=2 Item C: input type=text name=number_in_stock['ItemC']** value=258 input type=submit name=submit value=store /form This results in: $_POST = array( 'number_in_stock' = array( 'ItemA' = '8', 'ItemB' = '2', 'ItemC' = '258' ) ); Wow, now you can actually use this info when updating your table in the DB! foreach($_POST['number_in_**stock'] as $item=$number) { mysql_query(UPDATE table SET stock='.$number.' WHERE itemId='.$item); } This will run over each element in the $_POST['number_in_stock'] array. It will (for that single loop-run) stick the key in $item and the value in $number. For each run, it will run the update query. Then in the next run, a new set of values is supplied, and a new query is ran. If you want to expand this to give you the ability to define which items should be updated and which should not, you could add checkboxes. When checked, the item will be updated; otherwise it won't. Checkboxes have a great feature where if they are checked, they have the value supplied in their value attribute. If they are not checked, they have no value. So, you could add something like: form action=... method=post input type=checkbox name=item_list['ItemA'] value=1 Item A: input type=text name=number_in_stock['ItemA']** value=8 input type=checkbox name=item_list['ItemB'] value=1Item B: input type=text name=number_in_stock['ItemB']** value=2 input type
[PHP] Is it possible???
$item_amount_in_store = 223; $update_amount = 7; $update_item_amount_in_store += $update_amount; $update_amoint_in_store is now 227; Why? That should be 230! Karl
[PHP] Fwd: Is it possible???
Error in my last post This is corrected: $item_amount_in_store = 223; $update_amount = 7; $item_amount_in_Store += $update_amount; It show the result = 227 and not 230. Why is this happen? Karl -- Forwarded message -- From: Karl-Arne Gjersøyen karlar...@gmail.com Date: 2013/6/24 Subject: Is it possible??? To: PHP Mailinglist php-general@lists.php.net $item_amount_in_store = 223; $update_amount = 7; $update_item_amount_in_store += $update_amount; $update_amoint_in_store is now 227; Why? That should be 230! Karl -- Hjemmeside: http://www.karl-arne.name/
[PHP] Hmm remarkable things?
Hello again. Thanks for last answere. It works very well but now I have another remarkable things. Perhaps logic but not for me yet.. I have this source code: (In norwegian but I translate my thoughts through it in english.) The problem with this source code is that it work very well if I select one single item and post it. But when select 2 or more items the same amount are filled in all field named stk_pa_lager in the database. // count and increase the amount of tubes. if(isset($_POST['oppdater_antall_stk_rorladning'])){ // Get store $valgt_lager = $_POST['valgt_lager']; // Get serial number (Array input type=number name=varenr[] size=3) $varenr = $_POST['varenr']; // number of items in store $stk_pa_lager = $_POST['stk_pa_lager']; // Create an array (input type=number name=oppdater_antall_stk_rorladning[] size=3) $oppdater_antall_stk_rorladning = $_POST['oppdater_antall_stk_rorladning']; // Extract the array and save it induvidual as items in $rorladning foreach($oppdater_antall_stk_rorladning as $rorladning){ // Multiply and add new items to that one already is in store $oppdatert_antall_stk_rorladning = $stk_pa_lager + $rorladning; // Extract serialnumber and save them one by one in $vnr foreach($varenr as $vnr){ // Connect to MySQL database include('../../tilkobling.php'); // Update table rorladning $sql = UPDATE rorladning SET stk_pa_lager = '$oppdatert_antall_stk_rorladning' WHERE valgt_lager = '$valgt_lager' AND varenr = '$vnr'; mysql_query($sql, $tilkobling) or die(mysql_error()); } // Output the result to screen echo pRoslash;rladning med varenr: b$vnr/b er oppdatert fra b$stk_pa_lager/b til b$oppdatert_antall_stk_rorladning/b paring; lager: b$valgt_lager/b./p; //echo $oppdatert_antall_stk_rorladningbr; unset($rorladning); unset($vnr); } } // My database table: mysql SELECT * FROM rorladning; ++-+---+-+--+-+--+-+ | leverandor | valgt_lager | un_nr | varenavn| varenr | dim_mm | stk_pa_lager | kg_pa_lager | ++-+---+-+--+-+--+-+ | Orica | Tengs | 0081 | Hvit Rør | ETX1.22X1000 | 22x1000 | 70 | 3.7 | | Orica | Tengs | 0081 | Orange Rør | ETX1.17X460 | 17x460 | 70 | 0.95| ++-+---+-+--+-+--+-+ 2 rows in set (0.00 sec) mysql What I think i am doing wrong is the way I write the php/mysql stuff. What I want is to store differt values in stk_pa_lager based on the particular serialnumber. (field varenr). I will be very thankful if you can tell me what is wrong here and point out what to do with it. Thanks for your time. Karl
[PHP] One more newbie question. About foreach..
Hello again. I Got the solution for my last mention problem. Now I can update several rows at once by one single submit action. In my form I have many records and therefor I use an checkbox to just mark those records I like to update. This work just fine in PHP/HTML5 form and I got it as I want. But the problem now is, how to recognize just those selected records by serialnumber? include('../../connect.php'); // Foreach get all given serialnumbers as I want it foreach($serialnumber as $snr){ // I got the number of serialnumbers given in the array $count = count($serialnumber); // I thought that a for loop would do the trick together with foreach // And repeat the $sql = SELECT below but that did not happen. for($i = 0; $i = $count; $i++){ // Connect and get only those records with given serialnumber $sql = SELECT * FROM explosive WHERE serialnumber = '$snr'; } // End of for loop } // End of foreach loop $result = mysql_query($sql, $connect) or die(mysql_error()); $count = mysql_num_rows($result); I have tried to search in google and on PHP.net but can't fine anything that explain my problem. I like to have new $sql = SELECT queries for every given serialnumber ($snr) Thanks for your help. Karl
[PHP] Newbie form question
Hello. I have an application that generete HTML5 form in PHP. The form is written in a while loop and therefore the form field has exact same name for every row in the loop. And that is the problem. Because when my PHP document shall handle submitted data it only take the very last row in the while loop and show the result of it. if(isset($_POST['update_explosive'])){ $item_serial_number = $_POST['item_serial_number']; $update_item_in_store = $_POST['update_item_in_store']; if($item_serial_number === ETX1.22X1000){ echo h1$update_item_in_store/h1; } if($item_serial_number === ETX1.17X460){ echo h1$update_item_in_store/h1; } } I think the solution will be to create different and unike fieldname dymamic. For example I tried to write input type=text name=?php echo $item_serial_number; ? value=?php echo $item_serial_number; ? in the HTML5/PHP form. But the problem is that periode . not is allowed as $variable_name. I then try to write it this way: if(isset($_POST['update_explosive'])){ $item_serial_number = $_POST['ETX1.22X1000']; $update_item_in_store = $_POST['update_item_in_store']; if($item_serial_number === ETX1.22X1000){ echo h1$update_item_in_store/h1; } if($item_serial_number === ETX1.17X460){ echo h1$update_item_in_store/h1; } } But this last part did not make any sense to me. I recive no output when tried that one. One problem is that I have between 2 and 25 items with different serial number. Sometimes only 5 of this shall be updated and other times all 25 items. I like to do this through one simple form and not for one time for every single item. (I know how to do when select one by one and update them, but that is a long and hard way for people using my application. A better solution is to just use one form and view all items there. Then just write the amount of item in input type=number name=update_item_in_store size=6 field.) If you have time to help me *understand* this newbie question by explain or give me an example or post a link to a tutorial that can help me though, I am very thankful. Karl
[PHP] Sort question..
Hello again. I have a photo album that show all images in a specified directory. but I like to sort them by filename as one possibillity and random sort the photos as another feature. I don't know how to do this.. Here is my soruce-code: !DOCTYPE html html lang=no head meta charset=utf-8 titleBildegalleri/title link rel=stylesheet href=standard.css media=screen /head body h1Bildegalleri/h1 pa href=bildegalleri.htmlLast opp nye bilder/a |nbsp; a href=vis_bildegalleri.php?sorter_filnavnSorter på filnavn/a |nbsp; a href=vis_bildegalleri.php?tilfeldig_sorteringTilfeldig sortering/a/p ul ?php // Skann katalogen og hent fram bildene $bilde = new DirectoryIterator('bilder/'); while($bilde-valid()){ if(!$bilde-isDot()){ if($_GET['sorter_filnavn']){ echo 'liimg src=bilder/'.sort($bilde-getFilename()).' alt='.sort($bilde-getFilename()).' height=200/li'; } elseif($_GET['tilfeldig_sortering']) { echo 'liimg src=bilder/'.rand($bilde-getFilename()).' alt='.rand($bilde-getFilename()).' height=200/li'; } else { echo 'liimg src=bilder/'.$bilde-getFilename().' alt='.$bilde-getFilename().' height=200/li'; } } $bilde-next(); } unset($bilde); ? /ul /body /html I will be lucky if somebode have time to help me out here.. I am sure it is some functions in php that can do the trick, but haven't found anything yet. Thanks for your time. Karl -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Find/count different word in a text
Hello again. I am looking for a way to find and count different word in a text.. I am thinking on save the text as array and iterate through the array. Then I like to register all different words in the text. For example. If bread is used more than one time, I will not count it. After the check were I have found single (one) word of every words, I count it and tell how many different word that is in the text. Is this difficult to do? Can you give me a hint for were I shall look on www.php.net for a solution to fix this problem? What function am I in need of? Thank you very much. Kind Regards, Karl -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Hmm.. this is strange..
Hello. I have a upload form in a html file and a corresponding PHP file that shall take care of the information. But I am doing something newbie error here.. What am I doing wrong? (The text is norwegian, but you still see and understand the PHP code) bildegalleri.html - !DOCTYPE html html lang=no head meta charset=utf-8 titleOpplasting til Fotogalleri/title link rel=stylesheet href=standard.css media=screen /head body h1Opplasting til Fotogalleri/h1 form action=bildegalleri.php method=post enctype=multipart/form-data fieldset legendVelg bilde for opplasting/legend label for=filbaneFilbane/labelbr input type=file id=filbane name=filbane input type=submit name=last_opp_fil value=Last opp bildet /fieldset /form /body /html bildegalleri.php - ?php if(!isset($_POST['last_opp_fil'])){ header('Location: bildegalleri.html'); } elseif(empty($_FILES['filbane'])){ header('Location: bildegalleri.html'); } else { ? !DOCTYPE html html lang=no head meta charset=utf-8 titleBildegalleri/title /head body h1Bildegalleri/h1 ?php echo OK; } ? /body /html When I run this script, I always get Ok. Even when the input file field is empty.. Can someone tell me what I am doing wroing in this? Thanks for you time and effort to help me out. Karl -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Hmm.. this is strange..
Here I try to check if the input file is empty or not. But still it did not work. I receive OK even when the input file field is empty.. ?php if(!isset($_POST['last_opp_fil'])){ header('Location: bildegalleri.html'); } else { $bildefil = $_FILES['filbane']; if(empty($bildefil)){ header('Location: bildegalleri.html'); } else { ? !DOCTYPE html html lang=no head meta charset=utf-8 titleBildegalleri/title /head body h1Bildegalleri/h1 ?php echo OK; } } ? /body /html Den 16:48 24. april 2012 skrev Serge Fonville serge.fonvi...@gmail.com følgende: Hi, Instead of just checking if the variable is not set, additionally check if it is empty Kind regards/met vriendelijke groet, Serge Fonville http://www.sergefonville.nl Convince Google!! They need to add GAL support on Android (star to agree) http://code.google.com/p/android/issues/detail?id=4602 2012/4/24 Karl-Arne Gjersøyen karlar...@gmail.com: Hello. I have a upload form in a html file and a corresponding PHP file that shall take care of the information. But I am doing something newbie error here.. What am I doing wrong? (The text is norwegian, but you still see and understand the PHP code) bildegalleri.html - !DOCTYPE html html lang=no head meta charset=utf-8 titleOpplasting til Fotogalleri/title link rel=stylesheet href=standard.css media=screen /head body h1Opplasting til Fotogalleri/h1 form action=bildegalleri.php method=post enctype=multipart/form-data fieldset legendVelg bilde for opplasting/legend label for=filbaneFilbane/labelbr input type=file id=filbane name=filbane input type=submit name=last_opp_fil value=Last opp bildet /fieldset /form /body /html bildegalleri.php - ?php if(!isset($_POST['last_opp_fil'])){ header('Location: bildegalleri.html'); } elseif(empty($_FILES['filbane'])){ header('Location: bildegalleri.html'); } else { ? !DOCTYPE html html lang=no head meta charset=utf-8 titleBildegalleri/title /head body h1Bildegalleri/h1 ?php echo OK; } ? /body /html When I run this script, I always get Ok. Even when the input file field is empty.. Can someone tell me what I am doing wroing in this? Thanks for you time and effort to help me out. Karl -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Hmm.. this is strange..
Thank you very much Tolga! if(empty($_FILES['filbane']['name'])) 24.04.2012 17:54 tarihinde, Karl-Arne Gjersøyen yazdı: Here I try to check if the input file is empty or not. But still it did not work. I receive OK even when the input file field is empty.. ?php if(!isset($_POST['last_opp_fil'])){ header('Location: bildegalleri.html'); } else { $bildefil = $_FILES['filbane']; if(empty($bildefil)){ header('Location: bildegalleri.html'); } else { ? !DOCTYPE html html lang=no head meta charset=utf-8 titleBildegalleri/title /head body h1Bildegalleri/h1 ?php echo OK; } } ? /body /html Den 16:48 24. april 2012 skrev Serge Fonville serge.fonvi...@gmail.com følgende: Hi, Instead of just checking if the variable is not set, additionally check if it is empty Kind regards/met vriendelijke groet, Serge Fonville http://www.sergefonville.nl Convince Google!! They need to add GAL support on Android (star to agree) http://code.google.com/p/android/issues/detail?id=4602 2012/4/24 Karl-Arne Gjersøyenkarlar...@gmail.com: Hello. I have a upload form in a html file and a corresponding PHP file that shall take care of the information. But I am doing something newbie error here.. What am I doing wrong? (The text is norwegian, but you still see and understand the PHP code) bildegalleri.html - !DOCTYPE html html lang=no head meta charset=utf-8 titleOpplasting til Fotogalleri/title link rel=stylesheet href=standard.css media=screen /head body h1Opplasting til Fotogalleri/h1 form action=bildegalleri.php method=post enctype=multipart/form-data fieldset legendVelg bilde for opplasting/legend label for=filbaneFilbane/labelbr input type=file id=filbane name=filbane input type=submit name=last_opp_fil value=Last opp bildet /fieldset /form /body /html bildegalleri.php - ?php if(!isset($_POST['last_opp_fil'])){ header('Location: bildegalleri.html'); } elseif(empty($_FILES['filbane'])){ header('Location: bildegalleri.html'); } else { ? !DOCTYPE html html lang=no head meta charset=utf-8 titleBildegalleri/title /head body h1Bildegalleri/h1 ?php echo OK; } ? /body /html When I run this script, I always get Ok. Even when the input file field is empty.. Can someone tell me what I am doing wroing in this? Thanks for you time and effort to help me out. Karl -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- Hjemmeside: http://www.karl-arne.name/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] What is wrong here?
Hello again. I can't figure out what is wrong here. move_uploaded_file() get error message from die() and can't copy/move temp_file into directory bilder I have try to chmod 0777 bilder/ but it did not help. Also I have try to chown www-data.www-data bilder/ since Ubuntu Server run apache as www-data user... Here is my souce code -- // Temfil lagres midlertidig på serveren som // spesifisert i php.ini $tmp_fil = $_FILES['filbane']['temp_name']; // lagre filnavnet.. $filnavn = bilder/ . $_FILES['filbane']['name']; // ..og legg fila i katalogen bilder move_uploaded_file($tmp_fil, $filnavn) or die(Feilmelding: Kunne ikke flytte $filnavn); Karl -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Att: saeed ahmed
Try this: mysql CREATE DATABASE addressbook; Query OK, 1 row affected (0.00 sec) mysql USE addressbook; Database changed mysql CREATE TABLE userData(id INT(4) NOT NULL AUTO_INCREMENT PRIMARY KEY, firstName VARCHAR(50) NOT NULL, lastName VARCHAR(50) NOT NULL, telephone INT(12) NOT NULL, email VARCHAR(100) NOT NULL); Query OK, 0 rows affected (0.11 sec) Now when you have the databse created and a table to store data, you need to write a PHP page that do the trick. Here is a simpe sample. Read all comments and look at the source code... !DOCTYPE html PUBLIC -//W3C//DTD XHTML 1.1//EN http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd; html xmlns=http://www.w3.org/1999/xhtml; xml:lang=en head meta http-equiv=content-type content=application/xhtml+xml; charset=utf-8 / titleAddressbook/title meta name=generator content=BBEdit 10.1 / /head body ?php if(!isset($_POST['updateDB'])){ ? form action=addressbook.php method=post fieldset legendContact info:/legend p label for=firstNameFirst Name:/labelbr / input type=text id=firstName name=firstName / /p p label for=lastNameLast Name:/labelbr / input type=text id=lastName name=lastName / /p p label for=telephoneTelephone:/labelbr / input type=text id=telephone name=telephone / /p p label for=emailAddressEmail Address:/labelbr / input type=text id=emailAddress name=emailAddress / /p p input type=submit name=updateDB value=Update DB / /p /fieldset /form ?php } else { // Formfields $firstName = $_POST['firstName']; $lastName = $_POST['lastName']; $telephone = $_POST['telephone']; $email = $_POST['emailAddress']; // Delete all kind of tags that may be found in form fields $firstName = strip_tags($firstName); $lastName = strip_tags($lastName); $telephone = strip_tags($telephone); $email = strip_tags($email); // Just a simple way to a little more secure query $firstName = mysql_real_escape_string($firstName); $lastName = mysql_real_escape_string($lastName); $telephone = mysql_real_escape_string($telephone); $email = mysql_real_escape_string($email); // Connect to the Database $connectDB = mysql_connect(localhost,root,br0ok2meg) or die(mysql_error()); // Select Database $selectDB = mysql_select_db(addressbook) or die(mysql_error()); // Now create the query that insert data into table userData $sql = INSERT INTO userData(firstName,lastName,telephone,email)VALUES(\$firstName\,\$lastName\,\$telephone\,\$email\); // Run the query that actually insert data into the table userData mysql_query($sql,$connectDB) or die(mysql_error()); echo pThe Contact information is registred/p; } ? pa href=addressbook.php?viewView Contact Info/a/p ?php if(isset($_GET['view'])){ // Connect to the Database $connectDB = mysql_connect(localhost,root,br0ok2meg) or die(mysql_error()); // Select Database $selectDB = mysql_select_db(addressbook) or die(mysql_error()); // Ask for information in table userData $sql = SELECT * FROM userData; $result = mysql_query($sql,$connectDB) or die(mysql_error()); // Handle received data while($row = mysql_fetch_array($result)){ $firstName = $row['firstName']; $lastName = $row['lastName']; $telephone = $row['telephone']; $email = $row['email']; // Print the result to screen echo pstrongFirst Name:/strong $firstNamebr /; echo strongLast Name:/strong $lastNamebr /; echo strongTelephone:/strong $telephonebr /; echo strongEmail:/strong $emailbr /; echo /p; } } ? /body /html Hope this can be in help for you. Karl -- Hjemmeside: http://www.karl-arne.name/ Den 08:45 31. mars 2012 skrev saeed ahmed mycomputerbo...@gmail.com følgende: i have made a php script with a tutorial helpi dont know where is a error.please have a look ?php //connect and select a database mysql_connect(localhost,root, ); mysql_select_db(addressbook); //Run a query $result=mysql_query(select(SELECT*FROM COLLEAGUE); ? !DOCTYPE html PUBLIC-//w3c//DTD XHTML 1.0 Transitional//EN http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd; html xmlns=http://www.w3.org/1999/xhtml; head titleAddress Book/title meta http-equiv=content-type content=text/html;charset=utf-8 /head body h1Address Bookh1 table Border=1 cellpadding=2cellspacing=3 summary=table holda colleague contacts information tr th ID/th thFirst Name/th thLast Name/th thTelephone/th thEmail Address/th /tr ?php //LOOP through all table rows while ($row=mysql_fetch_array($result)) { echotr; echotd.$row['id'] . /td; echo td . $row['firstName'] . /td; echo td .
[PHP] Pear Auth problem
Hello. I am trying to use pear Auth packet but am doing something wrong. I am currently looking at the simple example in the documentation, but something is wrong in my source code, because if I write a username and a password in the fields and hit the submit button, I receive a blank pages without any informatio at all.. Here is my source code: --- ?php require_once('Auth.php'); if(!isset($_POST['submit'])){ function loginFunction($username = null, $status = null, $auth = null){ ? form action=index.php method=post fieldset legendLogin:/legend p label for=usernameUsername:/labelbr input id=username name=username type=text /p p label for=passwordPassword:/labelbr input id=password name=password type=password /p p input id=submit name=submit type=submit value=Login /p /fieldset /form ?php } $options = array( 'dsn' = mysql://username:password@localhost/database, ); $a = new Auth(DB, $options, loginFunction); $a-start(); if($a-checkAuth()){ header(Location: http://www.karl-arne.name/;); } } ? The example is located at: http://pear.php.net/manual/en/package.authentication.auth.intro.php Thanks for your time. Karl -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] PEAR_Error reporting
Hello. I ran into trouble with a PEAR module and got only a blank (empty) page after filling in a loginform with PEAR::Auth I have error reporting in php.ini that create ordinary error message on my CentOS box, but it do not write error message when using PEAR. In a book I have is PEAR_Error mention, but it did not explain how to get it or run it. If you can help me in this question I am thankful for your time. Karl -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php