JQuery Onclick display selected info - php

I want to display the selected price, category and size on the dropdown slideingDiv. But what I have done below is not working. I have try to echo out to see if the data have been sent thought but I got nothing. Is anything wrong with my code?
Script
<script type="text/javascript">
$(document).ready(function () {
$(".slidingDiv").hide();
$(".show_hide").show();
$('.show_hide').click(function () {
$(".slidingDiv").slideToggle();
});
});
</script>
Button
<button a href="product.php?ProdID=<?php echo $id; ?>" class="show_hide" id="button" name="button">Add to cart</a></button>
PHP
<?php
dbconnect();
if(isset($_POST['pid']) && isset($_POST['length']) && isset($_POST['Qty']) && `isset($_POST['Category'])){`
$pid = $_POST['pid'];
$length = $_POST["length"];
$qty = $_POST['Qty'];
$Category = $_POST['Category'];
echo $pid; // I have add this echo to see data have been passed though but i get nothing in return
echo $length;
$stmt4 = $conn->prepare("
SELECT Product.Name as ProductName, Category.Name, size, Price
FROM item_Product, Product, Category
WHERE Product.ProdID =:pid
AND size= :length AND Category.Name = :Category Limit 1");
$stmt4->bindParam('pid',$pid);
$stmt4->bindParam('length',$length);
$stmt4->bindParam('Category',$Category);
$stmt4->execute();
foreach ($stmt4->fetchAll(PDO::FETCH_ASSOC) as $row4 ) {
$product_name = $row4["ProductName"];
$price = $row4["Price"];
$length = $row4["size"];
$Category = $row4["Name"];
?>
Item was added shopping bag </br>
Name:<?php echo $row4['ProductName']; ?> </br>
Length:<?php echo $row4['size']; ?> </br>
Category:<?php echo $row4['Name']; ?> </br>
Price:<?php echo $row4['Price']; ?> </br>
<?php } }
?>
View Cart
</div>
TABLE
<td width="160">Price:</td>
echo '<td name="pricetag" id="pricetag">'.$row2['Price'].'</td>';
</tr>
<tr>
<td>Category</td>
<td>
<select id="Category" name="Category">
echo '<option value="'.$row['Name'].'">'.$row['Name'].'</option>';
</select>
</td>
</tr>
<tr>
<td width="160">Length:</td>
<td>
<select name="length" id="length">
<option SELECTED value="'.$row3['size'].'">'.$row3['size'].</option>
</select>
</td>
</tr>
<tr>
<td>Quantity</td>
<td><input type="text" name="Qty" id="Qty" value="1" style="width: 20px; text-align: right" /></td>
</tr>
</table>
<div class="cleaner h20"></div>
<input type="hidden" name="pid" id="pid" value="<?php echo $id; ?>" />
<div class="button">
<button class="show_hide" id="button" name="button">Add to cart</button>
</div>

Try this: SEE MY FIDDLE
HTML
<table>
<tr>
<td>Price</td>
<td>
<select id='priceTag'>
<option value='p1'>price 1</option>
<option value='p2'>price 2</option>
</select>
</td>
</tr>
<tr>
<td>Category</td>
<td>
<select id='Category'>
<option value='c1'>cat 1</option>
<option value='c2'>cat 2</option>
</select>
</td>
</tr>
<tr>
<td>Size</td>
<td>
<select id='Size'>
<option value='s1'>size 1</option>
<option value='s2'>size 2</option>
</select>
</td>
</tr>
</table>
<button id='button'>Submit</button>
<div id='selected'>
<table cellpadding="5" border='1'>
<tr>
<td>Price:</td>
<td id='sprice'></td>
</tr>
<tr>
<td>Category:</td>
<td id='scat'></td>
</tr>
<tr>
<td>Size:</td>
<td id='ssize'></td>
</tr>
</table>
</div>
JQuery
$(document).ready(function()
{
$('#selected').hide();
$('#button').click(function()
{
var price = $('#priceTag').val();
var cat = $('#Category').val();
var size = $('#Size').val();
$('#sprice').text(price);
$('#scat').text(cat);
$('#ssize').text(size);
$('#selected').slideDown();
});
});

Seems that you do not have a space in your <?php} ?>
Do something like <?php } ?>

