增加/减少元素值并插入数据库 [英] Increase/decrease an elements value and insert to database

查看:76
本文介绍了增加/减少元素值并插入数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个jquery移动项目,我有三个水平分组的按钮。单击最左侧或最右侧按钮时,中间按钮中的文本会增大或减小。当我尝试通过php将文本作为int提交到MySQL数据库时,我将值0插入到字段中。显然,#seatCounter2没有获得值。我怎样才能获得#seatCounter2的价值?

任何帮助/建议都将不胜感激。



I have a jquery mobile project and I have three buttons grouped horizontally. When the far left or far right button are clicked the text in the middle button increases or decreases. When I try to submit the text as an int to MySQL database through php, I get the value 0 inserted into the field. Obviously #seatCounter2 is not getting a value. How can I get the value of #seatCounter2?
Any help/advice would be appreciated.

<fieldset class="ui-grid-a" style="margin-removed10px" >
    <label for="name" class="ui-block-a" date-inline="true" style="margin-top:5px">Seats Available</label>

    <div data-role="controlgroup" data-type="horizontal" date-inline="true" class="ui-block-b" >
        
        <a id="seatIncrease" data-role="button" style="width:2.8em" data-theme="c">+</a>
        <a href="#" id="seatCounter" data-role="button" style="width:50px; height:39px" data-theme="b"><span id="seatCounter2" name="seatCounter2" style="margin-removed10px, padding-removed35px">1</span></a>
        <a id="seatDecrease" data-role="button" style="width:2.8em" data-theme="c">-</a>

    </div>

</fieldset>	







// Seat available Counter
$(function(){
    $("#seatIncrease").click(function(){
        $("#seatCounter2").text( Number($("#seatCounter2").text()) + 1 );
    });
    $("#seatDecrease").click(function(){
        $("#seatCounter2").text( Math.max(1, Number($("#seatCounter2").text()) - 1) );													
    });
});







$seatcounter = intval($_POST['seatCounter2']);

//will only get executed if true
if ($canSubmitForm)
{
	if ($isFormEmpty == false)
	{
	require_once('database.php');
	$query = "INSERT INTO journey
		(from_destination,to_destination,journey_type,depart_date,depart_time,return_date,return_time,seats_available,journey_message,user_type)
		VALUES('$pjFrom','$pjTo','$radioJourneyType', STR_TO_DATE('$departDate','%d/%m/%Y'),'$newDepTime',STR_TO_DATE('$returnDate','%d/%m/%Y'),'$newRetTime ','$seatcounter','$textareanotes','$radUserType')";
	$db->exec($query);
	
	include('index.php');
	}
}
else
{
	$error = "Invalid product data. Check all fields and try again.";
	include('error.php');
}

推荐答案

function (){


#seatIncrease)。click( function (){
("#seatIncrease").click(function(){


#seatCounter2)。text( Number


这篇关于增加/减少元素值并插入数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