sonofjack
06-28-2010, 09:58 PM
I have a page where you can post and edit a listing. However when you go into edit mode, all the fields appear filled in with the previous data except for the date and time. I know this is probably something to do with the format of each of these but I can't work out how these should be labelled in the code.
I've tried different ways except for the correct one it would seem.
Can anyone out there help please?
<?php
else: // Edit listings
$id = $_GET['id'];
$listings = @mysql_query (
"SELECT id, day, date_format(date,'%Y/%m/%d') as d, channel, programmetitle, time_format
(starttime, '%h:%i%p') as t, duration, notes FROM listings WHERE id='$id'");
if (!$listings) {
exit ('<p>Error fetching listings: ' .
mysql_error() . '</p>');
}
$listings = mysql_fetch_array($listings);
?>
<?php
function safe($value){
return mysql_real_escape_string($value);
}
?>
<?php
$id = $listings['id'];
$day = $listings['day'];
$date = $listings['date'];
$channel = $listings['channel'];
$programmetitle = $listings['programmetitle'];
$starttime = $listings['starttime'];
$duration = $listings['duration'];
$notes = $listings['notes'];
//Convert special characters for safe use
$id = htmlspecialchars($id);
$day = htmlspecialchars($day);
$date = htmlspecialchars($date);
$channel = htmlspecialchars($channel);
$programmetitle = htmlspecialchars($programmetitle);
$starttime = htmlspecialchars($starttime);
$duration = htmlspecialchars($duration);
$notes = htmlspecialchars($notes);
?>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
<fieldset>
<legend>Enter listings</legend>
<div><label for="day">Day:</label> <br /><input id="day" type="text" name="day" value="<?php
echo $day; ?>"></div>
<div><label for="date">Date:</label><br /><input id="date" type="text" name="date" value="<?php
echo $date; ?>" /></div>
<div><label for="channel">Channel:</label> <br /><input id="channel" type="text" name="channel"
value="<?php echo $channel; ?>" /></div>
<div><label for="prog_title">Prog Title:</label><br /> <textarea id="prog_title"
name="programmetitle" rows="1" cols="70"><?php echo $programmetitle; ?></textarea></div>
<div><label for="starttime">Start time:</label><br /> <input id="starttime" type="text"
name="starttime" value="<?php echo $starttime; ?>" ></div>
<div><label for="duration">Duration:</label> <br /><input id="duration" type="text"
name="duration" value="<?php echo $duration; ?>" ></div>
<div><label for="notes">Notes:</label><br /> <textarea id="notes" name="notes" rows="5"
cols="70"><?php echo $notes; ?></textarea></div>
<input type="hidden" name="id" value="<?php echo $id; ?>" >
<div><input type="submit" value="SUBMIT"></div>
</form>
Thank you
I've tried different ways except for the correct one it would seem.
Can anyone out there help please?
<?php
else: // Edit listings
$id = $_GET['id'];
$listings = @mysql_query (
"SELECT id, day, date_format(date,'%Y/%m/%d') as d, channel, programmetitle, time_format
(starttime, '%h:%i%p') as t, duration, notes FROM listings WHERE id='$id'");
if (!$listings) {
exit ('<p>Error fetching listings: ' .
mysql_error() . '</p>');
}
$listings = mysql_fetch_array($listings);
?>
<?php
function safe($value){
return mysql_real_escape_string($value);
}
?>
<?php
$id = $listings['id'];
$day = $listings['day'];
$date = $listings['date'];
$channel = $listings['channel'];
$programmetitle = $listings['programmetitle'];
$starttime = $listings['starttime'];
$duration = $listings['duration'];
$notes = $listings['notes'];
//Convert special characters for safe use
$id = htmlspecialchars($id);
$day = htmlspecialchars($day);
$date = htmlspecialchars($date);
$channel = htmlspecialchars($channel);
$programmetitle = htmlspecialchars($programmetitle);
$starttime = htmlspecialchars($starttime);
$duration = htmlspecialchars($duration);
$notes = htmlspecialchars($notes);
?>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
<fieldset>
<legend>Enter listings</legend>
<div><label for="day">Day:</label> <br /><input id="day" type="text" name="day" value="<?php
echo $day; ?>"></div>
<div><label for="date">Date:</label><br /><input id="date" type="text" name="date" value="<?php
echo $date; ?>" /></div>
<div><label for="channel">Channel:</label> <br /><input id="channel" type="text" name="channel"
value="<?php echo $channel; ?>" /></div>
<div><label for="prog_title">Prog Title:</label><br /> <textarea id="prog_title"
name="programmetitle" rows="1" cols="70"><?php echo $programmetitle; ?></textarea></div>
<div><label for="starttime">Start time:</label><br /> <input id="starttime" type="text"
name="starttime" value="<?php echo $starttime; ?>" ></div>
<div><label for="duration">Duration:</label> <br /><input id="duration" type="text"
name="duration" value="<?php echo $duration; ?>" ></div>
<div><label for="notes">Notes:</label><br /> <textarea id="notes" name="notes" rows="5"
cols="70"><?php echo $notes; ?></textarea></div>
<input type="hidden" name="id" value="<?php echo $id; ?>" >
<div><input type="submit" value="SUBMIT"></div>
</form>
Thank you