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
  #1  
Old 28-Oct-2009, 20:47
Pulaskee Pulaskee is offline
New Member
 
Join Date: Apr 2009
Posts: 17
Pulaskee is on a distinguished road

Script to manage Invoices


I am an amateur at coding so please forgive the probable naivety of this question.

Let me try to describe what it is i am trying to do.

I have a table that is being populated by crew via the post method through a html page. The table has ID(auto) Time Invoice Amount Paid. Next i have a page that echos the data so it can be viewed by accounting and marked paid.
this is were i am running into issues. i can only get the update to work on the last row echoed. What should i search for? Should i not be using echo?
Code follows:
Look up code
PHP Code:

<?php
$con = mysql_connect("localhost","******","******");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }

mysql_select_db("tablenamehere", $con);

$result = mysql_query("SELECT * FROM nine2400 ORDER BY Time DESC");
echo "<form action='92400pinupdateB.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' id='ID' value='" . $row['ID'] . "'/></td>";
  echo "<td>" . $row['Time'] . "</td>";
  echo "<td>" . $row['Invoice'] . "</td>";
  echo "<td>" . $row['Amount'] . "</td>";
  echo "<td><input name='Paid' id='Paid' value='" . $row['Paid'] . "'/></td>";
  echo "</tr>";
  }
echo "</table>
<input type='submit' value='Update' />
</form>";

mysql_close($con);
?>


Update code
PHP Code:

<?php
$Paidv = $_POST[Paid];
$IDv = $_POST[ID];
$con = mysql_connect("localhost","******","******");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }

mysql_select_db("tablenamehere", $con);

mysql_query("UPDATE nine2400 SET Paid = '$Paidv' WHERE ID = '$IDv'  ");

echo "
<table style='text-align:center'>
<tr>
<td><img src='logoo.jpg' width='300'></img><td>
</tr>
<tr>
<td> Your Updated Order has been submited</td>
</tr>
<tr>
<td>Thank you</td>
</tr>
<tr>
<td><a href='/'>Return to Forums</a></td>
</tr>
</table>";

mysql_close($con)
?>

Thanks for any help.
Last edited by admin : 29-Oct-2009 at 03:48. Reason: Please insert your example PHP codes between [PHP] and [/PHP] tags
  #2  
Old 29-Oct-2009, 17:45
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: You guys have helped me before, could you agian?


If I understand correctly, even though all the lines differ, you are only getting the values of the last row?...and the expectation is to process every row when 'Update' is clicked?

This is happening because ALL the rows have the SAME control name and id. So, the last row WILL be the values used. Notice that in the update script, you are getting ONE posted Paid/id pair, and that will be the values of the very last row.

You will need a way to have distinct name and pair references for EACH row that will need processing. For example, the id can be used to create concatenated references in the loop: (only applied to the name properties in this example)
PHP Code:

// assuming a particular $row['ID'] = 5, then
 echo "<td><input name='ID_" . $row['ID'] . "' id='ID' value='" . $row['ID'] . "' /></td>";

 echo "<td><input name='Paid_" . $row['ID'] . "' id='Paid' value='" . $row['Paid'] . "' /></td>"; 


will look like:
Code:
<td><input name='ID_5' id='ID' value='5' /></td> <td><input name='Paid_5' id='Paid' value='' /></td>
Then the update script will need modification to process the rows that will be posted.
__________________
Use the force...read the source!!
WYCIWYG -- what you code is what you get!
  #3  
Old 30-Oct-2009, 01:51
Pulaskee Pulaskee is offline
New Member
 
Join Date: Apr 2009
Posts: 17
Pulaskee is on a distinguished road

Re: You guys have helped me before, could you agian?


Thanks i can see what you did.
I've been kicking my self after reading it. One of my tries touched on this code but the try didn't work and i gave up on it.
I'm hoping you can give me hint on the update code. i think im on the right path. Im trying to get the Post to have a variable that is equal to an array?
  #4  
Old 30-Oct-2009, 21:40
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: You guys have helped me before, could you agian?


Quote:
Originally Posted by Pulaskee
...Im trying to get the Post to have a variable that is equal to an array?
The $_POST superglobal is an array. It should be possible to use that as the array.

EDIT:
Somewhere near the top of the update script, add this:
PHP Code:

print_r($_POST); // show the array values. 


HTH
__________________
Use the force...read the source!!
WYCIWYG -- what you code is what you get!
  #5  
Old 31-Oct-2009, 06:09
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


First, let's examine the (markup) form that is meant for the "accounting" people. Within every INPUT element/tag you should set the TYPE attribute. For example:

HTML Code:
<input type="text" ... /> <input type="checkbox" ... /> <input type="submit" ... />

Because you have NOT set this attribute in your example markup above, it is difficult to understand how you expect this form to work.

Second, you must uniquely identify each ID attribute in a single document. In other words, using "ID" as a common value for the id= attribute in more than one INPUT element is invalid. Read what the www.w3.org has to say about the ID attribute:

