Hello all,
So I have a database table called contacts where users can enter, view, update and delete. I've got the enter, view and delete part taken care of just fine. My updating is the problem. First off, when I go to the page to update it only populates the text boxes with the first record in the database instead of the correct record. Here's ahref I use to open that page;
<?
require '../globals/dbconnect.php';
$query = ("SELECT * FROM contacts WHERE con_id = '$con_id'");
//make the title a link
echo "<a href='edittenants.php?con_id=$con_id'>Edit</a>";
?>
heres the update page aka edittenants.php
<?
require '../globals/dbconnect.php';
$user_name = $_SESSION['user_name'];
$query = "SELECT * from contacts WHERE user_record = '$user_name' ";
//then call the query and display it
$result = mysql_query($query) or die('Query failed: ' . mysql_error());
$myrow = mysql_fetch_array($result);
?>
<form action="tenedit.php" method="post">
<input type=hidden name="id" value="<?php $_GET['con_id'] ?>">
<table width="100%" border="1" align="center" cellpadding="1" cellspacing="1" bordercolor="#CCCCCC" bgcolor="#F8F8F8">
<tr bordercolor="#F8F8F8" bgcolor="#FFFFFF">
<td colspan="4"><div align="center"><strong><span class="style5"><img src="../images/tenant.gif" width="242" height="47"> </span></strong></div></td>
</tr>
<tr valign="top" bordercolor="#F8F8F8" bgcolor="#F8F8F8">
<td width="20%" bgcolor="#F0F0F0">Name</td>
<td width="26%"><input name="con_name" type="text" class="style1" id="con_name" value="<?php echo $myrow["con_name"]?>" size="15"></td>
<td width="22%" bgcolor="#F0F0F0">Email</td>
<td width="32%"><input name="con_email" type="text" class="style1" id="con_email" value="<?php echo $myrow["con_email"]?>" size="15"></td>
</tr>
<tr valign="top" bordercolor="#F8F8F8" bgcolor="#F8F8F8">
<td bgcolor="#F0F0F0">Company</td>
<td><input name="con_biz" type="text" class="style1" id="con_biz" value="<?php echo $myrow["con_biz"]?>" size="15"></td>
<td bgcolor="#F0F0F0">Company Type </td>
<td><input name="con_biztype" type="text" class="style1" id="con_biztype" value="<?php echo $myrow["con_biztype"]?>" size="15"></td>
</tr>
<tr valign="top" bordercolor="#F8F8F8" bgcolor="#F8F8F8">
<td bgcolor="#F0F0F0"><p>Property </p> </td>
<td><textarea name="con_addr" cols="16" rows="5" class="style1" id="con_addr"><?php echo $myrow["con_addr"]?></textarea></td>
<td bgcolor="#F0F0F0">Status </td>
<td><p>
<label> </label>
<input name="con_status" type="text" class="style1" id="con_status" value="<?php echo $myrow["con_status"]?>" size="15">
<br>
</p></td>
</tr>
<tr valign="top" bordercolor="#F8F8F8" bgcolor="#F8F8F8">
<td bgcolor="#F0F0F0">Phone</td>
<td><input name="con_ph" type="text" class="style1" id="con_ph" value="<?php echo $myrow["con_ph"]?>" size="15"></td>
<td bgcolor="#F0F0F0">Date Moved In </td>
<td><input name="bar" type="text" value="<?php echo $myrow["bar"]?>" size="15" />
<a href="#" onClick="return getCalendar(document.foo.bar);"><img src="calendar.png" width="22" height="19" border="0" /></a></td>
</tr>
<tr valign="top" bordercolor="#F8F8F8" bgcolor="#F8F8F8">
<td bgcolor="#F0F0F0">Fax</td>
<td><input name="con_fax" type="text" class="style1" id="con_fax" value="<?php echo $myrow["con_fax"]?>" size="15"></td>
<td bgcolor="#F8F8F8"> </td>
<td bgcolor="#F8F8F8"> </td>
</tr>
<tr bordercolor="#F8F8F8" bgcolor="#F8F8F8">
<td colspan="4"><div align="center">
<input name="Submit2" type="submit" class="style1" value="Edit Contact">
</div></td>
</tr>
</table>
</form>
Now even if I am to attempt editing that first and only record that gets displayed, it still wont pass through the update script correctly. Heres the update script that the form posts to
tenedit.php
<?
session_start();
header("Cache-control: private");
require '../globals/dbconnect.php';
$user_name = $_SESSION['user_name'];
$query = "SELECT * from contacts WHERE user_record = '$user_name' ";
$con_id=$_POST['id'];
$con_name=$_POST['con_name'];
$con_addr=$_POST['con_addr'];
$con_biz=$_POST['con_biz'];
$con_biztype=$_POST['con_biztype'];
$con_ph=$_POST['con_ph'];
$con_fax=$_POST['con_fax'];
$con_email=$_POST['con_email'];
$con_status=$_POST['con_status'];
$bar=$_POST['bar'];
$query="UPDATE contacts SET con_name='$con_name', con_addr='$con_name', con_biz='$con_biz', con_biztype='$con_biztype', con_ph='$con_ph', con_fax='$con_fax', con_email='$con_email', con_status='$con_status', bar='$bar' WHERE id='$con_id'";
mysql_query($query) or die('Error, record update failed');
header("Location: ../sampleacct/tenants.php");
?>
Oh yea by the way, I'm sure you noticed all of the sessions going on here. The purpose of that is because these records are user specific and I have dedicated a field in my table to the user_name variable that gets passed page to page. Any suggestions on how to get this bohemoth working? :queasy: