Jump to content

Freedom-n-Democrazy

Members
  • Posts

    295
  • Joined

  • Last visited

    Never

Everything posted by Freedom-n-Democrazy

  1. I tried the following, but I still got the same error: if ($_POST['action']) == 'Register' { if ($_POST['action'] == 'Register') {
  2. I see what you mean. Is this correct?: if $_POST['action'] == 'Register' { ... should actually be: if ($_POST['action']) == 'Register' {
  3. Previously, the PHP codebase I was using was that written by others, and I used their code to tinker with so I could get an understanding how PHP works. Now that I am comfortable using PHP, I have written my own short PHP script from scratch with the aim of it seeing my newsletter system functioning at minimal, for the first time. The newsletters system is made with HTML/PHP/MySQL. I am having a problem with the PHP side of things where I am getting an error: ... which is: if $_POST['action'] == 'Register' { I am hoping someone that knows allot about PHP could take a look at my code and see whats wrong with it? PHP code within confirm.html: <?php $link = mysql_connect('localhost', 'testusr', 'testpw'); mysql_select_db('testdb', $link); $email = $_POST['e-mail']; $query = if $_POST['action'] == 'Register' { if $_POST['newsletter'] == 'Mens' { "INSERT INTO newsletters(mens) VALUES('$email')"; } elseif $_POST['newsletter'] == 'Mens & Womens' { "INSERT INTO newsletters(mensandwomens) VALUES('$email')"; } elseif $_POST['newsletter'] == 'Womens' { "INSERT INTO newsletters(womens) VALUES('$email')"; } ;} mysql_query ($link, $query); mysql_close($link); ?> HTML FORM code within index.html: <FORM action="confirm.html" method="post"> <DIV> <SPAN class="input"> Action: <SELECT name="action"> <OPTION>Register</OPTION> <OPTION>Unregister</OPTION> </SELECT>&nbsp&nbsp&nbsp E-mail: <INPUT name="e-mail" type="text"></INPUT>&nbsp&nbsp&nbsp Newsletter: <SELECT name="newsletter"> <OPTION>Mens</OPTION> <OPTION>Mens & Womans</OPTION> <OPTION>Womens</OPTION> </SELECT>&nbsp&nbsp&nbsp <INPUT class="submit" type="submit" value="Submit"> </SPAN> </DIV> </FORM>
  4. Good afternoon guys, I used this code, and get the error "Error: Query was empty". I've gone over and over it, but can't figure out whats going wrong. Can you guys see any problem in it?? <?php $link = mysql_connect('localhost', 'testusr', 'testpw'); if (!$link) { die('Could not connect: ' . mysql_error()); } echo 'Connected successfully'; mysql_select_db('testdb', $link); if ($_SERVER['REQUEST_METHOD'] == 'POST') { if (isset($_POST['action']) && $_POST['action'] == 'register') { if (isset($_POST['newsletter']) && ($_POST['newsletter'] == 'mens' || $_POST['newsletter'] == 'mensandwomens' || $_POST['newsletter'] == 'womens')) { $email = mysql_real_escape_string($_POST['e-mail']); if ($_POST['newsletter'] == 'mens') { $sql = "INSERT INTO newsletters(mens) VALUES('$email')"; } elseif ($_POST['newsletter'] == 'mensandwomens') { $sql = "INSERT INTO newsletters(mensandwomens) VALUES('$email')"; } elseif ($_POST['newsletter'] == 'womens') { $sql = "INSERT INTO newsletters(womens) VALUES('$email')"; } } } } if (!mysql_query($sql,$link)) { die('Error: ' . mysql_error()); } echo 'Done!'; mysql_close($link); ?>
  5. Fuck. This thread is trashed. I made a mistake in my last post. I will start a new post tomorrow after I have slept, and I will write it up well. MOD please lock this thread.
  6. I'm going to have three newsletters, does this mean I would write: if(isset($_POST['newsletter']) && ($_POST['newsletter'] == 'mens' || $_POST['newsletter'] == 'womens')) || $_POST['newsletter'] == 'mensandwomens')) { $email = mysql_real_escape_string($_POST['email']); if($_POST['newsletter'] == 'mens') { $sql = "INSERT INTO newsletters(mens) VALUES('$email')" } if { $sql = "INSERT INTO newsletters(womens) VALUES('$email')" } if { $sql = "INSERT INTO newsletters(mensandwomens) VALUES('$email')" } Also, must you use "else" if its the last instruction, or is "if" fine?
  7. Ah huh! Read it a few times over. I now see how it works. Thank you very much. Now I see how it works, I can build the full PHP will all entries. You mentioned validate e-mail. I do want this, but I fear it will be too time consuming for me to learn how to do it. Is it very hard?
  8. Hi, Thanks for your reply. Is there an easier way to do it? I know I can simply cut and copy that code, but I want to learn whats going on.. That code you write is confusing as hell as its introduced all of these elements I've never heard of before. EDIT: I'm new to PHP.
  9. Hi all, I am making a newsletter sign up system and needing a little help with the PHP side of things. The HTML code I am about to quote is a stripped back version of what I am trying to do (keeping it simple for the thread). HTML code: PHP code: I know the HTML part is fine, but its the PHP code where I am making the mistakes. I think I am treating it too much like Python. What am I doing wrong?
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.