Solved

Delete, Add or Edit Records

Posted on 2015-01-25
4
103 Views
Last Modified: 2015-01-26
I have a table that displays records.

http://www.mediascrubber.com/records.php

How can I make this page interactive to add, edit and delete records.
Thank you.
0
Comment
Question by:DS928
4 Comments
 
LVL 30

Accepted Solution

by:
Marco Gasi earned 250 total points
ID: 40570043
Well, start using php only (next you'll can add javascript and do all stuff via Ajax).
- Add a lat column and call it 'Actions
- Set its colspan to 3 (<th colspan="3">Actions</th>)
- Put here two links to two php scripts edit.php and delete.php adding them a querystring to identify the record:
while($row = $result->fetch_assoc()) {
				echo "<tr class='viewpost'>";
  			if(!empty($row['recordId'])) {
      			echo '<td>' . $row['recordId'] . '</td>';
    			}
					else
					{
      			echo '<td>NA</td>';
					}
                                  ....
                         echo "<td>
                                         <a href='edit.php?id=". $row['recordId'] ."'>Edit</a> 
                                         <a href='delete.php?id=". $row['recordId'] ."'>Delete</a> 
                                   </td>"
					echo "</tr>"; //closing row
				}
  			echo '</tbody>';
  			echo '</table>';

Open in new window

In the scripts you get the id of the record diplay a form to edit fields and/or execute the action, then redirect the user to the original script.
0
 
LVL 108

Assisted Solution

by:Ray Paseur
Ray Paseur earned 250 total points
ID: 40570313
The general design of what you want to do is called "table maintenance."  Some of the design principles are shown in this article.
http://www.experts-exchange.com/Web_Development/Web_Languages-Standards/PHP/A_12335-PHP-and-MySQLi-Table-Maintenance.html
0
 
LVL 6

Expert Comment

by:Leon Teale
ID: 40570686
if you are wanting jsut the base of the code then please see here
<?PHP

$user_name = "root";
$password = "";
$database = "addressbook";
$server = "127.0.0.1";

$db_handle = mysql_connect($server, $user_name, $password);
$db_found = mysql_select_db($database, $db_handle);

if ($db_found) {

$SQL = "INSERT INTO tb_address_book (First_Name, Surname, Address) VALUES ('bill', 'gates', 'Microsoft')";

$result = mysql_query($SQL);

mysql_close($db_handle);

print "Records added to the database";

}
else {

print "Database NOT Found ";
mysql_close($db_handle);

}

?>

Open in new window



else if you are wanting explanations then see the other comments. i just wasnt sure what sort of answer you needed.
0
 

Author Closing Comment

by:DS928
ID: 40570895
Thank you everyone.  I appreciate the help.
0

Featured Post

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Introduction Got endorsements from your clients?  Great!  There is almost nothing better than word-of-mouth advertising.  But how can you do that on the internet?  Sure you can make a page for endorsement quotations and list them all, but who is …
OverviewThis article demonstrates a simple search form using AJAX. The purpose of the article is to demonstrate how to use the same code to render a page and javascript (JQuery) and AJAX to make subsequent calls to refine the results. The princip…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

746 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now