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
https://forums.phpfreaks.com/topic/117184-query-help/
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
https://forums.phpfreaks.com/topic/117184-query-help/#findComment-602744
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
https://forums.phpfreaks.com/topic/117184-query-help/#findComment-602799
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
https://forums.phpfreaks.com/topic/117184-query-help/#findComment-602881
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.