Php 使用web服务器的我的应用程序为了保存数据并将数据加载到数据库,如何在不单击提交按钮的情况下保存表单?

Php 使用web服务器的我的应用程序为了保存数据并将数据加载到数据库,如何在不单击提交按钮的情况下保存表单?,php,iphone,mysql,html,objective-c,Php,Iphone,Mysql,Html,Objective C,我有一个iphone应用程序,当用户按下按钮时,我收集数据并将其发送到由php编写的web服务器。我在那里制作了一个表单,当然我的表单有一个提交按钮,但当用户按下应用程序中的按钮时,我如何告诉表单提交用户选择的文本。这是我的php代码 <?php require_once('Connections/local.php')?> <?php if (isset($_POST['appy_level'])){ $id=mysql_insert_id(); $appy_level=$

我有一个iphone应用程序,当用户按下按钮时,我收集数据并将其发送到由php编写的web服务器。我在那里制作了一个表单,当然我的表单有一个提交按钮,但当用户按下应用程序中的按钮时,我如何告诉表单提交用户选择的文本。这是我的php代码

<?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>

快乐水平:
原因:
性别:
国家:
城市:
年份:

没有“提交”按钮,我如何提交表格。当用户在iphone应用程序中按下“确定”按钮时,我想将其信息提交到数据库。

我看不到您连接到数据库的位置,您尝试使用的连接是
$local
,此处:

mysql_query($insertSQL, $local) or die(mysql_error());
如果要插入的值是字符串,则需要将它们括在单引号中:

INSERT INTO tableName(col1, col2, col3, ..., colN) VALUES('val1', 'val2', 'val3', ..., 'valN')
您应该将字符串值括在引号中,并且不要忘记通过转义字符串来防止sql注入:

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

$year=$\u POST['year']您的“年”表单字段在哪里?您现在可以看到mate抱歉,我忘了发布您试图保存为用户类型的所有表单,以便稍后重新加载它?或者什么?是的,当用户单击应用程序中的“显示”按钮时,我将从数据库中检索它们