Jump to content
tshing70

how to make Add and Edit in one form?

Recommended Posts

I have a lndex.php to show the data, and Add , Edit text link to member.php....but how can i do the ADD and EDIT in one form???anyone can provide some example code???

Share this post


Link to post
Share on other sites

you can pass any flag in action attribue of the form like http://somesite.com/member.php?action=addon the recieving page you will check $_GET['action'] and act depending upon that.

Share this post


Link to post
Share on other sites

Sry, but i quite confuse... can help check my code??index.php<HTML><HEAD><TITLE>List</TITLE></HEAD> <BODY> <table border="1" width"400"><tr> <td>Id</td><td>Name</td><td>Gender</td><td>Dob</td><td>Address</td><td>State</td><td>Ismember</td></tr> <?php $link=mysql_connect("localhost","root",""); $db=mysql_select_db("member_db", $link); $querry="SELECT * FROM newmember"; $result = mysql_query($querry); $i = 1; while ( $row = mysql_fetch_array($result, MYSQL_ASSOC) ) ?> <tr> <td><?php echo $row['P_Id']; ?></td> <td><?php echo $row['Name']; ?></td> <td><?php echo $row['Gender'];?></td> <td><?php echo $row['Dob'];?></td> <td><?php echo $row['Address']; ?></td> <td><?php echo $row['State'];?></td> <td><?php echo $row['Ismember'];?></td> <td>[<a href =editform.php?id=<?php echo $row['P_Id]?>">Edit</a>] [<a href =deleteform.php?id=<?php echo $row['P_Id]?>">Delete</a>] </td> </tr> <a href = "member.php?id=<?php echo $row['P_Id']?>">Add New Member</a> </TABLE></BODY></HTML> member.php<HTML> <?php if (isset($_POST['submit'])){$name = $_POST['Name'];$gender = $_POST['Gender'];$dob = $_POST['Dob'];$address = $_POST['Address'];$state = $_POST['State'];$ismember = $_POST['Ismember']; $link=mysql_connect("localhost","root","");$db=mysql_select_db("member_db", $link); $sql = "INSERT INTO newmember (Name,Gender,Dob,Address,State,Ismember)VALUES ('','$name','$gender','$dob','$address','$state','$ismember')";$result = mysql_query($sql);if($result){echo("<br>Input data is sucess");}else{echo("<br>Input data is fai;l");}}?><HEAD><TITLE>Form</TITLE> <script type="text/javascript" src="tcal.js"></script><link rel="stylesheet" type="text/css" href="tcal.css" /></HEAD> <BODY> <FORM ACTION ="index.php" method="POST"> <table border='1'><tr><td>Name</td><td><Input type ="text" NAME="name"></td></tr> <tr><td>Gender</td><td><Input type = "radio" NAME="gender" VALUE="M">Male<Input type = "radio" NAME="gender" VALUE="F">Female</td></tr> <tr><td>D.O.B</td><td><Input type = "date" NAME="dob" class="tcal" value=""></td></tr> <tr><td>Address</td><td><textarea NAME = "address" ROWS = "4" COLS="30"></textarea></td></tr> <tr><td>State</td><td><select name = "state"><option><option>SABAH<option>SARAWAK<option>KUCHING<option>SIBU<option>MIRI</select></td></tr> <tr><td>Is Member</td><td><input type ="checkbox" name ="ismember" value="Yes"></td></tr> <tr><td></td><td><input type ="reset" NAME = "reset" value="Clear"><input type ="submit" NAME ="submit" value="Save"></td></tr></FORM></BODY></HTML> thank a lot.....

Share this post


Link to post
Share on other sites

your add,edit text link does not point to member.php . I thought you want to pass that in same script and do the processing from that page. or i am missing something?

Share this post


Link to post
Share on other sites
your add,edit text link does not point to member.php . I thought you want to pass that in same script and do the processing from that page. or i am missing something?
your add,edit text link does not point to member.php . I thought you want to pass that in same script and do the processing from that page. or i am missing something?
Sorry about that, haven't change it...heheAnd also , this code i cant add new data to my index.php...can see what is the problem??

Share this post


Link to post
Share on other sites

<a href = 'member.php?page_mode=add_user'>this send name value pairs via GET so the data will be available in $_GET super global array. you can check $_GET['page_mode'] and take certain action depending upon its value.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×