Lambert Posted March 2, 2007 Share Posted March 2, 2007 Hello, I'm a newbie in PHP and in this forum. When I run my PHP code, my browser shows me an error message "Out of range value adjusted for column 'id' at row 1". I searched the results by this keyword in this forum. But, my PHP knowledge is not enough to understand what's wrong. The code I wrote is below: <? //Set up a couple of functions function doDB() { global $conn; //connect to server and select database; you may need it $conn = mysql_connect("localhost", "root", "1234") or die(mysql_error()); mysql_select_db("mydatabase1", $conn) or die(mysql_error()); } function emailChecker($email) { global $conn, $check_result; //check that email is not already in list $check = "select id from subscribers where email = '$email'"; $check_result = mysql_query($check, $conn) or die(mysql_error()); } //determine if they need to see the form or not if ($_POST[op] != "ds") { //they do, so create form block $display_block = " <form method = POST action =\"$_SERVER[php_SELF]\"> <p><strong>Your E-mail Address: </strong><br> <input type = text name =\"email\" size = 40 maxlength = 150> <p><strong>Action: </strong><br> <input type = radio name = \"action\"value = \"sub\" checked>Subscribe <input type = radio name = \"action\"value = \"unsub\">Unsubscribe <input type = \"hidden\" name =\"op\"value = \"ds\"> <p><input type = submit name = \"Submit\" value = \"Submit Form\"></p> </form>"; } else if (($_POST[op] == "ds") && ($_POST[action] == "sub")) { //trying to subscribe; validate email address if ($_POST[email] == "") { header("Location: manage.php"); exit; } //connect to database doDB(); //check that email is in list emailChecker($_POST[email]); //get number of results and do action if (mysql_num_rows($check_result) < 1) { //add record $sql = "insert into subscribers values('', '$_POST[email]')"; echo mysql_error(); $result = mysql_query($sql, $conn) or die(mysql_error()); $display_block = "<p>Thanks for signing up!</p>"; } else { //print failure message $display_block = "<p>You're already subscribed!</p>"; } } else if (($_POST[op] == "ds") && ($_POST[action] == "unsub")) { //trying to unsubscribe; validate email address if ($_POST[email] == "") { header("Location: manage.php"); exit; } //connect to database doDB(); //check that email is in list emailChecker($_POST[email]); //get number of results and do action if (mysql_num_rows($check_result) < 1) { //print failure message $display_block = "<p>Couldn't find your address!</p> <p>No action was taken.</p>"; } else { //unsubscribe the address echo $id = mysql_result($check_result, 0, "id"); //$sql = "delete from subscriber where id = '$id'"; //$result = mysql_query($sql); //$display_block = "<p>You are unsubscribed!</p>"; } } ?> <html> <head> <title>Subscribe/Unsubscribe</title> </head> <body> <h1>Subscribe/Unsubscribe</h1> <? echo "$display_block"; ?> </body> </html> If, you could help me in this code and show me what is wrong, I will be thankful. Quote Link to comment Share on other sites More sharing options...
monk.e.boy Posted March 2, 2007 Share Posted March 2, 2007 Make a new PHP file with just the bug in it (minimal HTML + PHP) - then it'll be easier for us to help you. monk.e.boy Quote Link to comment Share on other sites More sharing options...
itsmeArry Posted March 2, 2007 Share Posted March 2, 2007 and also do post the database structure... 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.