pcw Posted March 24, 2011 Share Posted March 24, 2011 Hi, I have this script which I would like to delete a column from a table. I cant seem to get it right although it gives no errors. case "deletefield": include_once("data/mysql.php"); $fieldName = $_GET['fieldName']; $mysqlPassword = (base64_decode($mysqlpword)); $con = mysql_connect("$localhost", "$mysqlusername", "$mysqlPassword") or die(mysql_error()); mysql_select_db("$dbname", $con) or die(mysql_error()); mysql_query("DELETE FROM profiles WHERE $fields = mysql_num_fields('$fieldName')"); mysql_close($con); header("Location: admin.php?cmd=profileFields&username=admin"); break; $fieldName is carried to the form correctly, I just cant work out the code for $fields = mysql_num_fields Any help is much appreciated Quote Link to comment Share on other sites More sharing options...
The Little Guy Posted March 25, 2011 Share Posted March 25, 2011 Try this: mysql_query("DELETE FROM profiles WHERE $fields = ".mysql_num_fields('$fieldName')); Quote Link to comment Share on other sites More sharing options...
pcw Posted March 26, 2011 Author Share Posted March 26, 2011 Hi, thanks for your reply. I tried this and now get these errors: Warning: mysql_num_fields(): supplied argument is not a valid MySQL result resource in /home/tropicsb/public_html/MemberSiteMaker/admin.php on line 621 Warning: Cannot modify header information - headers already sent by (output started at /home/tropicsb/public_html/MemberSiteMaker/admin.php:621) in /home/tropicsb/public_html/MemberSiteMaker/admin.php on line 624 thanks Quote Link to comment Share on other sites More sharing options...
The Little Guy Posted March 26, 2011 Share Posted March 26, 2011 Oops, I put quotes around $fieldName, you should remove them NVM still an error Quote Link to comment Share on other sites More sharing options...
PFMaBiSmAd Posted March 26, 2011 Share Posted March 26, 2011 A DELETE query will delete a ROW from your table. If you want to remove an actual column from your whole table, you would use an ALTER TABLE query. If you want to clear the value in a column in one or more rows in your table, you would use an UPDATE query. What exactly are you trying to accomplish? Quote Link to comment Share on other sites More sharing options...
pcw Posted March 27, 2011 Author Share Posted March 27, 2011 I am trying to remove an actual column from the profiles table, but am still having no luck Quote Link to comment Share on other sites More sharing options...
PFMaBiSmAd Posted March 27, 2011 Share Posted March 27, 2011 Check out the DROP COLUMN syntax at this link - http://dev.mysql.com/doc/refman/5.1/en/alter-table.html Quote Link to comment Share on other sites More sharing options...
pcw Posted March 27, 2011 Author Share Posted March 27, 2011 Hi PFMaBiSmAd, thanks very much for pointing me in the right direction, problem solved :-) mysql_query("ALTER table profiles DROP column $fieldName"); Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.