Hello....I need some help :)
Posted: Mon Oct 13, 2003 6:25 am
Hi all
I wrote some php code (I am a beginner at this) and part of it won't work. Access to DB works well, create, update, view of records works but what doesn't work is when I cklick the link where it should pass a variable to itself...and reload itself and to the other thing with the var set. It won't work....do I have to set something on my web server (apache) so it works?
echo("<p><a href='$PHP_SELF?addjoke=1'>Add joke</a></p>");
that is the code that acctually won't work but I send the complete code, maybe the error is somewhere else..
Thanks for the help, the code is below.
d.
I wrote some php code (I am a beginner at this) and part of it won't work. Access to DB works well, create, update, view of records works but what doesn't work is when I cklick the link where it should pass a variable to itself...and reload itself and to the other thing with the var set. It won't work....do I have to set something on my web server (apache) so it works?
echo("<p><a href='$PHP_SELF?addjoke=1'>Add joke</a></p>");
that is the code that acctually won't work but I send the complete code, maybe the error is somewhere else..
Thanks for the help, the code is below.
d.
Code: Select all
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>PHP testing page</title>
</head>
<body>
<?php
//if the user wants to add a joke
if (isset($addjoke))
{
?>
<form action="<?php echo($PHP_SELF); ?>" METHOD=POST>
<p>Upisi vic ovdje:<br>
<textarea name="joketext" ROWS=10 COLS=40 WRAP></textarea><br>
<input type=submit name="submitjoke" VALUE="SUBMIT">
</p>
</form>
<?php
}
else
{
//Connect to DB server
$dbcnx = @mysql_connect("localhost");
if (!$dbcnx)
{
echo("<p> Unable to connect to DB server! </p>");
exit();
}
else
{
// echo("<p> Connection established! </p>");
}
if(! @mysql_select_db("jokes",$dbcnx))
{
echo("<p> Couln't find the database!</p>");
exit();
}
else
{
// echo("<p> Database found! </p>");
}
//If a joke has been submited add it to DB
if ("SUBMIT" == $submitjoke)
{
$sql = "insert into jokes set JokeText = '$joketext', JokeDate = CURDATE()";
$result = mysql_query($sql);
if($result)
{
// echo("<p> Query sucessfull! </p>");
}
else
{
echo("<p> Query failed! </p>");
echo("<p> error: " . mysql_error() . " </p>");
}
}
echo("<p> Jokes in DB </p>");
$result = mysql_query("select JokeText from Jokes");
if($result)
{
// echo("<p> Query sucessfull! </p>");
while($row = mysql_fetch_array($result))
{
echo("<p> " . $row["JokeText"] . " </p>");
}
}
else
{
echo("<p> Query failed! </p>");
echo("<p> error: " . mysql_error() . " </p>");
}
//When clicked this link will load this page with the joke subbmission form displayed
if(!empty($addjoke))
{
echo("<p>addjoke set</p>");
}
else
{
echo("<p>addjoke NOT set</p>");
}
echo("<p><a href='$PHP_SELF?addjoke=1'>Add joke</a></p>");
}
?>
</body>
</html>