Ok, i made a script, which appears to be correct, however it wont update the database, instead it just does nothing. It is split into two parts - the form page (update.php), and the updateprocess.php page
Here is the script around the form on the form page:
<?php //connect to Database!
include("dbconnect.php");
//Get Values Query to display in form fields
$query2='SELECT * FROM news WHERE newsid='.$newsid;
$result2=mysql_query($query2,$db);
//Condition
if (mysql_num_rows($result2)==0) {
// Part 1
$newstitle2='Error';
$newscontent2='This news item does not exist.';
$maincontent2='blank';
$image2='';
// Part 2
} else {
$newstitle2=mysql_result($result2,0,'newstitle');
$newscontent2=mysql_result($result2,0,'newscontent');
$maincontent2=mysql_result($result2,0,'maincontent');
$image2=mysql_result($result2,0,'image');
}
?>
- <?php //connect to Database!
-
- include("dbconnect.php");
-
-
-
- //Get Values Query to display in form fields
-
-
-
- $query2='SELECT * FROM news WHERE newsid='.$newsid;
-
- $result2=mysql_query($query2,$db);
-
-
-
- //Condition
-
-
-
- if (mysql_num_rows($result2)==0) {
-
-
-
- // Part 1
-
- $newstitle2='Error';
-
- $newscontent2='This news item does not exist.';
-
- $maincontent2='blank';
-
- $image2='';
-
-
-
- // Part 2
-
-
-
- } else {
-
-
-
-
-
- $newstitle2=mysql_result($result2,0,'newstitle');
-
- $newscontent2=mysql_result($result2,0,'newscontent');
-
- $maincontent2=mysql_result($result2,0,'maincontent');
-
- $image2=mysql_result($result2,0,'image');
-
- }
-
- ?>
<form action="updateprocess.php" method="post">
<table width="629" border="0" cellspacing="0" cellpadding="00">
<tr>
<td width="104" height="27" valign="top"><strong>Title of Article </strong></td>
<td valign="top"><input name="newstitle" type="text" class="form" id="newstitle" value="<?php echo $newstitle2;?>" size="30"></td>
<td valign="top">This is what will appear as the Article Title </td>
</tr>
<tr>
<td height="26" valign="top"><strong>Image URL <br>
</strong></td>
<td width="190" valign="top"><input name="image" type="text" class="form" id="image" value="<?php echo $image2;?>" size="30"> </td>
<td width="335" valign="top">Leave this Field as it is (do not change the Image URL) <?php echo '<input type="hidden" name="action" value="update">';?>
</td>
</tr>
<tr>
<td height="84" valign="top"><strong>Brief Description</strong></td>
<td valign="top"><textarea name="maincontent" cols="30" rows="4" wrap="VIRTUAL" class="form" id="maincontent"><?php echo $maincontent2;?>
</textarea> </td>
<td valign="top">This is the leader text which appears on the home page. An idea would be type out the <strong>Full Content first </strong>(below), and then copy the first few lines of it into this text box here. </td>
</tr>
<tr>
<td height="86" valign="top"><strong>Full Content</strong></td>
<td valign="top"><textarea name="newscontent" cols="30" rows="4" wrap="VIRTUAL" class="form" id="newscontent"><?php echo $newscontent2;?>
</textarea></td>
<td valign="top">This what will appear on the news page related to this article, for example news.php?newsid=5. In this box enter the <strong>FULL </strong>Content. If you ever want to break sections of content up, i.e adding paragraphs add this code before the break <br><br>. </td>
</tr>
<tr>
<td> </td>
<td><input name="Submit" type="submit" class="form" value="Update"></td>
<td valign="top"><strong>[<a href="delete.php">Delete This Article!</a>] </strong></td>
</tr>
</table>
</form>
- <form action="updateprocess.php" method="post">
- <table width="629" border="0" cellspacing="0" cellpadding="00">
- <tr>
- <td width="104" height="27" valign="top"><strong>Title of Article </strong></td>
- <td valign="top"><input name="newstitle" type="text" class="form" id="newstitle" value="<?php echo $newstitle2;?>" size="30"></td>
- <td valign="top">This is what will appear as the Article Title </td>
- </tr>
- <tr>
- <td height="26" valign="top"><strong>Image URL <br>
- </strong></td>
- <td width="190" valign="top"><input name="image" type="text" class="form" id="image" value="<?php echo $image2;?>" size="30"> </td>
- <td width="335" valign="top">Leave this Field as it is (do not change the Image URL) <?php echo '<input type="hidden" name="action" value="update">';?>
- </td>
- </tr>
- <tr>
- <td height="84" valign="top"><strong>Brief Description</strong></td>
- <td valign="top"><textarea name="maincontent" cols="30" rows="4" wrap="VIRTUAL" class="form" id="maincontent"><?php echo $maincontent2;?>
- </textarea> </td>
- <td valign="top">This is the leader text which appears on the home page. An idea would be type out the <strong>Full Content first </strong>(below), and then copy the first few lines of it into this text box here. </td>
- </tr>
- <tr>
- <td height="86" valign="top"><strong>Full Content</strong></td>
- <td valign="top"><textarea name="newscontent" cols="30" rows="4" wrap="VIRTUAL" class="form" id="newscontent"><?php echo $newscontent2;?>
- </textarea></td>
- <td valign="top">This what will appear on the news page related to this article, for example news.php?newsid=5. In this box enter the <strong>FULL </strong>Content. If you ever want to break sections of content up, i.e adding paragraphs add this code before the break <br><br>. </td>
- </tr>
- <tr>
- <td> </td>
- <td><input name="Submit" type="submit" class="form" value="Update"></td>
- <td valign="top"><strong>[<a href="delete.php">Delete This Article!</a>] </strong></td>
- </tr>
- </table>
- </form>
That is the code which covers the form.
Here is the code on the updateprocess page:
<?php include("dbconnect.php");
//get the ID of the News Article
$newsid=$_GET["newsid"];
?>
<?php
//Get the Action from the form
$action=$_POST["action"];
if ($action=='update') {
# Comment has been saved, so add to the database
//Variables
$newstitle=$_POST["newstitle"];
$image=$_POST["image"];
$maincontent=$_POST["maincontent"];
$newscontent=$_POST["newscontent"];
//update Query Start
$query='UPDATE news
SET newstitle = "'.$newstitle.'"
newscontent="'.$newscontent.'"
image ="'.$image.'"
maincontent="'.$maincontent.'"
where newsid='.$newsid.' LIMIT 1';
// result
$result=mysql_query($query,$db);
// update saved to database, refresh home page!!
echo '<meta HTTP-EQUIV="REFRESH" content="0; url=index.php">';
die;
}
?>
- <?php include("dbconnect.php");
-
-
-
- //get the ID of the News Article
-
-
-
- $newsid=$_GET["newsid"];
-
- ?>
-
- <?php
-
- //Get the Action from the form
-
-
-
- $action=$_POST["action"];
-
- if ($action=='update') {
-
-
-
- # Comment has been saved, so add to the database
-
-
-
- //Variables
-
-
-
- $newstitle=$_POST["newstitle"];
-
- $image=$_POST["image"];
-
- $maincontent=$_POST["maincontent"];
-
- $newscontent=$_POST["newscontent"];
-
-
-
- //update Query Start
-
-
-
- $query='UPDATE news
-
- SET newstitle = "'.$newstitle.'"
-
- newscontent="'.$newscontent.'"
-
- image ="'.$image.'"
-
- maincontent="'.$maincontent.'"
-
- where newsid='.$newsid.' LIMIT 1';
-
-
-
- // result
-
-
-
- $result=mysql_query($query,$db);
-
-
-
- // update saved to database, refresh home page!!
-
-
-
- echo '<meta HTTP-EQUIV="REFRESH" content="0; url=index.php">';
-
- die;
-
- }
-
- ?>
Any ideas why it wont actually update the fields?
Thanks,
Steve