Created
May 3, 2013 09:08
-
-
Save INDIAN2020/5508106 to your computer and use it in GitHub Desktop.
crud
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <!doctype html> | |
| <html lang="en"> | |
| <head> | |
| <meta charset="UTF-8"> | |
| <title>Document</title> | |
| </head> | |
| <body> | |
| <?php | |
| //defining the values | |
| $isValid = false; | |
| $myname = $_POST['fullname']; | |
| $hiddenID = $_POST['hiddenID']; | |
| //database connection | |
| $dbc = mysqli('localhost','','',''); | |
| // did user press the submit button | |
| if (isset($_POST['submit'])) { | |
| if (strlen($myname) <= 3) { | |
| echo "You can not be that cool!!<br />"; | |
| } | |
| } else { | |
| if (empty($hiddenID)) { | |
| $isValid = true; | |
| //do what is SAVE NAME | |
| //table=names | |
| $insert = "insert into names(personname) values ($myname)"; | |
| $results = mysqli_query($dbc, $insert); | |
| echo "Done<br />"; | |
| $myname = ''; //make the input field empty after the query execution | |
| } | |
| else { | |
| //update | |
| $update = "update names set personname='$myname' where id='$hiddenID'"; | |
| mysqli_query($dbc, $update); | |
| } | |
| } | |
| //show all names from the database | |
| $myQuery = "select * from names orderby id"; | |
| $results = mysqli_query($dbc, $myQuery); | |
| if (!$isValid) { | |
| ?> | |
| <form action="<?php echo $_SERVER['PHP_SELF']; ?>"> | |
| <label for="firstname">Enter Name: </label> | |
| <input type="text" id="fullname" name="fullname" value="<?php echo $myname; ?>" /> | |
| <input type="hidden" name="hiddenID" value="<?php echo $idtoedit;?>" /> | |
| <input type="submit" name="submit" value="Save" /> | |
| </form> | |
| <?php | |
| } | |
| //show the data READ | |
| while($row = mysqli_fetch_array($results)){ | |
| echo "<p> ID: ".$row['id']." ".$row['personname']."<a href=\"".$_SERVER['PHP_SELF']."?idtodelete=".$row['id']."\">DELETE</a>"." "."<a href=\"".$_SERVER['PHP_SELF']."?idtoedit=".$row['id']."\">EDIT</a>"; | |
| } | |
| mysqli_close($dbc); | |
| ?> | |
| </body> | |
| </html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
thanks man :)