If action = Remove , you look up (1 on 1 web hosting) the
If action = Remove , you look up the user ID in the ml_users database. If you find a user id, you pass that ID on to remove.php, along with the mailing list id. Your job is done, so you redirect the user to remove.php. case Remove : $sql = SELECT user_id FROM ml_users . WHERE email= . $_POST[ email ] . ; $result = mysql_query($sql, $conn); if (mysql_num_rows($result)) { $row = mysql_fetch_array($result); $user_id = $row[ user_id ]; $url = http:// . $_SERVER[ HTTP_HOST ] . dirname($_SERVER[ PHP_SELF ]) . /remove.php?u= . $user_id . &ml= . $_POST[ ml_id ]; header( Location: $url ); exit(); } $redirect = user.php ; break; Note the exit() function immediately following header(). This is important, so the rest of the page is not loaded. The end of each case statement contains a break so that the rest of the case statements are not executed. If the user clicks the Subscribe button, a number of things have to happen. First, you must look up the e-mail address that was provided to see if the user already exists: case Subscribe : $sql = SELECT user_id FROM ml_users . WHERE email= . $_POST[ email ] . ; $result = mysql_query($sql, $conn); If the user does not exist (no rows were returned from your query), you will insert a new record in the ml_users table. MySQL automatically assigns a user id. if (!mysql_num_rows($result)) { $sql = INSERT INTO ml_users . (firstname,lastname,email) . VALUES ( . $_POST[ firstname ] . , . . $_POST[ lastname ] . , . . $_POST[ email ] . ) ; $result = mysql_query($sql, $conn); To retrieve that user id, use the PHP function mysql_insert_id. The variable $conn is optional, but it s usually a good idea to include it. If you omit it, it will automatically use the last open connection. The mysql_insert_id function will return a valid value only if the last SQL statement run resulted in a column being automatically incremented. In this case that did happen the column is user_id, which is the value you need for the next part of your code. $user_id = mysql_insert_id($conn); 506 Chapter 14
In case you need affordable webhost to host your website, our recommendation is ecommerce web host services.