Send data to website, website puts data into Database
#1

Hey people.
I would like to send data to my website. The format is like s|s|i|i|i.
1. How do i send data with HTTP to the website?
2. How do i make that the website responses that way, that it puts it into a mysql database?

I hope you can help me, cuz i am a noob at http and php and html and stuff :/
Thanks!
Reply
#2

Why not let the server put it in mysql?
Reply
#3

Quote:
Originally Posted by Wrath2k10
Посмотреть сообщение
Why not let the server put it in mysql?
Cuz i need the password to be anonymous, so nobody will be able to access over PHPMyAdmin to the Database.
Reply
#4

pawn Код:
stock sendHTTPInformation(string1[], string2[], integer1, integer2, integer3) {
    new
        submitString[255]; // This might be bigger, you will probably have to raise the array size.
       
    format(submitString, sizeof(submitString), "fwright.com/aoao.php?string1=%s&string2=%s&integer1=%d&integer2=%d&integer3=%d", string1, string2, integer1, integer2, integer3);
    HTTP(0, HTTP_POST, urlString, "", "httpResponse");
}

forward httpResponse(index, response_code, data[]) {
    print("[server] It worked! [Response Code: %d | Data Retrieved: %s]", response_code, data);
}
Untested.

Change the URL accordingly, this would be page 'aoao.php'
PHP код:
<?php
// connection info here.
// select db here...
if(!isset($_GET['string1']) || !isset($_GET['string2']) || !isset($_GET['integer1']) || !isset($_GET['integer2']) || !isset($_GET['integer3'])) { // Check all URL parameters exist.
    
echo "The data could not be entered, due to the fact that one of the required URL parameters appears to be missing.";
}
else {
    
mysql_query("INSERT INTO databasename (String1, String2, Integer1, Integer2, Integer3) VALUES('" mysql_real_escape_string($_GET['string1']) . "', '" mysql_real_escape_string($_GET['string2']) ."', '" mysql_real_escape_string($_GET['integer1']) . "', '" mysql_real_escape_string($_GET['integer2']) . "', '" mysql_real_escape_string($_GET['integer3']) . "')");
}
?>
Reply
#5

I guess urlString should be submitString (in the first code)?

I changed it already and used it but my server is crashing. Array size is 600 now, so it can't be too small.

pawn Код:
forward httpResponse(index, response_code, data[]);

Buh(playerid)
{
    new submitString[600];
    new PName[MAX_PLAYER_NAME];
    GetPlayerName(playerid, PName, sizeof(PName));
   
    new PIP[16];
    GetPlayerIp(playerid, PIP, sizeof(PIP));

    new Day, Month, Year;
    getdate(Year, Month, Day);

    format(submitString, sizeof(submitString), "wayne.pytalhost.net/buh.php?name=%s&IP=%s&Day=%d&Month=%d&Year=%d&Amount=%d", PName, PIP, Day, Month, Year);
    HTTP(0, HTTP_POST, submitString, "", "httpResponse");
}

