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 ...
|
|||||||
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
|
|||
|
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 |
|
|||
|
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. |
|
|||
|
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/ |
|
|||
|
"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)); |
|
|||
|
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. |
|
|||
|
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. |