473,401 Members | 2,068 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,401 software developers and data experts.

updateing multiple rows at once, with different values..

15
Hello Gents,

I want to be able to reward my members with credits, banner advertisements, text advertisements and even cash, but on a partially manual basis.

I created a page where I could decide how many members would get a reward, and then update them based on the member id and details I enter, here's the code for the page:
Expand|Select|Wrap|Line Numbers
  1. <?php
  2. /**
  3.  * @author Raymond Dube
  4.  * @copyright 2008
  5.  * @version 1.0
  6.  */
  7. include ('../../system.php');
  8. function ryg_mailer($message)
  9. {
  10.   mail("$gReceivingEmail", "Bonus Updater", $message, "From:  Bonus Updater\r\nContent-type: text/html; charset=us-ascii");
  11.   return;
  12. }
  13.  
  14. if(!$_POST["save"])
  15. {
  16.   ?>
  17.   <html>
  18.   <head>
  19.   <title>Bonus Manager</title>
  20.   <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
  21.   <link rel="stylesheet" type="text/css" href="../css/config.css">
  22.   </head>
  23.   <body>
  24.   <form action='bonus.php' method='POST' name='number_or_members'>
  25.     <table width="100%" class="configuration"  bgcolor="#F2F2F2" align="center">
  26.       <tr>
  27.         <th>Bonus Giveaway</th>
  28.         <th>
  29.           <table width="100%">
  30.             <tr>
  31.               <td align="center">
  32.                 <input type="button" value="Close Configuration" onClick="window.location.replace('../frames/home.php');" name="close" class="buttonsubmit">
  33.               </td>
  34.               <td>
  35.                 <input type="submit" value="Submit" name="save" class="buttonsubmit" style="float: right;">
  36.               </td>
  37.             </tr>
  38.           </table>
  39.         </th>
  40.       </tr>
  41.       <tr>
  42.         <td width="50%" class="c_col_left">How Many Members?<br>
  43.           <font size="1">
  44.             Enter the number of members you want to award bonuses to, then click Submit!
  45.           </font>
  46.         </td>
  47.         <td width="50%" align="center" class="c_col_right">
  48.           <input size="8" value="<? echo $mems; ?>" name="mems">
  49.         </td>
  50.       </tr>
  51.       <tr>
  52.         <th width="100%" colspan="2">
  53.           <p style="text-align: center">
  54.           <input type="submit" value="Submit" name="save" class="buttonsubmit">
  55.         </th>
  56.       </tr>
  57.     </table>
  58.   </form>
  59.   </body>
  60.   </html>
  61.   <?
  62. }
  63.  
  64. if($_POST["save"] == "Submit")
  65. {
  66.   $mems = $_POST[mems];
  67.   ?>
  68.   <html>
  69.   <head>
  70.   <title>Bonus Manager</title>
  71.   <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
  72.   <link rel="stylesheet" type="text/css" href="../css/config.css">
  73.   </head>
  74.   <body>
  75.   <form action='bonus.php' method='POST' name='bonus_form'>
  76.   <input type="hidden" name="mems" value="<? echo $mems;?>">
  77.   <table width="100%" class="configuration"  bgcolor="#F2F2F2" align="center">
  78.     <tr>
  79.       <th>Bonus Giveaway</th>
  80.       <th>
  81.         <table width="100%">
  82.           <tr>
  83.             <td align="center">
  84.               <input type="button" value="Close Configuration" onClick="window.location.replace('../frames/home.php');" name="close" class="buttonsubmit">
  85.             </td>
  86.             <td>
  87.               <input type="submit" value="Award Members" name="save" class="buttonsubmit" style="float: right;">
  88.             </td>
  89.           </tr>
  90.         </table>
  91.       </th>
  92.     </tr>
  93.     <tr>
  94.       <td width="50%" class="c_col_left">Member IDs<br>
  95.         <font size="1">
  96.           Enter the member id, one id per box please.
  97.         </font>
  98.       </td>
  99.       <td class="c_col_right">
  100.         <table>
  101.           <tr>
  102.   <?
  103.   $i=0;
  104.   while($i < $mems)
  105.   {
  106.     //build table with the number of cells equal to the number of members to update.
  107.     echo "<td><input size=\"8\" value=\"\" name=\"memid[$i]\" id=\"memid[$i]\"></td>";
  108.     $i++;
  109.   }
  110.   ?>
  111.           </tr>
  112.         </table>
  113.       </td>
  114.     </tr>
  115.     <tr>
  116.       <td width="50%" class="c_col_left">Cash<br>
  117.         <font size="1">
  118.           Enter the Cash Amount for each member.
  119.         </font>
  120.       </td>
  121.       <td class="c_col_right">
  122.         <table>
  123.           <tr>
  124.   <?
  125.   $i=0;
  126.   while($i < $mems)
  127.   {
  128.     //build table with the number of cells equal to the number of members to update.
  129.     echo "<td><input size=\"8\" value=\"\" name=\"cashb[$i]\" id=\"cashb[$i]\"></td>";
  130.     $i++;
  131.   }
  132.   ?>
  133.           </tr>
  134.         </table>
  135.       </td>
  136.     </tr>
  137.     <tr>
  138.       <td width="50%" class="c_col_left">Credits<br>
  139.         <font size="1">
  140.           Enter the Credit Amount for each member.
  141.         </font>
  142.       </td>
  143.       <td class="c_col_right">
  144.         <table>
  145.           <tr>
  146.   <?
  147.   $i=0;
  148.   while($i < $mems)
  149.   {
  150.     //build table with the number of cells equal to the number of members to update.
  151.     echo "<td><input size=\"8\" value=\"\" name=\"creds[$i]\" id=\"creds[$i]\"></td>";
  152.     $i++;
  153.   }
  154.   ?>
  155.           </tr>
  156.         </table>
  157.       </td>
  158.     </tr>
  159.     <tr>
  160.       <td width="50%" class="c_col_left">Banners<br>
  161.         <font size="1">
  162.           Enter the Banner Amount for each member.
  163.         </font>
  164.       </td>
  165.       <td class="c_col_right">
  166.         <table>
  167.           <tr>
  168.   <?
  169.   $i=0;
  170.   while($i < $mems)
  171.   {
  172.     //build table with the number of cells equal to the number of members to update.
  173.     echo "<td><input size=\"8\" value=\"\" name=\"bnrs[$i]\" id=\"bnrs[$i]\"></td>";
  174.     $i++;
  175.   }
  176.   ?>
  177.           </tr>
  178.         </table>
  179.       </td>
  180.     </tr>
  181.     <tr>
  182.       <td width="50%" class="c_col_left">Texts<br>
  183.         <font size="1">
  184.           Enter the Text Amount for each member.
  185.         </font>
  186.       </td>
  187.       <td class="c_col_right">
  188.         <table>
  189.           <tr>
  190.   <?
  191.   $i=0;
  192.   while($i < $mems)
  193.   {
  194.     //build table with the number of cells equal to the number of members to update.
  195.     echo "<td><input size=\"8\" value=\"\" name=\"txts[$i]\" id=\"txts[$i]\"></td>";
  196.     $i++;
  197.   }
  198.   ?>
  199.           </tr>
  200.         </table>
  201.       </td>
  202.     </tr>
  203.     <tr>
  204.       <th width="100%" colspan="2">
  205.         <table width="100%">
  206.           <tr>
  207.             <td align="center">
  208.               <input type="button" value="Reset" onClick="window.location.replace('bonus.php');" name="close" class="buttonsubmit">
  209.             </td>
  210.             <td>
  211.               <input type="submit" value="Award Members" name="save" class="buttonsubmit" style="float: right;">
  212.             </td>
  213.           </tr>
  214.         </table>
  215.       </th>
  216.     </tr>
  217.   </table>    
  218.   </form>
  219.   <?
  220. }
  221. if($_POST["save"] == "Award Members")
  222. {
  223.   $mems = $_POST['mems'];
  224.   $i=0;
  225.   while ($i < $mems)
  226.   {
  227.     $memid = $_POST['memid'][$i];
  228.     $cashb = $_POST['cashb'][$i];
  229.     $creds = $_POST['creds'][$i];
  230.     $bnrs = $_POST['bnrs'][$i];
  231.     $txts = $_POST['txts'][$i];
  232.     $GET_SQL = "UPDATE `vtp_members` SET `cash`=`cash`+'$cashb', `hits`=`hits`+'$creds', `banner_total`=`banner_total`+'$bnrs', `text_total`=`text_total`+'$txts' WHERE `id`='$memid'";
  233.     echo "<br>Query: ".$GET_SQL;
  234.     /*$update_result = mysql_query($GET_SQL);
  235.     if (!$update_result)
  236.     {
  237.       $error = "Bonus Update did not function as expected.  Member: $membid; Cash: $cashb; Credits: $creds; Banners: $bnrs; Texts: $txts.";
  238.       ryg_mailer($error);
  239.     }*/
  240.   ++$i;
  241.   }
  242. }
  243. ?>
  244.  
