Results 1 to 4 of 4

Thread: MySql error message, please help

  1. #1
    Join Date
    Feb 2008
    Location
    Melbourne, Australia
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default MySql error message, please help

    I am new to programming and typed out an exercise in a book and ended up with the following error message Incorrect integer value "for colum 'id' at row 1. Could someone please explain to me what this means.

  2. #2
    Join Date
    May 2006
    Location
    Sydney, Australia - Near the coast.
    Posts
    1,995
    Thanks
    0
    Thanked 8 Times in 7 Posts

    Default

    PLEASE: Include the URL to your problematic webpage that you want help with.
    Peter - alotofstuffhere[dot]com - Email Me - Donate via PayPal - Got spare hardware? Donate 'em to me :) Just send me a PM.
    Currently: enjoying the early holidays :)
    Read before posting: FAQ | What you CAN'T do with JavaScript | Form Rules | Thread Title Naming Guide

  3. #3
    Join Date
    Feb 2008
    Location
    Melbourne, Australia
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Thanks heaps. I am working locally on my computer and provide you with the code from the book I'm working with.


    Code:
    <?php
    //set up a couple of functions
    function doDB(){
    	global $conn;
    	//connect to sever and select database; you may need it
    	$conn = mysql_connect("localhost", "username", "password")
    		or die(mysql_error());
    	mysql_select_db("testDB",$conn) or die(mysql_error());
    }
    
    function emailChecker($email){
    	global $conn, $check_result;
    	//check the 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]')";
    		$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 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
    		$id = mysql_result($check_result, 0, "id");
    		$sql = "delete from subscribers where id = '$id'";
    		$result = mysql_query($sql,$conn) or die(mysql_error());
    		$display_block = "<p>You're unsubscribed!</p>";
    	}
    }
    ?>
    <HTML>
    <HEAD>
    <TITLE>Subscribe/Unsubscribe</TITLE>
    </HEAD>
    <BODY>
    <h1>Subscribe/Unsubscribe</h1>
    <?php echo "$display_block"; ?>
    </BODY>
    </HTML>
    Edit: Removed mysql user info and added code tags. Please never post your login info in any code snippet and post your code in [CODE] tags.
    Last edited by thetestingsite; 02-25-2008 at 04:03 PM.

  4. #4
    Join Date
    Jul 2006
    Location
    just north of Boston, MA
    Posts
    1,806
    Thanks
    13
    Thanked 72 Times in 72 Posts

    Default

    Welcome to the forums...

    when posting code please use the [code][/code] tags, and also you shouldn't display your user name / password to connect to your database... that is a major security hole. A malicious user could search for this page then hack into your system.


    now regarding your question, it appears like you may have not assigned the id field as an integer data type?

    the other thing could be
    $sql = "insert into subscribers values('','$_POST[email]')";
    if you were trying to activate the auto-increment ?? id and just insert the email, you should use a different query. that query is trying to assign an empty string to the that id field. If that field is labeled as an integer correctly and/or it is a primary key, that could be where your error is occurring... try
    Code:
    $sql = "INSERT INTO subscribers(email) VALUES('$_POST[email]')";
    Edit: Removed note to moderators about removing user info in code snippet
    Last edited by thetestingsite; 02-25-2008 at 04:02 PM.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •