
June 24th, 2003, 08:20 PM
|
|
Junior Member
|
|
Join Date: Jan 2003
Posts: 5
Time spent in forums: < 1 sec
Reputation Power: 0
|
|
|
Trouble Editing a record
I have a page that has a form. This form is either left empty or populated with a record, depending on what variable is passed. However, when I go to edit a record, the form isn't populated with the records information.
Here's the page passing the variable
PHP Code:
<?php
$db="";
$connect = mysql_connect("","","");
if (! $connect)
die ("Couldn't connect to MySQL");
mysql_select_db($db, $connect) or die ("Select DB Error: ".mysql_error());
$query = "SELECT * FROM ***";
$result = mysql_query($query,$connect);
?>
<table width="100%" border="0" cellspacing="1" cellpadding="1">
<? while ($myrow = mysql_fetch_array($result)) {
$partydate=$myrow["PartyDay"];
$party=$myrow["Party"];
$prodco=$myrow["ProdCo"];
$address=$myrow["Address"];
$city=$myrow["City"];
$state=$myrow["State"];
$phone=$myrow["Phone"];
$partytime=$myrow["PartyTime"];
$age=$myrow["Age"];
$price=$myrow["Price"];
$url=$myrow["URL"];
?>
<tr>
<td><?php echo date("F jS, Y",strtotime($partydate)); ?>
<span class="party"><?php echo "$party"; ?></span>
<span class="clubinfo">(<?php echo "$prodco - ", "$address, ", "$city ", "$state - ", "$phone ", "$partytime ", "$age ", "$price - "; ?> <a href="<?php echo "$url"; ?>"><?php echo "$url"; ?></a>)</span></td>
<td><?php echo "<a href=\"eventadd-test1.php?id=".$myrow["ID"]."\">Edit</a>"; ?>
<?php echo "<a href=\"eventdelete.php?id=".$myrow["ID"]."\">Delete</a>";?></td>
</tr>
<?
}
?>
</table>
here's the page that has the form
PHP Code:
<?php
if(isset($_POST['submit']))
{
// open connection
$db="";
$connect = mysql_connect("","","");
if (! $connect)
die ("Couldn't connect to MySQL");
mysql_select_db($db, $connect) or die ("Select DB Error: ".mysql_error());
$sql = "INSERT INTO illumparty VALUES ('','$party','$party_day','$prod_co','$location',' $city',
'$state','$infolines','$partytime','$age','$price' ,'$url')" or die("Insert table Error: ".mysql_error());
$result = mysql_query($sql);
echo "Thank you! Information entered.\n";
}
else if(isset($_POST['update']))
{
$db="";
$connect = mysql_connect("","","");
mysql_select_db($db,$connect);
$sql = "UPDATE illumparty SET party='$party',
party_day='$party_day', prod_co='$prod_co', location='$location', city='$city', state='$state',
infolines='$infolines', partytime='$partytime', age='$age', price='$price', url='$url WHERE ID=$id";
$result = mysql_query($sql);
echo "Thank you! Information updated.<br />
<a href='eventadd.php'>Enter another event</a><br />
<a href='events.php'>View Events</a>\n";
}
else if(isset($_POST['id']))
{
$db="";
$connect = mysql_connect("","","");
mysql_select_db($db,$connect);
$result = mysql_query("SELECT * FROM illumparty WHERE ID=$id",$connect);
$myrow = mysql_fetch_array($result);
?>
<form action="<?php echo $PHP_SELF ?>" method="post">
<table width="300" border="0">
<tr>
<td><input type="hidden" name="ID" value="<?php echo $myrow["ID"]?>"></td>
<td> </td>
</tr>
<tr>
<td><div align="right">Name</div></td>
<td><input name="party" type="text" id="party" value="<?php echo $myrow["party"]?>"></td>
<tr>
<td><div align="right">Date</div></td>
<td><input name="party_day" type="text" id="party_day" value="<?php echo $myrow["party_day"]?>"></td>
</tr>
<tr>
<td><div align="right">Promoter</div></td>
<td><input name="prod_co" type="text" id="prod_co" value="<?php echo $myrow["prod_co"]?>"></td>
</tr>
<tr>
<td><div align="right">Location</div></td>
<td><input name="location" type="text" id="location" value="<?php echo $myrow["location"]?>"></td>
</tr>
<tr>
<td><div align="right">City</div></td>
<td><input name="city" type="text" id="city" value="<?php echo $myrow["city"]?>"></td>
</tr>
<tr>
<td><div align="right">State</div></td>
<td><input name="state" type="text" id="state" value="<?php echo $myrow["state"]?>"></td>
</tr>
<tr>
<td><div align="right">InfoLines</div></td>
<td><textarea name="infolines" cols="25" rows="5" id="infolines" value="<?php echo $myrow["infolines"]?>"></textarea></td>
</tr>
<tr>
<td><div align="right">Time</div></td>
<td><input name="partytime" type="text" id="partytime" value="<?php echo $myrow["partytime"]?>" size="20"></td>
</tr>
<tr>
<td><div align="right">Age</div></td>
<td><input name="age" type="text" id="age" value="<?php echo $myrow["age"]?>" size="20"></td>
</tr>
<tr>
<td><div align="right">Price </div></td>
<td><input name="price" type="text" id="price" value="<?php echo $myrow["price"]?>"></td>
</tr>
<tr>
<td><div align="right">URL</div></td>
<td><input name="url" type="text" id="url" value="<?php echo $myrow["url"]?>"></td>
</tr>
<tr>
<td><div align="right">
<input type="submit" name="update" value="Update information">
</div></td>
<td></td>
</tr>
</table>
</form>
<?
}
else
{
?>
<form action="<?php echo $PHP_SELF ?>" method="post" name="EventAdd" id="EventAdd">
<table width="300" border="0">
<tr>
<td><div align="right">Name</div></td>
<td><input name="party" type="text" id="party"></td>
</tr>
<tr>
<td><div align="right">Date</div></td>
<td><input name="party_day" type="text" id="party_day" size="20"></td>
</tr>
<tr>
<td><div align="right">Promoter</div></td>
<td><input name="prod_co" type="text" id="prod_co"></td>
</tr>
<tr>
<td><div align="right">Location</div></td>
<td><input name="location" type="text" id="location"></td>
</tr>
<tr>
<td><div align="right">City</div></td>
<td><input name="city" type="text" id="city"></td>
</tr>
<tr>
<td><div align="right">State</div></td>
<td><input name="state" type="text" id="state"></td>
</tr>
<tr>
<td><div align="right">InfoLines</div></td>
<td><textarea name="infolines" cols="25" rows="5" id="infolines"></textarea></td>
</tr>
<tr>
<td><div align="right">Time</div></td>
<td><input name="partytime" type="text" id="partytime" size="20"></td>
</tr>
<tr>
<td><div align="right">Age</div></td>
<td><input name="age" type="text" id="age" size="20"></td>
</tr>
<tr>
<td><div align="right">Price </div></td>
<td><input name="price" type="text" id="price2"></td>
</tr>
<tr>
<td><div align="right">URL</div></td>
<td><input name="url" type="text" id="url2"></td>
</tr>
<tr>
<td><div align="right">
<input name="submit" type="submit" id="submit" value="submit">
</div></td>
<td><input name="reset" type="reset" id="reset2" value="reset"></td>
</tr>
</table>
</form>
<?
}
?>
Can anybody help?
Thanks!
|