Jump to content

HELP big time


rogerc

Recommended Posts

Hello

I am new to php and need some help,The code below is for selecting a record to delete through drop down list.I wonder could it be possible to change it text a box where you type a letter and all the records starting with it would be shown its been wrecking my head for yonks i have no idea how to fix it any help would be greatly appreciated this is the code for it.

 

thanks rogerc

 

<?

//start a session

session_start();

 

//check validity of user

if ($_SESSION[valid] != "yes"){

  header("Location:http://127.0.0.1/contact_menu.php");

  exit;

}

 

//set up table and database names

$db_name = "resultsdb";

$table_name = "grades";

 

//connect to server and select database

$connection = @mysql_connect("localhost") or die(mysql_error());

$db = @mysql_select_db($db_name,$connection) or die(mysql_error());

 

//build and issue query

$sql ="SELECT id, f_name, l_name FROM $table_name ORDER BY l_name";

$result = @mysql_query($sql,$connection) or die(mysql_error());

 

//check the number of results

$num = @mysql_num_rows($result);

 

if ($num < 1) {

  //if there are no results,display message

  $display_block = "<P>Sorry!No results.</p>";

 

} else {

 

  //if results are found,loop through them

  //and make a form selection block

  while ($row =mysql_fetch_array($result)){

      $id = $row['id'];

      $f_name = $row['f_name'];

      $l_name = $row['l_name'];

      $option_block .="<option value=\"$id \">$l_name,$f_name</option>";

 

  }

 

  //create the entire form block

  $display_block ="

  <FORM METHOD=\"POST\" ACTION=\"show_delcontact.php\">

  <P><strong>Student:</strong>

  <select name=\"id\">

  $option_block

  </select>

 

  <INPUT TYPE=\"SUBMIT\" NAME=\"submit\" VALUE=\"Select Student\"></P>

  </form>";

 

}

?>

 

<HTML>

<HEAD>

<TITLE></TITLE>

</HEAD>

<BODY>

<h1></h1>

 

 

<P>Select Student Info from the list below.</P>

<? echo "$display_block"; ?>

 

 

 

<p><a href="contact_menu.php">Return to Main Menu[/url]</p>

</BODY>

</HTML>

 

 

 

Link to comment
Share on other sites

Roger,

 

You may want to just start from scratch as what you are requesting is quite a change to the way things are currently laid out in your script.

 

Basic logic would be to build a form that submits the desired letter... build a query to get the results of the search, display them with a delete link/button at the end of each field that would point to a confirmation page with the unique ID for that row appended to the end of the confirmation page URL. When someone comfirms the delete, remove the record from the database.

 

Hope that helps get you started,

 

Matt

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.