Forum Moderators: coopster
<body>
<?php if (isset($_REQUEST['addjoke'])): // If the user wants to add a joke?>
<form action="<?=$_SERVER['PHP_SELF']?>" method="post">
<p>Überschrift:<br>
<textarea name="eventheader" rows="1" cols="40" wrap></textarea><br>
<p>Beschreibung:<br>
<textarea name="joketext" rows="10" cols="40" wrap></textarea><br>
<p>BildLink:<br>
<textarea name="bildlink" rows="10" cols="40" wrap></textarea><br>
<input type="submit" name="submitjoke" value="SUBMIT"></p>
</form>
<?php else:
// Connect to the database server
$dbcnx = @mysql_connect($mysqlhost, $mysqlusr, $mysqlpass);
if (!$dbcnx) {
echo("<p>Unable to connect to the database server at this time.</p>");
exit();
}
// Select the jokes database
if (! @mysql_select_db("andy")) {
echo("<p>Unable to locate the joke database at this time.</p>");
exit();
}
// If a joke has been submitted, add it to the database.
if (isset($_POST['joketext'])) {
$sql = "INSERT INTO Jokes SET BildLink='$_POST[bildlink]', EventHeader='$_POST[eventheader]', JokeText='$_POST[joketext]', JokeDate=CURDATE()";
if (@mysql_query($sql)) {
echo("-------Termin added-------</br>");
} else {
echo("<P>Error adding submitted Termin: " . mysql_error() . "</P>");
}
}
// UPDATE PROBLEM!
if (isset($_REQUEST['bearbeitenjoke'])) {
$sql = "UPDATE Jokes SET JokeText='$_POST[joketext]' WHERE ID=$_REQUEST[bearbeitenjoke].";
if (@mysql_query($sql)) {
echo("<p>Der Termin wurde bearbeitet</p>");
} else {
echo("<p>Error bearbeiten joke: " . mysql_error() . "</p>");
}
}
// If a joke has been deleted, remove it from the database.
if (isset($_REQUEST['deletejoke'])) {
$sql = "DELETE FROM Jokes WHERE ID=$_REQUEST[deletejoke]";
if (@mysql_query($sql)) {
echo("<p>Der Termin wurde gelöscht</p>");
} else {
echo("<p>Error deleting joke: " . mysql_error() . "</p>");
}
}
echo("<h1>Unsere Termine:</h1>");
// Request die ID, Header und Text von allen Terminen
$sql = "SELECT ID, BildLink, EventHeader, JokeText FROM Jokes";
if (isset($_POST['searchtext'])) {
$sql .= " WHERE JokeText LIKE '%".$_POST['searchtext']."%' OR EventHeader LIKE '%".$_POST['searchtext']."%'";
}
$result = @mysql_query($sql);
if (!$result) {
echo("<p>Error performing query: " . mysql_error() . "</p>");
exit();
}
// Display the text of each joke in a paragraph with a "Delete this Joke" link next to each.
while ($row = mysql_fetch_array($result)) {
$jokeid = $row["ID"];
$bildlink = $row["BildLink"];
$eventheader = $row["EventHeader"];
$joketext = $row["JokeText"];
echo("<table width='50%'><th colspan='1'>$eventheader</th>" .
"<tr><td width='150px'><img src='$bildlink'></td>
<td><textarea name='joketext' rows='10' cols='40'>$joketext</textarea><br></td>" .
"<td width='10%'><a href='$_SERVER[PHP_SELF]?bearbeitenjoke=$jokeid'>" . "Bearbeiten</a></td>" .
"<td width='10%'><a href='$_SERVER[PHP_SELF]?deletejoke=$jokeid'>" . "Delete</a></td></tr></table>");
}
// When clicked, this link will load this page with the joke submission form displayed.
echo("</blockquote><a href='$_SERVER[PHP_SELF]?addjoke=1'>Termin hinzufügen</a>");
endif;?>
</br></br>
<table>
<th>Suchen:</th>
<tr><td>
<FORM action="<?=$_SERVER['PHP_SELF']?>" method="post">
<P>Zeige Termine die den folgenden Text enthalten:<BR>
<INPUT TYPE=TEXT NAME="searchtext" VALUE="<?php if (isset($_POST['searchtext'])) echo($_POST['searchtext']);?>">
<INPUT TYPE=SUBMIT NAME="submit" VALUE="Go">
</P>
</FORM>
</td></tr>
</table>
</body>
</html>
//Sorry for that but I am German
//I would also appreciate if someone could send me something similiar like this script!
//So and now: Show me your skillz!
[edited by: jatar_k at 8:49 pm (utc) on Aug. 12, 2004]
[edit reason] removed url [/edit]
A couple things that I see...
First off this line
$sql = "UPDATE Jokes SET JokeText='$_POST[joketext]' WHERE ID=$_REQUEST[bearbeitenjoke].";
When you click on the Update link nothing will be in the $_POST variables.
So change this
<a href='$_SERVER[PHP_SELF]?bearbeitenjoke=$jokeid'>
to this
<a href='$_SERVER[PHP_SELF]?bearbeitenjoke=$jokeid&joketext=$joketext'>
Now the jokeid and the joketext will be in the $_GET variables. So your sql update statement should look like this.
$sql = "UPDATE Jokes SET JokeText='$_GET[joketext]' WHERE ID=$_GET[bearbeitenjoke].";
Hope that helps,
Tim
p.s. There's a good thread here [webmasterworld.com] on troubleshooting PHP/MySQL.