/    Sign up×
Community /Pin to ProfileBookmark

Question about PHP and MYSQL

Hey everyone. I have a quick quesiton. (quick question, but long answer im afraid.

This is what I want to do. I want to use PHP and MYSQL in conjunction with an html form to keep a daily attendance record for my local Martial Arts studio.

I would like to use the form to mass select the students names and when the submit button is hit then the database is updated with the date and the students name.

Then I would like to have a feature on the site so that the student/school owner could go out and search for the students name and/or a paticular day.

Ok here is my question. For someone that does not know PHP or MYSQL how hard would this be? Would this be simple in php and mysql terms or a more robust project?

By looking at random code it looks like using php to update and query the code will be semi easy.

Thats my question and I hope you all can help point me in the correct direction.

to post a comment
PHP

3 Comments(s)

Copy linkTweet thisAlerts:
@TyeMJan 24.2008 — I don't think I have the time to give you a solution just the concept and some direction. There are a few ways you can do this, I will give one.

You could have a simple HTML form with names from the database filling a select element . The code would be something like.

[code=php]
<? //connect to database
$conn = mysql_connect("localhost", "mysql_user", "mysql_password") or die();
$db = mysql_select_db("databasename") or die();

$query = "Select * from students;";
$result = mysql_query($query);

?>

<select id="names" name="studentnames" multiple="multiple">

<? //PHP loop
while($data = mysql_fetch_assoc($result)){ ?>
<option value="<? echo $data["name"] ?>">$data["name"]</option>
<?
//$data["name"] is the field
}
?>

</select>
[/code]


Then when you post the form to the PHP page. It will process the form and perform an insert via a loop. The loop is needed because I think the names pass as an array to php name based on the name attribute "studentnames". So as you go through the array you will have to perform an "INSERT into attendance_table", that query will have to make use of the SQL DATE() to get the current date and insert it into its own field along side the student name.

Later when you want to retrieve the info. Use a query like

SELECT * from attendance_table WHERE date_field BETWEEN $date1 AND $date2. I think there is a to_date() SQL function, I can not remember. $date 1 and $date2 will have to come from another HTML form where the teacher selects the date fields to be searched between.

Simple application layout

database tables - students, attendance_table

HTML form - attendance input

PHP code to process attendance

HTML form - check attendance input

PHP code to process check
Copy linkTweet thisAlerts:
@__EricJan 25.2008 — Hey everyone. I have a quick quesiton. (quick question, but long answer im afraid.

This is what I want to do. I want to use PHP and MYSQL in conjunction with an html form to keep a daily attendance record for my local Martial Arts studio.

I would like to use the form to mass select the students names and when the submit button is hit then the database is updated with the date and the students name.

Then I would like to have a feature on the site so that the student/school owner could go out and search for the students name and/or a paticular day.

Ok here is my question. For someone that does not know PHP or MYSQL how hard would this be? Would this be simple in php and mysql terms or a more robust project?


By looking at random code it looks like using php to update and query the code will be semi easy.


Thats my question and I hope you all can help point me in the correct direction.[/QUOTE]


My first direction would be to advise you to take some time and learn the languages of the products you wish to use.

PHP and MYSQL are not terribly difficult to learn but if you don't know how to write secure scripts you are putting user data and the integrity of your site at risk.

For what it's worth, I've found that trying to use PHP/MYSQL without learning the basics can really turn you off to the language. The above example is a good solution but if you don't understand what it does then you're setting yourself up to fail in the future when something happens and you aren't quite sure how to update it or stay on top of security best practices.
Copy linkTweet thisAlerts:
@joopauthorJan 25.2008 — Thanks guys, that gives me exactly what I need. Yes that code makes total sense to me, I used to be a cobol programmer so I have a knack for programming, just not familiar with the coding of php and mysql.

This points me in a great direction. Once I get the code up and running I will post it for others that might need help.


Thanks again.
×

Success!

Help @joop spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 4.29,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...