» An ultimate catalog of computer data
Forum posts for ps2.exe
Return a value from PHP to HTML
I am in the process of creating a website and I am using HTML to create a form for the user to enter information. Once the user enters this information, a PHP program reads the input and sends it to a Python program. This python program creates a user database and then returns the user's unique ID number. However, I am not quite sure how to return the value from Python back to HTML via PHP.
Any suggestions?
Thank you!
EDIT (I am adding some code):
The HTML is of the form below. You can see that it calls example.php.
<section id='content'>
<div id='shady bott-27'></div>
<div id='inner clearfix'>
<div id='inner-t'>
<div id='col1'>
<div id='heading'>
<h3 id='Contact' href='#Contact'><strong><span style='color:#87CEEB'>Preliminary Information</span></strong></h3>
</div>
<br>
</div>
<div id='col1-2'>
<h4></h4>
<form id='contact' method='post' action='example.php'>
<div>
<label>Something*</label> <input id='something' type='text' name='something' />
</div>
The PHP code is:
$something = $_REQUEST['something'];
$command = 'python /var/www/html/pythonfile.py';
$command .= ' '$something' 2>&1';
$pid = popen( $command,'r');
while( !feof( $pid ) )
{
echo fread($pid, 256);
flush();
ob_flush();
usleep(100000);
}
pclose($pid);
?>
And finally, the Python code:
def examplepython(something):
#this function creates a new vendor
appID = ....
apiKey = ....
url = ...
ps2 = {'field_1': something}
headers = {
'Content-Type': 'application/json',
'X-Knack-Application-Id': appID,
'X-Knack-REST-API-Key': apiKey
}
datas = json.dumps(ps2)
req = urllib2.Request(url, datas, headers)
try:
f = urllib2.urlopen(req)
except urllib2.HTTPError, ex:
if ex.fp:
extra = ex.fp.read()
print '%s' % extra
else:
raise
data = json.loads(f.read())
identification = data['id']
print 'Your ID number is: ' + identification
View complete forum thread with replies
Other posts related to ps2.exe
See Related Forum Messages: Follow the Links Below to View Complete Thread
MySQL query SELECT GREATEST int row VALUE beetween limits
netty open 2 port server & 1 port client
Sliding multiple divs left to right with jquery toggle
Timed autosave with Batch
Return a value from PHP to HTML
Related object not saved
Attempting to enter values to database tables using jdbc transaction