...

View Full Version : Major Issue Outputting Information for Updating...



gc40
08-26-2007, 01:23 PM
I am trying to update a database entry from a web browser. However, whenever I call the entry, the Title would only display partly and not entirely.

For example, if the title was meant to be "USEFUL TILTE", and I clicked edit, then when they form loads, the title field would just display "USEFUL" and I would have to manually type in "TITLE" so the update could be properly done.
Can anyone have a look at my code below and tell me if they can tell why the TITLE is being cut off and only the first word of the title string appears. Remember, this only happens when I go to update the database entry, no adding it. Just editing it.


<script language="javascript" type="text/javascript" src="jscripts/tiny_mce/tiny_mce.js"></script>
<script language="javascript" type="text/javascript">
// Notice: The simple theme does not use all options some of them are limited to the advanced theme
tinyMCE.init({
mode : "textareas",
theme : "simple"
});
</script>
<?php
if(session_id() == ""){
session_start();
}
header("Cache-control: private"); // IE 6 Fix.
Authenticate();
//error_reporting(E_ALL);
$today = date("Y-m-d");

if (get_magic_quotes_gpc())
{
$_POST = array_map('stripslashes', $_POST);
$_GET = array_map('stripslashes', $_GET);
$_COOKIE = array_map('stripslashes', $_COOKIE);
}
$id = intval($_REQUEST['id']);
$year = intval($_REQUEST['year']);
$month = intval($_REQUEST['month']);
$day = intval($_REQUEST['day']);
$del=$_REQUEST['del'];

if(isset($submit))
{
$fulldate = $year . "-" . $month . "-" . $date;

if($submit == 'Delete')
{
$sql = "delete from news_saxon_saxon where NEWSID = '$id'";

$result = mysql_query($sql, $db);

if($result)
{
echo("The news article was deleted successfully.");
echo("<form action='news_admin_index.php?action=editnews' method='POST'><p>");
echo("<input type='submit' name='submit' value='OK' class=\"submit button\"></form)");
}

}

else if($submit == 'Update')
{
$news = stripslashes($_POST['NEWS']);
$title = stripslashes($_POST['TITLE']);
$postdate = $year."-".$month."-".$day;
$sql = "UPDATE `news_saxon_saxon` set `TITLE`='" . mysql_real_escape_string($title) . "', `NEWS`='" . mysql_real_escape_string($news) . "', `Date`='$postdate' WHERE `NEWSID`='$id'";
$result = mysql_query($sql, $db);
if($result)
{
echo "$sql";
echo("The news article was updated successfully.");
echo("<form action='news_admin_index.php?action=editnews' method='POST' onSubmit='fnsubmit()'>");
echo("<input type='submit' name='submit' value='OK' class=\"submit button\"></form)");
}

}



else if (($submit == 'Cancel') || ($submit == 'OK'))
{ //header("Location:http://www.bviddm.com/control/nav_index.php?action=editstory");
?>
<script language="Javascript" type="text/javascript">
document.location.href='news_admin_index.php?action=editnews'
</script>
<?
}
}


