Menu
Hi All,
How the submit of a form will take place if there is more than one image in a single page
say i have one image.
[code=php]<input type=”image” img src=”images/addtocart.gif” width=”85″ height=”17″>
and i am getting the form values in this way
[code=php]
if(isset($_POST[‘x’]))
{
……
…….
}
Now if i have another image and i want to submit the form through 2nd image then how post will recognise which image has been used for which form?
Please advice me
Thanks all for your help………luv…….Raj
[CODE]<input type="image" src="images/addtocart.gif" width="85" height="17" name="x">
<input type="image" src="images/addtocart.gif" width="85" height="17" name="y">
if(isset($_POST['x']))
{
echo "bbb";
}
if(isset($_POST['y']))
{
echo "aaa";
}
[/CODE]
According to some specification for the input type image, you will get two values-- [I]name.x[/I] and [I]name.y[/I]. So maybe you should be checking if [I]x.x[/I] or [I]y.x[/I] are set.Is it what you mean?Not quite!
Raj[/QUOTE]
[code=html]<input type="image" img src="images/addtocart.gif" width="85" height="17" name="image1" value="some value">
<input type="image" img src="images/addtocart.gif" width="85" height="17" name="image2" value="some value">[/code]
[code=php]
<?
if($_POST['image1']=="value1")
{
do something....
}
else if($_POST['image2'] == "value2")
{
do something else....
}
?>
[/code]
[CODE]print_r($_POST);[/CODE]
It will show you exactly what you're receiving from the form. (Make sure you put <pre></pre> tags around this so it will be correctly formatted output.)1.If I do print_r($_POST) nothing is displaying....full blank...even array() this is not displayed[/QUOTE]You probably have GET as your form method.
[code=php]<?
session_start();
$sid=session_id();
//print_r($_SESSION);
ob_start();
include("db.php");
if(isset($_SESSION['mid']))
{
$cart_id=$mid;
}
else
{
$cart_id=$sid;
}
$pid=$_GET['pid'];
//add to cart sql
if(isset($_POST['submit']))
{
print_r($_POST);
$pid=$_POST['pid'];
$item_price=$_POST['item_price'];
$quantity=$_POST['quantity'];
$net_total=$quantity*$item_price;
//echo "insert into temp_cart(cart_id,pid,quantity,item_price,net_total) values('$cart_id','$pid','$quantity','$item_price','$net_total')";
$s_temp="insert into temp_cart(cart_id,pid,quantity,item_price,net_total) values('$cart_id','$pid','$quantity','$item_price','$net_total')";
$q_temp=mysql_query($s_temp) or die(mysql_error());
header("location:cart.php");
}
$sql="select * from product where pid='$pid'";
$q=mysql_query($sql) or die(mysql_error());
while($row=mysql_fetch_array($q))
{
$icode=$row['icode'];
$prdesc=$row['prdesc'];
$design=$row['design'];
$type=$row['type'];
$d1=$row['d1'];
$d2=$row['d2'];
$ht1=$row['ht1'];
$ht2=$row['ht2'];
$list=$row['list'];
}
?>
<link rel="stylesheet" href="style.css" type="text/css">
<body>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td align="left" valign="top">
<?include("header.php");?>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr align="left" valign="top">
<td width="249" class="rightnorder"><img src="images/metricseal.gif" width="249" height="200"></td>
<td width="514" class="rightnorder"><img src="images/innerimg.jpg" width="513" height="200"></td>
<td width="261" background="images/gradient.gif"> </td>
</tr>
<tr align="left" valign="top">
<td class="rightnorder">
<?include("login.php");?>
<?include("cat.php");?>
<?include("feedback.php");?>
</td>
<td class="rightnorder">
<table width="100%">
<tr>
<td align="right" width="36%"> </td>
<td align="right" width="39%"><img src="images/view_cart_icon.gif" width="26" height="24"></td>
<td align="left" valign="middle" class="ntext" width="25%" height="23"><a href="cart.php">
View Cart</a></td>
</tr>
</table>
<form name="form1" method="post" action="">
<table width="97%" cellpadding="3" class="table">
<tr align="center">
<td colspan="5" class="Subtitle">Product Details:</td>
</tr>
<tr>
<td width="18%" class="ntext"><b>Icode:</b></td>
<td width="39%" class="ntext" align="left" colspan="2">
<?=$icode;?>
</td>
<td width="43%" class="ntext" align="left" colspan="2">
<?=$prdesc;?>
</td>
</tr>
<tr>
<td width="18%" class="ntext"><b>Type:</b></td>
<td width="39%" class="ntext" colspan="2">
<?=$type;?>
</td>
<td width="43%" class="ntext" colspan="2">
<?=$design;?>
</td>
</tr>
<tr>
<td colspan="5" class="ntext"><b>Nominal Inner Diameter of Seal:
</b>
<?=$d1;?>
</td>
</tr>
<tr>
<td colspan="5" class="ntext"><b>Nominal Outer Diameter of Seal:
</b>
<?=$d2;?>
</td>
</tr>
<tr>
<td colspan="5" class="ntext"><b>Height of seal as it fits in
groove(HT1):</b>
<?=$ht1;?>
</td>
</tr>
<tr>
<td colspan="5" class="ntext"><b>Complete height of seal, including
extending lip(HT2):</b>
<?=$ht2;?>
</td>
</tr>
<tr>
<td colspan="5" class="ntext"><b>Product price</b>
<?=$list;?>
</td>
</tr>
<tr>
<td class="Subtitle" colspan="5"> </td>
</tr>
<tr>
<td width="18%" class="ntext">Quantity:</td>
<td width="19%" class="ntext">
<input type="text" name="quantity" value="1" size="7">
</td>
<td width="20%" class="ntext">
<input type="submit" name="submit" value="Add To Cart" class="button">
</td>
<td class="ntext" width="21%" valign="middle">
<input type="hidden" name="pid" value="<?=$pid;?>">
<input type="hidden" name="item_price" value="<?=$list;?>">
<!--<input type="image" img src="images/addtocart.gif" width="85" height="17" name="y" value="up">-->
<input type="button" value="Back" onClick="history.go(-1)" class="button" name="button">
</td>
<td class="ntext" width="22%" valign="middle"> </td>
</tr>
</table>
</form>
<br>
</td>
<td bgcolor="#F7F7F7"> </td>
</tr>
</table> </td>
</tr>
</table>
</body>
</html>[/code]
[code=html]<input type="image" img src="images/addtocart.gif" width="85" height="17" name="image1">
<input type="image" img src="images/addtocart.gif" width="85" height="17" name="image2">[/code]
On clicking the first image it outputs:[CODE]Array
(
[quantity] => 1
[pid] =>
[item_price] =>
[image1_x] => 45
[image1_y] => 9
)[/CODE]
Which makes the following code feasible:[code=php]if(isset($_POST['image1_x']))
{
# ***
}
elseif(isset($_POST['image2_x']))
{
# ***
}
else
{
# ***
}[/code]
0.1.9 — BETA 5.25