Jump to content


PHP Help


7 replies to this topic

#1 Hit3k

    Young Padawan

  • Members
  • Pip
  • 120 posts
  • Gender:Male
  • Location:Australia

Posted 06 March 2006 - 05:03 AM

Ok so.. I'm writing a CMS and on the edit page When i get the rows from the DB I have this
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?

#2 Mr. Matt

    Moderator

  • P2L Staff
  • PipPipPipPip
  • 1,945 posts
  • Gender:Not Telling

Posted 06 March 2006 - 06:56 AM

you need to change the link park of it, you are using two sets of ' ' in there. Change it to this:

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 Lang

    Young Padawan

  • Members
  • Pip
  • 198 posts
  • Gender:Male
  • Location:Ontario, Canada

Posted 06 March 2006 - 03:48 PM

Woah slow down there. There is a much more efficient way to do this. Gosh!

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 Hit3k

    Young Padawan

  • Members
  • Pip
  • 120 posts
  • Gender:Male
  • Location:Australia

Posted 06 March 2006 - 04:03 PM

Ok I'll try those and see if they work thanks
--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 liveman

    Young Padawan

  • Members
  • Pip
  • 246 posts
  • Location:New Jersey

Posted 07 March 2006 - 07:14 AM

I had that same problem, I just got rid of the $_GET[] and it worked ... I found that it was because I had some settings wrong in my php.ini ;-)

Edited by liveman, 07 March 2006 - 07:15 AM.


#6 Mr. Matt

    Moderator

  • P2L Staff
  • PipPipPipPip
  • 1,945 posts
  • Gender:Not Telling

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 Lang

    Young Padawan

  • Members
  • Pip
  • 198 posts
  • Gender:Male
  • Location:Ontario, Canada

Posted 07 March 2006 - 03:35 PM

Make sure id is in the URL. Other than that it should work.

#8 Hit3k

    Young Padawan

  • Members
  • Pip
  • 120 posts
  • Gender:Male
  • Location:Australia

Posted 07 March 2006 - 03:58 PM

-FIXED-

Edited by Hit3k, 08 March 2006 - 03:45 PM.






1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users