SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Evangelist GeekSupport's Avatar
    Join Date
    May 2002
    Location
    Southern California
    Posts
    408
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    mysql_query problems with INSERT INTO SET

    PHP Code:
        $sqlq "INSERT INTO survey SET
                name='
    $title',
                desc='
    $desc',
                rel_uid='
    $user',
                state='
    $state',
                start='
    $start',
                end='
    $end'";
        
        
        
    //mysql_query($sqlq);

        
    if(@mysql_query($sqlq)) 
        { 
            echo(
    "your entry has been added."); 
        }
        else
        { 
            echo(
    "Error"); 
        } 
        echo 
    mysql_affected_rows(); 
    can anyone see what i did wrong? affected rows displays -1 and i have included my common_db.inc.php file to make sure it connects to the db. i can do SELECT queries fine and the login/pass user in my common_db.inc.php file is the dba.

    looks like 2 of my fields (desc & end) are keywords for mysql. how do i escape them? i've already tried quoting them and putting a leading \ but both didn't work. i like the set way of doing things cause it's easier to follow than the (fields, in, here) values (values, over, there)
    Last edited by GeekSupport; Sep 18, 2002 at 16:56.

  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)
    Replace the line echo("Error"); with echo mysql_error(); and post the error message here.

    Paul

  3. #3
    SitePoint Evangelist GeekSupport's Avatar
    Join Date
    May 2002
    Location
    Southern California
    Posts
    408
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You have an error in your SQL syntax near 'desc='Description of survey', rel_uid='4', state='0', start='2002-02-' at line 3

    hmm, i wonder why start= doesnt show the whole value. when i echo out the $sqlq, it shows

    INSERT INTO survey SET name='This is the title here', desc='Description of survey', rel_uid='4', state='0', start='2002-02-02', end='2002-03-03'

    (state will be used to determine state of survey: either enabled or disabled 1/0)
    Last edited by GeekSupport; Sep 18, 2002 at 17:05.

  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)
    The problem is that DESC is a reserved word in mysql. You have to rename that column
    Code:
    ALTER TABLE survey CHANGE DESC NEW_COLUM_NAME COLUMN_DEFINITION
    Edit:

    Wrong sql command


    Paul
    Last edited by Paul S; Sep 18, 2002 at 17:13.

  5. #5
    SitePoint Evangelist GeekSupport's Avatar
    Join Date
    May 2002
    Location
    Southern California
    Posts
    408
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    DoH!

    thanks. i'll rename that field

    Edit:


    yep, that did the trick


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
  •