Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

Delete, Add or Edit Records

Posted on 2015-01-25
4
114 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 31

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 109

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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I found this questions asking how to do this in many different forums, so I will describe here how to implement a solution using PHP and AJAX. The logical flow for the problem should be: Write an event handler for the first drop down box to get …
These days socially coordinated efforts have turned into a critical requirement for enterprises.
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…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

860 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