mysql and php5 deleting rows

This is a discussion on mysql and php5 deleting rows within the PHP Language forums, part of the PHP Programming Forums category; I can't seem to delete rows from a mysql database. I have a database that I want to delete ...


Go Back   Usenet Forums > PHP Programming Forums > PHP Language

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 01-21-2005
Andrew M.
 
Posts: n/a
Default mysql and php5 deleting rows

I can't seem to delete rows from a mysql database. I have a database
that I want to delete rows from based on user name. i have researched
this extensively and can't seem to find anything that works. Any help is
greatly appreciated.
Reply With Quote
  #2 (permalink)  
Old 01-21-2005
News Me
 
Posts: n/a
Default Re: mysql and php5 deleting rows

Andrew M. wrote:
> I can't seem to delete rows from a mysql database. I have a database
> that I want to delete rows from based on user name. i have researched
> this extensively and can't seem to find anything that works. Any help is
> greatly appreciated.


What have you tried so far?

NM

--
convert uppercase WORDS to single keystrokes to reply
Reply With Quote
  #3 (permalink)  
Old 01-21-2005
Andrew M.
 
Posts: n/a
Default Re: mysql and php5 deleting rows



News Me wrote:

> Andrew M. wrote:
>
>> I can't seem to delete rows from a mysql database. I have a database
>> that I want to delete rows from based on user name. i have researched
>> this extensively and can't seem to find anything that works. Any help
>> is greatly appreciated.

>
>
> What have you tried so far?
>
> NM
>

Here is what i have been trying to get working.

<?php

//Connect to ple_security
$conn = mysql_connect( "localhost", "ple_security", "blah" )
or die ( "Unable to Connect" );

#select the database
$rs = mysql_select_db( "ple_security", $conn )
or die( "Could not select database" );

//create the query
//$sql = "DELETE FROM 'users' WHERE 'user_name' =\'$user_name_delete\'";

//execute query
mysql_query ("DELETE FROM users WHERE user_name = $user_name_delete");

?>

THANKS in advance for any help. I know that this is problem a newbie
problem.
Reply With Quote
  #4 (permalink)  
Old 01-21-2005
Geoff Berrow
 
Posts: n/a
Default Re: mysql and php5 deleting rows

I noticed that Message-ID: <5qeId.158387$Uf.12949@twister.nyroc.rr.com>
from Andrew M. contained the following:

I assume you are connecting to the database ok

>//create the query
>//$sql = "DELETE FROM 'users' WHERE 'user_name' =\'$user_name_delete\'";

This line is redundant
>
>//execute query
>mysql_query ("DELETE FROM users WHERE user_name = $user_name_delete");

Should work, provided $user_name_delete actually contains something.
Where does it come from?

--
Geoff Berrow (put thecat out to email)
It's only Usenet, no one dies.
My opinions, not the committee's, mine.
Simple RFDs http://www.ckdog.co.uk/rfdmaker/
Reply With Quote
  #5 (permalink)  
Old 01-21-2005
CJ Llewellyn
 
Posts: n/a
Default Re: mysql and php5 deleting rows

"Andrew M." <andrewm_nospam@rochester.rr.com> wrote in message
news:5qeId.158387$Uf.12949@twister.nyroc.rr.com...
>
>
> News Me wrote:
>
> > Andrew M. wrote:
> >
> >> I can't seem to delete rows from a mysql database. I have a database
> >> that I want to delete rows from based on user name. i have researched
> >> this extensively and can't seem to find anything that works. Any help
> >> is greatly appreciated.

> >
> >
> > What have you tried so far?
> >
> > NM
> >

> Here is what i have been trying to get working.
>
> <?php
>
> //Connect to ple_security
> $conn = mysql_connect( "localhost", "ple_security", "blah" )
> or die ( "Unable to Connect" );
>
> #select the database
> $rs = mysql_select_db( "ple_security", $conn )
> or die( "Could not select database" );
>
> //create the query
> //$sql = "DELETE FROM 'users' WHERE 'user_name' =\'$user_name_delete\'";
>
> //execute query
> mysql_query ("DELETE FROM users WHERE user_name = $user_name_delete");
>
> ?>
>
> THANKS in advance for any help. I know that this is problem a newbie
> problem.


