select & delete mysql queries

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
superman
Forum Commoner
Posts: 29
Joined: Tue Jul 08, 2003 2:54 am

select & delete mysql queries

Post by superman »

i've try to insert and delete record at the same page, but it only can insert and can't delete the record.
when i click submit button from the previous form, the record is insert into table B and delete from the table A.
is the code correct?

Code: Select all

<? $Connect = mysql_connect("localhost","root","");
                mysql_select_db("mw");
				$TodayDate = strftime("%Y-%m-%d"); 	
				$TodayTime = strftime("%H:%M:%S"); 	
				$result=mysql_query("insert into LeaveApplication1 (StaffID, LeaveType, JobTitle, FromDate, ToDate, Duration, Reason, TodayDate, TodayTime) values ('$StaffID', '$LeaveType', '$JobTitle', '$FromDate', '$ToDate', '$Duration', '$Reason', '$TodayDate')");

				$result=mysql_query("delete from LeaveApplication where StaffID='$StaffID' and LeaveType='$LeaveType' and JobTitle='$JobTitle' and FromDate='$FromDate' and ToDate='$FromDate' and Duration='$Duration' and Reason='$Reason' and TodayDate='$TodayDate' and TodayTime='$TodayTime'");
				 mysql_close();
			?>
User avatar
gjb79
Forum Commoner
Posts: 96
Joined: Fri Jul 18, 2003 6:35 am
Location: x <-- (DC)
Contact:

Simple stuff

Post by gjb79 »

I know it sounds dumb and there's a good chance you've already checked, but it is easy to over look.

Log into mysql and make sure the account your using in the script to log into it has permissions set to delete. Could save you a lot of trouble if it is the case.
User avatar
gjb79
Forum Commoner
Posts: 96
Joined: Fri Jul 18, 2003 6:35 am
Location: x <-- (DC)
Contact:

One more thing

Post by gjb79 »

If your inserting and deleting from the same table, you need these two lines to be identical as far as the table name:

"insert into LeaveApplication1"

"delete from LeaveApplication"

In your script you are missing the 1 in LeaveApplication in the delete code.
User avatar
xisle
Forum Contributor
Posts: 249
Joined: Wed Jun 25, 2003 1:53 pm

Re: select & delete mysql queries

Post by xisle »

I would recommend deleting based on the record id (primary key)
for the table. With this many 'where' conditions, the delete could
easily get overlooked.

Code: Select all

"delete from LeaveApplication where id='99999'";
kettle_drum
DevNet Resident
Posts: 1150
Joined: Sun Jul 20, 2003 9:25 pm
Location: West Yorkshire, England

...

Post by kettle_drum »

You may also not want to connect to the mysql server as root.

Maybe also try DELETE * FROM table WHERE id = '1'
Celtis
Forum Newbie
Posts: 3
Joined: Sun Jul 20, 2003 7:55 am
Contact:

Re: ...

Post by Celtis »

kettle_drum wrote:You may also not want to connect to the mysql server as root.
Good advice, and make sure that you change the root password (obviously change "password" to "YOUR PASSWORD!"):

Code: Select all

Use mysql; 
Update user set password=PASSWORD("password") where user='root';
kettle_drum wrote:Maybe also try DELETE * FROM table WHERE id = '1'
Delete * won't work in mysql, you just use delete instead :)
Post Reply