i want to provide an option to user to preview the form input before form submission, it runs well, but it does the same action on pressing submission or preview button
html
<form>
<tr>
<td width="26%" height="30" align="right"><font face="Calibri">Category:</font></td>
<input type="text" name="category" size="30"></td>
<td width="26%" height="30" align="right"><font face="Calibri">City:</font></td>
<input type="text" name="city" size="30"></td>
<td width="26%" height="30" align="right"><font face="Calibri">Ad Title:</font></td>
<input type="text" name="adTitle" size="30"></td>
</tr>
</table>
<p align="center">
<input name="put" type="submit" value="Submit" onclick="action='postAd.php?action=submit';">
<input name="put" type="submit" value="Preview" onclick="action='postAd.php?action=preview';">
</p>
</form>
the php script is as follow
if(isset($_POST['put'])) {
$category = $_POST['category'];
$city = $_POST['city'];
$adTitle = $_POST['adTitle'];
$action = $_POST['action'];
if ($action = 'preview')
{
echo $category;
echo $city;
echo $adTitle;
}
if ($action = 'submit')
{
if (!get_magic_quotes_gpc()) {
$category = addslashes($category);
$city = addslashes($city);
$adTitle = addslashes($adTitle);
}
$sql = "INSERT INTO `class-ads`.`post-ad` (ad_id, cat_name, city_name, ad_title, )
VALUES (NULL,'$category', '$city', '$adTitle')";
mysql_query($sql) or die('Error, Posting Ad failed : ' . mysql_error());
echo "You successfully posted the advertisment";
}
}
when i press submit it enters all data to database, but the same thing happens after pressing preview button as well.
i have tried every option, i know but in vain..i am not understanding where i am doing wrong. please some one guide me in this regard.
thanks in advance
shuja