i was sent this code to insert into jokeadd.php but it doesnot work or i cant do it please can you help to insert or check it? my prurpose is to add more than one joke once....
here is the code which should be inserted***
try this... insert into JOKES(farm_humor,city_humor,adult_humor) values('$farm_joke','$city_joke','$adult_joke')
there are 2 ways to do this. The way I'd choose is to add more joketext textareas and name them all joketext[]...
<textarea name="joketext[]" rows="10" cols="40" wrap></textarea>
Then loop thru the array $joketext in your PHP, performing an insert for each textarea to have a joke in it. Make sure to look for blank textareas.
<? if($joketext[0]!=""){
if ($joketext[$g]!=""){print $joketext[$g]."<br>";}
print $joketext[$g]."<br>";
}
}else{?>
<form action="<? echo $PHP_SELF;?>">
<textarea name="joketext[]" rows="10" cols="40" wrap></textarea><br>
<textarea name="joketext[]" rows="10" cols="40" wrap></textarea><br>
<textarea name="joketext[]" rows="10" cols="40" wrap></textarea><br>
<textarea name="joketext[]" rows="10" cols="40" wrap></textarea><br>
<input type=submit>
</form>
<?}?>
Then, instead of where print them out, sql there...
for ($g=0;$g<count($joketext);$g++){
$jokedate=CURDATE();
if ($joketext[$g]!=""){
$sql = "INSERT INTO Jokes(JokeText,JokeDate) values('$joketext[$g]','$jokedate')";
mysql_query($sql);
}
}
***** and that is the jokeadd.php which needs some adjustments,
<head>
<title> The Internet Joke Database </title>
</head>
<body>
<?php
if (isset($addjoke)): // If the user wants to add a joke
?>
<form action="<?=$PHP_SELF?>" method="post">
<p>Type your joke here:<br />
<textarea name="joketext" rows="10" cols="40" wrap></textarea><br />
<input type="submit" name="submitjoke" value="SUBMIT" /></p>
</form>
<?php
else: // Default page display
// Connect to the database server
$dbcnx = @mysql_connect("localhost", "root", "mypaswrd");
if (!$dbcnx) {
echo( "<p>Unable to connect to the " .
"database server at this time.</p>" );
exit();
}
// Select the jokes database
if (! @mysql_select_db("jokes") ) {
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 ($submitjoke == "SUBMIT") {
$sql = "INSERT INTO Jokes SET
JokeText='$joketext',
JokeDate=CURDATE()";
if (@($sql)) {
echo("<p>Your joke has been added.</p>");
} else {
echo("<p>Error adding submitted joke: " .
mysql_error() . "</p>");
}
}
echo("<p> Here are all the jokes in our database: </p>");
// Request the text of all the jokes
$result = @("SELECT JokeText FROM Jokes");
if (!$result) {
echo("<p>Error performing query: " . mysql_error() . "</p>");
exit();
}
// Display the text of each joke in a paragraph
while ( $row = mysql_fetch_array($result) ) {
echo("<p>" . $row["JokeText"] . "</p>");
}
// When clicked, this link will load this page
// with the joke submission form displayed.
echo("<p><a href='$PHP_SELF?addjoke=1'>Add a Joke!</a></p>");
endif;
?>
</body>