Jump to content

query help


rmt99e

Recommended Posts

hey guys, im making a news feed in php - i'm working on the edit page. everything works okay except it doesn't actually update the news in the DB ::).. Thanks

 

 

<?php
include("config.php");

if(isset($_POST['submit']))
	{
		$title = mysql_escape_string($_POST['title']); 
		$text1 = mysql_escape_string($_POST['text1']);

		$result = mysql_query("UPDATE news SET title='$title', text1='$text1' WHERE newsid='$newsid'",$connect);
		echo "News updated successfully. Redirecting...";
		echo "<meta http-equiv=Refresh content=2;url=view_news.php>";
	}

	elseif(isset($_GET['newsid']))

	{

		$result = mysql_query("SELECT * FROM news WHERE newsid='$_GET[newsid]'", $connect);
		while($myrow = mysql_fetch_assoc($result))
			{
			$title = $myrow["title"];
			$text1 = $myrow["text1"];				
?>

<form method="post" action="<?php echo $PHP_SELF ?>">
<input type="hidden" name="newsid" value="<? echo $myrow['newsid'] ?>">

Title<br>
<input name="title" size="40" maxlength="255" value="<? echo $title; ?>">
<br>Text<br>
<textarea name="text1" rows="7" cols="30"><? echo $text1; ?></textarea>
<br><br>
<input type="submit" name="submit" value="Update News">
</form>

<?
	}//end of while loop
}//end of else
?>

Link to comment
Share on other sites

Change:

$result = mysql_query("UPDATE news SET title='$title', text1='$text1' WHERE newsid='$newsid'",$connect);

 

To:

$result = mysql_query("UPDATE news SET title='$title', text1='$text1' WHERE newsid='$newsid'",$connect) or die(mysql_error());

 

Tell us what it says after that.

Link to comment
Share on other sites

the problem lies further than what is shown in the code

 

in his form he has the following:

 

<input type="hidden" name="newsid" value="<? echo $myrow['newsid'] ?>">

 

that assumes that $myrow['newsid'] actually has a value or does it? i bet you the problem is there...

Link to comment
Share on other sites

Got it. I added

 

$newsid = $_GET['newsid'];

 

at the top.

 

<?php
include("config.php");

if(isset($_POST['submit']))
	{
		$title = mysql_escape_string($_POST['title']); 
		$text1 = mysql_escape_string($_POST['text1']);
		$newsid = $_GET['newsid'];

		$result = mysql_query("UPDATE news SET title='$title', text1='$text1' WHERE newsid='$newsid'",$connect) or die(mysql_error());
		echo "News updated successfully. Redirecting...";
		echo "<meta http-equiv=Refresh content=2;url=view_news.php>";
	}

	elseif(isset($_GET['newsid']))

	{

		$result = mysql_query("SELECT * FROM news WHERE newsid='$_GET[newsid]'", $connect);
		while($myrow = mysql_fetch_assoc($result))
			{
			$title = $myrow["title"];
			$text1 = $myrow["text1"];				
?>

<form method="post" action="<?php echo $PHP_SELF ?>">
<input type="hidden" name="newsid" value="<? echo $myrow['newsid'] ?>">

Title<br>
<input name="title" size="40" maxlength="255" value="<? echo $title; ?>">
<br>Text<br>
<textarea name="text1" rows="7" cols="30"><? echo $text1; ?></textarea>
<br><br>
<input type="submit" name="submit" value="Update News">
</form>

<?
	}//end of while loop
}//end of else
?>

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.