Jump to content

delete record


gBase

Recommended Posts

Hi, I am implementing a form in my database to allow the user to remove records by ID # (which is the primary key for the table.)  The form calls to a php file that has this code:

[code]
$sql="DELETE FROM table (ID, Name, Organization, Title, Street, City, State, Zip)
VALUES
('$_POST[ID]','$_POST[Name]','$_POST[Organization]','$_POST[Title]','$_POST[Street]','$_POST[City]','$_POST[State]','$_POST[Zip]')
WHERE ID='$ID'";
[/code]

Will this work as intended?  Just want to get another pair of eyes to check this over before I try it.  I am working with a live database and while I'm trying to remove a non-used record, I don't want to risk any of the other data.
Link to comment
https://forums.phpfreaks.com/topic/22912-delete-record/
Share on other sites

Ohhh ok.  Thanks for clearing that up.  I was going to post a new thread but I didn't want to junk up the board...I have another question based on the fact that I'm using ID as my primary key.  Currently, I have a form on my app that inserts new records into my database...only problem is that currently you have to enter in the new ID manually.  Is there a way to clean this up so it updates the ID automagically?  ;)

Here's my code:

[code]
$sql="INSERT INTO table01 (ID, Name, Organization, Title, Street, City, State, Zip)
VALUES
('$_POST[ID]','$_POST[Name]','$_POST[Organization]','$_POST[Title]','$_POST[Street]','$_POST[City]','$_POST[State]','$_POST[Zip]')";

$result = mysql_query("SELECT ID, Name, Organization, Title, Street, City, State, Zip FROM table");

if
(!mysql_query($sql,$connection))
  {
  die ('Error: ' . mysql_error());
  }
echo "1 record added";
[/code]
Link to comment
https://forums.phpfreaks.com/topic/22912-delete-record/#findComment-103331
Share on other sites

Something like this.

[code]
$sql = "
INSERT INTO table01
(Name, Organization, Title, Street, City, State, Zip)
VALUES
('$_POST[Name]','$_POST[Organization]','$_POST[Title]','$_POST[Street]','$_POST[City]','$_POST[State]','$_POST[Zip]')";

if (!mysql_query($sql,$connection))
die ('Error: ' . mysql_error());
else
echo "1 record added";
[/code]
Link to comment
https://forums.phpfreaks.com/topic/22912-delete-record/#findComment-103370
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.