Quote:
Originally Posted by www.w3.org about the ID attribute
This attribute assigns a name to an element. This name must be unique in a document. See http://www.w3.org/TR/html401/struct/global.html#h-7.5.2

You should have described the DB column types with your question. I have no idea what goes into the `Paid` column or even what the differences are between the `ID` and `Invoice` columns in your database table structure. I assume `Paid` is a BIT/TINYINT(1)/BOOLEAN column where the values are either 1 or 0. I assume the `Invoice` and `ID` columns contain unique identifiers aka Invoice numbers. If so, why have both?

Third, how does the form submission really work? Are all the invoices set to paid at once, or do you require they (the Invoices) be managed one or more at a time? How is the form to display records (invoices) that are already paid?

If you had taken the time to explain your problem clearly, maybe you could have been assisted much sooner.

If you wish the form to return an array within the superglobal $_POST array, the best idea is to set the name for the common elements like this: myvalues[], where $_POST["myvalues"] would be an array.

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.
__________________
Custom BB codes you can use here:
[HTML] | [C++] | [CSS] | [JAVA] | [PY] | [VB]
  #6  
Old 02-Nov-2009, 17:33
Pulaskee Pulaskee is offline
New Member
 
Join Date: Apr 2009
Posts: 17
Pulaskee is on a distinguished road

Re: Script to manage Invoices


It has taken me most of an hour trying to get my account reactivated. SO forgive me if i come across as a bit pissed.
For starters admin, accounting is accounting not "accounting". Just because my code isnt up to your high standards doesn't mean its not being used the way i say it is, it just means that
a: Im new to php and not thinking clearly
b: take shortcuts because i know were its going
c: was taught differently, or in the case of php not at all.

I believe you will find that my ID column is described as Auto, as in auto increment. TurboPT seemed to have no issue in understanding what i was looking for. and even was able to assist me greatly in fixing my idiotic mistake of not naming the ids/name differently. Something that i knew had to be done just couldn't figure how. he was even able to do it in a timely manner.

You have assumed incorrectly about the PAID field. Look at my code, its a simple input. that is all. why? you don't need to know that.

Quote:
How is the form to display records (invoices) that are already paid?
i echo the whole table. so that they can be seen/edited. as you can see in the code,
PHP Code:

while($row = mysql_fetch_array($result))
  {
  echo "<tr>";
  echo "<td><input name='ID' id='ID' value='" . $row['ID'] . "'/></td>";
  echo "<td>" . $row['Time'] . "</td>";
  echo "<td>" . $row['Invoice'] . "</td>";
  echo "<td>" . $row['Amount'] . "</td>";
  echo "<td><input name='Paid' id='Paid' value='" . $row['Paid'] . "'/></td>";
  echo "</tr>";
  }
echo "</table>
<input type='submit' value='Update' />
</form>"; 



If your going to try to help at lest look at what i have instead of assuming im some 14 year old idiot looking for a free ride. -cheers.
Last edited by admin : 02-Nov-2009 at 17:37. Reason: Please insert your example PHP codes between [PHP] and [/PHP] tags
  #7  
Old 02-Nov-2009, 17:45
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


I have NEVER assumed anyone is here for a "free ride". I believe sharing knowledge, or anything else for that matter, is something very important in this world.

When you mentioned "marked paid", I understood that to mean that it was a ON/OFF thingy.

I understand that you are pissed, but I am not. If I have offended you in any way, it was not intentional.
__________________
Custom BB codes you can use here:
[HTML] | [C++] | [CSS] | [JAVA] | [PY] | [VB]
  #8  
Old 02-Nov-2009, 17:52
Pulaskee Pulaskee is offline
New Member
 
Join Date: Apr 2009
Posts: 17
Pulaskee is on a distinguished road

Re: Script to manage Invoices


understood.
I have many more things to read and try for the update script before i ask for more help here.
Could you however try to explain your myvalues code again? Maybe what method your using so i can look it up?
  #9  
Old 02-Nov-2009, 17:58
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


Here is a simple script that you can save as a PHP file that will demonstrate how the INPUT tags work.

PHP Code:

<?php
if( $_POST )
{
    echo "<pre>"; print_r( $_POST ); echo "</pre>";
}
else
{
    ?>
        <form method="post" action="<?php echo $_SERVER["PHP_SELF"]; ?>">
            <table>
                <tr>
                    <th>Stuff</th>
                </tr>
                <tr>
                    <td>
    <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 />
                    </td>
                </tr>
            </table>
            <input type="submit" name="ok" value="Submit" />
        </form>    
<?php
}
?>

__________________
Custom BB codes you can use here:
[HTML] | [C++] | [CSS] | [JAVA] | [PY] | [VB]
  #10  
Old 02-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


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.
 
 

Recent GIDBlogOnce again, no time for hobbies 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 23:42.


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