Hello all. I have recently been studying PHP and MySQL. For quite some time I have been working on the code I am about to post below. I am essentialy creating a simple little form for my MUD staff members to submit a few details on what areas they are creating ect. What happens is that the form is shown, yet when you submit the details, it doesnt actualy seem to post them. Perhaps I have messed up the logic somewhat. I am more than a little confused and the more time I seem to spend with this the more I seem to get nowhere 🙁
Any help would be greatly appreciated.
<?php
if ($_POST[op] != "done") {
$display_block = "
<form method=\"post\" action=\"$_SERVER[PHP_SELF]\">
<table>
<tr>
<td>Area Name</td>
<td><input type=text name=aname size=20></td>
<tr>
<td>Author</td>
<td><input type=text name=auth size=20></td>
<tr>
<td>Area Filename</td>
<td><input type=text name=fname size=20></td>
<tr>
<td>Area Class</td>
<td><input type=text name=aclass size=20></td>
<tr>
<td>Area Alignment</td>
<td><input type=radio name=align value=evil>Evil
<input type=radio name=align value=neut>Neutral
<input type=radio name=align value=good>Good</td>
<tr>
<td>Area Description <br>Make sure you put all relevant area specific details in!</td>
<td><input type=text name=adesc size=20></td>
</table>
<BR>
<input type=\"hidden\" name=\"op\" value\"done\">
<p><input type=\"submit\" name=\"submit\" value=\"Submit Area\"></p>
</form>";
} else if ($_POST[op] == "done") {
echo "<br> Test 1<br>";
// a check for blank fields
if (($_POST[aname] == "") || ($_POST[auth] == "") || ($_POST[fname] == "") || ($_POST[aclass] == "") || ($_POST[align] == "") || ($_POST[adesc] == "")) {
$display_block = "<p> You need to fill all the details in.</p>";
echo "<br> Test 2<br>";
}
mysql_connect("host", "user", "pass") or die(mysql_error());
mysql_select_db("builders") or die(mysql_error());
echo "<br> Test 3 <br>";
$sql = "SELECT Area_Name FROM areas where Area_Name = '$_POST[aname]'";
$result = mysql_query($sql) or die(mysql_error());
$numrows = mysql_num_rows($result);
if ($numrows >= 1) {
$display_block = "<p>That area exists already. Use the modify form to alter its details or select a new area name</p>";
}
else if ($numrows < 1) {
$sql = "insert into areas values('$_POST[aname]', '$_POST[auth]', '$_POST[fname]', '$_POST[aclass]', '$_POST[align]', '$_POST[adesc]')";
mysql_query($sql) or die(mysql_error());
$display_block = "<p>Thankyou for your area submission.</p>";
}
}
?>
<html>
<head><title>IahMUD Area submission form.</title></head>
<body>
<h1> Area subission form.</h1><br>
<p> Please check all details to ensure they are correct.</p>
<hr>
<?php echo "$display_block"; ?>
</body>
</html>
Perhaps I tried to do something too complex for my 1st try. I took the liberty of altering the mysql_connect("host", "user", "pass") statment for obvious reasons. The MySQL side of this seems fine as I manualy set the post options in the code once and they went thru. I do think its something to do with my logic here but I just can't put my finger on it. What that code does right now is loops the form back and its blank after you "submit" the form. Nothing even hits the DB. Those echo lines are where I attempted to get some feedback on where its going wrong. But to no avail. It no longer makes any sence to me. sigh :queasy: