Adding / Editing / Deleting Entries In A Database
Posted: Mon Feb 23, 2009 5:16 pm
Hi guys,
I'm sure you've heard these questions a million times before, but please bear with me, I am truly desperate and dry out of ideas, you guys are my last hope. So I managed to set up a little MySQL search engine that looks up keywords from a database and spits them out in the form of a table full of content. The thing I need to do now is to give the user the ability to edit and delete each individual entry that the search came up with, by clicking on the appropriate link on the right side of each item. When you click on "Edit", a little html form should pop out on the bottom of the page (or in a different page, it doesn't really matter, as long as it gets the job done), already having the old values of each field present in the input fields, that you'll be able to edit and save to the database.
I'm in a total block and I can't figure out how to get the different fields' unique entries over to the form and how to trigger these different actions (Edit, Delete, Add New Entry) using an HTML link...
Here's what I have so far, I'd really appreciate some help guys!
Here's the search engine online - http://bodyad.co.uk/search_test/search.php
Thanks in advance!!
I'm sure you've heard these questions a million times before, but please bear with me, I am truly desperate and dry out of ideas, you guys are my last hope. So I managed to set up a little MySQL search engine that looks up keywords from a database and spits them out in the form of a table full of content. The thing I need to do now is to give the user the ability to edit and delete each individual entry that the search came up with, by clicking on the appropriate link on the right side of each item. When you click on "Edit", a little html form should pop out on the bottom of the page (or in a different page, it doesn't really matter, as long as it gets the job done), already having the old values of each field present in the input fields, that you'll be able to edit and save to the database.
I'm in a total block and I can't figure out how to get the different fields' unique entries over to the form and how to trigger these different actions (Edit, Delete, Add New Entry) using an HTML link...
Here's what I have so far, I'd really appreciate some help guys!
Here's the search engine online - http://bodyad.co.uk/search_test/search.php
Code: Select all
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Bodyad Search Engine</title>
<link href="css/style.css" rel="stylesheet" type="text/css" />
</head>
<body>
<?
$hostname_logon = "localhost" ;
$database_logon = "bodyad_main" ;
$username_logon = "bodyad" ;
$password_logon = "aamer12345" ;
$connections = mysql_connect($hostname_logon, $username_logon, $password_logon) or die ( "Unabale to connect to database" );
mysql_select_db($database_logon) or die ( "Unable to locate database" );
$limit = 10000;
$var = @$_GET['q'] ;
$trimmed = trim($var);
$trimmed_array = explode(" ",$trimmed);
if ($trimmed == "") {
$resultmsg = "<p>Please enter a valid search parameter</p>" ;
}
if (!isset($var)){
$resultmsg = "<p>Please enter a search parameter</p>" ;
}
foreach ($trimmed_array as $trimm){
$query = "SELECT * FROM MASTER WHERE ID LIKE \"%$trimm%\" OR BUSINESS_N LIKE \"%$trimm%\" OR FIRST_NAME LIKE \"%$trimm%\" OR LAST_NAME LIKE \"%$trimm%\" OR ADDRESS LIKE \"%$trimm%\" OR ADDRESS_LI LIKE \"%$trimm%\" OR TOWN LIKE \"%$trimm%\" OR COUNTY LIKE \"%$trimm%\" OR POST_CODE LIKE \"%$trimm%\" OR PHONE_NUMB LIKE \"%$trimm%\" OR MOBILE_NUM LIKE \"%$trimm%\" OR EMAIL LIKE \"%$trimm%\" OR WEBSITE LIKE \"%$trimm%\" OR DOOR_STAFF LIKE \"%$trimm%\" OR COMMENTS LIKE \"%$trimm%\" OR CAPACITY LIKE \"%$trimm%\" OR EMAILED LIKE \"%$trimm%\" OR MEMO_BOX LIKE \"%$trimm%\" OR RESPONSE_B LIKE \"%$trimm%\" OR RESPONSE_D LIKE \"%$trimm%\" OR RESPONSE_I LIKE \"%$trimm%\" ORDER BY LAST_NAME ASC" ;
$numresults=mysql_query ($query);
$row_num_links_main =mysql_num_rows ($numresults);
if (empty($s)) {
$s=0;
}
$query .= " LIMIT $s,$limit" ;
$numresults = mysql_query ($query) or die ( "Could not execute query" );
$row= mysql_fetch_array ($numresults);
do{
$adid_array[] = $row[ 'ID' ];
}while( $row= mysql_fetch_array($numresults));
}
if($row_num_links_main == 0 && $row_set_num == 0){
$resultmsg = "<p>Search results for <strong>" . $trimmed ."</strong>.</p><p>Sorry, your search returned zero results</p>" ;
}
$tmparr = array_unique($adid_array);
$i=0;
foreach ($tmparr as $v) {
$newarr[$i] = $v;
$i++;
}
?>
<div align="center">
<table width="100%" align="center" cellpadding="10" cellspacing="0" border="0">
<tr>
<td colspan="8">
<form action="search.php" method="get" name="search">
<input name="q" type="text" value="<?php echo $q; ?>" size="15" />
<input name="search" type="submit" value="Search" />
</form>
<?
if( isset ($resultmsg)){
echo $resultmsg;
echo "</td></tr></table></div></body></html>";
exit();
}else{
echo "<p>Search results for <strong>" . $var . "</strong></p>";
}
?>
</td>
</tr>
<tr class="title_row">
<td><strong>First Name</strong></td>
<td><strong>Last Name</strong></td>
<td><strong>Business Name</strong></td>
<td><strong>Address Line 1</strong></td>
<td><strong>Address Line 2</strong></td>
<td><strong>Town</strong></td>
<td><strong>County</strong></td>
<td><strong>Options</strong></td>
</tr>
<?
foreach($newarr as $value){
$query_value = "SELECT * FROM MASTER WHERE ID = '$value'";
$num_value=mysql_query ($query_value);
$row_linkcat= mysql_fetch_array ($num_value);
$row_num_links= mysql_num_rows ($num_value);
$first_name = preg_replace ( "'($var)'si" , "<b>\\1</b>" , $row_linkcat[ 'FIRST_NAME' ] );
$last_name = preg_replace ( "'($var)'si" , "<b>\\1</b>" , $row_linkcat[ 'LAST_NAME' ] );
$business_name = preg_replace ( "'($var)'si" , "<b>\\1</b>" , $row_linkcat[ 'BUSINESS_N' ] );
$address_line_1 = preg_replace ( "'($var)'si" , "<b>\\1</b>" , $row_linkcat[ 'ADDRESS' ] );
$address_line_2 = preg_replace ( "'($var)'si" , "<b>\\1</b>" , $row_linkcat[ 'ADDRESS_LI' ] );
$town = preg_replace ( "'($var)'si" , "<b>\\1</b>" , $row_linkcat[ 'TOWN' ] );
$county = preg_replace ( "'($var)'si" , "<b>\\1</b>" , $row_linkcat[ 'COUNTY' ] );
foreach($trimmed_array as $trimm){
if($trimm != 'b' ){
$first_name = preg_replace( "'($trimm)'si" , "<b>\\1</b>" , $first_name);
$last_name = preg_replace( "'($trimm)'si" , "<b>\\1</b>" , $last_name);
$business_name = preg_replace( "'($trimm)'si" , "<b>\\1</b>" , $business_name);
$address_line_1 = preg_replace( "'($trimm)'si" , "<b>\\1</b>" , $address_line_1);
$address_line_2 = preg_replace( "'($trimm)'si" , "<b>\\1</b>" , $address_line_2);
$town = preg_replace( "'($trimm)'si" , "<b>\\1</b>" , $town);
$county = preg_replace( "'($trimm)'si" , "<b>\\1</b>" , $county);
}
$row_style = ($item_counter % 2 == 1) ? "normal_row" : "altered_row";
echo "
<a href=\"\"><tr class=\"" . $row_style . "\">
<td>" . $first_name . "</td>
<td>" . $last_name . "</td>
<td>" . $business_name . "</td>
<td>" . $address_line_1 . "</td>
<td>" . $address_line_2 . "</td>
<td>" . $town . "</td>
<td>" . $county . "</td>
<td><a href=\"\">Edit</a> <a href=\"\">Delete</a></td>
</tr></a>";
$item_counter ++;
}
}
echo "
<tr class=\"title_row\">
<td colspan=\"8\">Items found: <strong>" . $item_counter . "</strong></td>
</tr>
";
?>
<tr>
<td colspan="8"><a href=""><strong>Add New Entry</strong></a></td>
</tr>
</table>
</div>
</body>
</html>