简体   繁体   English

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

[英]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 user choses.我有一个 iphone 应用程序,当用户按下按钮时,我收集数据并将其发送到由 php 编写的 web 服务器。我在那里制作了一个表单,当然我的表单有一个提交按钮,但是当用户按下应用程序中的按钮时我如何告诉表单提交用户选择的文本。 here is my php code这是我的 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>

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.当用户在 iphone 应用程序中按下按钮确定时,我想将他的信息提交到数据库。

I do not see where you are connecting to your database, the connection you are trying to use is $local , here:我没有看到您连接到数据库的位置,您尝试使用的连接是$local ,这里:

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:您应该将字符串值括在引号中,并且不要忘记防止 escaping 注入 sql 字符串:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何将表单数据保存到数据库中 - How can I save my form data into the database 如何使用php在提交按钮单击时将数据从文本框保存到数据库 - how to save data from textboxes to database on submit button click using php 如何在不使用数据库的情况下将数据保存在服务器上? - How to save data on server without using database? 我如何在没有单击提交按钮的情况下发送帖子? - How can I send a post form without click submit button? 可以在$ _POST数据中保存表单按钮的值,而不会触发表单提交onClick - Can one save a form button's value in $_POST data without it also triggering form submit onClick 点击编辑加载表格并保存提交 - Load a form on click edit & save on submit 如果我没有更新更新表单中的任何信息,然后单击“保存”按钮,则数据库的价值会自动增加 - If I do not update any information in my update form and click “Save” button,the valu of my database auto increase 如何在不运行的情况下gzinflate和保存膨胀的数据? (发现我认为是服务器上的木马) - How can I gzinflate and save the inflated data without running it? (Found what I think is a trojan on my server) 如何在没有提交按钮的情况下从输入类型文本保存数据 - How to Save Data from Input Type Text Without Submit Button 保存提交变量而不使用数据库? - Save submit variables without using Database?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM