Solved

Delete, Add or Edit Records

Posted on 2015-01-25
4
121 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
[X]
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
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 110

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: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone 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

This article discusses how to create an extensible mechanism for linked drop downs.
Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
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 …

726 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