Page 1 of 2 12 Last
  • Jump to page:
    #1
  1. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Mar 2008
    Posts
    774
    Rep Power
    42

    query problem


    Hello, OK, I am getting nowhere with this query. Can someone point out my error? I have checked the variables and data numerous times.

    PHP Code:
    if (mysqli_query($con,"INSERT INTO become_distributor (id, first_name, last_name, email, phone, business_name, street, city, state, zip, years_in_business, document, document_changed_name, password, date_applied, questions_comments, approved)
    VALUES ('NULL', 
    $first_name$last_name,  $email$phone$business_name$street$city$state$zip$years_in_business,  $file_name$filename_new$password, 'NULL', $comments, 'NULL')");)===TRUE
    {

    echo 
    'succcess'
    thanks
    Last edited by Will-O-The-Wisp; June 15th, 2016 at 12:14 PM.
  2. #2
  3. No Profile Picture
    Super Moderator
    Devshed Intermediate (1500 - 1999 posts)

    Join Date
    Jun 2009
    Location
    Hartford, WI
    Posts
    1,563
    Rep Power
    112
    One place to start... You currently have this in your example: (With assumed closing curly)
    PHP Code:
    if(mysqli_query($con,"Query...");)===TRUE { echo 'success'; } 
    Do you see anything wrong there?
    He who knows not that he knows not is a fool, ignore him. He who knows that he knows not is ignorant, teach him. He who knows not that he knows is asleep, awaken him. He who knows that he knows is a leader, follow him.
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Mar 2008
    Posts
    774
    Rep Power
    42

    hello Triple_Nothing


    Not sure, as I am basically cutting and pasting code from tutorial sites, and replacing the variables.

    I've also tried:
    PHP Code:
    $con=mysqli_connect($host,$user,$pass,$db);
    // Check connection
    if (mysqli_connect_errno())
      {
      echo 
    "Failed to connect to MySQL: " mysqli_connect_error();
      }

    $sql="INSERT INTO become_distributor ('NULL', $first_name$last_name,  $email$phone$business_name$street$city$state$zip$years_in_business,  $file_name$filename_new$password, 'NULL', $comments, 'NULL')";
    if (
    $result=mysqli_query($con,$sql))
      {
      
    // Return the number of rows in result set
      
    $rowcount=mysqli_num_rows($result);
      
    printf("Result set has %d rows.\n",$rowcount);
      
    // Free result set 
    more code here, etc.

    But it doesn't work. I haven't worked in PHP for a while, but this should be simple, at least I thought it would be.
    thanks ; )
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Mar 2008
    Posts
    774
    Rep Power
    42
    No, I do not see what is wrong. I have trouble with the syntax in programming, not so much the logic, but I guess they go hand in hand.
    thanks
  8. #5
  9. No Profile Picture
    Contributing User
    Devshed Regular (2000 - 2499 posts)

    Join Date
    Apr 2009
    Posts
    2,233
    Rep Power
    1297
    Don't put the raw sql statement in the conditional. Instead, assign it to a variable and use that var in the conditional. This will allow you to output the statement if/when you need to troubleshoot its syntax and it will also make it easier to troubleshoot the syntax in the conditional. You should also add some vertical and horizontal whitespace to it to make it more readable and maintatinable.

    PHP Code:
    $sql "INSERT INTO become_distributor (id,
                                            first_name,
                                            last_name,
                                            email,
                                            phone,
                                            business_name,
                                            street,
                                            city,
                                            state,
                                            zip,
                                            years_in_business,
                                            document,
                                            document_changed_name,
                                            password,
                                            date_applied,
                                            questions_comments,
                                            approved)
            VALUES ('NULL',
                    
    $first_name,
                    
    $last_name,
                    
    $email,
                    
    $phone,
                    
    $business_name,
                    
    $street,
                    
    $city,
                    
    $state,
                    
    $zip,
                    
    $years_in_business,
                    
    $file_name,
                    
    $filename_new,
                    
    $password,
                    'NULL',
                    
    $comments,
                    'NULL')"

  10. #6
  11. No Profile Picture
    Super Moderator
    Devshed Intermediate (1500 - 1999 posts)

    Join Date
    Jun 2009
    Location
    Hartford, WI
    Posts
    1,563
    Rep Power
    112
    As per my example, what you have is:
    PHP Code:
    if($var)===TRUE { echo 'success'; } 
    while the intended would be:
    PHP Code:
    if($var === TRUE) { echo 'success'; } 
    The whole statement in question by the if() is to remain within the parenthesis.

    Now, if you were to echo the query to the page so you could copy/paste it to phpMyAdmin to run on your own, would the query have echo'ed correctly to the page? If yes, does it run just fine when pasted into phpMyAdmin? If not, it should help narrow down where your issue would be.
    He who knows not that he knows not is a fool, ignore him. He who knows that he knows not is ignorant, teach him. He who knows not that he knows is asleep, awaken him. He who knows that he knows is a leader, follow him.
  12. #7
  13. SQL Consultant
    Devshed Supreme Being (6500+ posts)

    Join Date
    Feb 2003
    Location
    Toronto Canada
    Posts
    27,795
    Rep Power
    4331
    i don't do php but i'm guessing your strings need to have single quotes around them

    change this --
    Code:
    VALUES ('NULL', $first_name, $last_name, $email, $phone ...
    to this --
    Code:
    VALUES (NULL, '$first_name', '$last_name', '$email', '$phone' ...
    note NULL is a reserved word so it ~doesn't~ get single quotes
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL
  14. #8
  15. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Mar 2008
    Posts
    774
    Rep Power
    42
    Hello, This should be so easy as I've done many times in the and this is a very basic form for PHP to process. None of my form fields are placed in the db, but the image gets uploaded to the server.

    Here is code::
    PHP Code:
    $sql "INSERT INTO become_distributor (id, 
                                            first_name, 
                                            last_name, 
                                            email, 
                                            phone, 
                                            business_name, 
                                            street, 
                                            city, 
                                            state, 
                                            zip, 
                                            years_in_business, 
                                            document, 
                                            document_changed_name, 
                                            password, 
                                            date_applied, 
                                            questions_comments, 
                                            approved) 
            VALUES (NULL, 
                    '
    $first_name', 
                    '
    $last_name', 
                    '
    $email', 
                    '
    $phone', 
                    '
    $business_name', 
                    '
    $street', 
                    '
    $city', 
                    '
    $state', 
                    '
    $zip', 
                    '
    $years_in_business', 
                    '
    $file_name', 
                    '
    $filename_new', 
                    '
    $password', 
                     'FROM_UNIXTIME("
    .$datestr.")',
                    '
    $comments', 
                    NULL)"
    ;  

    $status=mysqli_query($con$sql);

    if(
    $status==TRUE){
    echo 
    'succcess';
    echo 
    'result is $result';

    }
    elseif (
    $status==FALSE){
        echo 
    'status is FALSE';
    }
    else{
        echo 
    'nothing happened';

    Honestly have been working on this for hours. Have to get into the PHP zone again.

    Thanks for all the help, and let me know if you need more info.

    thanks
  16. #9
  17. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Mar 2008
    Posts
    774
    Rep Power
    42
    Oh, the result is "status is FALSE".
  18. #10
  19. SQL Consultant
    Devshed Supreme Being (6500+ posts)

    Join Date
    Feb 2003
    Location
    Toronto Canada
    Posts
    27,795
    Rep Power
    4331
    again, i don't do php, but shouldn't you be using three equals, not two?
    Code:
    if($status === TRUE)
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL
  20. #11
  21. Lord of the Dance
    Devshed Specialist (4000 - 4499 posts)

    Join Date
    Oct 2003
    Posts
    4,184
    Rep Power
    2012
    You should use mysqli_error($con) to see what goes wrong.
  22. #12
  23. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Mar 2008
    Posts
    774
    Rep Power
    42
    Oh, the result is "status is FALSE".

    also I have this code to check the connection::


    PHP Code:
    $con=mysqli_connect($host$user$pass$db);
    // Check connection
    if (mysqli_connect_errno())
      {
      echo 
    "Failed to connect to MySQL: " mysqli_connect_error();
      } 
  24. #13
  25. No Profile Picture
    Super Moderator
    Devshed Intermediate (1500 - 1999 posts)

    Join Date
    Jun 2009
    Location
    Hartford, WI
    Posts
    1,563
    Rep Power
    112
    Can you also provide us with an echo of $sql?
    He who knows not that he knows not is a fool, ignore him. He who knows that he knows not is ignorant, teach him. He who knows not that he knows is asleep, awaken him. He who knows that he knows is a leader, follow him.
  26. #14
  27. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Mar 2008
    Posts
    774
    Rep Power
    42
    OK, I'm getting "Error : (1064) You have an error in your SQL syntax;"
    I think is because the "@"in the email address.

    How do I echo the $sql?
  28. #15
  29. SQL Consultant
    Devshed Supreme Being (6500+ posts)

    Join Date
    Feb 2003
    Location
    Toronto Canada
    Posts
    27,795
    Rep Power
    4331
    FROM_UNIXTIME is a function -- if you wrap it in single quotes, it becomes a string
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL
Page 1 of 2 12 Last
  • Jump to page:

IMN logo majestic logo threadwatch logo seochat tools logo