$sql = "DELETE FROM 'users' WHERE 'user_name' =\'$user_name_delete\'";
$result = mysql_query($sql, $conn);
if(! $result || mysql_error($conn))
{
eho "Unable to delete user [$sql] : " . mysql_error($conn);
}

Always formulate your SQL quiries into a string, that way you can see what
you are asking the database to do.

Always test IO (input/output) operations for errors.

You should see where your query is wrong.

$sql = "DELETE FROM users WHERE user_name = '$user_name_delete'";

Note that this is prone to abuse (SQL injection) so if you've not got magic
quotes switched on you'll have to escape the $user_name_delete variable.

$sql = sprintf("DELETE FROM users WHERE user_name = '%s'",
addslashes($user_name_delete));



Reply With Quote
  #6 (permalink)  
Old 01-22-2005
Andrew M.
 
Posts: n/a
Default Re: mysql and php5 deleting rows



CJ Llewellyn wrote:

> "Andrew M." <andrewm_nospam@rochester.rr.com> wrote in message
> news:5qeId.158387$Uf.12949@twister.nyroc.rr.com...
>
>>
>>News Me wrote:
>>
>>
>>>Andrew M. wrote:
>>>
>>>
>>>>I can't seem to delete rows from a mysql database. I have a database
>>>>that I want to delete rows from based on user name. i have researched
>>>>this extensively and can't seem to find anything that works. Any help
>>>>is greatly appreciated.
>>>
>>>
>>>What have you tried so far?
>>>
>>>NM
>>>

>>
>>Here is what i have been trying to get working.
>>
>><?php
>>
>>//Connect to ple_security
>>$conn = mysql_connect( "localhost", "ple_security", "blah" )
>>or die ( "Unable to Connect" );
>>
>>#select the database
>>$rs = mysql_select_db( "ple_security", $conn )
>>or die( "Could not select database" );
>>
>>//create the query
>>//$sql = "DELETE FROM 'users' WHERE 'user_name' =\'$user_name_delete\'";
>>
>>//execute query
>>mysql_query ("DELETE FROM users WHERE user_name = $user_name_delete");
>>
>>?>
>>
>>THANKS in advance for any help. I know that this is problem a newbie
>>problem.

>
>
> $sql = "DELETE FROM 'users' WHERE 'user_name' =\'$user_name_delete\'";
> $result = mysql_query($sql, $conn);
> if(! $result || mysql_error($conn))
> {
> eho "Unable to delete user [$sql] : " . mysql_error($conn);
> }
>
> Always formulate your SQL quiries into a string, that way you can see what
> you are asking the database to do.
>
> Always test IO (input/output) operations for errors.
>
> You should see where your query is wrong.
>
> $sql = "DELETE FROM users WHERE user_name = '$user_name_delete'";
>
> Note that this is prone to abuse (SQL injection) so if you've not got magic
> quotes switched on you'll have to escape the $user_name_delete variable.
>
> $sql = sprintf("DELETE FROM users WHERE user_name = '%s'",
> addslashes($user_name_delete));


Thank you very much. That's the ticket.
Reply With Quote
  #7 (permalink)  
Old 01-22-2005
Andrew M.
 
Posts: n/a
Default Re: mysql and php5 deleting rows



Geoff Berrow wrote:

> I noticed that Message-ID: <5qeId.158387$Uf.12949@twister.nyroc.rr.com>
> from Andrew M. contained the following:
>
> I assume you are connecting to the database ok
>
>
>>//create the query
>>//$sql = "DELETE FROM 'users' WHERE 'user_name' =\'$user_name_delete\'";

>
> This line is redundant
>
>>//execute query
>>mysql_query ("DELETE FROM users WHERE user_name = $user_name_delete");

>
> Should work, provided $user_name_delete actually contains something.
> Where does it come from?
>

My problem was fixed as soon as I made it = '$user_name_delete' ");

Thanks for all the help.
Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT +1. The time now is 10:28 AM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0