Now the ony problem is that the update portion is not working properly. When I first visit the page a textbox appears asking me how many members I want to reward, so I chose 5 for example, after clicking on submit, I get 5 text boxes on each for for each type I want to reward.

Now when I put numbers in these fields, and click submit again, I get incorrect date, in fact, I get the letters that spell Array, so something is wrong, but I just can't seem to see it.

Help! Please! :)

Ray
Apr 20 '09 #1
9 1845
RayDube
15
Expand|Select|Wrap|Line Numbers
  1. if($_POST["save"] == "Submit")
  2. {
  3.   $mems = $_POST[mems];
  4.   $i=0;
  5.   while($i < $mems)
  6.   {
  7.     //build table with the number of cells equal to the number of members to update.
  8.     echo "<tr>";
  9.     echo "<td><input type=\"text\" id=\"memid[]\" name=\"memid[]\" value=\"\" size=8></td>";
  10.     echo "<td><input type=\"text\" id=\"cashb[]\" name=\"cashb[]\" value=\"\" size=8></td>";
  11.     echo "<td><input type=\"text\" id=\"creds[]\" name=\"creds[]\" value=\"\" size=8></td>";
  12.     echo "<td><input type=\"text\" id=\"bnrs[]\" name=\"bnrs[]\" value=\"\" size=8></td>";
  13.     echo "<td><input type=\"text\" id=\"txts[]\" name=\"txts[]\" value=\"\" size=8></td>";
  14.     echo "</tr>";
  15.     $i++;
  16.   }
  17. }
