while ($row = mysql_fetch_array ($r)) {
print "<tr><td valign='top'><a href='?page=edit&id={$row['news_id']}'>{$row['news_id']}</a> </td><td valign='top'>{$row['news_author']}</td></tr>";
}
when I select the one to edit It goes to the same page using the ?page=edit&id="id of news" except it doesnt recieve the value of name any ideas?
PHP Help
#1
Posted 06 March 2006 - 05:03 AM
#2
Posted 06 March 2006 - 06:56 AM
while ($row = mysql_fetch_array ($r)) {
print "<tr><td valign='top'><a href=\"?page=edit&id={$row['news_id']}\">{$row['news_id']}</a> </td><td valign='top'>{$row['news_author']}</td></tr>";
}
that should do it i think
#3
Posted 06 March 2006 - 03:48 PM
First off I never use double quotes with my PHP. I either close the php tag, put my HTML code and reopen the tag or use a single quuote echo. I have examples of both.
while ($row = mysql_fetch_array ($r)) {
print '<tr><td valign="top"><a href="?page=edit&id='.$row['news_id'].'>'.$row['news_id'].'</a> </td><td valign="top">'.$row['news_author'].'</td></tr>';
}
Notice I escape the single quote for variables. Now for my way. I use this, I find when using a WYSIWYG editor it helps to show all HTML outside of the PHP.
while ($row = mysql_fetch_array ($r)) {
?>
<tr><td valign="top"><a href="?page=edit&id=<? echo $row['news_id']; ?>"><? echo $row['news_id']; ?></a> </td><td valign="top"'><? echo $row['news_author']; ?> </td></tr>
<?
}
Edited by Lang, 06 March 2006 - 03:48 PM.
#4
Posted 06 March 2006 - 04:03 PM
--EDIT--
It does receive the data but it doesnt print the form
I've included the from Source Code
if (isset ($_GET['id'])) {
echo '' . $_GET['id'] . '';
$query = "SELECT * FROM newscms WHERE news_id={$_GET['id']}";
if ($r = mysql_query ($edit)) {
$row = mysql_fetch_array ($r);
echo '<form action="modify.php" method="post">';
echo 'Title<br />';
echo '<input type="text" name="title" value="' . $row['news_title'] . '"><br />';
echo 'Story<br />';
echo '<textarea value="' . $row['news'] . '"></textarea><br />';
echo 'Author<br />';
echo '<input type="text" value="' . $row['news_author'] . '"><br />';
echo'<input type="submit" name="save" value="Save It!">';
echo '</form>';
}
}
Edited by Hit3k, 07 March 2006 - 12:34 AM.
#5
Posted 07 March 2006 - 07:14 AM
Edited by liveman, 07 March 2006 - 07:15 AM.
#6
Posted 07 March 2006 - 08:58 AM
if (isset ($_GET['id'])) {
$id = $_GET['id'];
echo $id;
$query = "SELECT `news_title`, `news`, `news_author` FROM `newscms` WHERE `news_id` = '$id'";
if ($r = mysql_query ($edit)) {
$row = mysql_fetch_array ($r);
echo '<form action="modify.php" method="post">';
echo 'Title<br />';
echo '<input type="text" name="title" value="$row[0]"><br />';
echo 'Story<br />';
echo '<textarea name="story">$row[1]</textarea><br />';
echo 'Author<br />';
echo '<input type="text" value="$row[2]"><br />';
echo'<input type="submit" name="save" value="Save It!">';
echo '</form>';
} }
I have changed a few things here:
With the query i selected the rows needed and not all of them (helps speed up the running of the query)
With the Textarea, there is no value=" " for it, the "value" goes inbetween the open and close tags as i have done
And i also set the $_GET to a variable $id.
It might work now, if it still doesnt work post any error messages you get.
Also with these lines:
$query = "SELECT `news_title`, `news`, `news_author` FROM `newscms` WHERE `news_id` = '$id'";
if ($r = mysql_query ($edit)) {
$row = mysql_fetch_array ($r);
isnt it meant to be - if ($r = mysql_query ($query)) { - ????
Edited by deadly, 07 March 2006 - 09:04 AM.
#7
Posted 07 March 2006 - 03:35 PM
#8
Posted 07 March 2006 - 03:58 PM
Edited by Hit3k, 08 March 2006 - 03:45 PM.
1 user(s) are reading this topic
0 members, 1 guests, 0 anonymous users
