How to allow a specfied external ip's to insert to the mysql database
Posted by: JimSundqvist (---.ias.bredband.telia.com)
Date: January 02, 2015 02:27PM

Hi there.
I've made a website for my friend and we're having an issue with mysql.
The plan is to use a program which I created using C# (far from finished) instead of an admin area on the website itself.
The program insert a image from a specified location on the pc, e.g: uploadFile(@"D:\image.jpg" ). Which works without any problem both for me and for my friend.

The program then inserts a row to the database table e.g: sqlClient.Insert("images", "title, alternative, type, slider, image", "'none', 'none', '1', '0', 'image.jpg'" ) ;
So the website understand what image it is and where to display it on the website.

The insert works locally on my computer where i set up the server to make the website visible to the world (which it is).

However when my friend in this case tries to insert the same thing to the database from his pc, in his home, using the same program it only uploads the file to the ftp, but it does not insert anything to the database (I believe it's because mysql only allow local connections to insert to the database).

I've forwarded every port I've come across that might help me solve the issue to allow external ip's to upload to the ftp, sql and gain access to the site itself.

Ports forwarded: 20, 21, 80, 443, 3306, 50000-51000

The forwards have been made in both the router and windows firewall.

I've been searching on this matter for a couple of days but still haven't been able to locate a answer/ fix for this so i believe this is my last resort.


So the question is as the subject:
How can i allow just my friend to insert rows to the mysql database on my server(pc) using the program?
An IP whitelist or something?

Hopefully you'll be able to assist me.


Needed information from sticky:

1 - Windows version used (Specify whether 32 or 64 bit)

I'm using the latest 32-bit version
___

2 - Version WampServer (Specify whether 32 or 64 bit)

Version 2.5(?) latest
___

3 - Apache Version

Version: 2.4.9
___

4 - PHP Version

Version: 5.5.12
___

5 - MySQL Version

Version: 5.6.17
___

6 - What color is the WampServer icon (in the notification area of the taskbar)

The color is green
___

7 - In the file c:\Windows\System32\drivers\etc\hosts, what are the active lines with the name [localhost] in them?

127.0.0.1 localhost www.mysite.com mysite.com
___

8 - Do you have access to localhost (Homepage WampServer)?

Yes i have access to localhost.
___

9 - Do you have access to phpMyAdmin?

Yes i have access to phpMyAdmin.
---

10 - If you refer to an error message, please include the EXACT wording of the error in your post

The only error would be that he is not local so he can't insert anything to the database.
___

11 - If you use an Antivirus and / or Firewall, please include the names of these

Currently I'm using the windows firewall, router firewall, and Bitdefender free antivirus
___

12 - What is the full path to the installation of WampServer (eg D:\wamp\)

The install location is D:\Programs\wamp\



Edited 1 time(s). Last edit at 01/02/2015 02:36PM by JimSundqvist.

Options: ReplyQuote
Re: How to allow a specfied external ip's to insert to the mysql database
Posted by: RiggsFolly (---.as43234.net)
Date: January 02, 2015 06:11PM

Yes that was me.



Can you show your database connection parameters please. ( Not the userid and password of course )

---------------------------------------------------------------------------------------------
(Windows 10 Pro 64bit) (Wampserver 3.3.4 64bit) Aestan Tray Menu 3.2.5.4
<Apache versions MULTIPE> <PHP versions MULTIPLE> <MySQL Versions MULTIPLE>
<MariaDB versions MULTIPLE> <phpMyAdmin versions MULTIPLE> <MySQL Workbench 8.0.23>

Read The Manuals Apache -- MySQL -- PHP -- phpMyAdmin
Get your Apache/MySQL/mariaDB/PHP ADDONs here from the WAMPServer alternate Repo
-X-X-X- Backup your databases regularly Here is How dont regret it later! Yes even when developing -X-X-X-



Edited 3 time(s). Last edit at 01/02/2015 06:35PM by RiggsFolly.

Options: ReplyQuote
Re: How to allow a specfied external ip's to insert to the mysql database
Posted by: JimSundqvist (---.ias.bredband.telia.com)
Date: January 02, 2015 06:31PM

RiggsFolly Wrote:
-------------------------------------------------------
> Yes that was me.
>
> Am I right in thinking you are using SQLServer?
>
> Can you show your SQLServer connection parameters
> please.


Sorry to dissapoint but I'm not using any SQLServer, i just have MySQL which came with wamp tongue sticking out smiley

All i have is what i downloaded, and that's Wamp, then i went and downloaded filezilla server in order to get ftp up and running. That's about it.


//These lines go to a C# class where it inserts to the database given //

E.g. MySQLClient sqlClient = new MySQLClient("host", "database", "user", "password " );

The SQL code posted above:
sqlClient.Insert("images", "title, alternative, type, slider, image", "'none', 'none', '1', '0', 'image.jpg' " ) ;

// To C# class //

public void Insert(string table, string column, string value)
{
//Insert values into the database.

//Example: INSERT INTO names (name, age) VALUES('John Smith', '33')
//Code: MySQLClient.Insert("names", "name, age", "'John Smith, '33'" );
string query = "INSERT INTO " + table + " (" + column + " ) VALUES (" + value + " ) ";

try
{
if (this.Open())
{
//Opens a connection, if successful; run the query and then close the connection.

MySqlCommand cmd = new MySqlCommand(query, conn);

cmd.ExecuteNonQuery();
this.Close();
}
}
catch (Exception ex)
{
MessageBox.Show("An error occurred: " + ex); //However this does not work for some reason.
}
return;
}

//C# Class //

//EDIT//

Forgot to add the constructor:

public MySQLClient(string hostname, string database, string username, string password)
{
conn = new MySqlConnection("host=" + hostname + ";database=" + database +";username=" + username +";password=" + password +";" );
}


Do i have to add a port number to the conn string for it to work for my friend?

//EDIT//


So It's almost like a PHP script to insert into the database.

Could it be that he tries to insert into a database which doesn't exist because he doesn't have a database on his pc?

If so, how would it be possible to send it to my server on my pc?



Edited 4 time(s). Last edit at 01/02/2015 08:07PM by JimSundqvist.

Options: ReplyQuote
Re: How to allow a specfied external ip's to insert to the mysql database
Posted by: RiggsFolly (---.as43234.net)
Date: January 03, 2015 07:02PM

I think you are getting there.....



This line :
MySQLClient sqlClient = new MySQLClient("host", "database", "user", "password " );

Is where you need to look.

I was hoping for you to only obfiscate the uid and pwd but whatever, lets assume you have something like this


MySQLClient sqlClient = new MySQLClient("localhost", "MyDataBase", "user", "password" );

You may have used localhost or 127.0.0.1

The use of either will be your problem, as this points to the PC running the code. You need to make that use your WAN ip on your friends PC.

---------------------------------------------------------------------------------------------
(Windows 10 Pro 64bit) (Wampserver 3.3.4 64bit) Aestan Tray Menu 3.2.5.4
<Apache versions MULTIPE> <PHP versions MULTIPLE> <MySQL Versions MULTIPLE>
<MariaDB versions MULTIPLE> <phpMyAdmin versions MULTIPLE> <MySQL Workbench 8.0.23>

Read The Manuals Apache -- MySQL -- PHP -- phpMyAdmin
Get your Apache/MySQL/mariaDB/PHP ADDONs here from the WAMPServer alternate Repo
-X-X-X- Backup your databases regularly Here is How dont regret it later! Yes even when developing -X-X-X-

Options: ReplyQuote
Re: How to allow a specfied external ip's to insert to the mysql database
Posted by: JimSundqvist (---.ias.bredband.telia.com)
Date: January 03, 2015 08:25PM

I ended up uninstalling wamp, installing mysql server, installing wamp again and then force traffic to the mysql server instead of the wamp mysql.

With this it suddenly started to work smiling smiley

Thanks for taking your time to answer to my questions.

@RiggsFolly

Regarding the pm about url i ended up getting another domain name from a domain only site and using their dns forward system i believe it's called and then voila it worked too. tongue sticking out smiley

Must have been something wrong with the web host i used which caused lots of problems with the url.

Thanks once again.

Options: ReplyQuote
Re: How to allow a specfied external ip's to insert to the mysql database
Posted by: RiggsFolly (---.as43234.net)
Date: January 03, 2015 09:07PM

There is no reason that the MYSQL that comes with WAMPServer should not work.

Its a fully functional complete MYSQL.


Maybe you should compare the 2 configurations for mysql that may throw some light on why it would not work using the WAMPServer version of MYSQL

---------------------------------------------------------------------------------------------
(Windows 10 Pro 64bit) (Wampserver 3.3.4 64bit) Aestan Tray Menu 3.2.5.4
<Apache versions MULTIPE> <PHP versions MULTIPLE> <MySQL Versions MULTIPLE>
<MariaDB versions MULTIPLE> <phpMyAdmin versions MULTIPLE> <MySQL Workbench 8.0.23>

Read The Manuals Apache -- MySQL -- PHP -- phpMyAdmin
Get your Apache/MySQL/mariaDB/PHP ADDONs here from the WAMPServer alternate Repo
-X-X-X- Backup your databases regularly Here is How dont regret it later! Yes even when developing -X-X-X-

Options: ReplyQuote
Re: How to allow a specfied external ip's to insert to the mysql database
Posted by: JimSundqvist (---.ias.bredband.telia.com)
Date: January 03, 2015 11:10PM

@RiggsFolly

The only thing that seem to be different it that the localhost for the mysql server is localhost:3306 to allow tcp connections i believe.

Options: ReplyQuote


Sorry, only registered users may post in this forum.