Script not generating my html code as expected
Posted: Fri Feb 08, 2008 3:23 pm
Hi Everyone,
I've tried writing a script but having trouble getting it to work. I want a user to be able to fill in some text fields and from these fields add an entry in mysql database. The first time I call the script I expect the $POST[addverb] to be blank and therefore it should jump to the code where it generates my html form where a user can enter some data. This isn't happening though. When I call it I just get a blank page. Any ideas why that might be? I've pasted the script below.
Thanks,
Tim.
I've tried writing a script but having trouble getting it to work. I want a user to be able to fill in some text fields and from these fields add an entry in mysql database. The first time I call the script I expect the $POST[addverb] to be blank and therefore it should jump to the code where it generates my html form where a user can enter some data. This isn't happening though. When I call it I just get a blank page. Any ideas why that might be? I've pasted the script below.
Thanks,
Tim.
Code: Select all
<?php
if ($_POST[addverb] != "add")
{
// haven't seen the form so show it
$displayBlock = "
<h1>Add an entry</h1>
<form method=\"post\" action\"$_SERVER[PHP_SELF]\"
<p><strong>Verb ID</strong><br></p>
<input type=\"text\" name=\"verb_id\" size=2>
<p><strong>Tense ID</strong><br>
<input type=\"text\" name=\"tense_id\" size=2></p>
<p><strong>1st pers sing</strong><br>
<input type=\"text\" name=\"f_sng\" size=30 maxlength=255></p>
<p><strong>2nd pers sing</strong><br>
<input type=\"text\" name=\"s_sng\" size=30 maxlength=255></p>
<p><strong>3rd pers sing</strong><br>
<input type=\"text\" name=\"t_sng\" size=30 maxlength=255></p>
<p><strong>1st pers plr</strong><br>
<input type=\"text\" name=\"f_plr\" size=30 maxlength=255></p>
<p><strong>2nd pers plr</strong><br>
<input type=\"text\" name=\"s_plr\" size=30 maxlength=255></p>
<p><strong>3rd pers plr</strong><br>
<input type=\"text\" name=\"t_plr\" size=30 maxlength=255></p>
<input type=\"hidden\" name=\"addverb\" value=\"add\">
<p><input type=\"submit\" name=\"submit\" value=\"Add Entry\"></p>
</form>";
}
else if ($_POST[addverb] == "add")
{
// time to add to tables, so check for required fields
if (($_POST[verb_id] == " ") || ($_POST(tense_id)))
{
header("1st pers sing and tense: addentry.php");
exit;
}
// connect to database
$connection = mysql_connect("localhost", "guest","guest") or die(mysql_error());
mysql_select_db("greekverbs", $connection) or die(mysql_error());
if (($_POST[verb_id]) || ($_POST[tense_id]) || ($_POST[f_sng]) || ($_POST[s_sng]) || ($_POST[t_sng]) || ($_POST[f_plr]) || ($_POST[s_plr]) || ($_POST[t_plr]))
{
$add_verb = "insert into conjugats values ('', '$_POST[verb_id]', '$_POST[tense_id]','$_POST[f_sng]', '$_POST[s_sng])'$_POST[t_sng]', $_POST[f_plr]', $_POST[s_plr]','$_POST[t_plr]')";
mysql_query($add_verb) or die(mysql());
}
$displayBlock = "<h1>Entry added</h1>
<p>Your entry has been added. Would you like to <a href=\"addentry.php\">add another</a>?</p>";
}
?>
<html>
<head>
<title>Add an Entry</title>
</head>
<body>
<?php echo $display_block;?>
</body>
</html>