Page 1 of 1

help I'm desperate!!

Posted: Wed Nov 19, 2003 6:21 pm
by lisawebs
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>

Posted: Wed Nov 19, 2003 6:24 pm
by microthick
This is probably your error:

viewtopic.php?t=511

Posted: Wed Nov 19, 2003 6:51 pm
by infolock
try using this instead of what you have lisa :

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();
} 
?>
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.

not sure about the sintax you wrote...

Posted: Wed Nov 19, 2003 7:24 pm
by lisawebs
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 ???

Posted: Wed Nov 19, 2003 7:48 pm
by infolock
$sql = "UPDATE Jokes SET JokeDate=CURDATE()JokeText='".$joketext."'";

should be this instead :

$sql = "UPDATE Jokes SET JokeDate=CURDATE(), JokeText='".$joketext."'";

forgot the comma there

Why ???

Posted: Wed Nov 19, 2003 10:20 pm
by lisawebs
why we need double quotes and points, I didn't see that in manuals

Posted: Wed Nov 19, 2003 10:29 pm
by infolock
why we need double quotes and points, I didn't see that in manuals
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.

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.