开发者

My app using web server inorder to save and load data to the database how can i save the form without click the submit button?

I have a iphone application when the user presses the button i collect data and send it to web server that is written by php.I made a form there and of course my form has a submit button but when the user press the button in the application how can i tell the form to submit the text that开发者_JAVA百科 user choses. here is my php code

<?php require_once('Connections/local.php')?>
<?php
if (isset($_POST['appy_level'])){
$id=mysql_insert_id();

$appy_level=$_POST['appy_level'];
$year=$_POST['year'];
$date =date('Y');
$year=$date-$year;
$reasons = $_POST['reasons'];
$reasons = str_replace(","," ",$reasons); 
if(isset($_POST['sex']))
 $sex=$_POST['sex'];
$country=$_POST['country'];
$city=$_POST['city'];
$id=mysql_insert_id();

$insertSQL = "INSERT INTO user (age,wname,slid,time,sex) VALUES                 (".$year.",".$reasons.",".$appy_level.",CURRENT_TIMESTAMP,".$sex.")";
 $insertSQL1="INSERT INTO country (c_name) VALUES (".$country.")";
 $insertSQL2="INSERT INTO city (ci_name) VALUES (".$city.")";
mysql_select_db($database_local, $local);
mysql_query($insertSQL, $local) or die(mysql_error());
mysql_query($insertSQL1, $local) or die(mysql_error());
mysql_query($insertSQL2, $local) or die(mysql_error());

}
?>


  <body>
    <form action="" method="post" name="form1" id="form1">
 <table>
<tr>
<td>Happyness level:</td>
<td>
<input type="text" name="appy_level" value="" maxlength="100" />
</td>
</tr>
<tr>
<td>Reasons:</td>
<td>
<input type="text" name="reasons" value="" maxlength="100" />
</td>
</tr>
<tr>
<td>Gender:</td>
<td>
<input type="text" name="sex" value=""  maxlength="100" />
</td>
</tr>
<tr>
<td>Country:</td>
<td>
<input type="text" name="country" value="" maxlength="100" />
</td>
</tr>
<tr>
<td>City:</td>
<td>
<input type="text" name="city" value="" maxlength="100" />
</td>
</tr>
<tr>
<td>Year:</td>
<td>
<input type="text" name="year" value="" maxlength="100" />
</td>
</tr>
<tr><td> </td>
<td>
<input type="submit" value="Submit" />
</td>
</tr>
</table>        
</body>

How can i submit my form without a submit button. when the user presses the button ok in iphone application i want to submit his information to database.


I do not see where you are connecting to your database, the connection you are trying to use is $local, here:

mysql_query($insertSQL, $local) or die(mysql_error());

If the values you are trying to insert are strings, you need to enclose them in single quotes:

INSERT INTO tableName(col1, col2, col3, ..., colN) VALUES('val1', 'val2', 'val3', ..., 'valN')

You should wrap the string values in quotes and not forget to protect against sql injection by escaping the strings:

$val1 = mysql_real_escape_string($_POST['val1']);
$query = "INSERT INTO tableName(val1) VALUES('" . $val1 . "')";
mysql_query($query, $local);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