Hi there people.
Just started with PHP not long ago and have been doing examples etc.. However I have some strange problems that I can't figure out. I have Apache 2 install which works fine, mySQL 4.0.12 and PHP4 installed on xp pro. For some reason when I try examples on the web they display which is fine but when interacting with the database gives me strange results. here is a small example I am trying to run.
<html>
<head>
<title>Putting Data in the Database</title>
</head>
<body bgcolor="#FFFFFF">
<?php
if(isset($submit)):
$db = mysql_connect("localhost", "root");
mysql_select_db("needATOOL", $db);
$date = date("Y-m-d");
$sql = "INSERT INTO news
VALUES(NULL,'$heading','$body',
'$date','$auth','$auth_email')";
mysql_query($sql);
print("<h2>The Data Has Been Entered</h2>\n");
print("<b>You can add another news story below</b>\n");
endif;
?>
<p><h3>Enter your news item into the database</h3>
<form action="data_in.php" method="post">
Name:<br><input type="text" name="auth"><p>
Email:<br> <input type="text" name="auth_email"><p>
Heading:<br><input type="text" name="heading"><p>
News:<br><textarea cols=40 rows=20 name="body"></textarea><p>
<input type="submit" name="submit" value="Submit News!">
</form>
</body>
</html>
The page loads up fine but when I press the submit button the form just resets and does nothing. The funny thing is when I replace if(isset($submit)): with if(!isset($submit)): it then adds data such as the date and Id which is auto incremented in mysql. I don't understand why the not (!) is allowing the data to be inserted and when it is not being using it doesn't do jack. Running other examples from the web ie web monkey examples I get similar results. I can get data out and in but not in the way I want it?
Seems like things aren't getting interpreted or PHP functions aren't working or recognised??
Anyway help would be greatly appreciated !!
cheers Dennis