Jump to content

[SOLVED] Help with Deleting records


rockindano30

Recommended Posts

Good morning every one,

 

well i solved one problem but came across another one. just when i thought i had it all working fine, noticed something else.

 

i'm working on a app. and i have three tables, employees, departments, and emp_keys,

 

well I had the problem to get the correct emp_id (primary key from employees) to be pass and delete that record. well i figured that one out. now my table has over 30 employees, it passes the key able to delete but only up to emp_key 9 once it gets to 10 it starts again at 1.

 

don't know if i am making sense or not but here is some of my code:

			$emp_id=$_GET["emp_id"];

			$search=$_POST["search"];
			$search2=$_POST["search2"];

			$search= trim($search);
			$search2= trim($search2);




			if(!isset($search) || empty($search) || !isset($search2) || empty($search2))
					{
						print"<p>Your search was not sucessfull due for one of the followings:<br />";
						print "Make sure that you have the first and last name filled.<br />";
						print "Make sure that you spelled the employee's name currectly.<br />";
						print "Or there are no keys asigned to that employee.</p>";

					}
			else{
			$search=addslashes($search);
			$search2=addslashes($search2);


			//get the mysql and store them in $result
			$query = "select employees.emp_id,Fname,Lname, email, dept, group_concat(key_num separator ' - ') as key_num, group_concat(accss separator ' - ') as accss FROM departments, employees, emp_keys where Fname like '%$search%' and Lname like '$search2' and departments.dept_id= employees.dept_id and emp_keys.emp_id=employees.emp_id group by employees.emp_id";				
			$result = mysql_query($query); 
			$num_result = mysql_num_rows($result);


			if ($num_result < 1)
			 print "<p>No employee found by that name.<br />Please make sure that you typed in the employee's name correctly.<br />Or there is no keys asigned to that employee.</p>";
			else {


		//grab all the content
		while($r=mysql_fetch_array($result))
		{	
		   //the format is $variable = $r["nameofmysqlcolumn"];
		   $dept=$r["dept"];			   
		   $Fname=$r["Fname"];
		   $Lname=$r["Lname"];
		   $email=$r["email"];
		   $key_num=$r["key_num"];
		   $accss=$r["accss"];
		   $emp_id=$r["emp_id"];
		?>
            <p style="padding:0px; text-decoration:underline">Your Search Results are below:</p><br  />
              <table width="100%" border="0" cellpadding="1" cellspacing="0" class="table1">
                <tr><td width="20%"><strong>Department:</strong></td>
                  <td width="80%"><font face="Arial, Helvetica, sans-serif"><?php print $dept; ?></font></td>
                </tr>
                <tr><td width="20%"><strong>Name:</strong></td>
                  <td width="80%"><font face="Arial, Helvetica, sans-serif"  style="color:#CC6600"><?php print $Fname." ".$Lname; ?></font></td>
                </tr>
                <tr><td width="20%"><strong>Email:</strong></td>
                  <td width="80%"><font face="Arial, Helvetica, sans-serif"><?php print $email; ?></font></td>
                </tr>
                <tr><td width="20%"><strong>Key #:</strong></td>
                  <td width="80%"><font face="Arial, Helvetica, sans-serif"><?php print $key_num; ?></font></td>
                </tr>
                <tr><td width="20%"><strong>Key Access:</strong></td>
                  <td width="80%"><font face="Arial, Helvetica, sans-serif"><?php print $accss; ?></font></td>
                </tr>
                <tr><td width="20%">
			<?php 
                                       //here it print the correct emp_id
                                       print $emp_id;
				?>
			</td>
                  <td width="80%">
                  <?php 
                        ///but here once it gets to emp_id 9 it starts all over again at 1.
                       print"<a href=\"delete.php?emp_id={$emp_id['emp_id']}\">Remove"; ?>
                  </td>
                </tr>
              </table>
          <?php
		  }//end while loop
		}
	}
		?>

 

see code for comments.

Link to comment
https://forums.phpfreaks.com/topic/105268-solved-help-with-deleting-records/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

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