Hi, I'm hoping that someone can help me with my update script. I'm been playing around with php for a few months but I'm still a beginner so I apologize in advance if my code is hard to read, or fraught with errors.
I'm making an update script for my friend and it's just not working. I've created a private members area which works fine and now I'm trying to create a text box which has the old information already in it so that it's easy to modify.
Here are my problems:
1) The old info does not appear in the text box.
2) The script will not even post to the database.
It was actually posting before I made changes to it, but it would make an additional 2 blank duplicates and it would not edit the current entry - it would just make a new one.
Below is my code. I've been tweaking it for about 2 weeks now and I'm stuck.
<?php
require_once("connect.php");
// check session variable
if (isset($_SESSION['valid_user']))
{
echo '<p>You are logged in as '.$_SESSION['valid_user'].'</p>';
// Gets the article_ID from link and sets it to a variable.
$ArticleID = $_GET['article_ID'];
$Content = $_GET['articles_content'];
// Selects the fields that will be displayed
$query="SELECT articles_ID,articles_content FROM articles WHERE articles_ID=".$_GET['articles_ID']."";
$result=mysql_query($query,$connect);
?>
<html>
<head>
<title>Edit Article</title>
</head>
<body>
<table>
<form action="editarticles.php" method=GET>
<font size=2>
<tr><td>Content</td><td><textarea name="articles_content" rows="3" cols="20"><?php echo $Content ?></textarea></td></tr>
<tr><td><input type=submit name="submit" value="submit"></td>
<td><input type=Reset name="reset" value="Reset"></td></tr>
</font>
</form>
</table>
<?php
// This receives and handles the data generated from the form"
//$edit_content=$_GET['articles_content'];
$query="UPDATE articles
SET articles_content='$articles_content'
WHERE articles_ID=".$_GET['articles_ID']."";
$result=mysql_query($query,$connect);
if ($_GET['submit'] == true) //This means the form HAS been submitted:
{
if (mysql_query($query,$connect)) {
echo "Article has been edited\n";
echo "<a href='addarticles.php'>Click here to add another story</a>";
}else {
echo "System error. Article was not edited\n";
}
}
mysql_close($connect);
}
// Not logged in
else
{
echo '<p>You are not logged in.</p>';
echo '<p>Only logged in members may see this page.</p>';
}
echo '<a href="authmain.php">Back to main page</a>';
?>
A friend of mine told me that I need to put this line somewhere:
list($articles_content) = mysql_fetch_row($query);
Is this correct and if so why would I need it? I'm guessing that it would go right after my SELECT query.
Thanks.