Hi people I am a beginner to PHP/MySQL and have been reading a lot lately… This is an admin edit page script I am working on, my problem is when I go to the edit section it…
-
Doesn’t show the headline story in the story text area form, but it brings up the info on the date, headline title and posted by forms… Plus when I change the story form to just an average one like the others and not a text area it shows it.
-
When I change any part and hit update it shows me the Headline updates message but it doesn’t actually update any of the information.
Theirs probably more errors than just that in the coding but I am a beginner so please, bare with me… And if anybody notices what else is wrong and could explain where I have went wrong I would really appreciate it… The add and delete parts work fine though. Thanks a lot people.
PS. I’m aware the HTML isn’t perfect, that will be fixed it was just kind of thrown together as I wanted to test the PHP script.
[php]<?php
include(“settings.php”);
include("…/header.php");
$pagename = $_SERVER[‘PHP_SELF’];
$action = $_REQUEST[“action”];
$recid = $_REQUEST[“recid”];
$dbh=mysql_connect ($db_server, $db_username, $db_password) or die (‘I cannot connect to the database.’);
mysql_select_db ($db_database);
?>
News Administration |
Add | Update | Delete |
<?php
if ($action == "add") {
echo "";
echo "
|
}
elseif ($action == "add2") {
$headlinetitle = $_REQUEST['headlinetitle'];
$postedby = $_REQUEST['postedby'];
$date = $_REQUEST['date'];
$story = $_REQUEST['story'];
$SQL = "INSERT INTO " . $db_table . " (headlinetitle,postedby,date,story) VALUES('$headlinetitle','$postedby','$date','$story')";
$result = @mysql_query($SQL) or die("could not complete your query");
echo "Headline added.";
}
elseif ($action == "update") {
$SQL = "SELECT * FROM " . $db_table . " ORDER BY headlinetitle";
$result = @mysql_query($SQL) or die("could not complete your query");
echo “<form method=“post” action=”$pagename?action=update2">";
echo “<select class=“textBox” name=“recid” size=“15”>”;
while($row = @mysql_fetch_array($result)) {
$value = $row[‘id’];
$headlinetitle = $row[‘headlinetitle’];
echo “<option value=”$value">";
if ($headlinetitle != $headlinetitle) {
echo “$headlinetitle ($headlinetitle)”;
} else {
echo “$headlinetitle”;
}
echo “”;
}
echo "
<input class=“button” type=“submit” value=“Update”>\n";
}
elseif ($action == “update2”) {
$SQL = “SELECT * FROM " . $db_table . " WHERE id=$recid”;
$result = @mysql_query($SQL) or die(“could not complete your query”);
while($row = @mysql_fetch_array($result)) {
$id = $row[‘id’];
$headlinetitle = $row[‘headlinetitle’];
$postedby = $row[‘postedby’];
$date = $row[‘date’];
$story = $row[‘story’];
}
echo "Record Number: $recid";
echo “<form method=“post” action=”$pagename?action=update3">";
echo “<table width=“779” border=“0” cellspacing=“0” cellpadding=“0” align=“center”>”;
echo"
echo"
echo”
echo"
echo"<td class=“textR” width=“100”>Headline Title:";
echo"<td width=“225”><input class=“textBox” type=“text” name=“headlinetitle” size=“25” value="$headlinetitle">";
echo"
echo"
echo"
echo”
echo"
echo"<td class=“textR” width=“100”>Posted By:";
echo"<td width=“225”><input class=“textBox” type=“text” name=“postedby” size=“25” value="$postedby">";
echo"
echo"
echo"
echo”
echo"
echo"<td class=“textR” width=“100”>Date:";
echo"<td width=“225”><input class=“textBox” type=“text” name=“date” size=“25” value="$date">";
echo"
echo"
echo"
echo”
echo"
echo"<td class=“textR” width=“100”>News Story:";
echo"<td width=“225”><textarea class=“textBox” name=“story” rows=“10” cols=“50” value="$story">";
echo"
echo"
echo"
echo”
echo"
echo “<INPUT TYPE=“hidden” NAME=“recid” VALUE=”$recid">";
echo “<INPUT TYPE=“hidden” NAME=“headlinetitle” VALUE=”$headlinetitle">";
echo “<INPUT TYPE=“hidden” NAME=“postedby” VALUE=”$postedby">";
echo “<INPUT TYPE=“hidden” NAME=“date” VALUE=”$date">";
echo “<INPUT TYPE=“hidden” NAME=“story” VALUE=”$story">";
echo"<td class=“text” width=“100”> “;
echo”<td width=“225”><input class=“button” type=“submit” name=“submit” value=“Update”>";
echo"
echo"";
echo"";
}
elseif ($action == “update3”) {
$headlinetitle = $_REQUEST[‘headlinetitle’];
$postedby = $_REQUEST[‘postedby’];
$date = $_REQUEST[‘date’];
$story = $_REQUEST[‘story’];
$SQL = "UPDATE " . $db_table . " SET headlinetitle='$headlinetitle',postedby='$postedby',date='$date',story='$story' WHERE id=$recid";
$result = @mysql_query($SQL) or die("could not complete your query");
echo "Headline updated.";
}
elseif ($action == "delete") {
$SQL = "SELECT * FROM " . $db_table . " ORDER BY headlinetitle";
$result = @mysql_query($SQL) or die("could not complete your query");
echo "<form method=\"post\" action=\"$pagename?action=delete2\">";
echo "<select class=\"textBox\" name=\"recid\" size=\"15\">";
while($row = @mysql_fetch_array($result)) {
$value = $row['id'];
$headlinetitle = $row['headlinetitle'];
echo "<option value=\"$value\">";
if ($headlinetitle != $headlinetitle) {
echo "$headlinetitle ($headlinetitle)";
} else {
echo "$headlinetitle";
}
echo "</option>";
}
echo "</select>
<input class=“button” type=“submit” value=“Delete”>";
}
elseif ($action == “delete2”) {
$SQL = “DELETE FROM " . $db_table . " WHERE id=$recid”;
$result = @mysql_query($SQL) or die(“could not complete your query”);
echo “Headline Deleted!”;
}
else {
echo “Please select a choice.”;
}
?>
</td>
</tr>
[/php]