Jump to content

PHP Help


Lil Smurth

Recommended Posts

I know its my first post and most forums don't like the first post to be about help, but I'm in dire need. I'm a complete novice when it comes to php and mySql. I'm currently taking a summer class and I'm just not understanding the language. I've only had one class so far and my professor gives us the following assignment.  If you all could help in any way, please post. Here is my assignment:

 

1. (10 pts) Create a file called index.html inside your php-lab folder; that file should include your name, and links to all other files mentioned below (all files must be inside your php-lab folder)

 

 

2. (15 pts) display_all.php which displays all rows in your student table, inside an html table.

 

 

3. (25 pts) add_student.html, which has a form with 3 fields, one for id, one for age and one for name, and sends data to add_student.php, and add_student.php, which adds the corresponding row to the student table.

 

 

4. (25 pts) change_student.html which has a form with three fields, id, name and age, and sends data to change_student.php, which changes the name and age for the student with that id (if any).

 

 

5. (25 pts) delete_student.html which has a form with one fiel, id, and sends data to delete_student.php, which deletes the student with that id (if any).

 

 

I was able to do 2. and the first part of 3, 4, and 5.

 

I understand if you can't flat out help me, but any help is appreciated.

Link to comment
https://forums.phpfreaks.com/topic/160529-php-help/
Share on other sites

Here is my add_student.html:

 

<HTML>

<HEAD>

  <TITLE> Student form </TITLE>

</HEAD>

 

<BODY>

<FORM action="add_student.php">

  Id:  <input type="text" name="id"><P>

  Age:  <input type="text" name="age"><P>

  Name: <input type="text" name="name"><P>

  <input type="submit">

</FORM>

</BODY>

</HTML>

 

 

and here is my add_student.php so far:

 

<html>

<head>

    <title> forms </title>

</head>

<body>

 

<?php

include("connect.php");

$id=$_GET["id"];

$age=$_GET["age"];

$name=$_GET["name"];

 

 

?>

 

</BODY>

</HTML>

 

</html>

Link to comment
https://forums.phpfreaks.com/topic/160529-php-help/#findComment-847206
Share on other sites

Okay so I assume you know some SQL if you can query the DB for information on the student table. To add a row to a table, use SQL INSERT.

 

Example:

INSERT INTO tablename (col1, col2 [, coln...]) VALUES ('data1', 'data2' [, 'datan' ...]);

 

http://www.w3schools.com/PHP/php_mysql_insert.asp

 

So that link gives you something to look at how to use PHP to insert. Basically change tablename to the table name you're using, the col1, col2, etc are the names of columns you want to insert into and data1, data2, etc are the values for each corresponding column. Of course you don't have to have 2 or more columns. If you only want to insert into one column, just list one column and one value.

 

For number 4, use SQL UPDATE.

 

Example:

UPDATE tablename SET col1 = 'data1', col2 = 'data2' [, coln = 'datan' ...] WHERE id = '1';

 

http://www.w3schools.com/PHP/php_mysql_update.asp

 

So that updates tablename setting col1 to data1, col2 to data2 etc.. Again if you only need to update one column, just use one and forget about col2 etc. The last part is sem-important. The WHERE id = '1' is a condition that you need. If you don't specify it, the UPDATE SQL will update ALL the rows in the table with the data. That's not what you want. Since each student would have a unique ID (or in your case I hope so), specify WHERE id = 'student_number_here' so it only updates that one student.

 

Lastly, use SQL DELETE to delete a row.

 

Example:

DELETE FROM tablename WHERE id='1';

 

http://www.w3schools.com/PHP/php_mysql_delete.asp

 

Like with update, the WHERE clause is important. If you don't specify it, it will delete all rows in your table!

 

Hope this helps. Please mess around with it and come back if you need more help.

Link to comment
https://forums.phpfreaks.com/topic/160529-php-help/#findComment-847217
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.