SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    And your point is.... redgoals's Avatar
    Join Date
    Feb 2002
    Location
    Birmingham, UK
    Posts
    496
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Angry null values being entered into DB

    im getting null values being entered in the article column, well actually they are "0" values.

    heres the code:

    <?
    if($submit)
    {
    mysql_connect("localhost","user","pass");
    mysql_select_db("dbname");
    $result=MYSQL_QUERY("INSERT INTO news (cat,title,article)".
    "VALUES ('$cat', '$title', article='".addslashes( $article )."')");
    print "<p>added<a href=\"javascript:history.go(-1)\">Return</a>";
    }

    else
    {
    ?>


    here is the DB table setup:

    id int(11) NOT NULL auto_increment,
    cat varchar(20) NOT NULL default '',
    article blob NOT NULL,
    title varchar(255) NOT NULL default '',
    date timestamp(14) NOT NULL,
    PRIMARY KEY (id),
    UNIQUE KEY date (date)


    i reckon its something to do with the addslashes function, i got that from someone on these forums.

    btw, if i change:

    "VALUES ('$cat', '$title', article='".addslashes( $article )."')");

    to:

    "VALUES ('$cat', '$title', '$article')");

    the article will not add to the table.

    any ideas?
    http://redgoals.com ... my site ... nuff said

  2. #2
    Action! filmfoto's Avatar
    Join Date
    Dec 2001
    Location
    Sweden
    Posts
    278
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I would change the article column in your table setup to text, and not use blob. Blob is for binary data. Have a look here.





    Cheers.

  3. #3
    And your point is.... redgoals's Avatar
    Join Date
    Feb 2002
    Location
    Birmingham, UK
    Posts
    496
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Angry it didnt work

    i changed the article column to text but no luck.

    i still get "0's" in the article column

    any ideas?
    http://redgoals.com ... my site ... nuff said

  4. #4
    Action! filmfoto's Avatar
    Join Date
    Dec 2001
    Location
    Sweden
    Posts
    278
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Re: null values being entered into DB

    Originally posted by redgoals
    $result=MYSQL_QUERY("INSERT INTO news (cat,title,article)".
    "VALUES ('$cat', '$title', article='".addslashes( $article )."')");
    Try changing this to:
    PHP Code:
    $article addslashes($article);
    $sql "INSERT INTO news (cat, article, title) VALUES ($cat$article$title)";
    $result=MYSQL_QUERY($sql); 
    Hope this helps.





    Cheers.

  5. #5
    And your point is.... redgoals's Avatar
    Join Date
    Feb 2002
    Location
    Birmingham, UK
    Posts
    496
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Angry can insert a row now

    even with or without a ' it still does not enter a row.

    stumped
    http://redgoals.com ... my site ... nuff said

  6. #6
    And your point is.... redgoals's Avatar
    Join Date
    Feb 2002
    Location
    Birmingham, UK
    Posts
    496
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    oops you missed the single quotes around the values,
    it works now, cheers mate.
    http://redgoals.com ... my site ... nuff said


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
  •