The Way to Programming
The Way to Programming
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
define('TIMEZONE', 'Africa/Harare'); date_default_timezone_set(TIMEZONE); $ip = $_SERVER["REMOTE_ADDR"]; $post_time = date("U"); $mxitua = $_SERVER["HTTP_X_DEVICE_USER_AGENT"]; $mxitcont = $_SERVER["HTTP_X_MXIT_CONTACT"]; $mxituid = $_SERVER["HTTP_X_MXIT_USERID_R"]; $mxitid = $_SERVER["HTTP_X_MXIT_ID_R"]; $mxitlogin = $_SERVER["HTTP_X_MXIT_LOGIN"]; $mxitnick = $_SERVER["HTTP_X_MXIT_NICK"]; $mxitloc = $_SERVER["HTTP_X_MXIT_LOCATION"]; $mxitprof = $_SERVER["HTTP_X_MXIT_PROFILE"]; if(!isset($mxitid)) { $mxitid = "DEFAULT"; } 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)"); mysqli_close($con); ?>
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…
ok the error message is gone but no records were added to my database…
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."')");
In PHP it is advantageous to use single quotes (‘) over double quotes (“) as you can insert variables within single quotes per se
Sign in to your account