SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    Old Fogey mancroft's Avatar
    Join Date
    Oct 2002
    Location
    lost
    Posts
    445
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Angry Data couldn't be entered into the database

    I am trying to get the database to work and it is generating the following error:

    POST Data couldn't be entered into the database

    from the code below.

    Two questions:

    1. does this mean that:

    $con = mysql_connect("localhost","mancroft","xxxx")

    and

    $db = mysql_select_db("$database")

    are working alright?

    2. what is wrong with:

    #lets strip some chars and slashes
    $name = stripslashes($name);
    $name = htmlspecialchars($name);
    $http = stripslashes($http);
    $http = htmlspecialchars($http);
    $msg = stripslashes($msg);
    $msg = htmlspecialchars($msg);

    $query = "INSERT INTO mytagboard(name,http,msg) VALUES('$name,$http,$msg')";

    $result = mysql_query($query)

    thanks.

    ................................................................................................



    <?php
    #change localhost to the sql server, user to the correct username, and pass to the correct

    password
    $con = mysql_connect("localhost","mancroft","xxxx") or die("Unable to establish a connection to the database.");

    #change database to the database name
    $database = "mancroft_tagboard";
    $db = mysql_select_db("$database") or die("Couldn't select database $database.");

    #lets strip some chars and slashes
    $name = stripslashes($name);
    $name = htmlspecialchars($name);
    $http = stripslashes($http);
    $http = htmlspecialchars($http);
    $msg = stripslashes($msg);
    $msg = htmlspecialchars($msg);

    $query = "INSERT INTO mytagboard(name,http,msg) VALUES('$name,$http,$msg')";

    $result = mysql_query($query) or die("POST Data couldn't be entered into the database.");

    echo "Click <a href='view.php'>here</a>.";
    ?>

  2. #2
    Happy Holidays !! Paul S's Avatar
    Join Date
    Mar 2001
    Location
    Mexico
    Posts
    1,287
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    To have a better idea, replace
    PHP Code:
    die("POST Data couldn't be entered into the database."); 
    with
    PHP Code:
    die(mysql_error()) 
    Paul

  3. #3
    Old Fogey mancroft's Avatar
    Join Date
    Oct 2002
    Location
    lost
    Posts
    445
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    error says:

    Column count doesn't match value count at row 1

    the sql syntax is:
    --sql syntax--
    CREATE TABLE tagboard (id TINYINT (4) not null AUTO_INCREMENT, name VARCHAR (32), msg VARCHAR (50), http VARCHAR (32) , PRIMARY KEY (id))

    the phpmyadmin table layout is:

    Field Type Attributes Null Default Extra Action
    id tinyint(4) No auto_increment Change Drop Primary Index Unique Fulltext
    name varchar(32) Yes NULL Change Drop Primary Index Unique Fulltext
    msg varchar(50) Yes NULL Change Drop Primary Index Unique Fulltext
    http varchar(32) Yes NULL Change Drop Primary Index Unique Fulltext



    thanks
    Last edited by mancroft; Oct 26, 2002 at 11:26.

  4. #4
    Happy Holidays !! Paul S's Avatar
    Join Date
    Mar 2001
    Location
    Mexico
    Posts
    1,287
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Here's the problem: in your query you wrote
    PHP Code:
    INSERT INTO mytagboard(name,http,msgVALUES('$name,$http,$msg'
    and it should be
    PHP Code:
    INSERT INTO mytagboard(name,http,msgVALUES('$name','$http','$msg'
    The problem was the quotes, if you write '$name,$http,$msg' then for mysql is single string and since you are trying to insert three fields this creates a fatal error.

    Paul

  5. #5
    Old Fogey mancroft's Avatar
    Join Date
    Oct 2002
    Location
    lost
    Posts
    445
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    thanks!


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
  •