And

Expand|Select|Wrap|Line Numbers
  1. if($_POST["award"])
  2. {
  3.   $mems = $_POST['mems'];
  4.   $i=0;
  5.   for($i=0;$i<$mems;$i++)
  6.   {
  7.     $memid = $_POST['memid'][$i];
  8.     $cashb = $_POST['cashb'][$i];
  9.     $creds = $_POST['creds'][$i];
  10.     $bnrs = $_POST['bnrs'][$i];
  11.     $txts = $_POST['txts'][$i];
  12.     $GET_SQL = "UPDATE `vtp_members` SET `cash`=`cash`+'$cashb', `hits`=`hits`+'$creds', `banner_total`=`banner_total`+'$bnrs', `text_total`=`text_total`+'$txts' WHERE `id`='$memid'";
  13.     echo "<br>Query: ".$GET_SQL;
  14.   }
  15. }
The code looks good, but doesn't work, what's up folks, I need an assist...

Ray
Apr 22 '09 #2
code green
1,726 Expert 1GB
It is difficult to wade through somebody else's code.
You need to isolate the problem more.

Echo out some values at different stages then you can see what is there.
Array() means very little, but it generally appears when reading a variable which is actually an array or it could be an empty array

As a tip there is no need to echo out every line of HTML.
Also use single quotes
Expand|Select|Wrap|Line Numbers
  1. echo '<tr>
  2.     <td><input type="text" id="memid[]" name="memid[]" value="" size=8></td>
  3.     <td><input type="text" id="cashb[]" name="cashb[]" value="" size=8></td>
  4.     <td><input type="text" id="creds[]" name="creds[]" value="" size=8></td>etc...';
This is more efficient and avoids the ugly escapes
Apr 23 '09 #3
RayDube
15
Hi code green,

I agree, no need to echo each line, but it was done because of "compressing" there is a little bit of extra functionality in between that was edited out.

Meanwhile, this *should* work, but doesn't, which is why I need an assist.

Ray
Apr 23 '09 #4
code green
1,726 Expert 1GB
I have looked ar your code but may have missed the problem because there is a lot.

At the moment you are working blind and have no idea what is happening.
That is why I suggested putting some debug help in there.
Simply place print_r($_POST) and echo $mems etc at strategic locations
in your code.
This will help narrow down to where the problem is.

