tshing70 Posted July 13, 2012 Share Posted July 13, 2012 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??? Link to comment Share on other sites More sharing options...
niche Posted July 13, 2012 Share Posted July 13, 2012 (edited) You do the add and edit in the php script that's defined in the form's action. EDIT http://www.w3schools.com/tags/att_form_action.asp Edited July 13, 2012 by niche Link to comment Share on other sites More sharing options...
birbal Posted July 13, 2012 Share Posted July 13, 2012 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. Link to comment Share on other sites More sharing options...
tshing70 Posted July 13, 2012 Author Share Posted July 13, 2012 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..... Link to comment Share on other sites More sharing options...
birbal Posted July 13, 2012 Share Posted July 13, 2012 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? Link to comment Share on other sites More sharing options...
tshing70 Posted July 13, 2012 Author Share Posted July 13, 2012 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?? Link to comment Share on other sites More sharing options...
justsomeguy Posted July 13, 2012 Share Posted July 13, 2012 There are several examples of processing forms in this thread: http://w3schools.invisionzone.com/index.php?showtopic=12509 Link to comment Share on other sites More sharing options...
tshing70 Posted July 14, 2012 Author Share Posted July 14, 2012 There are several examples of processing forms in this thread: http://w3schools.inv...showtopic=12509 If i don't use the<input type="hidden" name="page_mode" value="add_user"> method change to <a href = 'member.php'> method, how it look like??? Can give some example??? thank Link to comment Share on other sites More sharing options...
birbal Posted July 14, 2012 Share Posted July 14, 2012 <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. Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now