I'm trying to use basic PHP functions,
but can't even work with this simple tutorial,
why isn't working? , at the same time I'm running phpdevadmin
and work fine with the database, so apache, php and mysql
are running ok... what's wrong??
---------------------------------------------
<html><head><title>PHP_test</title>
</head>
<body>
<?php
$dbcnx = @mysql_connect("localhost");
if (!$dbcnx) {
echo( "<P>Unable to connect to the " .
"database server at this time.</P>" ); exit(); }
if (! @mysql_select_db("jokes") ) {
echo( "<P>Unable to locate the joke " .
"database at this time.</P>" ); exit(); }
?>
<FORM ACTION="<?php echo($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">
</FORM>
<?php
if ("SUBMIT" == $submitjoke) {
$sql = "UPDATE Jokes SET " .
"JokeDate=CURDATE()";
"JokeText='$joketext', " .
if (mysql_query($sql)) {
echo("<P>Your joke has been added.</P>");
} else {
echo("<P>Error adding submitted joke: " .
mysql_error() . "</P>"); }
}
?>
</body>
</html>
help I'm desperate!!
Moderator: General Moderators
-
microthick
- Forum Regular
- Posts: 543
- Joined: Wed Sep 24, 2003 2:15 pm
- Location: Vancouver, BC
try using this instead of what you have lisa :
also, as microthick suggested, read that post. it covers a lot of detailed info on passing vars. but mainly, you just had a few things wrong in your script.
Code: Select all
<html><head><title>PHP_test</title>
</head>
<body>
<?php
$dbcnx = @mysql_connect("localhost") or die('Unable to connect to the database server at this time');
@mysql_select_db("jokes") or die('Unable to locate the joke database at this time.' );
?>
<FORM ACTION="<?php echo($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">
</FORM>
<?php
if (!isset($_POST['joketext']))
{
echo 'You MUST enter a joke!';
}
$joketext = $_POST['joketext'];
$sql = "UPDATE Jokes SET JokeDate=CURDATE() JokeText='".$joketext."'";
$result = mysql_query($sql) or die('Error adding submitted joke due to '.MySQL_Error());
echo("<P>Your joke has been added.</P>");
mysql_close();
}
?>not sure about the sintax you wrote...
the following line, as I read it, gives a parse error:
$sql = "UPDATE Jokes SET JokeDate=CURDATE()JokeText='".$joketext."'";
_____________
What is this double comas and quotes ???
$sql = "UPDATE Jokes SET JokeDate=CURDATE()JokeText='".$joketext."'";
_____________
What is this double comas and quotes ???
actually, it's not a required way, but it's the way I do it, namely for being able to find out where I call my variable names in my function.why we need double quotes and points, I didn't see that in manuals
it does the exact same thing as calling it regularly, it just exits the string in which you are using, and then does an add statement for the viarble you want to insert. you don't have to follow that method, it's just how i learned to use it and kinda do it everytime i'm gonna use a variable and string in the same call.