I guess your HTML array is emptying somewhere
Apr 23 '09 #5
RayDube
15
Hi there,

Not many places to put those codes, but I did try to streamline it a bit and still can't imagine where the Array could possibly be emptying...

This is the result after the first post (where the number of members to be awarded is determined):
1 member:
Expand|Select|Wrap|Line Numbers
  1. Array ( [mems] => 1 [save] => Submit ) 
5 members:
Expand|Select|Wrap|Line Numbers
  1. Array ( [mems] => 5 [save] => Submit )
After second post (where bonus amts are added):
1 member:
Expand|Select|Wrap|Line Numbers
  1. Array ( [mems] => 1 [memid] => Array [cashb] => Array [creds] => Array [bnrs] => Array [txts] => Array [Award] => Award )
5 members:
Expand|Select|Wrap|Line Numbers
  1. Array ( [mems] => 5 [memid] => Array [cashb] => Array [creds] => Array [bnrs] => Array [txts] => Array [Award] => Award )
Any suggestions?

Ray
Apr 23 '09 #6
code green
1,726 Expert 1GB
OK. From this output
Expand|Select|Wrap|Line Numbers
  1. Array ( [mems] => 5 [memid] => Array [cashb] => Array [creds] => Array [bnrs] => Array [txts] => Array [Award] => Award ) 
I can now see the $_POST elements.
The inner arrays can be seen by
Expand|Select|Wrap|Line Numbers
  1. print_r($_POST['memid']); 
  2. print_r($_POST['cashb']);
  3. print_r($_POST['creds']); etc
If you want to check their contents.
I will study this further, but just as a thought do you have register globals turned on?
If so, as memid is an HTML array AND a php variable there may be a problem here
Apr 23 '09 #7
RayDube
15
Hi there,

I've managed to find the problem, one of the included files is stripping the contents of the array, even though it's not supposed to do so.

We're working with the original script creator to remove the problem code, unf, it's encoded... :(

Ray
Apr 23 '09 #8
code green
1,726 Expert 1GB
Did you spot this by echoing out the variables?
I am happy if you take away this valuable lesson
Apr 24 '09 #9
RayDube
15
Well, honestly?

I re-wrote the script, entirely, forgot the include they had for sql setup, and the variables were passing, when I added the include, it stopped...

Unfortunately, had I done that in the first place, I would have spotted it directly.

Ray
Apr 24 '09 #10

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: Gleep | last post by:
Hey Guys, I've got a table called Outcomes. With 3 columns and 15 rows 1st col 2nd col 3rdcol outcome date price There are 15 rows...
7
by: RotterdamStudents | last post by:
Hello there, i have a strange problem. I can't get php to insert multiple rows at once in a MySQL database. I use the $sql = "INSERT INTO database (a,b,c,d,e) VALUES ('$a', '$b' ,'$c', '$d',...
16
by: noah | last post by:
Does PHP have a feature to associate Cookie sessions with a persistent database connection that will allow a single transaction across multiple HTTP requests? Here is how I imagine my process: I...
12
by: Philip Smith | last post by:
Call this a C++ programmers hang-up if you like. I don't seem to be able to define multiple versions of __init__ in my matrix class (ie to initialise either from a list of values or from 2...
6
by: Steven An | last post by:
Howdy, I need to write an update query with multiple aggregate functions. Here is an example: UPDATE t SET t.a = ( select avg(f.q) from dbo.foo f where f.p = t.y ), t.b = ( select sum(f.q)...
8
by: pb648174 | last post by:
I have a single update statement that updates the same column multiple times in the same update statement. Basically i have a column that looks like .1.2.3.4. which are id references that need to...
32
by: tshad | last post by:
Can you do a search for more that one string in another string? Something like: someString.IndexOf("something1","something2","something3",0) or would you have to do something like: if...
52
by: MP | last post by:
Hi trying to begin to learn database using vb6, ado/adox, mdb format, sql (not using access...just mdb format via ado) i need to group the values of multiple fields - get their possible...
20
by: talktozee | last post by:
Hey, everyone! Basically, I need to insert *multiple rows* into table A from table B based upon some criteria, and I need to insert some static values along with each row from table A. For...
24
by: Henry J. | last post by:
My app needs to insert thousand value rows into a mostly empty table (data are read from a file). I can either use inserts, or use merge. The advantage of using merge is that in the few cases...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.