public httpResponse(index, response_code, data[])
{
    printf("[server] It worked! [Response Code: %d | Data Retrieved: %s]", response_code, data);
}
PHP код:
<?php
$con 
mysql_connect('URL''USER''PASS'); 
$db mysql_select_db('DB'$con);
if(!isset(
$_GET['name']) || !isset($_GET['IP']) || !isset($_GET['Day']) || !isset($_GET['Month']) || !isset($_GET['Year'] || !isset($_GET['Amount'])) { // Check all URL parameters exist.
    
echo "The data could not be entered, due to the fact that one of the required URL parameters appears to be missing.";
}
else {
    
mysql_query("INSERT INTO table(name, IP, Day, Month, Year, Amount) VALUES('" mysql_real_escape_string($_GET['name']) . "', '" mysql_real_escape_string($_GET['IP']) ."', '" mysql_real_escape_string($_GET['Day']) . "', '" mysql_real_escape_string($_GET['Month']) . "', '" mysql_real_escape_string($_GET['Year']) . "', '" mysql_real_escape_string($_GET['Amount']) . "')");
}
mysql_close($con);
?>
Whats wrong?
Reply
#6

Quote:
Originally Posted by DeathOnaStick
Посмотреть сообщение
I guess urlString should be submitString (in the first code)?

I changed it already and used it but my server is crashing. Array size is 600 now, so it can't be too small.

pawn Код:
forward httpResponse(index, response_code, data[]);

Buh(playerid)
{
    new submitString[600];
    new PName[MAX_PLAYER_NAME];
    GetPlayerName(playerid, PName, sizeof(PName));
   
    new PIP[16];
    GetPlayerIp(playerid, PIP, sizeof(PIP));

    new Day, Month, Year;
    getdate(Year, Month, Day);

    format(submitString, sizeof(submitString), "wayne.pytalhost.net/buh.php?name=%s&IP=%s&Day=%d&Month=%d&Year=%d&Amount=%d", PName, PIP, Day, Month, Year);
    HTTP(0, HTTP_POST, submitString, "", "httpResponse");
}

public httpResponse(index, response_code, data[])
{
    printf("[server] It worked! [Response Code: %d | Data Retrieved: %s]", response_code, data);
}
PHP код:
<?php
$con 
mysql_connect('URL''USER''PASS'); 
$db mysql_select_db('DB'$con);
if(!isset(
$_GET['name']) || !isset($_GET['IP']) || !isset($_GET['Day']) || !isset($_GET['Month']) || !isset($_GET['Year'] || !isset($_GET['Amount'])) { // Check all URL parameters exist.
    
echo "The data could not be entered, due to the fact that one of the required URL parameters appears to be missing.";
}
else {
    
mysql_query("INSERT INTO table(name, IP, Day, Month, Year, Amount) VALUES('" mysql_real_escape_string($_GET['name']) . "', '" mysql_real_escape_string($_GET['IP']) ."', '" mysql_real_escape_string($_GET['Day']) . "', '" mysql_real_escape_string($_GET['Month']) . "', '" mysql_real_escape_string($_GET['Year']) . "', '" mysql_real_escape_string($_GET['Amount']) . "')");
}
mysql_close($con);
?>
Whats wrong?
Try change the mode thing to HTTP_GET
Reply
#7

Quote:
Originally Posted by Calgon
Посмотреть сообщение
Try change the mode thing to HTTP_GET
Still same prob :/
Reply
#8

Bump.

Here the code i use to test it:

Pawn:

pawn Код:
forward httpResponse(index, response_code, data[]);

forward MessageShow();
public MessageShow()
{
//...
print("Test1");
HTTP(25, HTTP_POST, "MyURL.host.net/lister.php?name=Idiot&IP=128.0.0.1&Day=28&Month=9&Year=2010&Amount=2", "", "httpResponse");
print("Test2");
print("\n");
return 1;
}


public httpResponse(index, response_code, data[])
{
    printf("[server] It worked! [Response Code: %d | Data Retrieved: %s]", response_code, data);
}
PHP-code located in .../lister.php on my homepage:

PHP код:
<?php
$con 
mysql_connect('URL''Username''Password'); 
$db mysql_select_db('Databasename'$con);
if(!isset(
$_GET['name']) || !isset($_GET['IP']) || !isset($_GET['Day']) || !isset($_GET['Month']) || !isset($_GET['Year'] || !isset($_GET['Amount'])) { // Check all URL parameters exist.
    
echo "The data could not be entered, due to the fact that one of the required URL parameters appears to be missing.";
}
else {
    
mysql_query("INSERT INTO tablename (name, IP, Day, Month, Year, Amount) VALUES('" mysql_real_escape_string($_GET['name']) . "', '" mysql_real_escape_string($_GET['IP']) ."', '" mysql_real_escape_string($_GET['Day']) . "', '" mysql_real_escape_string($_GET['Month']) . "', '" mysql_real_escape_string($_GET['Year']) . "', '" mysql_real_escape_string($_GET['Amount']) . "')");
}
mysql_close($con);
?>
It prints Test1 and Test2 then it crashes. Why?
Reply
#9

Quote:
Originally Posted by ******
Посмотреть сообщение
You're submitting the data over POST, but passing and reading it as GET. Try put a print BEFORE the print in httpResponse with just "hi".
Tried it and it did not post more than Test1 and Test2.

I think at the moment the PHP-Site is a bigger problem. It will take me some time to fix the warnings and stuff, that i get at the moment.
I guess this might cause the problems i get when running the script.

Edit:


Alright.
I can connect now so far, but it does not put anything into the MySQL-table yet, but i guess i will be able to fix it.

Thanks to anyone that helped (so far)

Seems like this line does not work properly:

PHP код:
mysql_query("INSERT INTO tablename (name, IP, Day, Month, Year, Amount) VALUES('" mysql_real_escape_string($_GET['name']) . "', '" mysql_real_escape_string($_GET['IP']) ."', '" mysql_real_escape_string($_GET['Day']) . "', '" mysql_real_escape_string($_GET['Month']) . "', '" mysql_real_escape_string($_GET['Year']) . "', '" mysql_real_escape_string($_GET['Amount']) . "')"); 

Edit 2.0:


Now it works. I just made one wrong entry at the connection-information... All works fine, finally, thanks to everybody.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)