help I'm desperate!!

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
lisawebs
Forum Commoner
Posts: 44
Joined: Wed Nov 19, 2003 6:21 pm

help I'm desperate!!

Post 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>
microthick
Forum Regular
Posts: 543
Joined: Wed Sep 24, 2003 2:15 pm
Location: Vancouver, BC

Post by microthick »

This is probably your error:

viewtopic.php?t=511
User avatar
infolock
DevNet Resident
Posts: 1708
Joined: Wed Sep 25, 2002 7:47 pm

Post 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.
lisawebs
Forum Commoner
Posts: 44
Joined: Wed Nov 19, 2003 6:21 pm

not sure about the sintax you wrote...

Post 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 ???
User avatar
infolock
DevNet Resident
Posts: 1708
Joined: Wed Sep 25, 2002 7:47 pm

Post 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
lisawebs
Forum Commoner
Posts: 44
Joined: Wed Nov 19, 2003 6:21 pm

Why ???

Post by lisawebs »

why we need double quotes and points, I didn't see that in manuals
User avatar
infolock
DevNet Resident
Posts: 1708
Joined: Wed Sep 25, 2002 7:47 pm

Post 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.
Post Reply