SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Member
    Join Date
    Feb 2005
    Posts
    3
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question php/mysql - unwanted blank row...

    hello there,
    i've been trying to get this to work properly for hours now, but even after reducing the code to the bare minimum, i can't find what's wrong... maybe someone here can help me...
    i'm working with php and mysql. i have a page that is supposed to insert a row of text into the database from a form, which it happily does. the problem is that everytime TWO rows are inserted of which the first one is blank. here is the code:

    <?
    $username="username";
    $password="password";
    $database="database_name";

    $ins_content=$_POST['ins_content'];

    mysql_connect(localhost,$username,$password);
    @mysql_select_db($database) or die( "Unable to select database");

    $query = "INSERT INTO content (content_text) VALUES ('$ins_content')";
    mysql_query($query);

    mysql_close();
    echo "'$ins_content' written to database";
    ?>


    any ideas? please let me know.

  2. #2
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,215
    Mentioned
    58 Post(s)
    Tagged
    3 Thread(s)
    sounds like a php problem, not a mysql problem

    well, except for the fact that if you really are inserting "blank rows" then you have failed to declare the table properly
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"

  3. #3
    SitePoint Member
    Join Date
    Feb 2005
    Posts
    3
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Smile you're right...

    thanks for your reply. sometimes one is just looking in all the wrong places... like you said it was the php not mysql. the blank row got inserted when the page loaded. all it needed was a little if(){} statement... doh!
    cheers again - kabe243


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
  •