Welcome Guest, Not a member yet? Register   Sign In
Trouble with inserting data
#1

[eluser]marcusl[/eluser]
Hi everyone. I hope you're well.

I'm having trouble with inserting data into a database on a remote machine. The error message I received is:

A Database Error Occurred
Error Number: INSERT INTO tableName (fieldName) VALUES ('value')

At first, I thought it might be an issue with permissions. However, I'm able to make GET and PUT calls without any problems. Also, my workmate is able to insert data into the database just fine. We're using the same php script, so I'm a bit stumbled.

Here's what I've got in database.php:

$active_group = "mssql_shared";
$active_record = TRUE;

$db['mssql_shared']['hostname'] = "hostname";
$db['mssql_shared']['username'] = "username";
$db['mssql_shared']['password'] = "password";
$db['mssql_shared']['database'] = "databasename";
$db['mssql_shared']['dbdriver'] = "mssql";
$db['mssql_shared']['dbprefix'] = "";
$db['mssql_shared']['pconnect'] = TRUE;
$db['mssql_shared']['db_debug'] = TRUE;
$db['mssql_shared']['cache_on'] = FALSE;
$db['mssql_shared']['cachedir'] = "";
$db['mssql_shared']['char_set'] = "utf8";
$db['mssql_shared']['dbcollat'] = "utf8_general_ci";

My insert code in the php is as follows:

$data = array(
'fieldName' => 'value'
);
$this->db->insert('tableName', $data);

I have a different database on my machine, and I can make insert calls to that one successfully. So, again, I'm wondering if it's related to the fact that I'm making this call to a remote database. However, if the error is permission related, shouldn't I get a different error message? One that relates to permissions?

If anyone knows of the solution, please let me know. If you need more information, please tell me and I can provide them. Thank you very much. Any advice would be appreciated.
#2

[eluser]marcusl[/eluser]
I've discovered that it wasn't working because there's a field on the table named "id", which I haven't provided when inserting the data. I've set "id" as the primary key with auto increment switched on. I thought if I did that, a new id will be generated every time I post a new entry? I'm probably still missing something here. I'm still new to this, so if anyone knows what I'm doing wrong, please let me know. Cheers.
#3

[eluser]rogierb[/eluser]
It can be a permission problem if you and your workmate have different IP's and the permission for the remote user is IP based. Check if the remote database user is restricted by IP or if it is not restricted (eg % = bad security).

Edit: to late:-)




Theme © iAndrew 2016 - Forum software by © MyBB