GIDForums  

Go Back   GIDForums > Computer Programming Forums > MySQL / PHP Forum
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #11  
Old 02-Nov-2009, 19:10
TurboPT's Avatar
TurboPT TurboPT is offline
Senior Member
 
Join Date: Feb 2006
Location: Atlanta, GA
Posts: 1,140
TurboPT is a jewel in the roughTurboPT is a jewel in the roughTurboPT is a jewel in the rough

Re: Script to manage Invoices


Quote:
Originally Posted by admin
For example:

HTML Code:
<input type="checkbox" name="invoiceNo[]" id="invoiceNo_00012" value="00012" checked="checked" /> ...<br /> <input type="checkbox" name="invoiceNo[]" id="invoiceNo_00056" value="00056" /> ...<br /> <input type="checkbox" name="invoiceNo[]" id="invoiceNo_00856" value="00856" /> ...<br /> <input type="checkbox" name="invoiceNo[]" id="invoiceNo_00990" value="00990" /> ...<br /> <input type="checkbox" name="invoiceNo[]" id="invoiceNo_01526" value="01526" /> ...<br /> <input type="checkbox" name="invoiceNo[]" id="invoiceNo_03589" value="03589" /> ...<br />

Note the unique id attributes for each in the example markup.
Thanks for sharing that with us admin, I have not seen the array syntax used in the name before, and that damn sure can simplify the handling. [I was hoping you might chime in with some ideas! -- and that's why YOU are admin! ]

My attempt would have gone about a solution the HARD way, which would've involved a situation that would give Pulaskee and I both a moment!
__________________
Use the force...read the source!!
WYCIWYG -- what you code is what you get!
  #12  
Old 02-Nov-2009, 20:41
Pulaskee Pulaskee is offline
New Member
 
Join Date: Apr 2009
Posts: 17
Pulaskee is on a distinguished road

Re: Script to manage Invoices


Now you tell me

Turbo yours makes more sense to me, but i will try Admins next and see what i can do with it. i think i will still run into my issue of trying to getting mutable items in the array to update if more then one entree is edited. If that happens.
  #13  
Old 02-Nov-2009, 20:44
admin's Avatar
admin admin is offline
Administrator
 
Join Date: Sep 2002
Posts: 841
admin will become famous soon enough

Re: Script to manage Invoices


Quote:
Originally Posted by Pulaskee
I think i get that.

i can not for the life of me figure out the update code here.
i can get it to update one row, any row, as long as i tell it the ID, how do i get it to update all of them? any examples i find have you name the row or value you want to use.

I hope this made sense, my head has about had it today.
Pulaskee,

If you really want us to help you quickly, give us something to work with. Maybe give us sample data off your DB table (maybe 5 lines). And also give us the markup of the form.
__________________
Custom BB codes you can use here:
[HTML] | [C++] | [CSS] | [JAVA] | [PY] | [VB]
  #14  
Old 02-Nov-2009, 23:39
Pulaskee Pulaskee is offline
New Member
 
Join Date: Apr 2009
Posts: 17
Pulaskee is on a distinguished road

Re: Script to manage Invoices


The db only has a few entrees and all of them are test entrees to make sure the initial entree form was working. Its a simple html file, and the php is a simple insert.
I do not have a ton of security in mind. hence the openness of the inputs. This system is NOT easily accessible via the internet.
There are some things that will change, but there only cosmetic. Example, the ID input will be hidden so it cant be tampered with. But to work on it i need to see it.
  #15  
Old 05-Nov-2009, 16:19
Pulaskee Pulaskee is offline
New Member
 
Join Date: Apr 2009
Posts: 17
Pulaskee is on a distinguished road

Re: Script to manage Invoices


Why wont this work?
Code:
<?php $con = mysql_connect("******","******","******"); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("Pinestate", $con); $size = 100; $i = 1; while ($i < $size) { $paidv= $_POST['Paid'][$i]; $idv = $_POST['ID'][$i]; $query = "UPDATE table SET Paid = $paidv WHERE ID = $idv LIMIT 1"; mysql_query($query) or die ("Error in query: $query"); print " <table style='text-align:center'> <tr> <td><img src='logoo.jpg' width='300'></img><td> </tr> <tr> <td> Your Pinestate Order has been submited</td> </tr> <tr> <td>Thank you</td> </tr> <tr> <td><a href='/'>Return to Lukoil Forums</a></td> </tr> </table>"; ++$i; } mysql_close(); ?>
Cause that makes sense to me.
  #16  
Old 07-Nov-2009, 19:42
TurboPT's Avatar
TurboPT TurboPT is offline
Senior Member
 
Join Date: Feb 2006
Location: Atlanta, GA
Posts: 1,140
TurboPT is a jewel in the roughTurboPT is a jewel in the roughTurboPT is a jewel in the rough

Re: Script to manage Invoices


What about the code from the form side?
__________________
Use the force...read the source!!
WYCIWYG -- what you code is what you get!
  #17  
Old 07-Nov-2009, 20:28
Pulaskee Pulaskee is offline
New Member
 
Join Date: Apr 2009
Posts: 17
Pulaskee is on a distinguished road

Re: Script to manage Invoices


Right, sorry spaced it.
For this i used your concept because i had it done already.
Code:
<?php $con = mysql_connect("******","******","******"); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("Pinestate", $con); $result = mysql_query("SELECT * FROM nine2400 ORDER BY Time DESC"); echo "<form action='92400pinupdateC.php' method='post'>"; echo "<table border='1'> <tr> <th>ID</th> <th>Date</th> <th>Invoice</th> <th>Amount</th> <th>Paid</th> </tr>"; while($row = mysql_fetch_array($result)) { echo "<tr>"; echo "<td><input name='ID" . $row['ID'] . "' id='ID" . $row['ID'] . "' value='" . $row['ID'] . "'/></td>"; echo "<td><input name='Date" . $row['ID'] . "' id='Date" . $row['ID'] . "' value='" . $row['Date'] . "'/></td>"; echo "<td><input name='Invoice" . $row['ID'] . "' id='Invoice" . $row['ID'] . "' value='" . $row['Invoice'] . "'/></td>"; echo "<td><input name='Amount" . $row['ID'] . "' id='Amount" . $row['ID'] . "' value='" . $row['Amount'] . "'/></td>"; echo "<td><input name='Paid" . $row['ID'] . "' id='Paid" . $row['ID'] . "' value='" . $row['Paid'] . "'/></td>"; echo "</tr>"; } echo "</table> <input type='submit' value='Update' /> </form>"; mysql_close($con); ?>
  #18  
Old 07-Nov-2009, 20:39
Pulaskee Pulaskee is offline
New Member
 
Join Date: Apr 2009
Posts: 17
Pulaskee is on a distinguished road

Re: Script to manage Invoices


I just thought, could it be that the generated number dosnt correspond with the ID number? example. the first generated number is one 1 but the first ID in the array is 2? or would it jut skip over and go to the next number?
  #19  
Old 07-Nov-2009, 21:50
TurboPT's Avatar
TurboPT TurboPT is offline
Senior Member
 
Join Date: Feb 2006
Location: Atlanta, GA
Posts: 1,140
TurboPT is a jewel in the roughTurboPT is a jewel in the roughTurboPT is a jewel in the rough

Re: Script to manage Invoices


Thinking about what the admin has shared with us, I think that explicitly setting the id value as the array index will be more like what you need. However, that could also make for 'useless' processing, as the admin has also suggested, because of the potential to process rows that don't really need an update. [and a potential to change a value from what it was originally, when not actually desired]

I'm thinking you could take each row [in the form] like this: (inside the loop)
PHP Code:

echo "<tr>";
  echo "<td>" . $row['ID']   . "</td>";
  echo "<td>" . $row['Date'] . "</td>";
  echo "<td>" . $row['Invoice'] . "</td>";
  echo "<td>" . $row['Amount'] . "</td>";
  echo "<td><input type='text' name='invoices[" . $row['ID'] . "]' value='" . $row['Paid'] . "' /></td>";
  echo "</tr>"; 


Then, at the processing side, these could handled like so: (without having to worry about a size variable)
PHP Code:

// ...
foreach( $_POST['invoices'] as $key => $value )
{
   $query = "UPDATE table SET Paid = {$value} WHERE ID = {$key} LIMIT 1";
   mysql_query($query) or die ("Error in query: $query");
}
// ... 


This is untested, though, so let us know if there may be issues.
__________________
Use the force...read the source!!
WYCIWYG -- what you code is what you get!
  #20  
Old 09-Nov-2009, 18:57
Pulaskee Pulaskee is offline
New Member
 
Join Date: Apr 2009
Posts: 17
Pulaskee is on a distinguished road

Re: Script to manage Invoices


Error in query: UPDATE nine2400 SET Paid = 4lll WHERE ID = 2 LIMIT 1

i don't under stand why i would get this. the code makes sense. i read up some on $key i never knew about it and its helpful. i think im understanding how that works now.


ID 2 is the first record in the DB record one was blank due to a error and i deleted it.
i cant see any mistakes in the table or the DB. so i dont know why this wont work.
 
 

Recent GIDBlogAccepted for Ph.D. program by crystalattice

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

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

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
how do u guys know???? devin Open Discussion Forum 9 06-Feb-2007 22:29
+ Hey Guys EthicsD New Member Introductions 0 10-Oct-2006 11:39
Newbie Problems. Help me guys the_last_rites Apache Web Server Forum 4 18-Jan-2005 12:57

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 17:53.


vBulletin, Copyright © 2000 - 2009, Jelsoft Enterprises Ltd.