Freedom-n-Democrazy Posted September 10, 2011 Share Posted September 10, 2011 I have a table called "newsletters": +----------------+------+--------+ | email | mens | womens | +----------------+------+--------+ | test1@test.com | 0 | 1 | | test2@test.com | 1 | 1 | +----------------+------+--------+ What I want to do is make it so after PHP unregisters a user, it checks the database to see if they are signed up to any other newsletters, and if they arn't, then to delete the key (email) from the table: Unregistering an e-mail address from the mens newsletter would go something along the lines of this: $query = "INSERT INTO newsletters(email, mens) VALUES('$email', 0) ON DUPLICATE KEY UPDATE mens = 0"; if (MySQL table newsletters(email == $email + womens == 0) { $query = "delete from testdb.newsletters where email='$email'"; } This is the line where I need PHP to check, the rest of the code is fine. This line is made up - to give an idea of what I'm trying to do. if (MySQL table newsletters(email == $email + womens == 0) { Quote Link to comment Share on other sites More sharing options...
Cagecrawler Posted September 10, 2011 Share Posted September 10, 2011 $newsletters = mysql_assoc(mysql_query("SELECT mens, womens FROM newsletters WHERE email = '$email' LIMIT 1")); if($newsletters['mens'] == 0 && $newsletters['womens'] == 0){ Quote Link to comment Share on other sites More sharing options...
Freedom-n-Democrazy Posted September 10, 2011 Author Share Posted September 10, 2011 Thanks bro! Is there an easier way to write it? Quote Link to comment Share on other sites More sharing options...
Cagecrawler Posted September 10, 2011 Share Posted September 10, 2011 It's only two lines, it's about as simple as you can get it... And I made a typo - the function is mysql_fetch_assoc, not mysql_assoc. Quote Link to comment Share on other sites More sharing options...
Freedom-n-Democrazy Posted September 10, 2011 Author Share Posted September 10, 2011 ah huh! So thats why it wasn't working. Thanks for your help bro. Where did you learn PHP? Almost all of my PHP has been learn't off talking with people like you from forums, but I would rather be able to read from a book, or quality documentation or something, so I don't have to depend on forums so much. Quote Link to comment Share on other sites More sharing options...
redarrow Posted September 10, 2011 Share Posted September 10, 2011 you learn php from loads of web sites. Popular web site. http://www.w3schools.com/php/ Then the manual http://php.net/manual/en/index.php the rest come naturally. also study. mysql. xhtml.<<<< properly html. ajax. javascript. css <<<< properly Quote Link to comment Share on other sites More sharing options...
Cagecrawler Posted September 10, 2011 Share Posted September 10, 2011 Don't use w3schools. The information is quite often out of date (they still list .php3 as a php file extension) or just plain wrong. If you really want a beginner site like that, I'd recommend Tizag but the first sections of the manual explain the syntax pretty well. As for the list of other things to learn, xhtml is dead. Use html5, that's where the standard is going. Also, ajax is javascript. The best way to learn is to practice. Write a script for any problem you have, whether it's organising your music collection or grabbing the latest tweets. Quote Link to comment Share on other sites More sharing options...
redarrow Posted September 10, 2011 Share Posted September 10, 2011 html5 is based on canvas for videos and media files <> browser compatibility will take years.(nothing wrong learning html and then xhtml) xhtml is not dead, that stupid, it a extension of html, and html is the back bone of the internet. also You can learn ajax without learning all the aspects of JavaScript, even thu javascript is the backbone of ajax but you just learn the DOM and basics. w3schools , show you example with a .php3, because the internal workings of the script that is used on w3schools, is configured to see .php3 as normal .php files. There currently running 5.8 php system there no code on w3school that wrong and is cheeked frequently even universities use that web site. Quote Link to comment Share on other sites More sharing options...
voip03 Posted September 10, 2011 Share Posted September 10, 2011 About w3school http://w3fools.com/ Quote Link to comment Share on other sites More sharing options...
voip03 Posted September 10, 2011 Share Posted September 10, 2011 Buy a good PHP text book , that will be your PHP bible for some time. eg. Practical PHP & MySQL 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.