Forum Moderators: coopster

Message Too Old, No Replies

PHP4, mySQL interface structure suggestions?

How should I separate php pages to best suit what I'm doing?

         

thegnu

7:54 pm on Oct 4, 2004 (gmt 0)

10+ Year Member



I'm trying to get a PHP/MySQL database interface for a client. He owns rental spaces: some houses, some apartment buildings. I have no experience with PHP.

What he wants this database to do is keep track of payment amount, payment due dates, payment collection, contact info.

My current plan for the database side is have one the following tables:

Locations:
ID*, Name, Address, ManagerName, etc

Rental:
ID*, Room #, tenants.period (monthly or weekly), tenants.cost, location.ID, etc.

Tenants:
rental.ID, First, Last, Phone, period, cost, etc

ID* is the unique ID. The idea I have is to have the tenants table be separate from the Rental table so you don't ever have to modify the rental table. Does my layout appear to be sound? Does MySQL work this way? What am I overlooking?

OK. The actual question about PHP:

If I want to add a location using forms, do I need to have an addlocation.php that has a form action leading to locationadded.php? Do I have to do that for each table, or is there a better way?

My current php structure is like so:
<form action="locationadded.php" method="post">
Name: <input type="text" name="name"><br>
Street Address: <input type="text" name="address"><br>
City: <input type="text" name="city"><br>
State: <input type="text" name="state"><br>
ZIP: <input type="text" name="zip"><br>
Manager: <input type="text" name="manager"><br>
Phone: <input type="text" name="phone"><br>
<input type="Submit">
</form>

This will run locationadded.php, which would insert the values into the database. This seems really rudimentary.

theriddla1019

8:02 pm on Oct 4, 2004 (gmt 0)

10+ Year Member



Its all a matter of opinion of the coder, I myself have the actual "add" form or "edit" form then an update form that either inserts or adds to the db. But you can do this all on one page testing the value of a variable when you refresh the page back to itself. I think it is easier to separate them so your pages dont get to big though. Your theory looks good and seems sound. Good Luck :)

eggy ricardo

8:05 pm on Oct 4, 2004 (gmt 0)

10+ Year Member



Hiya,

Firstly i suppose it depends what you mean by "I have no experience with PHP." If that means you can't actually code PHP then I think you may struggle. If you can, and like me you class say a few DB driven sites as still fairly inexperienced you may be ok. If you don't know PHP and/or MySQL I would recommend you read PHP and MySQL For Dynamic Websites by Larry Ullman as I think that should soon set you on your way.

As for inserting into the database, you could do it one of two ways. You could have addlocation.php displaying the form and then POST the values to locationadded.php and let this handle the form and enter the data into the DB. Alternatively you could use addlocation.php to display the form, and then POST the values to itself, and use an if(isset ($_POST['submit'])) to check whether the form is submitted, and thus whether to handle it and insert into the DB or whether to display the form.

[edit] What theriddla1019 was saying was the former of those two methods. I personally use the latter on most occasions but that is just personal preference as he/she said.

Hope this helps
Cheers
Richard

thegnu

8:15 pm on Oct 4, 2004 (gmt 0)

10+ Year Member



OK, thanks. I have very little experience with PHP, only fooling around with very simple scripts. I've got access to the PHP/MySQL O'Reilly book and I'll probably just stuff my head with that.

I was posting this to make sure that there weren't any glaring flaws in my reasoning that a book wouldn't catch.

Thanks,
Nathan