Help with PHP CODE

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Patsman77
Forum Newbie
Posts: 18
Joined: Thu Jun 04, 2009 10:09 am

Help with PHP CODE

Post by Patsman77 »

Hello All,

I am hoping I can get a little assistance. I am pulling data from a mysql database with php arrays. What I want to do is be able to update 1 or all records on one submit. The information pulls from mysql correctly and displays on my form correctly. But when I go to update, it updates empty values. Here is the code so far:

Code: Select all

<body style="text-align: center">
 
<center><strong>League Payment Update Sheet</strong><br></center><br>
 
<?php
$host="localhost"; // Host name 
$username="xxxx"; // Mysql username 
$password="xxxx"; // Mysql password 
$db_name="xxxx"; // Database name 
$tbl_name="xxxx"; // Table name  
 
// Connect to server and select databse.
mysql_connect("$host", "$username", "$password")or die("cannot connect"); 
mysql_select_db("$db_name")or die("cannot select DB");
 
$sql="SELECT Name, Total, Paid, Confirmed FROM $tbl_name";
$result=mysql_query($sql);
$count=mysql_num_rows($result);
 
// Count table rows 
$count=mysql_num_rows($result);
?>
<table width="33" border="0" cellspacing="1" cellpadding="0">
<form name="form1" method="post" action="">
<tr> 
<td>
<table width="33" border="0" cellspacing="1" cellpadding="0">
 
<div><center>
<tr>
<td align="center"><strong>Name</strong></td>
<td align="center"><strong>Total</strong></td>
<td align="center"><strong>Paid</strong></td>
<td align="center"><strong>S</strong></td>
</tr>
<?php
while($rows=mysql_fetch_array($result)){
?>
 
<tr>
 
<td align="center"><input name="Name[0]" type="text" size=20 id="Name" value="<? echo $rows['Name']; ?>"></td>
<td align="center"><input name="Total[0]" type="int" size=6 id="Total" value="<? echo $rows['Total']; ?>"></td>
<td align="center"><input name="Paid[0]" type="int" size=6 id="Paid" value="<? echo $rows['Paid']; ?>"></td>
<td align="center"><input name="Confirmed[0]" type="int" size=1 id="Confirmed" value="<? echo $rows['Confirmed']; ?>"></td>
</tr></center></div>
 
<?php
}
?>
<tr>
<td colspan="4" align="center"><input type="submit" name="Submit" value="Submit"></td>
</tr>
</table>
</td>
</tr>
</form>
</table>
<?php
// Check if button name "Submit" is active, do this 
if (isset($_POST['Submit'])){
for($i=2;$i<$count;$i++){
$sql1="UPDATE $tbl_name SET Name='{$Name[$i]}', Total='{$Total[$i]}', Paid='{$Paid[$i]}', Confirmed='{$Confirmed[$i]}'";
$result1=mysql_query($sql1);
}
}
if($result1){
header("location:uptest.php");
}
 
mysql_close();
?>
Any help would be appreciated.

Thanks,

Patsman77
Post Reply