MySQL Forums
Forum List  »  PHP

PHP array UPDATE to SQL help
Posted by: Jerry Hall
Date: June 04, 2009 10:49AM

Hello All,

I am having a problem updating info from mysql through PHP arrays. It populates to my form properly, but when I try to update it does not update anything. Any insight?

Thanks in advance.

Patsman77

<body style="text-align: center">

<center><strong>League Payment Update Sheet</strong><br></center><br>

<?php
$host="xxxx"; // Host name
$username="xxxx"; // Mysql username
$password="xxx"; // 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]}' where Name='$Name[$i]'";
$result1=mysql_query($sql1);
}
}
if($result1){
header("location:uptest.php");
}

mysql_close();
?>

Options: ReplyQuote


Subject
Written By
Posted
PHP array UPDATE to SQL help
June 04, 2009 10:49AM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.