473,385 Members | 2,005 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

delete the records using checkbox from database.

hi...this code of deleting a record from database using checkbox is not working...echo "<td>$row['FirstName']</td>;
echo "<td>$row['LastName']</td>";
echo "<td>$row['Age']....these lines print as it is...rather then displaying the records entered in the table....

Expand|Select|Wrap|Line Numbers
  1. <?php
  2.  
  3. $con = mysql_connect("localhost","root","root");
  4. if (!$con)
  5.   {
  6.   die('Could not connect: ' . mysql_error());
  7.   }
  8.        if ($_POST['submit'])
  9.        {
  10.     $FirstName = $_POST['FirstName'];
  11.     $query = "delete from student where FirstName ='$FirstName'";
  12.     $result = mysql_query($query,$con);
  13.  
  14.     echo "Record has been deleted";
  15.     //echo "<br/><br/><a href =customers3.php>Back to Customers Page</a>";
  16.     }
  17.  
  18.     else{
  19.  
  20.     $sql = "select * from student";
  21.  
  22.     $result = mysql_query($sql,$con);
  23.     mysql_close($con);
  24. ?>
  25.  
Expand|Select|Wrap|Line Numbers
  1. <html>
  2. <head>
  3. </head>
  4. <body>
  5.     <form name="Student info" action="delself.php" method="post">
  6.     <table border=1 align='left'>
  7.      <?php
  8.      while($row = mysql_fetch_array($result))
  9.      {
  10.     echo "<tr><td>$row['FirstName']</td>;
  11.     echo "<td>$row['LastName']</td>";
  12.     echo "<td>$row['Age']</td>";
  13.     echo "<td><input type='hidden' name='FirstName' value='$row[FirstName]'/></td>";
  14.     echo "<td><input type='submit' name='submit' value='Delete'/></td>";
  15.     echo </tr>";
  16.     }
  17.     echo "</table>";
  18.     ?>
  19. </form>
  20. </body>
  21. </html>
  22.  
Jan 25 '10 #1
1 4292
johny10151981
1,059 1GB
Start with the second file(if it works, cause i cant see any database connection):

say you have 10 recods in the database, yoy will get ten hidden variable with the same name included 10 submit button.

all of those submit button under one form

If you want to offer user to choose a name to delete from the database
1. Create a combobox(Drop down list) or
2. Create a list box
in the second file.
When you add a hidden type it mean when ever any one try submit button the set value will be transferred to the action page.

In the first file you have provided, few things to notice

you havent select any database. You must have to select database before you do any kind of query or you can tell the name of the database in the query.

something like that
mysql_query("select * from databasename.tablename");

In the else of the first file..

you have done a select query and right after select query you have closed the connection. if you dont use your result, returned from select query, dont do it. :)

By the way when you are saying that you got an error must post the error with the code.

Regards,
Johny
Jan 25 '10 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

5
by: hpi | last post by:
Hello, I have a table : Batch It contains fields batchnummer : Number (Long Integer) datum : Date/Time status : Number (Long Integer) nr_records : Number (Long Integer)
6
by: Paul T. Rong | last post by:
Dear all, Here is my problem: There is a table "products" in my access database, since some of the products are out of date and stopped manufacture, I would like to delete those PRODUCTS from...
1
by: bigabytes | last post by:
I'm just learning PHP (extreme novice) and I'm struggling with deleting records using a checkbox included within each row. I have a few idea but I'm not sure if my thoughts are correct. I think I...
4
by: felicia | last post by:
Hi All, Below is my code to delete records: adodcAllEntries.Recordset.MoveFirst Do While (adodcAllEntries.Recordset.EOF = False) If adodcAllEntries.Recordset.Fields(0) = selected_id Then...
3
madhoriya22
by: madhoriya22 | last post by:
I have solved the problem
7
by: mukeshrasm | last post by:
hello everyone I want to delete the selected records from database using checkbox. whch is generated dyanamically and checkbox is also generated dynamically,using php. so please help me. if you...
13
by: ramprakashjava | last post by:
hi, i hav "java.lang.NullPointerException" error while Deleting table records using checkbox in jsp here i enclosed files help quickly plzzz.. ...
1
by: tembil | last post by:
Hi, I'm designing a windows application in visual studio 2008 and connecting to oracle 10g XE but don't know how to add, update and delete records from my database using text boxes. Thanks in...
13
mseo
by: mseo | last post by:
hi, I have a form for deleting records but I use unbound controls in the mainform to set the criteria of filtering the records that will be viewed in the subform I have delete command button in...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.