• MySQLI and php problem in inserting unique info retrieved to database

    Maxim6m0cj Member

    Hi I’m trying to insert unique info retrieved to my database but seems like I’m doing something wrong with my quary my current setup is as follow:

    mxit.php

    
    
     
    

    and i’ve included the above file on my index.php

    
    

    but after I’ve opened up my index page I get an error

    Warning: mysqli_query(): Couldn't fetch mysqli in /home/vol1_1/mzzhost.com/mzzho_15247412/htdocs/try/mxit.php on line 44
    
    Warning: mysqli_close(): Couldn't fetch mysqli in /home/vol1_1/mzzhost.com/mzzho_15247412/htdocs/try/mxit.php on line 45
    

    And another question is how can I check the field contact in my databases and if the name already exists not to add the record to my database? Since I don’t want duplicate records…

  • Abhey Member

    Right after opening the connection to the db, you close it at line: 11
    So you can’t use it anymore. Remove the line 11:

    mysqli_close($con);
    
  • BuckRenard Member

    ok the error message is gone but no records were added to my database…

  • Abhey Member

    There is probably an error with your query.
    I guess it is because you don’t quote the text values you supply to the query.
    For example, the insert should be something like:

    mysqli_query($con,"INSERT INTO mxit (ip,time,user_agent,contact,userid,id,login,nick,location,profile) VALUES ('".$ip."','".$post_time."','".$mxitua."','".$mxitcont."','".$mxituid."','".$mxitid."','".$mxitlogin."','".$mxitnick."','".$mxitloc."','".$mxitprof."')");
    
  • BuckRenard Member

    In PHP it is advantageous to use single quotes (‘) over double quotes (“) as you can insert variables within single quotes per se

Viewing 4 reply threads
  • You must be logged in to reply to this topic.
en_USEnglish