Jump to content

Why is this data not being inserted into my database table?


Recommended Posts

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. :-)

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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"
Link to comment
Share on other sites

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
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.