Error:
<?php} ?>
try this,
<?php } ?> // add space between php and }

<?php}
should be
<?php }
Also
<button a href="product.php?ProdID=<?php echo $id; ?>" class="show_hide" id="button" name="button">Add to cart</a></button> is in correct
should be
<button>Add to cart</button>

Related

MSSQL procedure query return "Cannot insert the value NULL into column"

I have a form of 5 fields. when click on submit button it will fetch Amount against the fields from database MSSQL. Now when i fill form and submit it is giving an error. i have used MSSQL procedure query to execute it. please help me out i am in trouble now.
<div id="middle_pane">
<div>
<div id="inner_pane">
<div id="center_pane">
<div id="center_inner_pane">
<div class="txt_content">
<table width="385" height="200" style=" border:2px solid silver"
cellpadding="6px" cellspacing="0px" align="center" border="0">
<form method="POST" action="<?php bloginfo('url');?>/fedex-tariff">
<tr>
<td colspan="2" style="background:#0066FF; color:#FFFFFF;
fontsize:50px">Fedex Rate Card</td></tr>
<tr>
<td>Origin</td>
<td>
<select name="origin" id="origin" onChange="">
<option value="pakistan">Pakistan</option>
</select>
</td>
</tr>
<tr>
<td>Select Origin city </td>
<td>
<select name="city_id" id="city_id">
<option value="">--SELECT CITY--</option>
<?php
$city = "select * from branches";
$city_query = mssql_query($city);
while ($row_city = mssql_fetch_array($city_query)){
?>
<option value="<?php echo $row_city['name'];?>"> <?php echo
$row_city['name']; ?></option>
<?php } ?>
</select>
</td>
</tr>
<tr>
<td>Select Destination </td>
<td>
<select name="country_id" id="country_id">
<option value="">--SELECT Destination--</option>
<?php
$service= "select * from country";
$service_query= mssql_query($service);
while ($row_service = mssql_fetch_array($service_query)){
?>
<option value="<?php echo $row_service['Name'];?>"> <?php
echo $row_service['Name']; ?></option>
<?php } ?>
</select>
</td>
</tr>
<tr>
<td> Selection of Weight </td>
<td>
<div id="wgt">
<input type="text" id="weight" name="weight" value=""
placeholder="weight...." required="">
</div>
</td>
</tr>
<tr>
<td>Select Your Service</td>
<td>
<select name="service_id" id="service_id">
<option value="">--SELECT--</option>
<?php
$service_type = "SELECT distinct ServiceTypeId from
dbo.IntlZoneCountry where ServiceTypeId IN ('FedEx Cash Tariff
Docs','FedEx Box','FedEx Student Package')";
$res_type = mssql_query($service_type);
$cnt_type = mssql_num_rows($res_type);
while($row_type = mssql_fetch_array($res_type)){
?>
<option value="<?php echo $row_type['ServiceTypeId'];?>"><?php
echo $row_type['ServiceTypeId'];?></option>
<?php } ?>
</select>
</td>
</tr>
<tr>
<td> <input type="submit" value="Calculate" name="submit"
class="btn"></td>
</tr>
</form>
<table width="385" style=" border:2px solid silver"
cellpadding="6px" cellspacing="0px" align="center" border="0">
<tr>
<td>
<?php
if(isset($_POST['submit']))
{
$city_id = $_POST['city_id'];
$country_id = $_POST['country_id'];
$service_id = $_POST['service_id'];
$weight_id = $_POST['weight'];
if(empty($city_id) || empty($country_id) || empty($service_id) ||
empty($weight_id)){
?><center><?php echo "Please filled all the fields first.";?>
</center>
<?php
}
else{
$s = "[SP_UpdateCNPrice_Int_Tariff]
'$weight_id','$city_id','$country_id','$service_id'";
$result = mssql_query($s);
while($row = mssql_fetch_assoc($result)){
?>
</td>
</tr>
<tr style="background:#00CFFF; color:blue;">
<td>
<center>
<font size="3">
<?php
$val = $row['amount'];
$gst = $row['gst'];
echo "<strong>"."Rate : "."$".""." ".$val.$gst;
?>
</font>
</center>
</td>
</tr>
<tr style="background:#00CFFF; color:blue;">
<td><center> All Rates are Exclusive of 16% GST + 23% fuel
Charges (FSC).</center> </td>
</tr>
<?php
}
}
}
?>
</table>
</div>
</div>
</div>
</div>
</div>
MSSQL Procedure Screenshot
Front Display of Website

How to send dynamic option text and value using jquery and php

I have design a dynamic html table and it contains 2 table columns :
column1: Item Name. It comes from selected option.
column2: Item Price. It comes from selected option value.
Right now I am selecting option in first column and passing value into input field in second column. After adding as many rows I need, I want to pass both their text and value in php.
But php is getting only option value instead of having both text and value.
Here is my code
$('#myTable').on('change', '.mySelect', function() {
// you can use .closest() to find
// particular input on same row with select
$(this).closest('tr').find('.amount').val($(this).val());
//$(this).closest('tr').find('.mySelect').val($(".mySelect option:selected").text());
});
$('#myTable').on('click','.remScnt', function(e) {
e.preventDefault();
// find the tr element of remove link
// which is a parent
$(this).closest('tr').remove()
});
$(".mySelect option").filter(function() {
//may want to use $.trim in here
return $(this).text() == $(this).val();
}).prop('selected', true);
<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.0/jquery.min.js"></script>
<style>
table, th, td {
border-collapse: collapse;
margin: 10px auto;
}
</style>
<script>
function addMore() {
var table = document.getElementById("myTable");
var row = table.insertRow(-1);
var cell1 = row.insertCell(-1);
var cell2 = row.insertCell(-1);
var x = document.getElementById("myTable").rows[1].cells;
cell1.innerHTML = x[0].innerHTML;
cell2.innerHTML = x[1].innerHTML;
}
function removeLast() {
document.getElementById("myTable").deleteRow(-1);
}
function removeRowNo() {
var index = document.getElementById('value').value
document.getElementById("myTable").deleteRow(index);
}
</script>
</head>
<body>
<form action="testlist.php" method="post">
<table>
<tr>
<td>
Month:
</td>
<td>
<select name="SALMT" id="month" onchange="" size="1">
<option value="" disabled selected>Month</option>
<option value="1">January</option>
<option value="2">February</option>
<option value="3">March</option>
<option value="4">April</option>
<option value="5">May</option>
<option value="6">June</option>
<option value="7">July</option>
<option value="8">August</option>
<option value="9">September</option>
<option value="10">October</option>
<option value="11">November</option>
<option value="12">December</option>
</select>
</td>
<td>
Year:
</td>
<td> <input type="text" name="SALYR">
</td>
</tr>
<tr>
<td>
Employee ID:
</td>
<td> <input type="text" name="EMPID">
</td>
<td>
Name:
</td>
<td><input type="text" name="NM">
</td>
</tr>
<tr>
<td>
Department Code:
</td>
<td> <input type="text" name="DPTID">
</td>
<td>
Designation:
</td>
<td><input type="text" name="DSG">
</td>
</tr>
</table>
<table id="myTable">
<tr>
<th>Items</th>
<th>Amount</th>
</tr>
<tr>
<td >
Remove
<select class="mySelect" name="DESCRP[]" >
<option disabled="" selected="">Select</option>
<option value="100">Item-1</option>
<option value="200">Item-2</option>
<option value="300">Item-3</option>
<option value="400">Item-4</option>
<option value="500">Item-5</option>
</select>
</td>
<td> <input type="text" class="amount" name="ALAMT[]"></td>
</tr>
</table>
<table>
<tr>
<td><input type="submit" /> </td>
</tr>
</table>
</form>
<br>
<table>
<tr>
<td><button onclick="addMore()">Add More</button></td>
<td><button onclick="removeLast()">Remove Last Row</button></td>
</tr>
<tr>
<td><input type="text" maxlength="3" name="value" id='value'></td>
<td><button onclick="removeRowNo()">Remove By Row No.</button></td>
</tr>
</table>
</body>
</html>
Here is php code:
<?php
var_dump($_POST);
echo "<br>";
echo count($_POST["DESCRP"]);
foreach ($_POST["DESCRP"] as $d) {
echo "<br>";
echo $d;
}
echo "<br>Amount:";
echo count($amount = $_POST["ALAMT"]);
foreach ($_POST["DESCRP"] as $a) {
echo "<br>";
echo $a;
}
?>
You mean
<td>
<select class="mySelect">
<option value="">Select</option>
<option value="100">Item-1</option>
<option value="200">Item-2</option>
<option value="300">Item-3</option>
<option value="400">Item-4</option>
<option value="500">Item-5</option>
</select>
<input type="hidden" class="descr" name="DESCRP[]" />
</td>
<td> <input type="text" class="amount" name="ALAMT[]"></td>
using
$('#myTable').on('change', '.mySelect', function() {
$(this).closest('tr').find('.amount').val($(this).val());
$(this).closest('tr').find('.descr').val($("option:selected",this).text());
});
For DESCRP[0] = item-1, DESCRP[1] = item-5
modify the select as follows :
<option value="Item-1" data-val="100">Item-1</option>
$('#myTable').on('change', '.mySelect', function() {
$(this).closest('tr').find('.amount').val($(this).attr('data-val'));
});

How to create a jquery function to prevent duplicate entries to the database

I have created a form which takes the data and inserts it in the database. onlick of create button i want the function to check database whether the entry with employee_id already exists. if exists i want it to display the data already exists do you still want to insert, i am noob in this can anybody help me with this. the form is
<form id="myForm" name="myForm" action='insert.php' method='post' >
<input type='hidden' name='st' value=0>
<table style="text-align:center; width:100%">
<tr>
<td style="text-align:right"><label>Select SE/AE:</label></td>
<td style="text-align:left">
<?php include("configs.php");
$sql = "SELECT DISTINCT seae FROM se_ae ";?>
<select name="seae">
<option value="" selected></option>
<?php foreach ($dbo->query($sql) as $row) { ?>
<option value="<?php echo $row['seae']; ?>">
<?php echo $row['seae']; ?></option>
<?php }?>
</select>
</td>
</tr>
<tr>
<td style="text-align:right"><label>Select Brand:</label></td>
<td style="text-align:left">
<?php //include("configs.php");
$sql = "SELECT DISTINCT `brand` FROM se_ae ";?>
<select name="brand">
<option value="" selected> </option>
<?php foreach ($dbo->query($sql) as $row) { ?>
<option value="<?php echo $row['brand']; ?>">
<?php echo $row['brand']; ?></option>
<?php }?>
</select>
</td>
</tr>
<tr>
<td style="text-align:right"><label>Select Territory:</label></td>
<td style="text-align:left">
<?php //include("configs.php");
$sql = "SELECT DISTINCT `territory` FROM se_ae ";?>
<select name="territory">
<option value="" selected></option>
<?php foreach ($dbo->query($sql) as $row) { ?>
<option value="<?php echo $row['territory']; ?>">
<?php echo $row['territory']; ?></option>
<?php }?>
</select>
</td>
</tr>
<tr>
<td style="text-align:right"><label for="name">Employee Name:</label></td>
<td style="text-align:left">
<input type="text" id="name" name="name"/>
</td>
</tr>
<tr>
<td style="text-align:right"><label for="number">Employee ID:</label></td>
<td style="text-align:left">
<input type="text" id="number" name="number" />
</td>
</tr>
<tr>
<td style="text-align:right"><label for="email"> Email:</label></td>
<td style="text-align:left">
<input type="text" id="email" name="email" />
</td>
</tr>
<tr>
<td style="text-align:right"><label for="contact"> Contact:</label></td>
<td style="text-align:left">
<input type="text" id="contact" name="contact" />
</td>
</tr>
<tr>
<td style="text-align:right"><label for="exist"> Exist:</label></td>
<td style="text-align:left">
<input type="radio" id="exist" name="exist" value="Active"/>Active
<input type="radio" id="exist" name="exist" value="NA"/>NA
</td>
</tr>
<tr>
<td style="text-align:right" class='swMntTopMenu'>
<input style="background-color:rgb(255,213,32)" name="Reset" type="reset" value="Reset">
</td>
<td style="text-align:left" class='swMntTopMenu'>
<input style="background-color:rgb(255,213,32)" name="submit" type="submit" value="Create">
</td>
</tr>
</table>
</form>
You can use the Jquery validation
$(function () {
$("#resturantRegistration").validate({
rules: {
number: {
required: true,
remote:"user/checkEmployee"
}
},
messages: {
number: {
required: "Please enter Employee id",
remote: $.validator.format("Employee id already in use")
}
}
});
});
PHP function
function checkEmployee(){
$emailid = $_GET['number'];
if(!empty($emailid)){
$emailRes = $this->users->is_email_available($emailid);
if ($emailRes == ''){
echo 'false';
} else {
echo 'true';
}
}
}
Model function to check with database
/**
* Check if email available for registering
*
* #param string
* #return bool
*/
function is_email_available($email)
{
$this->db->select('1', FALSE);
$this->db->where('LOWER(email)=', strtolower($email));
$this->db->or_where('LOWER(new_email)=', strtolower($email));
$query = $this->db->get($this->table_name);
return $query->num_rows() == 0;
}
above code is follow the codeigniter MVC framework you can customize this in core PHP as well

One input not posting PHP/MSSQL

Trying to use this page to update an MSSQL table. My hidden field named hdnLine (2nd to last line of code) is not being posted on submit, though it is being populated with a value prior to the form being submitted. I had the page working, and all of the sudden I keep getting "Notice: Undefined index: hdnLine in C:\inetpub\wwwroot\clientadmin\agent-edit.php on line 11" when I try to submit. I have been messing with it all day trying to debug etc. and have had no luck with it. I'm assuming its a syntax error of sorts but can't figure it out. Any help would be gladly appreciated. The code is all below minus a few includes for db connectivity. I will do my best to help answer any questions pertaining.
<?php
if($_GET["Action"]=="Save"){
for($i=1;$i<=$_POST["hdnLine"];$i++)
{
$strSQL = "UPDATE RENTAGNT SET ";
$strSQL .="SPIFF = '".$_POST["txtSPIFF$i"]."' ";
$strSQL .=",PROMO = '".$_POST["txtPROMO$i"]."' ";
$strSQL .=",SPIFFVAL = '".$_POST["txtSPIFFVAL$i"]."' ";
$strSQL .=",AGNTLVL = '".$_POST["txtAGNTLVL$i"]."' ";
$strSQL .=",SPIFFDAYS = '".$_POST["txtSPIFFDAYS$i"]."' ";
$strSQL .=",MASTAGNTID = '".$_POST["txtMASTAGNTID$i"]."' ";
$strSQL .="WHERE RENTAGNTID = '".$_POST["hdnRENTAGNTID$i"]."' ";
$stmt = $conn->query($strSQL);
}
//exit();
}
$strSQL="SELECT RENTAGNTID, RENTAGNT.AGENTCODE, NAME, AGNTLVL,SPIFF, SPIFFVAL, PROMO, SPIFFDAYS,INACTIVE, MASTAGNTID FROM RENTAGNT WHERE INACTIVE='0' GROUP BY MASTAGNTID, RENTAGNT.AGENTCODE, RENTAGNT.NAME, RENTAGNTID, SPIFF, SPIFFVAL, SPIFFDAYS, AGNTLVL, INACTIVE, PROMO";
$stmt = $conn->query($strSQL);
?>
<form name="frmMain" method="POST" action="?Action=Save" >
<table id="res-list-table" class="tablesorter" width="90%" border="1" background="#fff">
<thead> <tr>
<th width="10%"> <div align="center">Rental Agent ID</div></th>
<th width="20%"> <div align="center">Agent Code </div></th>
<th width="35%"> <div align="center">Name </div></th>
<th width="5%"> <div align="center">1 Free</div></th>
<th width="5%"> <div align="center">Spiff Yes/No</div></th>
<th width="5%"> <div align="center">Spiff Amount </div></th>
<th width="5%"> <div align="center">Days Req. <br/> for Spiff</div></th>
<th width="5%"> <div align="center">Master Agent</div></th>
<th width="5%"> <div align="center">Agent Level</div></th>
</tr>
</thead><tbody>
<?php
$i = 1;
while ($row = $stmt->fetch( PDO::FETCH_ASSOC ) ){
$i++;
?>
<tr>
<td><div align="center">
<?php echo $row["RENTAGNTID"]; ?>
</div></td>
<td><div align="center">
<?php echo $row["AGENTCODE"]; ?>
</div></td>
<td><div align="center">
<?php echo $row["NAME"]; ?>
</div></td>
<td>
<input type="hidden" name="hdnRENTAGNTID<?=$i;?>" size="6" value="<?=$row["RENTAGNTID"];?>"/>
<select name="txtPROMO<?=$i;?>">
<option value="0" <?php if($row["PROMO"]=="0") { echo "selected='selected'"; } ?> >No</option>
<option value="1" <?php if($row["PROMO"]=="1") { echo "selected='selected'"; } ?> >Yes</option>
</select></td>
<td>
<select name="txtSPIFF<?=$i;?>">
<option value="0" <?php if($row["SPIFF"]=="0") { echo "selected='selected'"; } ?> >No</option>
<option value="1" <?php if($row["SPIFF"]=="1") { echo "selected='selected'"; }?> >Yes</option>
</select></td>
<td><input type="text" name="txtSPIFFVAL<?=$i;?>" size="5" style="width:75px;" value="<?=$row["SPIFFVAL"];?>" /></td>
<td><input type="text" name="txtSPIFFDAYS<?=$i;?>" size="5" style="width:75px;" value="<?=$row["SPIFFDAYS"];?>" /></td>
<td><input type="text" name="txtMASTAGNTID<?=$i;?>" size="5" style="width:75px;" value="<?=$row["MASTAGNTID"];?>" /></td>
<td>
<select name="txtAGNTLVL<?=$i;?>">
<option value="1" <?php if($row["AGNTLVL"]==1) { echo "selected='selected'"; }?> >Agent</option>
<option value="2" <?php if($row["AGNTLVL"]==2) { echo "selected='selected'"; }?> >Master Agent</option>
<option value="3" <?php if($row["AGNTLVL"]==3) { echo "selected='selected'"; }?> >Admin</option>
</select>
</td>
</tr>
<?php
}
?>
</tbody>
</table>
<input type="submit" name="submit" value="submit1" />
<input type="hidden" name="hdnLine" value="<?=$i;?>"/>
</form>
Seems like the short tags used to assign the value for the <input type="hidden" name="hdnLine" value="<?=$i;?>"/>. Is the short_open_tag = On in your php.ini?
If not change to on.
Or
Change throughout the code where <?=?> to <?php=?>

jQuery ajax form identify different forms on same page

I made a form in php. I am using 3 different forms in the document. So I have to distinguish these forms. Therefore I am using the submit "name-tag".
if ('POST' == $_SERVER['REQUEST_METHOD']) {
if (isset($_POST['submit_1'])) {
....
}
if (isset($_POST['submit_2'])) {
....
}
if (isset($_POST['submit_3'])) {
....
}
}
This is how I check these different submit-buttons.
But I noticed that I need to use the click function in JS instead of the submit function (cause the form shouldn't be submitted with a page-reload)
$('.erzaehlcafe_submit').click(function(){
if ($('#year_from').val() == 'none' || $('#month_from').val() == 'none'
|| $('#day_from').val() == 'none' || $('#topic').val() == '' || $('#contributer').val() == ''
|| $('#begin').val() == '' || $('#place').val() == '' || $('#entrance').val() == '') {
$("#dialog_empty").dialog( "open" );
return false;
}
var form = $('#erzaehlcafe_add');
var data = form.serialize();
$.ajax({
url: "index.php?section=events",
type: "POST",
data: data,
success: function (reqCode) {
alert(reqCode);
if (reqCode == 1) {
//Date inserted into DB
$("#dialog_add_event").dialog( "open" );
} else {
$("#dialog_add_event_error").dialog( "open" );
}
}
});
return false; //dont submit form
});
So how to make a difference between these forms? (All of them are using same names for same input).
The only way to solve the problem is to define other name indexes for all input typed. Is there any other way?
Edit: Here is my template ( remember I used submit_1, submit_2 and submit_3 instead of erzaehlcafe_submit and so on to make it more precise)
<div id="event_accordion">
<h3>Erzählcafé hinzufügen</h3>
<div>
<form id="erzaehlcafe_add" action="index.php?section=events" method="post" accept-charset="utf-8">
<table>
<tr>
<td>Datum:</td>
<td>
<select name="day_from" id="day_from">
<option value="none" class="bold italic">Tag</option>
<?php
for($i=1; $i<=31; $i++){
echo "<option value=\"".$i."\">".$i."</option>\n";
}
?>
</select>
<select name="month_from" id="month_from">
<option value="none" class="bold italic">Monat</option>
<?php
for($i=1; $i<=12; $i++){
echo "<option value=\"".$i."\">".$month_name[$i]."</option>\n";
}
?>
</select>
<select name="year_from" id="year_from">
<option value="none" class="bold italic">Jahr</option>
<?php
for($i=2008; $i<=$year; $i++){
echo "<option value=\"".$i."\">".$i."</option>\n";
}
?>
</select>
</td>
</tr>
<tr>
<td>Thema:</td>
<td><input type="text" name="topic" id="topic" /></td>
</tr>
<tr>
<td>Referent:</td>
<td><input type="text" name="contributer" id="contributer" /></td>
</tr>
<tr>
<td>Beginn:</td>
<td><input type="text" name="begin" id="begin" /> Uhr</td>
</tr>
<tr>
<td>Ort:</td>
<td><input type="text" name="place" id="place" /></td>
</tr>
<tr>
<td>Eintritt:</td>
<td><input type="text" name="entrance" id="entrance" /> €</td>
</tr>
</table>
<br />
<div id="add_erzaehlcafe">
<input type="submit" id="small" class="erzaehlcafe_submit" name="erzaehlcafe_submit" value="speichern">
</div>
</form>
</div>
<h3>Vortrag hinzufügen</h3>
<div>
<form name="vortrag_add" action="index.php?section=events" method="post" accept-charset="utf-8">
<table>
<tr>
<td>Datum:</td>
<td>
<select name="day_from">
<option value="0" class="bold italic">Tag</option>
<?php
for($i=1; $i<=31; $i++){
echo "<option value=\"".$i."\">".$i."</option>\n";
}
?>
</select>
<select name="month_from">
<option value="0" class="bold italic">Monat</option>
<?php
for($i=1; $i<=12; $i++){
echo "<option value=\"".$i."\">".$month_name[$i]."</option>\n";
}
?>
</select>
<select name="year_from">
<option value="0" class="bold italic">Jahr</option>
<?php
for($i=2008; $i<=$year; $i++){
echo "<option value=\"".$i."\">".$i."</option>\n";
}
?>
</select>
</td>
</tr>
<tr>
<td>Thema:</td>
<td><input type="text" name="name_topic" id="name_topic" /></td>
</tr>
<tr>
<td>Referent:</td>
<td><input type="text" name="name_contributer" id="name_contributer" /></td>
</tr>
<tr>
<td>Beginn:</td>
<td><input type="text" name="name_begin" id="name_begin" /> Uhr</td>
</tr>
<tr>
<td>Ort:</td>
<td><input type="text" name="name_place" id="name_place" /></td>
</tr>
<tr>
<td>Eintritt:</td>
<td><input type="text" name="name_entrance" id="name_entrance" /> €</td>
</tr>
</table>
<br />
<div id="add_vortrag">
<input type="submit" id="small" class="vortrag_submit" name="vortrag_submit" value="speichern">
</div>
</form>
</div>
<h3>Ausstellung hinzufügen</h3>
<div>
<form name="ausstellung_add" action="index.php?section=events" method="post" accept-charset="utf-8">
<table>
<tr>
<td>Von:</td>
<td>
<select name="day_from">
<option value="0" class="bold italic">Tag</option>
<?php
for($i=1; $i<=31; $i++){
echo "<option value=\"".$i."\">".$i."</option>\n";
}
?>
</select>
<select name="month_from">
<option value="0" class="bold italic">Monat</option>
<?php
for($i=1; $i<=12; $i++){
echo "<option value=\"".$i."\">".$month_name[$i]."</option>\n";
}
?>
</select>
<select name="year_from">
<option value="0" class="bold italic">Jahr</option>
<?php
for($i=2008; $i<=$year; $i++){
echo "<option value=\"".$i."\">".$i."</option>\n";
}
?>
</select>
</td>
</tr>
<tr>
<td>Bis:</td>
<td>
<select name="day_till">
<option value="0" class="bold italic">Tag</option>
<?php
for($i=1; $i<=31; $i++){
echo "<option value=\"".$i."\">".$i."</option>\n";
}
?>
</select>
<select name="month_till">
<option value="0" class="bold italic">Monat</option>
<?php
for($i=1; $i<=12; $i++){
echo "<option value=\"".$i."\">".$month_name[$i]."</option>\n";
}
?>
</select>
<select name="year_till">
<option value="0" class="bold italic">Jahr</option>
<?php
for($i=2008; $i<=$year; $i++){
echo "<option value=\"".$i."\">".$i."</option>\n";
}
?>
</select>
</td>
</tr>
<tr>
<td>Thema:</td>
<td><input type="text" name="name_topic" id="name_topic" /></td>
</tr>
<tr>
<td>Aussteller:</td>
<td><input type="text" name="name_contributer" id="name_contributer" /></td>
</tr>
<tr>
<td>Eintritt:</td>
<td><input type="text" name="name_entrance" id="name_entrance" /></td>
</tr>
</table>
<br />
<div id="add_ausstellung">
<input type="submit" id="small" class="ausstellung_submit" name="ausstellung_submit" value="speichern">
</div>
</form>
</div>
<h3>Termine bearbeiten/löschen</h3>
<div>
<button id="edit_event">Termin bearbeiten</button>
</div>
Add an <input type="hidden"> to each form with name="submit_X". The input type="submit" element seems to be ignored by serialize();.
Example:
<input type="text"​​​​​​​​​​​​ id="year_from" name="year_from" />
<!-- More inputs.... -->
<input type="hidden" name="submit_1" value="true" />​​​​​​​​​​​​​​​​​
You could also use JavaScript to add another key to the POST data.
Take a look at this fiddle: http://jsfiddle.net/cd7Yy/
You need to show your HTML too.
But from what I see, if you use OnClick event on buttons in your forms, you can create buttons in your HTML with different names for different forms, and then, in your PHP cheack which name you recieve in $_POST

Categories