By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
449,402 Members | 1,216 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 449,402 IT Pros & Developers. It's quick & easy.

Disscussion about deletion of record from php form

P: 22
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
Share this Question
Share on Google+
6 Replies


P: 3
hi, i am Tarsem SIngh
Please read PHP help Tutorial -- http://www.php-mysql-tutorial.com/
Jul 21 '07 #2

P: 22
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
Expert 5K+
P: 5,821
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
Expert 100+
P: 1,044
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
Expert 100+
P: 1,584
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

P: 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

Post your reply

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