473,398 Members | 2,125 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,398 software developers and data experts.

Disscussion about deletion of record from php form

Hi all,
I am Punit
I am working in php .i want to delete records from database from php form .
For this i code the code is:
Expand|Select|Wrap|Line Numbers
  1. <?php
  2.  
  3. $name = $_POST['firstname'];
  4.  
  5. $host="localhost"; // Host name 
  6. $username="root"; // Mysql username 
  7. $password="root"; // Mysql password 
  8. $db_name="projectdb"; // Database name 
  9. $tbl_name="person"; // Table name 
  10.  
  11. // Connect to server and select database.
  12. $dbconnection = mysql_connect("$host", "$username", "$password")or die("cannot connect"); 
  13. mysql_select_db("$db_name")or die("cannot select DB");
  14.  
  15. // delete data in mysql database 
  16. $sql="DELETE FROM person WHERE FirstName ='$name' ";
  17. echo "$sql";
  18. $result = mysql_query($sql,$dbconnection);
  19. echo"$result";
  20.  
  21. // if successfully deleted. 
  22. if($result == 1)
  23. {
  24. echo "Successful";
  25. echo "<BR>";
  26. echo "<a href='list_records.php'>View result</a>";
  27. }
  28.  
  29. else 
  30. {
  31. echo "ERROR";
  32. }
  33.  
  34. ?>
it is not working
when i echo sql statement it shows:

DELETE FROM person WHERE FirstName ='' 1Successful
As i am beginners in php so please suggest me .
Thanks
Jul 21 '07 #1
6 1577
tarsem
3
hi, i am Tarsem SIngh
Please read PHP help Tutorial -- http://www.php-mysql-tutorial.com/
Jul 21 '07 #2
Thanks Tarsem SIngh
I just go through the website which you refer to me.
Still i have a problem that value is not posting to another form.
As i use post for fetching the value:
$name = $_POST['firstname'];
in ane form i use table .In that table i use to create row and five col.
I want to fetch data from one col by the help of that data i delete the entire row from database.As if directly subsitute the value in query it perform the taskbut as i fetch the value from another form it is not working .
Then i use to create textbob in col.
by thismethod:
Expand|Select|Wrap|Line Numbers
  1. <td><input type = "text" name = "firstname" value="<? echo $rows['FirstName']; ?>" /></td> 
fetch the data in another form as previously i say.
but still it is not working.
please suggest me wht do.As i am beginner in php so please suggest me.
Thanks
punit
hi, i am Tarsem SIngh
Please read PHP help Tutorial -- http://www.php-mysql-tutorial.com/
Jul 21 '07 #3
pbmods
5,821 Expert 4TB
Heya, Punit.

Please use CODE tags when posting source code. See the REPLY GUIDELINES on the right side of the page next time you post.
Jul 21 '07 #4
kovik
1,044 Expert 1GB
I'd suggest you read more into the tutorial. Posted variables only exist *after* the form has been posted, and $rows would only exist after you've created it.

Also, some basic security can go a long way.
Jul 21 '07 #5
ak1dnar
1,584 Expert 1GB
Thanks Tarsem SIngh
I just go through the website which you refer to me.
Still i have a problem that value is not posting to another form.
As i use post for fetching the value:
$name = $_POST['firstname'];
in ane form i use table .In that table i use to create row and five col.
I want to fetch data from one col by the help of that data i delete the entire row from database.As if directly subsitute the value in query it perform the taskbut as i fetch the value from another form it is not working .
Then i use to create textbob in col.
by thismethod:
Expand|Select|Wrap|Line Numbers
  1. <td><input type = "text" name = "firstname" value="<? echo $rows['FirstName']; ?>" /></td> 
fetch the data in another form as previously i say.
but still it is not working.
please suggest me wht do.As i am beginner in php so please suggest me.
Thanks
punit
As I got, you are sending this form element to another script to deletion.
Expand|Select|Wrap|Line Numbers
  1. <td><input type = "text" name = "firstname" value="<? echo $rows['FirstName']; ?>" /></td> 
first try
Expand|Select|Wrap|Line Numbers
  1. <td><input type = "text" name = "firstname" value="pass_existing_firstname_here" /></td> 
If its is working,then the problem is with the script that you used to echo these lines.
Expand|Select|Wrap|Line Numbers
  1. <? echo $rows['FirstName']; ?>
double check it or post that script also.
Jul 22 '07 #6
abertay
10
Hi all,
I am Punit
I am working in php .i want to delete records from database from php form .
For this i code the code is:
Expand|Select|Wrap|Line Numbers
  1. <?php
  2.  
  3. $name = $_POST['firstname'];
  4.  
  5. $host="localhost"; // Host name 
  6. $username="root"; // Mysql username 
  7. $password="root"; // Mysql password 
  8. $db_name="projectdb"; // Database name 
  9. $tbl_name="person"; // Table name 
  10.  
  11. // Connect to server and select database.
  12. $dbconnection = mysql_connect("$host", "$username", "$password")or die("cannot connect"); 
  13. mysql_select_db("$db_name")or die("cannot select DB");
  14.  
  15. // delete data in mysql database 
  16. $sql="DELETE FROM person WHERE FirstName ='$name' ";
  17. echo "$sql";
  18. $result = mysql_query($sql,$dbconnection);
  19. echo"$result";
  20.  
  21. // if successfully deleted. 
  22. if($result == 1)
  23. {
  24. echo "Successful";
  25. echo "<BR>";
  26. echo "<a href='list_records.php'>View result</a>";
  27. }
  28.  
  29. else 
  30. {
  31. echo "ERROR";
  32. }
  33.  
  34. ?>
it is not working
when i echo sql statement it shows:

DELETE FROM person WHERE FirstName ='' 1Successful
As i am beginners in php so please suggest me .
Thanks

Remove the double qoutes in your mysql_connect & mysql_select_db query.
Because $host="localhost" so you dont need them again

Expand|Select|Wrap|Line Numbers
  1. mysql_connect($host,$root,$password);
  2. mysql_select_db($dbname);
  3.  
Jul 23 '07 #7

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

Similar topics

0
by: Vic | last post by:
Hi all, When I test the Delete multi table function in MySQL, DELETE table_name ...] FROM table-references I accidentally delete all data in one table. All data in that table are gone...
12
by: Dan Greenblatt | last post by:
I am writing some software that, among other things, needs to track the state of database tables. This includes occasionally checking the table to see what records or added, modified, or deleted....
8
by: Chuckles | last post by:
I have two unbound combo boxes on one form and would like to select an item in the first combo box which then brings up a list associated with that item in the second combo box That part is all set...
7
by: TJS | last post by:
javascript "confirm" fires after deletion instead of before deletion. how do I get this to stop the processing ? code ================== Sub ShowAlert(ByVal s As string)...
2
by: MRW | last post by:
Hello! I'm trying to execute a code so when a record in a DetailsView is deleted, it will first have to be confirmed (with as little code as possible). The DetailsView is attacked to an...
1
by: solargovind | last post by:
Hi, I have one Form in which i have one subform also which links together by one common_id(Payment_id). When i display record, I need to delete Current record in both form & Table. I used the...
3
by: brucedodds | last post by:
My application has a form based on a parent table with a subform based on a child table. The relationship is Cascade Delete. The first record displayed when the form opens has five child records....
2
by: illu1985 | last post by:
package area; import java.sql.*; import java.util.*; public class area { int id; public void setId(int id) {
10
beacon
by: beacon | last post by:
Hi everybody, This is probably going to sound unorthodox, but I have to log records that are deleted...I know, go figure. Anyway, I have a form with a (continuous) subform, and on the subform I...
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: 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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
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...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.