Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    New Coder
    Join Date
    Jan 2011
    Posts
    36
    Thanks
    5
    Thanked 0 Times in 0 Posts

    php/mysql insert..not inserting

    I just started having an issue with a script that was working before and now its not.. and I'm not so certain its the script that's not working. In the script I execute two insert statements (that insert into two different tables), which previously worked.. Now only one gets inserted while the other does not. I've thoroughly looked over the code and there is nothing wrong with it. Is there anything in my database that could be causing this to happen. I'm just very upset and lost on this, because I really dont understand why one insert statement is working and the other is not.

    PHP Code:
    //gather user information
    $query=mysql_query("SELECT * FROM users WHERE id='$_SESSION[id]'");
    while(
    $infomysql_fetch_assoc($query)){
    $name $info['name'];    
    $pic $info['propic'];    
    $realm $info['realm'];    
        
    }

    if(empty(
    $detail)){
    header('Location:error9.php');
    }
    elseif(isset(
    $detail)){
    //this is the one not inserting
    mysql_query("INSERT INTO classifieds VALUES ('','$_SESSION[id]','$name','$pic','$realm','$topic','$detail',now())");
    //this one inserts
    mysql_query("INSERT INTO activity VALUES ('$_SESSION[id]','$name','$txt',now())");    
    }
    header('Location:edit.php'); 
    I completely redid the form associated with the script and i completely redid the form associated with this script and made the appropriate changes in my code and redid the table in my database.
    Last edited by SweetG; 05-11-2011 at 09:44 PM. Reason: forgot to include code

  • #2
    New Coder
    Join Date
    Jan 2011
    Posts
    36
    Thanks
    5
    Thanked 0 Times in 0 Posts
    I added the code, I forgot to put it in when I posted.. sorry

  • #3
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,441
    Thanks
    76
    Thanked 4,372 Times in 4,337 Posts
    So did you *TRY* that query in a MySQL tool? Without using PHP?

    And why don't you have any error detection in your PHP code? Or debugging capability, either?

    At a minimum, you could do this:
    Code:
    $sql = "INSERT INTO classifieds VALUES ('','$_SESSION[id]','$name','$pic','$realm','$topic','$detail',now())";
    
    // echo the sql so you can try it via some tool, instead of in PHP
    echo "DEBUG SQL: " . $sql . "<hr>"; // you can comment this out after it starts working
    
    mysql_query( $sql ) or die( ... );
    Put something in the die() that tells you what the error was.

    The first thing that occurs to me is that, because you do *NOT* give a list of field names in you INSERT, you may have changed your classifieds table (added or removed a field?) so that you have the wrong number of fields being inserted. But there are other possible errors and until you debug you won't know.
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • #4
    New Coder
    Join Date
    Jan 2011
    Posts
    36
    Thanks
    5
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by Old Pedant View Post
    So did you *TRY* that query in a MySQL tool? Without using PHP?

    And why don't you have any error detection in your PHP code? Or debugging capability, either?

    At a minimum, you could do this:
    Code:
    $sql = "INSERT INTO classifieds VALUES ('','$_SESSION[id]','$name','$pic','$realm','$topic','$detail',now())";
    
    // echo the sql so you can try it via some tool, instead of in PHP
    echo "DEBUG SQL: " . $sql . "<hr>"; // you can comment this out after it starts working
    
    mysql_query( $sql ) or die( ... );
    Put something in the die() that tells you what the error was.

    The first thing that occurs to me is that, because you do *NOT* give a list of field names in you INSERT, you may have changed your classifieds table (added or removed a field?) so that you have the wrong number of fields being inserted. But there are other possible errors and until you debug you won't know.
    thanks for the debugging thing, i found out exactly what is was.. it was a user submitted ' that was screwing it all up. i think I can fix that

  • #5
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,441
    Thanks
    76
    Thanked 4,372 Times in 4,337 Posts
    mysql_real_escape_string()
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.


  •  

    Posting Permissions

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