Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- $con = mysql_connect("localhost","hairadmin","hairtest");
- function login(){
- global $con;
- $con = mysql_connect("localhost","hairadmin","hairtest");
- if (!$con)
- {
- die('Could not connect: ' . mysql_error());
- }
- mysql_select_db("hairs", $con);
- }
- function closeCon(){
- mysql_close($con);
- }
- function add_trad(){
- global $con;
- $sql="INSERT INTO Translators (FirstName, LastName, Tel, Email, Notes)
- VALUES
- ('$_POST[firstname]','$_POST[lastname]','$_POST[tel]','$_POST[email]','$_POST[notes]')";
- if (!mysql_query($sql,$con))
- {
- die('Error: ' . mysql_error());
- }
- header("HTTP/1.0 303 See other");
- header("Location: #");
- //echo "1 record added";
- }
- function edit_trad($trad){
- global $con;
- $sql_edit = mysql_query("SELECT * FROM Translators WHERE ID='$trad'");
- $myTrad = mysql_fetch_array($sql_edit);
- $t = $myTrad['ID'];
- if (isset($_POST['update_t'])) {
- save_trad($trad);
- //show_trad();
- closeCon();
- return;
- }
- echo "<div>";
- echo "<h1>Edit " . $myTrad['FirstName'] . $myTrad['LastName'] . "</h1>";
- echo "<br />";
- echo "<form action='' method='post'>";
- echo "Firstname: <input type='text' name='n_firstname' value='" . $myTrad['FirstName'] . "'/>";
- echo "Lastname: <input type='text' name='n_lLastname' value='" . $myTrad['LastName'] . "' />";
- echo "Tel: <input type='text' name='n_tel' value='" . $myTrad['Tel'] . "' />";
- echo "Email: <input type='text' name='n_email' value='" . $myTrad['Email'] . "' />";
- echo "Notes: <input type='text' name='n_notes' value='" . $myTrad['Notes'] . "' />";
- echo "<br /><br /><input type='checkbox' name='update_t' />";
- echo "<input type='submit' value='SAVE' />";
- echo "</form>";
- echo "</div>";
- echo $trad;
- }
- function save_trad($trad){
- global $con;
- $sql_save="UPDATE Translators SET FirstName='$_POST[n_firstname]', LastName='$_POST[n_lastname]', Tel='$_POST[n_tel]', Email='$_POST[n_email]', Notes='$_POST[n_notes]') WHERE ID=$trad";
- if (!mysql_query($sql_save,$con))
- {
- die('Error: ' . mysql_error());
- }
- // header("HTTP/1.0 303 See other");
- // header("Location: #");
- echo "1 record update:". $trad ;
- }
- function del_trad($trad){
- global $con;
- $sql="DELETE FROM Translators WHERE ID='$trad'";
- if (!mysql_query($sql,$con))
- {
- die('Error: ' . mysql_error());
- }
- header("HTTP/1.0 303 See other");
- header("Location: #");
- //echo "ID:". $trad . "deleted";
- }
- function show_trad(){
- $result = mysql_query("SELECT * FROM Translators");
- echo "<table border='1'>
- <tr>
- <th>ID</th>
- <th>Firstname</th>
- <th>Lastname</th>
- <th>Tel</th>
- <th>Email</th>
- <th>Notes</th>
- <th>Status</th>
- <th>Edit</th>
- <th>Delete</th>
- </tr>";
- while($row = mysql_fetch_array($result)){
- $ck_del ="del_" . $row['ID'];
- $ck_edit ="edit_" . $row['ID'];
- $a = $row['ID'];
- if (isset($_POST[$ck_del])) {
- login();
- del_trad($a);
- closeCon();
- return;
- }
- if (isset($_POST[$ck_edit])) {
- login();
- edit_trad($a);
- closeCon();
- return;
- }
- echo "<tr>";
- echo "<td>" . $row['ID'] . "</td>";
- echo "<td>" . $row['FirstName'] . "</td>";
- echo "<td>" . $row['LastName'] . "</td>";
- echo "<td>" . $row['Tel'] . " <input value='SMS' name='SMS' type='submit' /></td>";
- echo "<td>" . $row['Email'] . " <input value='Send' name='Send' type='submit' /></td>";
- echo "<td>" . $row['Notes'] . "</td>";
- echo "<td>" . $row['Status'] . "</td>";
- echo "<td><form method='post'><input type='checkbox' name='" . $ck_edit . "' /><input value='Edit' name='edit' type='submit' /></form></td>";
- echo "<td><form method='post'><input type='checkbox' name='" . $ck_del . "' /><input value='Delete' name='del' type='submit' /></form></td>";
- echo "</tr>";
- }
- echo "</table>";
- }
- login();
- show_trad();
- closeCon();
- ?>
- <html>
- <body>
- <div>
- <h1>New User</h1>
- <br />
- <form action="" method="post">
- Firstname: <input type="text" name="firstname" />
- Lastname: <input type="text" name="lastname" />
- Tel: <input type="text" name="tel" />
- Email: <input type="text" name="email" />
- Notes: <input type="text" name="notes" />
- Active: <input type="checkbox" name="status" value"active" />
- <br /><br />
- <input type="submit" />
- </form>
- </div>
- </body>
- </html>
- <?php
- if (isset($_POST['status'])) {
- login();
- add_trad();
- // show_trad();
- closeCon();
- return;
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement