Stuart_Westgate Posted May 14, 2013 Share Posted May 14, 2013 I have the following code set up to insert data into my table. This is just a test to see if it will work before I go further into development. I know I'm able to connect to my data as I have a message appear when that happens, but it won't insert data into the table for some reason. $phoneNumber = "0786352373"; $firstName = "jennifer"; $lastName = "dunne"; $profilePicture = ""; $photo = ""; $video = ""; $text = "text is here yes yes eys"; $call = "call is here yes yes eys"; $activity = "this is jennifers activity"; $latitude = "-50.889473"; $longitude = "3.845738"; $date = "23/05/2012"; $time = "13:29"; $sql = "INSERT INTO member (phoneNumber, firstName, lastName, profilePicture, photo, video, text, call, activity, latitude, longitude, data, time) "; $sql .= "VALUES ('$phoneNumber', '$firstName', '$lastName', '$profilePicture', '$photo', '$video', '$text', '$call', '$activity', '$latitude', '$longitude', '$data', '$time')"; if (!mysqli_query($sql, $con)) { die('Error: ' . mysqli_error()); } else { echo "Comment added"; } mysqli_close($con); I do get an error message come up, but all it says is the following and doesn't shine light on the situation at all. Error: I'm very new to mysql and always seem to struggle with it but want to get over my fear of it. :-) Quote Link to comment Share on other sites More sharing options...
trq Posted May 14, 2013 Share Posted May 14, 2013 You need to pass $conn to mysqli_error() so that it will work. You might want to turn error reporting on also because not passing $conn to mysqli_error() should have generated a php error. Quote Link to comment Share on other sites More sharing options...
Stuart_Westgate Posted May 14, 2013 Author Share Posted May 14, 2013 I've changed this line: die('Error: ' . mysqli_error()); to die('Error: ' . mysqli_error($con)); and I'm still getting no errors. I've tried to run this on localhost and on my server. On the server I get the Error: message and on localhost I get nothing at all (Which is strange) I've looked into my PHP.ini folder and the error settings are the following (Do I need to change any?) ;;;;;;;;;;;;;;;;;;; ; Quick Reference ; ;;;;;;;;;;;;;;;;;;; ; The following are all the settings which are different in either the production ; or development versions of the INIs with respect to PHP's default behavior. ; Please see the actual settings later in the document for more details as to why ; we recommend these changes in PHP's behavior. ; allow_call_time_pass_reference ; Default Value: On ; Development Value: Off ; Production Value: Off ; display_errors ; Default Value: On ; Development Value: On ; Production Value: Off ; display_startup_errors ; Default Value: Off ; Development Value: On ; Production Value: Off ; error_reporting ; Default Value: E_ALL & ~E_NOTICE & ~E_STRICT & ~E_DEPRECATED ; Development Value: E_ALL ; Production Value: E_ALL & ~E_DEPRECATED & ~E_STRICT ; html_errors ; Default Value: On ; Development Value: On ; Production value: Off ; log_errors ; Default Value: Off ; Development Value: On ; Production Value: On ; magic_quotes_gpc ; Default Value: On ; Development Value: Off ; Production Value: Off ; max_input_time ; Default Value: -1 (Unlimited) ; Development Value: 60 (60 seconds) ; Production Value: 60 (60 seconds) ; output_buffering ; Default Value: Off ; Development Value: 4096 ; Production Value: 4096 ; register_argc_argv ; Default Value: On ; Development Value: Off ; Production Value: Off ; register_long_arrays ; Default Value: On ; Development Value: Off ; Production Value: Off ; request_order ; Default Value: None ; Development Value: "GP" ; Production Value: "GP" ; session.bug_compat_42 ; Default Value: On ; Development Value: On ; Production Value: Off ; session.bug_compat_warn ; Default Value: On ; Development Value: On ; Production Value: Off ; session.gc_divisor ; Default Value: 100 ; Development Value: 1000 ; Production Value: 1000 ; session.hash_bits_per_character ; Default Value: 4 ; Development Value: 5 ; Production Value: 5 ; short_open_tag ; Default Value: On ; Development Value: Off ; Production Value: Off ; track_errors ; Default Value: Off ; Development Value: On ; Production Value: Off ; url_rewriter.tags ; Default Value: "a=href,area=href,frame=src,form=,fieldset=" ; Development Value: "a=href,area=href,frame=src,input=src,form=fakeentry" ; Production Value: "a=href,area=href,frame=src,input=src,form=fakeentry" ; variables_order ; Default Value: "EGPCS" ; Development Value: "GPCS" ; Production Value: "GPCS" Quote Link to comment Share on other sites More sharing options...
mac_gyver Posted May 14, 2013 Share Posted May 14, 2013 also, for mysqli_query(), the connection is the first parameter. The query is the second parameter. are you sure you are making a mysqli connection or is it a mysql connection? Quote Link to comment Share on other sites More sharing options...
Stuart_Westgate Posted May 14, 2013 Author Share Posted May 14, 2013 I'm making the connection I know this because I have a message appearing that tell me this plus I'm able to read data I already have in the database from another php page that is coded the same. I'm getting errors now after switching $sql and $con around. This is the error I'm getting: Error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '', 'dunne', '', '', '', 'text is here yes yes eys', 'callData is here yes yes ey' at line 1 Quote Link to comment Share on other sites More sharing options...
jazzman1 Posted May 14, 2013 Share Posted May 14, 2013 (edited) CALL is a mysql reserved word. Edited May 14, 2013 by jazzman1 Quote Link to comment Share on other sites More sharing options...
Stuart_Westgate Posted May 14, 2013 Author Share Posted May 14, 2013 Sorry, I'm very new to mysql, what does this mean? Quote Link to comment Share on other sites More sharing options...
Stuart_Westgate Posted May 14, 2013 Author Share Posted May 14, 2013 Sorry, I did change a few words as I knew they could be taken by PHP/MySQL. I don't have call there anymore. Quote Link to comment Share on other sites More sharing options...
jazzman1 Posted May 14, 2013 Share Posted May 14, 2013 Try enclosing the column named "call" with backticks, someting like: $sql = "INSERT INTO member (phoneNumber, firstName, lastName, profilePicture, photo, video, text, `call`, activity, latitude, longitude, data, time) "; https://dev.mysql.com/doc/refman/5.1/en/reserved-words.html Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.