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
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
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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