Forum Moderators: coopster
My clients wants a form which should have two fields
-----------------------------------------------------
Name
Message
Preview(Submit) Cancel(Reset)
-----------------------------------------------------
after filling he should get a preview of that
Like this e.g
-----------------------------------------------------
Name : India
Message : India rocks
Send(submit) Edit(submit) Delete(submit)
-----------------------------------------------------
I had modified all data but i had struck on this
when i had submitted send,edit,delete the page is redirecting
I had used <?php echo $PHP_SELF ?> for this.
I want all the action in the same page
--------------------------------------------------------------------
<?php
session_start();
include "../includes/dbConnection.php";
?>
<html>
<head>
</head>
<body>
<p>Manage Photos >> Add Invitations </p>
<form name="form" action="" method="POST" enctype="multipart/form-data" >
<table border="1" align="center">
<tr>
<td colspan="2" align="center">Add Invitation</td>
</tr>
<tr>
<td>Name : </td><td><input type="text" name="name" value="<?php echo $_POST['name'] ?>"></td></tr>
<tr><td>Invitation message :</td><td><textarea name="message"><?php echo $_POST['message'] ?></textarea></td>
</tr>
<tr><td colspan="2"> </td></tr>
<tr><td colspan="2" align="center">
<input type="submit" name="submit" value="Preview">
<input type="reset" name="reset" value="Cancel"></td></tr>
</table>
<br><br><br>
<?php
if($_POST['submit'])
{
$insert = mysql_query("insert into invitations
(inv_id,name,message)
values('','$_POST[name]','$_POST[message]')")or die("Unable to Insert :".mysql_error());
$insertid = mysql_insert_id();
$_SESSION['ins'] = $insertid;
$select = mysql_query("select * from invitations where inv_id='$insertid' ");
echo "select * from invitations where inv_id='$insertid' ";
$r = mysql_fetch_array($select);
?>
<?php
if(isset($_POST['send']))
{
$to = "saideep@example.com";
$subject = "Invitation from Eye-raters";
$body= "Name :";
$body.= stripslashes($_POST['ed_name']);
$body .= "\nMessage:";
$body .= stripslashes($_POST['ed_message']);
$from = "support@example.com";
$headers = "From:$from";
mail($to,$subject,$body,$headers);
//echo "<script language=javascript>window.location=\"index.php\";alert(\"Mailed Succesfully\");</script>";
echo "<center>Mailed succesfully<center>";
}
if(isset($_POST['edit']))
{
$update = mysql_query("update invitations set
name='$_POST[ed_name]',
message='$_POST[ed_message]' where inv_id='$insertid' ")or die("Unable to Update :".mysql_error());
echo "<center>update invitations set
name='$_POST[ed_name]',
message='$_POST[ed_message]' where inv_id='$insertid'<center>";
}
if(isset($_POST['cancel']))
{
$delete = mysql_query("delete from invitations where inv_id='$insertid' ")or die("Unable to delete :".mysql_error());
echo "<center>Deleted succesfully<center>";
}
?>
<?php
/*switch ($_POST['sub']) {
case 'Send Invitation':
$to = "saideep@example.com";
$subject = "Invitation from Eye-raters";
$body= "Name :";
$body.= stripslashes($_POST['ed_name']);
$body .= "\nMessage:";
$body .= stripslashes($_POST['ed_message']);
$from = "support@example.com";
$headers = "From:$from";
mail($to,$subject,$body,$headers);
//echo "<script language=javascript>window.location=\"index.php\";alert(\"Mailed Succesfully\");</script>";
echo "<center>Mailed succesfully<center>";
break;
case 'Edit':
$update = mysql_query("update invitations set
name='$_POST[ed_name]',
message='$_POST[ed_message]' where inv_id='$insertid' ")or die("Unable to Update :".mysql_error());
break;
case 'Cancel':
$delete = mysql_query("delete from invitations where inv_id='$insertid' ")or die("Unable to delete :".mysql_error());
echo "<center>Deleted succesfully<center>";
break;
}
*/
?>
<!-- <form name="theForm" method="POST" enctype="multipart/form-data" > -->
<table border="1" align="center">
</tr>
<tr><td>Name : </td><td><input type="text" name="ed_name" value="<?php echo $r['name'] ?>"></td></tr>
<tr><td>Invitation message :</td><td><textarea name="ed_message"><?php echo $r['message'] ?></textarea></td></tr>
<tr>
<td colspan=3 align=center>
<input type="submit" name="send" value="Send Invitation">
<input type="submit" name="edit" value="Edit">
<input type="submit" name="cancel" value="Cancel"></td>
</tr>
<!--
<tr>
<td colspan=3 align=center>
<input type="submit" name="sub" value="Send Invitation" onClick="document.theForm.action='send.php'">
<input type="submit" name="sub" value="Edit" onClick="document.theForm.action='<?php echo $PHP_SELF ?>'">
<input type="submit" name="sub" value="Cancel" onClick="document.theForm.action='cancel.php'"></td>
</tr>
-->
</table>
</form>
<?php
}
?>
</body>
</html>
--------------------------------------------------------------------
Solution by you is appreciated
Regards
saideep
[edited by: eelixduppy at 8:33 pm (utc) on Feb. 28, 2009]
[edit reason] exemplified [/edit]
i have changed the form submit buttons name like this
<tr>
<td colspan=3 align=center>
<input type="submit" name="send" value="Send Invitation">
<input type="submit" name="edit" value="Edit">
<input type="submit" name="cancel" value="Cancel"></td>
</tr>
I tried
Switch case
and your's solution
My problem is after submitting the page shouldn't redirect
at first submit button Its inserting values in DB
Send button ---->for submitting this values to mail
Edit button ---->To edit the values
Cancel button--->To delete the record
After click any button.I must able to stay in the same page
Kindly reply me
Waiting for some better reply's
Thanks