I'll start off with the easier of the two questions:
1) I am not sure that I am really understanding how a form works in conjunction with PHP. Currently I have some PHP scripting that will enter information into a database. The script does work, it will enter information via the website into the database table. Where I am not comfortable is how this is happening exactly. I have a form where I have defined an action, which I am not sure what that is exactly, but am guessing that the action is where you define what happens on submission. Then when the user clicks the button submit or presses enter it executes some PHP that makes the addition... really, I am just not sure how this code is working which makes me a poor programmer... here is the code:
echo "<p><b>Please submit a task</b><br>";
if ($submit)
{
$connection = mysql_connect($host, $user, $password) or die("Error! Could not connect to database!!\n"
;
$db = mysql_select_db($database, $connection) or die("Error! Could not select table!!\n"
;
$taskStat = "1";
$query = "INSERT INTO taskTable (task_Name, task_Status, task_Detail, task_Date) VALUES ('$taskName','$taskStat','$taskDetail', '$taskDate')";
$result = mysql_query($query) or die("Error! Could not submit data to table!!\n"
;
?>
<form method="post" action="<?php echo $PHP_SELF?>">
Task Name:<input type="text" size="25" name="taskName"><br>
Task Detail:<input type="text" size="75" name="taskDetail"><br>
<br><input type="Submit" name="submit" value="Submit Task">
</form>
<?php
}
else
{
?>
<form method="post" action="<?php echo $PHP_SELF?>">
Task Name:<input type="text" size="25" name="taskName"><br>
Task Detail:<input type="text" size="75" name="taskDetail"><br>
<br><input type="Submit" name="submit" value="Submit Task">
</form>
<?php
}
?>
that is the whole page minus the actual database connection stuff.
So really, my question is how exactly does that code work, the environment seems odd because I am not sure where and when the code executes, as far as how does the flow control work or whatever... meaning if I were using some other language like C, if I ask for input, the program waits for input, this environment is not the same however.
2) I would like to add logins to a site, I am assuming I can do this by having user names and passwords in the database and then have a page that takes the username and password and checks them against the database, then will forward you along to the pages on that site, however there would be some type of code in each page possibly included using includes or the header() function in PHP that makes sure you are an authenticated user somehow, maybe even using cookies... not sure... anyway, this might be too tough a question to be answered.
--Bryan
1) I am not sure that I am really understanding how a form works in conjunction with PHP. Currently I have some PHP scripting that will enter information into a database. The script does work, it will enter information via the website into the database table. Where I am not comfortable is how this is happening exactly. I have a form where I have defined an action, which I am not sure what that is exactly, but am guessing that the action is where you define what happens on submission. Then when the user clicks the button submit or presses enter it executes some PHP that makes the addition... really, I am just not sure how this code is working which makes me a poor programmer... here is the code:
echo "<p><b>Please submit a task</b><br>";
if ($submit)
{
$connection = mysql_connect($host, $user, $password) or die("Error! Could not connect to database!!\n"
$db = mysql_select_db($database, $connection) or die("Error! Could not select table!!\n"
$taskStat = "1";
$query = "INSERT INTO taskTable (task_Name, task_Status, task_Detail, task_Date) VALUES ('$taskName','$taskStat','$taskDetail', '$taskDate')";
$result = mysql_query($query) or die("Error! Could not submit data to table!!\n"
?>
<form method="post" action="<?php echo $PHP_SELF?>">
Task Name:<input type="text" size="25" name="taskName"><br>
Task Detail:<input type="text" size="75" name="taskDetail"><br>
<br><input type="Submit" name="submit" value="Submit Task">
</form>
<?php
}
else
{
?>
<form method="post" action="<?php echo $PHP_SELF?>">
Task Name:<input type="text" size="25" name="taskName"><br>
Task Detail:<input type="text" size="75" name="taskDetail"><br>
<br><input type="Submit" name="submit" value="Submit Task">
</form>
<?php
}
?>
that is the whole page minus the actual database connection stuff.
So really, my question is how exactly does that code work, the environment seems odd because I am not sure where and when the code executes, as far as how does the flow control work or whatever... meaning if I were using some other language like C, if I ask for input, the program waits for input, this environment is not the same however.
2) I would like to add logins to a site, I am assuming I can do this by having user names and passwords in the database and then have a page that takes the username and password and checks them against the database, then will forward you along to the pages on that site, however there would be some type of code in each page possibly included using includes or the header() function in PHP that makes sure you are an authenticated user somehow, maybe even using cookies... not sure... anyway, this might be too tough a question to be answered.
--Bryan