My button action:
NSString* content = @"LED0=1";
NSURL* url = [NSURL URLWithString:@"*****************************************************"];
NSMutableURLRequest* urlRequest = [[NSMutableURLRequest alloc] initWithURL:url];
[urlRequest setHTTPMethod:@"post"];
[urlRequest setHTTPBody:[content dataUsingEncoding:NSASCIIStringEncoding]];
my php form script:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta name="viewport" content="width=320; initial-scale=2.0; maximum-scale=2.0; user-scalable=0;"/>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>LED Control </title>
</head>
<body>
<?php
$control = fopen("control.txt", "r");
$data = fgetcsv($control, 10 , ',') or die ("can't open file");
$LED0status= $data[1];
fclose($control);
echo("LED0 Status is: ");
if ($LED0status ==1) {
echo("<font color='#00FF33'>ON</font>");
} else {
echo("<font color='red'>OFF</font>");
}
?>
<form action="control_submit.php" method="post" target="_self">
<table width="200">
<tr>
<td><label>
<input <?php if (!(strcmp("$LED0status","1"))) {echo "checked=\"checked\"";} ?> type="radio" name="LED0" value="1" id="LED0_0" />
ON</label></td>
</tr>
<tr>
<td><label>
<input <?php if (!(strcmp("$LED0status","0"))) {echo "checked=\"checked\"";} ?> type="radio" name="LED0" value="0" id="LED0_1" />
OFF</label></td>
</tr>
</table>
<input name="Submit" type="submit" />
</form>
</body>
</html>
now this is the php script that writes the value to a text file:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta content="text/html; charset=utf-8" http-equiv="Content-Type" />
<meta name="viewport" content="width=320; initial-scale=2.0; maximum-scale=2.0; user-scalable=0;"/>
<meta http-equiv="REFRESH" content="1;url=http://www.auburn.edu/~cjb0001/arduino/control_test.php">
<title>Data Test</title>
</head>
<body>
Saving Command...<br />
<?php $write = fopen("control.txt", 'w');
fwrite($write, "0");
fwrite($write, ",");
fwrite($write, $LED0);
fclose($write);
?>
</body>
</html>
Thanks in advance,
Andrew
This post has been edited by Boos199: 08 September 2011 - 10:16 PM

New Topic/Question
Reply



MultiQuote




|