Hi Everybody,
I have 3 pages which I am trying to set up to manage a simple mailing list;
mlist.php = displays info from database with an "update" link
upcustfrm.php = a modal popup which opens when the user clicks on "update" above.
updatecust.php = which runs the SQL to update the database when the submit button is pressed
DATABASE: Contains a table called "Customers"
"Customers" table
id
firstName
lastName
email
=====================
The problem is that when I press update it loads the modal popup but does not populate the text boxes with the selected row from the database. It appears blank, however if I amend the SELECT Statement on the "updatefrm.php" page and remove the "WHERE id='$update_id' then the first row of my database populates the text boxes.
Apologies if this is something really simple but I am a beginner at php and all my code is a result of a few different tutorials along with info from W3Schools.
the Code for my pages is as follows;
mlist.php
//Connect to DB
mysql_connect("localhost", "****", "****");
mysql_select_db("fidodb");
$tbl_name="customers";
//Run SQL Query to get list
$sql="SELECT * FROM $tbl_name";
$result=mysql_query($sql);
//Loop through records in database
while($rows=mysql_fetch_array($result)){
<tr>
<td><?php echo $rows['id']; ?></td>
<td><?php echo $rows['firstName']; ?></td>
<td><?php echo $rows['lastName']; ?></td>
<td><?php echo $rows['email']; ?></td>
<td><a href="upcustfrm.php?id=<?php echo $rows['id']; ?>" align="center" target="popup" onClick="wopen('upcustfrm.php', 'popup', 300 , 250); return false;"><img border="0" src="images/page_edit.png" width="32" height="32"/></a></td>
<td><a href="deletecust.php?id=<?php echo $rows['id']; ?>" align="center" onclick="return confirm('Do you really want to delete the customer?');"><img border="0" src="images/delete.png" width="32" height="32" /></a></td>
</tr>
======================================
upcustfrm.php
$host="localhost"; // Host name
$username="****"; // Mysql username
$password="****"; // Mysql password
$db_name="fidodb"; // Database name
$tbl_name="customers"; // 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");
// get value of id that sent from address bar
$update_id=$_GET['id'];
//Run SQL Query to get list
$sql="SELECT * FROM $tbl_name WHERE id='$update_id'";
$result=mysql_query($sql);
//Get info from row
$rows=mysql_fetch_array($result);
......
<table>
<form name="updatecust" method="get" action="updatecust.php">
<tr>
<td>First Name</td>
<td>:</td>
<td><input name="firstName" type="text" id="firstName" size="19" value="<?php echo $rows['firstName']; ?>"></td>
</tr>
<tr>
<td></td>
</tr>
<tr>
<td>Surname</td>
<td>:</td>
<td><input name="lastName" type="text" id="lastName" size="19" value="<?php echo $rows['lastName']; ?>"></td>
</tr>
<tr>
<td></td>
</tr>
<tr>
<td>Email Address</td>
<td>:</td>
<td><input name="email" type="text" id="email" size="19" value="<?php echo $rows['email']; ?>"></td>
</tr>
<tr>
<td></td>
</tr>
<tr>
<td></td>
<td><input name="id" type="hidden" id="id" value="<?php echo $rows['id']; ?>"></td>
<td><input type="submit" name="email" value="Update"></td>
</tr>
</form>
</table>
thanks very much guys,
Dwayne