Join 307,160 PHP Programmers for FREE! Get instant access to thousands of PHP experts, tutorials, code snippets, and more! There are 1,553 people online right now. Registration is fast and FREE... Join Now!
Dream.In.Code has a policy by which we prefer to see a good faith effort on your part before providing source code for homework assignments. Please post the code you have written in an effort to resolve the problem, and our members would be happy to provide some guidance. Be sure to include a description of any errors you are encountering as well.
<?php // Connects to your Database mysql_connect("localhost", "root", "") or die(mysql_error()); mysql_select_db("artista_salon") or die(mysql_error());
//checks cookies to make sure they are logged in if(isset($_COOKIE['ID_my_site'])) { $username = $_COOKIE['ID_my_site']; $pass = $_COOKIE['Key_my_site']; $check = mysql_query("SELECT * FROM salon WHERE username = '$username'")or die(mysql_error()); while($info = mysql_fetch_array( $check )) {
//if the cookie has the wrong password, they are taken to the login page if ($pass != $info['password']) { header("Location: about_us.php"); }
//otherwise they are shown the admin area else { ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <link rel="stylesheet" type="text/css" href="style.css" /> <title>Artista Salon - Angeles</title> <!--[if IE 6]> <link rel="stylesheet" type="text/css" href="iecss.css" /> <![endif]--> </head>
I haven't made my database table for that one, I'm confused on how I can connect other fields from other table to the table that is specified for the reservation.
e.g.
i've got a table for reservation, and another one is for the services.
the question is, how can i put the serviceid on the reservation table? i'm really confused with those things.
and also the admin page, i have made the adding and viewing for the services, but editing/updating and deleting is so difficult for me. i still have a lot of problems in my admin page, i still have to do the reservation, which is the main program, and for the users to be added and deleted..
oh well, i still have lots of things to do.. i'm really trying my best to do it, but i still need some help..
You should read up a little more on SQL to learn how to do more with your database. The SQL UPDATE statement is used to edit existing data in a database. The DELETE statement is for deleting records.
As far as putting data from one table to another, that is a database structure problem. You'll need to have a ServiceID field in the Reservation table to hold the ServiceID data from the Services table. In a database-driven application like a reservation system, you should make sure to add in all necessary fields to your table(s). With PHP, working between multiple tables is easy, as long as your tables are set up correctly. If you need more help on using MySQL with PHP, you should read W3School's PHP/MySQL Tutorials.
EDIT: On a side note, I don't think storing the administrator's password in your cookie is a good idea. It's a really bad idea actually, even if the password is hashed. I'd suggest looking into Session Handling in PHP for a more secure method of authenticating your administrator.
This post has been edited by Moonbat: 24 Feb, 2009 - 08:20 AM
@ Moonbat: I'm quite familiar with the update and delete, the problem is.. I'm not good at using conditions. Like, if I'm going to delete just one record inside this table that contains many records, how will I be able to do that? Or update it?
E.G.
id name 0001 bongbong modifydelete 0002 winwin modifydelete 0003 kimkim modifydelete 0004 dasgda modifydelete
there, how will i be able to modify/delete the each records ? I've only made my adding and viewing of records.
@ sl4ck3r: thanks. i'll keep that in mind. so if i'm going to put on a serviceid on my service table, will i still have to make another serviceid on my reservation table then?
You would use the WHERE clause in SQL to delete or update a row based on a condition (or multiple conditions).
If you already know how to make pages to add and view records, you should already know how to make a page to update and delete records. All you're really doing is using different SQL statements. The idea is the same.