First off, let me state that as of two days ago I had never touched SQL -or- PHP and at this point all I\'ve managed to do is create my database, populate it with a small amount of data so I can work on it, and I\'ve learned how to query it via a little php page. Most of my work has been with phpMyAdmin although I did create my initial table via command line.
That said, what I\'m working on now is trying to create a form I can hit from the web to insert data into my db.
Currently I’ve got my insert.html form, and my insert.php files separated – I believe I can make it a single file if I’m not mistaken, but for now it seems easier for me to keep them split.
As it stands right now, when I try to submit my form the javascript kicks me back and tells me I haven’t entered all the required values – It’s supposed to do this if the user leaves out a field, but since I’m completing my form then I assume it’s dying because the values aren’t being passed as variables to the php script.
The purpose of this small db/form is simply to track a list of employees, a date, and if they submitted their report (or why they didn\'t) on that date.
-- paste of insert.html --
<html>
<head>
<title>insert form</title>
</head>
<body>
<form method="POST" action="./insert.php" name="form">
Advisor\'s Name<BR><input name="adv_name" type="text" id="adv_name" size="50"><BR>
Record Date<BR><input name="rec_date" type="text" id="rec_date" size="10"><BR>
Record Status<select name="rec_status" id="rec_status">
<option selected>Yes</option>
<option value="No">No</option>
<option value="Off Work">Off Work</option>
<option value="Out Sick">Out Sick</option>
<option value="Exempt">Exempt</option>
</select>
<BR>
<input type="submit" name="Submit" value="Submit">
</form>
</body>
</html>
-- paste of insert.php --
[php:1:d09189e900]<?php
// Check if the variables exist (if the form fields have been filled in)
if (!$adv_name && !$rec_date && !$rec_status) {
echo \"You failed to complete all required fields.\";
echo \"Click <A HREF=\"javascript:history.go(-1);\">« here</A> to try again\";
}
else
{
// Connect to the sql database
$link = mysql_connect(\"localhost\", \"viewer\");
$db = mysql_select_db(\"aiu\", $link);
// The \'insert\' that will insert the data as a new row into your table
$query = \"INSERT INTO adls_records (adv_name, rec_date, rec_status) VALUES (\'$_POST[adv_name]\', \'$_POST[rec_date]\', \'$_POST[rec_status]\')\";
$result = mysql_query($query, $link);
// Echo this message to allow the user to access a new form
echo \"Click <A HREF=\"./insert.html\">here</A> to add another record.\";
}
?>[/php:1:d09189e900]
In the PHP script above, & is correctly entered as &
I finally got to the point where I\'ll admit I\'m stuck and ask for help, and this seems to be the place for it. Anyone have some advice?