0

I have a web based, php, DB system using mysql. users login, enter data in forms, click submit, and data is entered and can be read, analyzed, reported on, etc etc etc.

now we have a data provider who wants to send data to the mysql DB via a link, an external submission to the DB from a source not logged in to the system

"The most common way of how we get data over to our clients is by posting over our data to your system. In order to do this I would need a URL to post the data to as well as the required fields names."

I am not exactly sure what this means.

http://mysite.com/data.php?first_name=bob&last_name=smith  // ??

how do i set up, in the above example, data.php, so the data provider can input via the link and not have to post into a form?

Typically, i have an html form like this, on a page we'll call form1.php:

<html><body>
<form method="POST" NAME="form1" action="data.php">
<input type='text' name='first_name'>
<input type='text' name='last_name'>
<input type=submit value="Submit">
</form>
</body></html>

data.php looks like this:

<?
include("dbinfo.inc.php"); // has the access info for the DB, how to connect

$first_name = mysql_real_escape_string($_POST['first_name']);
$last_name = mysql_real_escape_string($_POST['last_name']);

$query = "INSERT INTO table1 (first_name, last_name) VALUES ('$first_name','$last_name')";
mysql_query($query);
mysql_close();

?> 


<html>
<head>
<meta HTTP-EQUIV="REFRESH" content="0; url=form1.php">
</head>
</html>

But in this example, the user would have to log in and post to the form. what is the way for the user to generate a link with the pertinent data, and have it submit via data.php not from a form, but directly from a link?

TIA

2
  • 1. Don't! Anyone could insert whatever they wanted if they have the URL. 2. Using the URL is a get request. Don't use get for insert/delete/modify. Only retrieval (get it). Commented Nov 4, 2013 at 19:40
  • A data provider, or a server if you will, usually sits there and waits for the client to connect and ask for data. The connection initiative belongs to the client. And that's for a shipload of reasons. Think about it. At least that's the old-fashioned way... o tempora o mores... Commented Nov 4, 2013 at 19:45

2 Answers 2

1

The GET method sends the data into the link. Your for should look like this:

<form method="GET" NAME="form1" action="data.php">
<input type='text' name='first_name'>
<input type='text' name='last_name'>
<input type=submit value="Submit">
</form>

This will send the browser, for example, to http://mysite.com/data.php?first_name=bob&last_name=smith

In PHP you can take these variables using $lastname=$_GET['last_name']; So you have to change only the method you take the data from the form in your data.php:

<?
include("dbinfo.inc.php"); // has the access info for the DB, how to connect

$first_name = mysql_real_escape_string($_GET['first_name']);
$last_name = mysql_real_escape_string($_GET['last_name']);

$query = "INSERT INTO table1 (first_name, last_name) VALUES ('$first_name','$last_name')";
mysql_query($query);
mysql_close();

?> 


<html>
<head>
<meta HTTP-EQUIV="REFRESH" content="0; url=form1.php">
</head>
</html>

Some help: http://www.w3schools.com/tags/ref_httpmethods.asp

Sign up to request clarification or add additional context in comments.

1 Comment

thanks ... i also added variables to identify the source to prevent unauthorized submissions to the DB.
0

You could learn about the webservices and REST to do it.

To persist given data, you should do it via a POST request instead of GET request (or PUT if it's an update).

The client will only use your URI and make a POST or PUT request to persist or update datas, and make a GET request to get datas and DELETE to remove datas.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.