else
{

if(isset($del))
{
$sql = "select * from news_saxon_saxon where NEWSID = '$id'";
$navset = mysql_query($sql, $db);
$onenav = mysql_fetch_object($navset);
echo("Are you sure you want to delete this news article ");
echo($onenav->NEWSID);
echo("?");
echo("<form action='news_admin_index.php?action=editnews' method='POST' onSubmit='fnsubmit()'>");
echo("<input type='hidden' name='id' value=" . $onenav->NEWSID . ">");
echo("<table><tr><td><input type='submit' name='submit' value='Delete' class=\"submit button\"></td><td><input type='submit' name='submit' value='Cancel' class=\"submit button\"></td></tr></table></form)");
}
else
{
if(isset($id))
{
$sql = "select * from news_saxon_saxon where NEWSID = '$id'";
$postdate = $year."-".$month."-".$day;
$navset = mysql_query($sql, $db);
$onenav = mysql_fetch_object($navset);
//list($year, $month, $day) = explode ("-", $row['DATE']);
list($year, $month, $day) = explode ("-", date("Y-m-d"));
?>
<form action= "news_admin_index.php?action=editnews" method="post">
<input type='hidden' name='id' value=<?php echo($id); ?>>
<table>
<tr><td>Day:</td><td>
<select name="day" id="day" value=<?php echo($day); ?>>
<?php
for ($i = 1; $i <= 31; $i++)
{
if ($i == $day) echo "<option value=\"$i\" selected=\"selected\">$i</option>\n";
else echo "<option value=\"$i\">$i</option>\n";
}
?>
</select>
</td>
</tr>
<tr>
<td>Month:</td><td>
<select name="month" id="month" value=<?php echo($month); ?>>
<?php
$monthList=array(
1 => "January",
2 => "February",
3 => "March",
4 => "April",
5 => "May",
6 => "June",
7 => "July",
8 => "August",
9 => "September",
10 => "October",
11 => "November",
12 => "December");

foreach($monthList as $code => $monthname)
{
if ($code == $month) echo "<option value=\"$code\" selected=\"selected\">$monthname</option>\n";
else echo "<option value=\"$code\">$monthname</option>\n";

}
?>
</select>
</td></tr>
<tr>
<td>Year:</td><td>
<select name="year" id="year" value=<?php echo($year); ?>>
<?php
$this_year = date("Y");
for ($i = $this_year; $i <= $this_year+10; $i++)
{
if ($i == $year) echo "<option value=\"$i\" selected=\"selected\">$i</option>\n";
else echo "<option value=\"$i\">$i</option>\n";
}
?>
</select><?php $postdate = $year."-".$month."-".$day;?></td>
</tr> <tr><td>Title</td><td><input type="text" name="TITLE" value=<?php echo($onenav->TITLE);?>></td></tr>
<tr><td>News</td><td><textarea name="NEWS" id="NEWS"><?php echo($onenav->NEWS);?></textarea></td></tr>
<tr><td colspan="2"><input type="submit" value="Update" name="submit" class="submit button"></td></tr>
</table>
</form>
<?php
}

else
{
?>

<table width="100%">
<tr><th class='right_title'>Date</th><th class='right_title'>Title</th>
<th colspan=2><center>Action</center></th></tr>

<?php

$navquery = "select * from news_saxon_saxon";

$navresult = mysql_query($navquery);
while ($row = mysql_fetch_object($navresult))
{
echo ("<tr>"."<td>".$row->DATE."</td>"."<td>".$row->TITLE."</td>");

echo("<td>"."<p align='center'>"."<a href='news_admin_index.php?action=editnews&id=$row->NEWSID'>"."<img src='..\images\button_edit.png' border='0' alt="."Edit".">"."</td>".
"<td><p align='center'>"."<a href='news_admin_index.php?action=editnews&id=$row->NEWSID&del=$row->NEWSID'>"."<img src='..\images\button_drop.png' border='0' alt="."Delete"."></td></tr>");
}

}
?>


</table>
<?php

}} ?>

p.s. If anyone sees any problems with my code as well, please point it out.

mcjwb
08-26-2007, 02:14 PM
This bit:

<input type="text" name="TITLE" value=<?php echo($onenav->TITLE);?>>
needs quotes around the value, like this:

<input type="text" name="TITLE" value="<?php echo($onenav->TITLE);?>">
If you don't put quotes in and $onenav-<TITLE has a space in it, anything after the space is not added to the value and is actually treated as another attribute of the input.

Other things:
Select elements don't have a value so you can get rid of the "value=<?php echo($month); ?>" part of:

<select name="month" id="month" value=<?php echo($month); ?>>and the same again for the other selects.

Also
when creating links using php variables in the query string you should use the function urlencode(). You may already know this as the variable $row->NEWSID is an integer so shouldn't need encoding but it's always good practice to encode everything you put in a querystring.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum