PHP - New/edit/delete Function
Hey i created a page to add/edit/remove job's i've posted.
I got everything running smoothly except for the edit function? any help would be really appreciated <?php $action = $_GET["action"]; if ($action == "delete"){ $delid = $_GET['delid']; $query = "DELETE FROM jobs WHERE id=".$delid." LIMIT 1"; $sql = mysql_query($query); echo("Job succesfully deleted! [ <a href='add_jobs.php'>Back</a> ]"); } if ($action == "edit"){ print("<strong>Editing a Job:</strong>"); $editid = $_GET['editid']; $sql = mysql_query("SELECT * FROM jobs WHERE id = ".$editid." ") or die ('Error: '.mysql_error ()); while ($row = mysql_fetch_array($sql)) { $id = $row['id']; $job_title = $row['job_title']; $job_description = $row['job_description']; $job_type = $row['job_type']; $job_area = $row['job_area']; $query2 = "UPDATE jobs SET (job_title, job_description, job_type, job_area, hot_job) VALUES ('$job_title', '$job_description', '$job_type', '$job_area', '$hot') WHERE id=$id"; echo("<form name='add' method='post' action='?action=edit'>"); echo("<input type='hidden' name='?action=edit'>"); echo("<table class=main cellspacing=0 cellpadding=5 width=50%>"); echo("<tr><td>Job Title: </td><td align='right'><input type='text' size=50 name='job_title' value='$job_title'></td></tr>"); echo("<tr><td>Job Description: </td><td align='right'><textarea size=50 name='job_description'>$job_description</textarea></td></tr>"); echo("<tr><td>Job Type: </td><td align='center'><select name='job_type'><option>Permanent</option><option>Locum or Contract</option></SELECT></td></tr>"); echo("<tr><td>Hot Job? </td><td align='center'>Yes <input type='radio' name='hot' value='Yes'> No <input type='radio' name='hot' value='no'></td></tr>"); echo("<tr><td>Job Area: </td><td align='center'><select name='job_area'><option>East Anglia</option><option>London / South East</option><option>Midlands</option><option>North West</option><option>Northern Ireland</option><option>Scotland</option><option>South</option><option>South West</option><option>Southern Ireland</option><option>Wales</option><option>Yorkshire / North East</option></SELECT></td></tr>"); echo("<tr><td></td><td><div align='right'><input type='Submit'></div></td></tr>"); echo("</table>"); } } if ($action == "add"){ $add = $_POST['add']; $job_title = $_POST['job_title']; $job_description = $_POST['job_description']; $job_type = $_POST['job_type']; $job_area = $_POST['job_area']; $hot = $_POST['hot']; $id = mysql_insert_id(); $query = "INSERT INTO jobs (id, job_title, job_description, job_type, job_area, hot_job) VALUES ('$id', '$job_title', '$job_description', '$job_type', '$job_area', '$hot')"; $sql = mysql_query($query) or die (mysql_error()); } print("<strong>Add A New Job!</strong>"); print("<br />"); print("<br />"); echo("<form name='add' method='post' action='?action=add'>"); echo("<input type='hidden' name='?action=add'>"); echo("<table class=main cellspacing=0 cellpadding=5 width=50%>"); echo("<tr><td>Job Title: </td><td align='right'><input type='text' size=50 name='job_title'></td></tr>"); echo("<tr><td>Job Description: </td><td align='right'><textarea size=50 name='job_description'></textarea></td></tr>"); echo("<tr><td>Job Type: </td><td align='center'><select name='job_type'><option>Permanent</option><option>Locum or Contract</option></SELECT></td></tr>"); echo("<tr><td>Hot Job? </td><td align='center'>Yes <input type='radio' name='hot' value='Yes'> No <input type='radio' name='hot' value='no' checked></td></tr>"); echo("<tr><td>Job Area: </td><td align='center'><select name='job_area'><option>East Anglia</option><option>London / South East</option><option>Midlands</option><option>North West</option><option>Northern Ireland</option><option>Scotland</option><option>South</option><option>South West</option><option>Southern Ireland</option><option>Wales</option><option>Yorkshire / North East</option></SELECT></td></tr>"); echo("<tr><td></td><td><div align='right'><input type='Submit'></div></td></tr>"); echo("</table>"); if($success == TRUE) { print("<strong>Success!</strong>"); } echo("<br>"); echo("</form>"); print("<strong>Existing Jobs:</strong>"); print("<br />"); print("<br />"); echo("<table class=main cellspacing=0 cellpadding=5>"); echo("<td>ID:</td><td>Title:</td><td>Description:</td><td>Type:</td><td>Area:</td><td>Edit (DO NOT USE YET):</td><td>Delete:</td>"); $query = "SELECT * FROM jobs WHERE 1=1"; $sql = mysql_query($query); while ($row = mysql_fetch_array($sql)) { $id = $row['id']; $job_title = $row['job_title']; $job_description = $row['job_description']; $job_type = $row['job_type']; $job_area = $row['job_area']; $position=18; $job_description2 = substr($job_description, 0, $position); echo("<tr><td><strong>$id</strong></td><td><strong>$job_title</strong></td><td><strong>$job_description2...</strong></td><td><strong>$job_type</strong></td><td><strong>$job_area</strong></td><td><a href='add_jobs.php?action=edit&editid=$id'>Edit</a></td><td><a href='add_jobs.php?action=delete&delid=$id'>Delete</a></td></tr>"); } ?> Similar TutorialsOld issue of mine that I'm coming back to. My question is I'm trying to figure out how to work with the select box of options and apply button so that if delete is chosen and the user clicks on apply it performs the deletedivision inside the process page I know it deals with jquery's ajax however this part of it does not that I'm trying to get fixed because as of right now I have if (isset($_POST['deletedivision'])) and I know that's not right and I know I can't apply a name to the option tag because name isn't one of option's allowable attributes. mods/divisions.php Code: [Select] <form action="" method="post"> <label for="actionSelect">With selected items: </label> <select class="select" name="actionSelect" id="actionSelect"> <option id="1">Edit</option> <option id="2">Delete</option> </select> <button class="button small-button"><strong>Apply</strong></button> </form> <?php while ( $row = mysqli_fetch_array ( $result, MYSQL_ASSOC ) ) { echo ' <tr> <td><input type=checkbox class=checkbox name=checkbox[] id=checkbox[] value="' . $row['id'] . '" /></td> <td>' . $row['divisionname'] . '</td> <td>' . $row['name'] . '</td> <td class=last>' . $row['datecreated'] . '</td> </tr>'; } ?> processes/divisions.php if (isset($_POST['deletedivision'])) { $checkbox = $_POST['checkbox']; $countCheck = count($_POST['checkbox']); for($i=0;$i<$countCheck;$i++) { $del_id = $checkbox[$i]; $query = "DELETE from `divisions` where id = $del_id"; mysqli_query($dbc,$query); } } Hi guys, I have a PHP site where logged user can book appointments. I would like the system to be able to monitor which users edited and deleted an appointment or appointments (e.g 'appointment edited/last edited by...'). I already understand how to edit and delete appointments from the MySQL, but the problem is how do I display who deleted/edited the appointment/s. Please your ideas and suggestions a more than welcome. Thanks Hey guys So my question is related to the delete and edit functions in a table When I am able to delete entries, I can't edit When I am able to edit entries, I can't delete Let me explain... Started with the table script first (excerpt): Code: [Select] echo "<form method = \"post\" action=\"{$_SERVER['PHP_SELF']}\"> <table> <tr> <td width=\"55\" class=\"formLabelsS2\"><input type=\"submit\" name=\"delete_mail\" value=\"Delete\" id=\"delete_mail\"></td> </tr> </table>"; echo "<table class=\"sortable\" id=\"query_quick2\" width=\"100%\" >\r\n"; echo "\t<tr><th class=\"sorttable_nosort\" ></th><th class=\"sorttable_nosort\" ></th> <th class=\"sorttable_alpha\" >Promoter Locus</th>\r\n"; if($result->num_rows){ while ($row = $result->fetch_array()){ $RowCount ++; $row_color = ($RowCount % 2) ? $color1 : $color2; echo "\t<tr id=\"{$row['id']}\" class=\"$row_color\" > <!--<form method = \"post\" action=\"{$_SERVER['PHP_SELF']}\">--> <td><input type =\"hidden\" name = \"id\" value=\"{$row['id']}\"/></td> <td><input name=\"checkbox[]\" type=\"checkbox\" id=\"checkbox[]\" value=\"{$row['id']} \"></td> <td>{$row['pro']}</td> <td><input type=\"submit\" name=\"edit_mail\" value = \"Edit\"/></td> <!--</form>--> </tr>"; } } echo "</table>"; echo "</form>"; Script for deleting entries (excerpt): Code: [Select] } elseif(isset($_SESSION['user_id']) AND isset($_POST['delete_mail'])){ //user is deleting existing queries $connect=db_connect_2(); if($_POST['checkbox']){ { foreach($_POST['checkbox'] as $check) { $delete = mysqli_query($connect, "DELETE FROM mailing_list WHERE id = '$check'"); } $msgs[] = "Entry deletion was successful!"; $body = "account.php"; } When "edit_mail" button is pressed: Code: [Select] } elseif(isset($_SESSION['user_id']) AND isset($_POST['edit_mail'])){ //user is editing existing queries $body = "mailingList_edit.php"; } A editing form is displayed based on the value of $id: Code: [Select] <?php //retrieve user information $conn=db_connect_2(); $id = mysqli_real_escape_string($conn, $_POST['id']); $result = $conn->query("SELECT * FROM mailing_list WHERE id = '$id';"); $mail = $result->fetch_array(); ?> <div class="viewTitles" >Edit Your Queries:</div> <form method = "post" action = "<? echo $_SERVER['PHP_SELF'] ?>"> <table> <tr><td width="88" class="formLabelsS2" align="left">Promoter Locus:</td></tr> <tr><td><input class = "basicTextField" type="text" name="pro_edit" value="<? echo $mail['pro']; ?>"></td></tr> </table> OK so what happens is: I can delete entries with no problems by checking off the entries I want to delete then click delete button But when I try to click "edit" button near a specific entry (individually), it DOES refer to a specific entry, but right after i SORT the table using sorttable.js, it would always refer to the LAST entry. So I am suspecting there's problem with positioning of the <form></form> inside the while loop (see the table script, as I put lot of space in between these lines for emphasis) Note that I put these <form> and </form> lines as comment so I could do what I mention above, otherwise I couldn't even delete any entries if I leave these 2 lines to be part of the while loop BUT !! I could edit specific entry even after I sort the table I know this is long thread, so please let me know if you need more clarification Thanks. Hi all. Here is my scripts which allow user to check multiple rows of data and delete it , but it require select data and click for twice to delete the rows , what should be the error? Code: [Select] <form name="frmSearch" method="post" action="insert-add.php"> <table width="600" border="1"> <tr> <th width="50"> <div align="center">#</div></th> <th width="91"> <div align="center">ID </div></th> <th width="198"> <div align="center">First Name </div></th> <th width="198"> <div align="center">Last Name </div></th> <th width="250"> <div align="center">Mobile Company </div></th> <th width="100"> <div align="center">Cell </div></th> <th width="100"> <div align="center">Workphone </div></th> <th width="100"> <div align="center">Group </div></th> </tr> </form> <? echo "<form name='form1' method='post' action=''>"; while($objResult = mysql_fetch_array($objQuery)) { echo "<tr>"; echo "<td align='center'><input name=\"checkbox[]\" type=\"checkbox\" id=\"checkbox[]\" value=\"$objResult[addedrec_ID]\"></td>"; echo "<td>$objResult[addedrec_ID] </td>"; echo "<td>$objResult[FirstName]</td>"; echo "<td>$objResult[LastName] </td>"; echo "<td>$objResult[MobileCompany] </td>"; echo "<td>$objResult[Cell] </td>"; echo "<td>$objResult[WorkPhone] </td>"; echo "<td>$objResult[Custgroup] </td>"; echo "</tr>"; } echo "<td colspan='7' align='center'><input name=\"delete\" type=\"submit\" id=\"delete\" value=\"Delete\">"; if (isset($_POST['delete']) && isset($_POST['checkbox'])) // from button name="delete" { $checkbox = ($_POST['checkbox']); //from name="checkbox[]" $countCheck = count($_POST['checkbox']); for($d=0;$d<$countCheck;$d++) { $del_id = $checkbox[$d]; $sql = "DELETE from UserAddedRecord where addedrec_ID = $del_id"; $result2=mysql_query($sql) or trigger_error(mysql_error());;; } if($result2) { $fgmembersite->GetSelfScript(); } else { echo "Error: ".mysql_error(); } } echo "</form>"; Thanks for every reply. Hello, Hi all. I built an online finance tracking thingy for myself and I got it to work using the following database table and PHP code. I didn't write the PHP code, rather, I edited it to suit my needs. It works great for my needs. I have a way to enter records and view the last 180 records in a table. The thing is, while viewing the table, I would lke to be able to edit and delete records. I don't know enough to be able to do this. Can it be done? I realize my PHP code would probably, for the most part, be totally different. Thanks for any help with this. Here is my DB table structu Code: [Select] DROP TABLE IF EXISTS `money`; CREATE TABLE IF NOT EXISTS `money` ( `id` int(5) NOT NULL AUTO_INCREMENT, `date` date NOT NULL, `type` varchar(18) NOT NULL, `checking` decimal(5,2) NOT NULL DEFAULT '0.00', `cash` decimal(5,2) NOT NULL DEFAULT '0.00', `description` varchar(25) NOT NULL, `who` varchar(25) NOT NULL, `note` varchar(50) NOT NULL, PRIMARY KEY (`id`) ) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ; And here is the PHP: Code: [Select] <?php $result = mysql_query ('SELECT date, type, checking, cash, who, description, note' . ' FROM money' . ' ORDER BY date DESC LIMIT 0,180') or die(mysql_error()); echo "<table border='1' cellpadding='5'>"; echo "<tr><th>Date</th><th>Type</th><th>Checking</th><th>Cash</th><th>Who?</th><th>Description</th><th>Note</th></tr>"; while($row = mysql_fetch_array( $result )) { // Print out the contents of each row into a table echo "<tr><td>"; echo $row['date']; echo "</td><td>"; echo $row['type']; echo "</td><td>"; echo $row['checking']; echo "</td><td>"; echo $row['cash']; echo "</td><td>"; echo $row['who']; echo "</td><td>"; echo $row['description']; echo "</td><td>"; echo $row['note']; echo "</td></tr>"; } echo "</table>"; ?> I want to add text to a file, getting it printed out in index.php and later want to edit/delete per row. I give codes page wise. first the form to take data: add.php: Code: [Select] <?php ?> <form method="post" action="add_data.php"> <fieldset> <legend>Student List</legend> Name : <input type="text" name="uname" /><br> Content : <input type="text" name="age" /> <br> <input type="submit" name="submit" value="send" /> </fieldset> </form> Next adding text to a file: add_data.php: Code: [Select] <?php $id = 1; if (file_exists("data.txt")) { $fp = fopen("data.txt", 'r'); $str = fread($fp, filesize("data.txt")); $str_arr = explode("|", $str); foreach ($str_arr as $rec) { if ($rec) { $id++; } } } $mode = (file_exists("data.txt"))? "a" : "w"; $fp = fopen("data.txt", $mode); $line = $id . "--" . $_POST['uname'] . "--" . $_POST['age'] . "|"; $res = fwrite($fp, $line); fclose($fp); header("location:index.php"); ?>In the index.php, I'd like to fetch data and edit them per row: Code: [Select] <?php $fp = fopen("data.txt", 'r'); $str = fread($fp, filesize("data.txt")); $str_arr = explode("|", $str); echo "<table border='1'>"; echo "<tr><td>ID</td><td>Name</td><td>Age</td><td>Option</td></tr>"; foreach ($str_arr as $rec) { if ($rec) { $rec_arr = explode("--", $rec); echo "<tr>"; foreach ($rec_arr as $col) { echo "<td>$col</td>"; } print "<td><a href=\"edit.php?id=$id\">Edit</a>/<a href=\"delete.php?id=$id\">Delete</a></td></tr>"; } } echo "</table>"; echo "<a href=\"add.php\">Add Data</a>"; ?> Next I want to Edit per row: edit.php: Code: [Select] <?php $fp = fopen("data.txt", 'r'); $str = fread($fp, filesize("data.txt")); $str_arr = explode("|", $str); foreach ($str_arr as $rec) { if ($rec) { $rec_arr = explode("--", $rec); $id = $rec_arr[0]; $name = $rec_arr[1]; $age = $rec_arr[2]; if ($id == $_REQUEST["id"]) { echo "<form action='edit_data.php' method='post'>"; echo "Name :<input type='text' name='uname' value='$name' /><br>"; echo "Age: <input type='text' name='age' value=$age /><br>"; echo "<input type='hidden' name='uid' value=$id />"; echo "<input type='submit' value='Edit'>"; echo "</form>"; } } } ?> From edit.php to edit_data.php where I practically try to edit per row: Code: [Select] <?php $fp = fopen("data.txt", 'r'); $str = fread($fp, filesize("data.txt")); $str_arr = explode("|", $str); foreach ($str_arr as $rec) { if ($rec) { $rec_arr = explode("--", $rec); $id = $rec_arr[0]; $name = $rec_arr[1]; $age = $rec_arr[2]; if ($id == $_POST['uid']) { $new_str = $id . "--" . $_POST['uname'] . "--" . $_POST['age'] . "|"; } else { $new_str = $id . "--" . $name . "--" . $age . "|"; } } } fclose($fp); $fp = fopen("data.txt", 'w'); fwrite($fp, $new_str); fclose($fp); ?> The mechanism is simple. Taking datas from a form, explode them to an array and get them into col/row pattern to edit and delete them. But my problem is when I want to edit in index.php page, specially in this part: Code: [Select] print "<td><a href=\"edit.php?id=$id\">Edit</a> It says, undefined index. But I try to catch this $id in the edit.php page, in this manner, as you see in my code: Code: [Select] foreach ($str_arr as $rec) { if ($rec) { $rec_arr = explode("--", $rec); $id = $rec_arr[0]; $name = $rec_arr[1]; $age = $rec_arr[2]; if ($id == $_REQUEST["id"]) { echo "<form action='edit_data.php' method='post'>"; echo "Name :<input type='text' name='uname' value='$name' /><br>"; echo "Age: <input type='text' name='age' value=$age /><br>"; echo "<input type='hidden' name='uid' value=$id />"; echo "<input type='submit' value='Edit'>"; echo "</form>"; } } } Have I done any mistake here? If anyone points out, I'll be obliged. Not sure how to go about making it so that I can delete and edit a post.. So I am stumped on how to make it to delete and edit post. The key factor for getting the information is the id field. And I am able to get it and display it, but how can I get it to work between all my functions? This is what I have so far. <?php include 'test.php'; function connection() { $connection = @mysql_connect('localhost','root','') or die('could not connect to mysql'); $select_db = @mysql_select_db('tutorials') or die('could not connect to database'); } function delete_post($id) { connection(); $query = "DELETE FROM `posts` WHERE `id` = '$id'"; $result = mysql_query($query); } function find_posts() { connection(); $query = 'SELECT `posts`.`title`, `posts`.`body`, `posts`.`id`, `users`.`username` FROM `posts`, `users` WHERE `posts`.`user_id` = `users`.`id`'; $result = mysql_query($query); while ($row = mysql_fetch_array($result)) { $id = $row['id']; echo '<b>' . $row['title'] . '</b>' .'<a href=/practice/model/posts.php?action=delete>[delete]</a> <a href=/practice/model/posts.php?action=edit>[edit]</a>' . '<br/>'; echo $row['body'] . '<br/>'; echo $row['username'] . '<p>'; } } function find_post($id) { connection(); $query = "SELECT `posts`.`title`, `posts`.`body`, `posts`.`id`, `users`.`username` FROM `posts`, `users` WHERE `posts`.`user_id` = `users`.`id` AND `posts`.`id` = '$id'"; $result = mysql_query($query); $row = mysql_fetch_array($result); echo '<b>' . $row['title'] . '</b>' . '<br/>'; echo $row['body'] . '<br/>'; echo $row['username'] . '<p>'; } function create_post() { connection(); $title = $_POST['title']; $body = $_POST['body']; $query = "INSERT INTO `posts` SET `title` = '$title', `body` = '$body', `created_at` = NOW(), `user_id` = 53"; $result = mysql_query($query); if(!$result) { echo mysql_error(); } } delete_post(7); find_posts(); ?> <?php $action = $_GET['action']; switch ($action) { case 'create': echo 'created' . '<br/>'; create_post(); break; case 'delete': echo 'deleted' . '<br/>'; delete_post($id); break; } ?> <form action="/practice/model/posts.php?action=create" method="POST"> <input type="text" col="40" name="title" /><br/> <textarea cols="30" rows="5" name="body"> </textarea><br/> <input type="submit" name="submit" /> </form> So yea, I am not sure how to get the 'id' parameters linked between everything that needs it. Sorry for the vague description, but its kind of hard to put it into words. If you need a more detailed description please let me know and I will try to. Pretty much want to be able to delete and edit my posts. Thank you! Hello! We our creating an admin page to display a list of all the items within a mysql database, these items are within a table called "item". Each item is categorized, these categories are in a table called "category" each category has an ID. There is then a table called "links" which links the items to their category using ID's. We want to display each item by their category with an edit and delete button. We have it so all the items display with the two buttons in no specific order however we are not too sure how to make it so they all display via their category. Here is the code we are currently using: Code: [Select] <?php $itemlist = mysql_query("SELECT item.item_name, item.item_description, item.item_image, item.item_price, item.item_id FROM item ORDER BY item.item_id ASC"); $item_count = 0; ?> <?php while( $row = mysql_fetch_array($itemlist) ){?> <?php if(($row['item.item_name'] == 1) && (isset($item_count) && $item_count < 1)) { ?> <?php $item_count ++; } ?> <li class="title"> <h3><?php echo $row['item_name'];?></h3><br /> <form action="ourworkadmin.php" method="get"> <input type="hidden" name="item_id" value="<?php echo $row['item_id'];?>" /> <input name="edit" value="Edit" type="submit" /> <input name="remove" value="Remove" type="submit" /> </form> </li> <?php } ?> </ul> <!--Close-items_list--> </div> Any help would be appreciated! Thank you!!! hi...again got in a mess...i m developing this ticketing system where once i check the checkbox and press the edit button,it takes me to the edit page with the same ticket no to be printed there....how do i do this i have attached the two pages for your smooth understanding attachment 1-->page where i check the ticket no from a list of ticket nos attachment2-->page where the ticket no must be displayed as checked on the previous page help is appreciated in advance.... Hey guys, i'm making an edit feature on my website so i can delete,edit or add more jobs, so far i've made the delete and add function's work however i can't seem to get the edit to work This is the edit function Code: [Select] if ($action == "edit"){ print("<strong>Editing a Job:</strong>"); $editid = $_GET['editid']; $s = 'SELECT * FROM jobs WHERE id="$editid"'; $sql = mysql_query($s) or die ('Error: '.mysql_error () . " IN $s"); while ($row = mysql_fetch_array($sql)) { $id = $row['id']; $job_title = $row['job_title']; $job_description = $row['job_description']; $job_type = $row['job_type']; $job_area = $row['job_area']; $query2 = "UPDATE jobs SET (job_title, job_description, job_type, job_area, hot_job) VALUES ('$job_title', '$job_description', '$job_type', '$job_area', '$hot') WHERE id=$id"; echo("<form name='add' method='post' action='?action=edit'>"); echo("<input type='hidden' name='?action=edit'>"); echo("<table class=main cellspacing=0 cellpadding=5 width=50%>"); echo("<tr><td>Job Title: </td><td align='right'><input type='text' size=50 name='job_title' value='$job_title'></td></tr>"); echo("<tr><td>Job Description: </td><td align='right'><textarea size=50 name='job_description'>$job_description</textarea></td></tr>"); echo("<tr><td>Job Type: </td><td align='center'><select name='job_type'><option>Permanent</option><option>Locum or Contract</option></SELECT></td></tr>"); echo("<tr><td>Hot Job? </td><td align='center'>Yes <input type='radio' name='hot' value='Yes'> No <input type='radio' name='hot' value='no'></td></tr>"); echo("<tr><td>Job Area: </td><td align='center'><select name='job_area'><option>East Anglia</option><option>All UK</option><option>London / South East</option><option>Midlands</option><option>North West</option><option>Northern Ireland</option><option>Scotland</option><option>South</option><option>South West</option><option>Southern Ireland</option><option>Wales</option><option>Yorkshire / North East</option></SELECT></td></tr>"); echo("<tr><td></td><td><div align='right'><input type='Submit'></div></td></tr>"); echo("</table>"); } Here is the whole code, Code: [Select] <?php include'modules/sides/header.php'; ?> <table cellpadding="0" cellspacing="0" width="100%" id="mainTable"> <tr> <td class="left"> <?php include'modules/sides/left.php';?> </td> <td id="centercolumn"> <table class="cont" cellspacing="0"> <tr> <td id="centerCcolumn"> <div class="block"> <?php if(session_is_registered('username')){ if ($userlevel = 3){ ?> <div class="blockTitle">Administration - Add/Remove Jobs</div> <div class="blockContent"> <?php $action = $_GET["action"]; if ($action == "delete"){ $delid = $_GET['delid']; $query = "DELETE FROM jobs WHERE id=".$delid." LIMIT 1"; $sql = mysql_query($query); echo("Job succesfully deleted! [ <a href='add_jobs.php'>Back</a> ]"); } if ($action == "edit"){ print("<strong>Editing a Job:</strong>"); $editid = $_GET['editid']; $s = 'SELECT * FROM jobs WHERE id="$editid"'; $sql = mysql_query($s) or die ('Error: '.mysql_error () . " IN $s"); while ($row = mysql_fetch_array($sql)) { $id = $row['id']; $job_title = $row['job_title']; $job_description = $row['job_description']; $job_type = $row['job_type']; $job_area = $row['job_area']; $query2 = "UPDATE jobs SET (job_title, job_description, job_type, job_area, hot_job) VALUES ('$job_title', '$job_description', '$job_type', '$job_area', '$hot') WHERE id=$id"; echo("<form name='add' method='post' action='?action=edit'>"); echo("<input type='hidden' name='?action=edit'>"); echo("<table class=main cellspacing=0 cellpadding=5 width=50%>"); echo("<tr><td>Job Title: </td><td align='right'><input type='text' size=50 name='job_title' value='$job_title'></td></tr>"); echo("<tr><td>Job Description: </td><td align='right'><textarea size=50 name='job_description'>$job_description</textarea></td></tr>"); echo("<tr><td>Job Type: </td><td align='center'><select name='job_type'><option>Permanent</option><option>Locum or Contract</option></SELECT></td></tr>"); echo("<tr><td>Hot Job? </td><td align='center'>Yes <input type='radio' name='hot' value='Yes'> No <input type='radio' name='hot' value='no'></td></tr>"); echo("<tr><td>Job Area: </td><td align='center'><select name='job_area'><option>East Anglia</option><option>All UK</option><option>London / South East</option><option>Midlands</option><option>North West</option><option>Northern Ireland</option><option>Scotland</option><option>South</option><option>South West</option><option>Southern Ireland</option><option>Wales</option><option>Yorkshire / North East</option></SELECT></td></tr>"); echo("<tr><td></td><td><div align='right'><input type='Submit'></div></td></tr>"); echo("</table>"); } } if ($action == "add"){ $add = $_POST['add']; $job_title = $_POST['job_title']; $job_description = $_POST['job_description']; $job_type = $_POST['job_type']; $job_area = $_POST['job_area']; $hot = $_POST['hot']; $id = mysql_insert_id(); $query = "INSERT INTO jobs (id, job_title, job_description, job_type, job_area, hot_job) VALUES ('$id', '$job_title', '$job_description', '$job_type', '$job_area', '$hot')"; $sql = mysql_query($query) or die (mysql_error()); } print("<strong>Add A New Job!</strong>"); print("<br />"); print("<br />"); echo("<form name='add' method='post' action='?action=add'>"); echo("<input type='hidden' name='?action=add'>"); echo("<table class=main cellspacing=0 cellpadding=5 width=50%>"); echo("<tr><td>Job Title: </td><td align='right'><input type='text' size=50 name='job_title'></td></tr>"); echo("<tr><td>Job Description: </td><td align='right'><textarea size=50 name='job_description'></textarea></td></tr>"); echo("<tr><td>Job Type: </td><td align='center'><select name='job_type'><option>Permanent</option><option>Locum or Contract</option></SELECT></td></tr>"); echo("<tr><td>Hot Job? </td><td align='center'>Yes <input type='radio' name='hot' value='Yes'> No <input type='radio' name='hot' value='no' checked></td></tr>"); echo("<tr><td>Job Area: </td><td align='center'><select name='job_area'><option>East Anglia</option><option>All UK</option><option>London / South East</option><option>Midlands</option><option>North West</option><option>Northern Ireland</option><option>Scotland</option><option>South</option><option>South West</option><option>Southern Ireland</option><option>Wales</option><option>Yorkshire / North East</option></SELECT></td></tr>"); echo("<tr><td></td><td><div align='right'><input type='Submit'></div></td></tr>"); echo("</table>"); if($success == TRUE) { print("<strong>Success!</strong>"); } echo("<br>"); echo("</form>"); print("<strong>Existing Jobs:</strong>"); print("<br />"); print("<br />"); echo("<table class=main cellspacing=0 cellpadding=5>"); echo("<td>ID:</td><td>Title:</td><td>Description:</td><td>Type:</td><td>Area:</td><td>Edit (DO NOT USE YET):</td><td>Delete:</td>"); $query = "SELECT * FROM jobs WHERE 1=1"; $sql = mysql_query($query); while ($row = mysql_fetch_array($sql)) { $id = $row['id']; $job_title = $row['job_title']; $job_description = $row['job_description']; $job_type = $row['job_type']; $job_area = $row['job_area']; $position=18; $job_description2 = substr($job_description, 0, $position); echo("<tr><td><strong>$id</strong></td><td><strong>$job_title</strong></td><td><strong>$job_description2...</strong></td><td><strong>$job_type</strong></td><td><strong>$job_area</strong></td><td><a href='add_jobs.php?action=edit&editid=$id'>Edit</a></td><td><a href='add_jobs.php?action=delete&delid=$id'>Delete</a></td></tr>"); } ?></p></table> </div> </div> <?php }else{echo'Stop hacking';}}?> </td> </tr> </table> <td class="right"> <?php include"modules/sides/right.php"; ?> </td> </tr> </table> <?php include'modules/sides/footer.php';?> Any help would be great, thankyou! How can I make this function say if $id is a set parameter, use it. If not, use globals $user_info['uid']? Code: [Select] function fetch_user_info_by_id() { global $user_info; $sql = "SELECT `users`.`id`, `users`.`firstname`, `users`.`lastname`, `users`.`username`, `users`.`email`, `users`.`gender`, `users`.`accounttype`, `users`.`personalweb`, `users`.`guestviews`, `users`.`iviews`, `users`.`eviews`, `users`.`credentials`, `users`.`specialties`, `users`.`country`, `users`.`city`, `users`.`state`, `users`.`phonenumber`, `users`.`dateofbirth` AS `dob`, `iQuestions`.`investortype`, DATE_FORMAT(`users`.`dateofbirth`,'%D \of %M %Y') AS `dateofbirth`, DATE_FORMAT(`users`.`signupdate`,'%D %M %Y') AS `signupdate`, SUM(`companies`.`capitalrequested`) AS `totalrequested`, SUM(`iQuestions`.`capitalavailable`) AS `totalavailable` FROM `users` LEFT JOIN `companies` ON `users`.`id` = `companies`.`adminid` LEFT JOIN `iQuestions` ON `users`.`id` = `iQuestions`.`userid` WHERE `users`.`id` = '${user_info['uid']}'"; $result = mysql_query($sql); return mysql_fetch_assoc($result); } I am trying to create a CMS management website, but I can't seem to get the update function to work. Everything else works fine but not the update function. Can anyone please tell me why or what the problem is? I have spent too long trying to fix it and have failed. It is correctly linked to the database when I hit the edit button all i get is UPDATE_CONTENT_FORM($_GET['ID'])?>where the text boxes should be is . Please help, I am really stuck. (sorry about spelling ) code in CMS_Class.php Class modernCMS{ var $host='localhost'; var $username='lmcmanus13'; var $password='k0gl0zfh3g1ccm4v'; var $db='lmcmanus13'; function connect(){ $con = mysql_connect($this->host, $this->username, $this->password); mysql_select_db($this->db,$con); } function get_content($id =''){ if ($id != ""): $id = mysql_real_escape_string($id);//helps to protect database from beening hacked $sql = "SELECT * FROM `CMS_Content` WHERE id ='$id'"; else: $sql = 'SELECT * FROM `CMS_Content` WHERE 1'; endif; //$query = 'SELECT * FROM `CMS_Content` WHERE 1'; $result = mysql_query($sql) or die(mysql_error()); if (mysql_num_rows($result)!=0): while($row= mysql_fetch_assoc($result)){ echo '<h1><a href="Animals.php?id=' . $row['id'] . '">' . $row['Title'] . '</h1>'; echo '<p>' . $row['Body'] . '</p>'; } else: echo '<p> we are sorry there seems to be a problem with your request</p>'; endif; echo $return='<p><a href ="Animals.php">Back</a></p>'; } function add_content($_POST){ $Title= mysql_real_escape_string($_POST['Title']); $Body= mysql_real_escape_string($_POST['Body']); if(! $Title || ! $Body): if(!$Title=""): echo"<p>The Title is required<p>"; endif; if(!$Body=""): echo"<p>The Body is required<p>"; echo '<a href="add-content.php">Try Again</a>'; endif; else: $sql="INSERT INTO `CMS_Content`(`id`, `Title`, `Body`) VALUES ('null','$_POST[Title]','$_POST[Body]')"; $result = mysql_query($sql) or die(mysql_error()); echo "<meta http-equiv='refresh' content='0;url=added.php'>"; endif; } function manage_content (){ echo '<div id ="manage">'; $sql = 'SELECT * FROM `CMS_Content`'; $result = mysql_query($sql) or die(mysql_error()); while ($row = mysql_fetch_assoc($result)): echo '<h1><a id=' . $row['id'] . '">' . $row['Title'] . '</h1>' ?> <div> <span ><a href="update-content.php?id=<?php= echo= $row['id']?>">Edit</a>|<a href="?delete=<?php echo $row['id']; ?>">Delete</a></a></span> </div> <?php endwhile; echo '</div>';//closes the manages div } Function delete_content($id){ if(!$id){ return false; }else{ $id=mysql_real_escape_string($id); $sql="DELETE FROM CMS_Content WHERE id='$id'"; $result = mysql_query($sql) or die(mysql_error()); echo "<meta http-equiv='refresh' content='0;url=deleted.php'>"; } function update_content_form($id) { $id = mysql_real_escape_string($id); $sql = "SELECT * FROM CMS_Content WHERE id = '$id'"; $res = mysql_query($sql) or die(mysql_error()); $row = mysql_fetch_assoc($res) ?> <form action="Animals.php" method="post" > <input type="hidden" name="update" value="true" /> <input type="hidden" name="id" value="<?php=$row['id']?>" /> <div> <label for="title">Title:</label> <input type="text" name="Title" id="Title" value="<?php=$row['Title']?>" /> </div> <div> <label for="body">Body:</label> <textarea name="body" id="body" rows="8" cols="40"><?php=$row['Body']?></textarea> </div> <input type="submit" name="submit" value="Update content" /> </form> <?php function update_content($p) { $title = mysql_real_escape_string($s['title']); $body = mysql_real_escape_string($s['body']); $id = mysql_real_escape_string($p['id']); if(!$title | !$body): if(!$title): echo "<p>The Title is Required</p>"; endif; if(!$body): echo "<p>The body is Required</p>"; endif; echo '<p><a href=" update_content.php?id=' . $id . '">Try Again</a></p>'; else: $sql = "UPDATE CMS_Content SET title = '$title', body = '$body' WHERE id = '$id'"; $res = mysql_query($sql) or die(mysql_error()); echo "Updated Successfully!"; endif; } } }//end of class } ?>code in Animals.php <h1> Our Animals </h1> <ul> <li><a href="manage-content.php">Manage Content</a></li> <li><a href="add-content.php">Add Content</a></li> </ul> <?php if(isset($_POST['add'])): $obj->add_content($_POST); elseif(isset($_POST['update'])): $obj->update_content_form($_POST); endif; ?> Code in update-content.php <h1> Our Animals j,j</h1> <h1> Update Content </h1> <?=$obj->update_content_form($_GET['id']) ?> Edited by Ch0cu3r, 10 December 2014 - 11:47 AM. Added code tags i'm creating a ticketing system and i need some assistance. The code directly below displays the database records and the delete works fine. The edit however isn't picking the values in the various fields.
<?Php require "config.php"; $page_name="currentout.php"; $start=$_GET['start']; if(strlen($start) > 0 and !is_numeric($start)){ echo "Data Error"; exit; } $eu = ($start - 0); $limit = 10; $this1 = $eu + $limit; $back = $eu - $limit; $next = $eu + $limit; $nume = $dbo->query("select count(id) from receipt")->fetchColumn(); echo "<TABLE class='t1'>"; echo "<tr><th>ID</th><th>Name</th><th>Pass</th><th>Amount</th><th>Action</th></tr>"; $query=" SELECT * FROM receipt limit $eu, $limit "; foreach ($dbo->query($query) as $row) { @$m=$i%2; @$i=$i+1; echo "<tr class='r$m'><td>$row[id]</td><td>$row[name]</td><td>$row[phone_num]</td><td>$row[Amount]</td><td><a href='delete.php?id=$row[id]'>delete</a></td><td><a href='edit.php?id=$row[id]'>Edit</a></td></tr>"; } echo "</table>"; if($nume > $limit ){ echo "<table align = 'center' width='50%'><tr><td align='left' width='30%'>"; if($back >=0) { print "<a href='$page_name?start=$back'><font face='Verdana' size='2'>PREV</font></a>"; } echo "</td><td align=center width='30%'>"; $i=0; $l=1; for($i=0;$i < $nume;$i=$i+$limit){ if($i <> $eu){ echo " <a href='$page_name?start=$i'><font face='Verdana' size='2'>$l</font></a> "; } else { echo "<font face='Verdana' size='4' color=red>$l</font>";} $l=$l+1; } echo "</td><td align='right' width='30%'>"; if($this1 < $nume) { print "<a href='$page_name?start=$next'><font face='Verdana' size='2'>NEXT</font></a>";} echo "</td></tr></table>"; } ?>The code below is edit.php. It's supposed to display the various fields when clicked to allow for editing but it isn't picking any field, PLEASE assist. <?Php require "config.php"; $sql = "SELECT FROM receipt WHERE ID= :ID"; $stmt = $dbo->prepare($sql); $stmt->bindParam(':ID', $_GET['id'], PDO::PARAM_INT); $stmt->execute(); ?> <form action="update.php" method="post" enctype="multipart/form-data"> <table align="center"> <tr> <td> <label><strong>Full Names</strong></label></td> <td> <input type='text' name='name' value=" <?php echo $row['name']; ?>" /> <input type="hidden" name="id" value="<?php echo $id; ?> " /> <br /></td> </tr> <tr> <td><label><strong>ID/Passport No. </strong></label></td> <td> <input type="text" name="pass" value="<?php echo $row['id_passno']; ?> " /><br /></td> </tr> <tr> <td> <label><strong>Phone No. </strong></label></td> <td><input type="text" name="phone" value="<?php echo $row['phone_num']; ?>" /> <br /></td> </tr> <tr> <td> <label><strong>Amount (KShs.) </strong></label></td> <td><input type="text" name="amount" value="<?php echo $row['Amount']; ?> "/> <br /></td> </tr> <tr> <td> <input type="reset" name="Reset" value="CANCEL" onClick="return confirm('Discard changes?');" /> <br></td> <td> <input type="submit" name="Submit2" value="SUBMIT" /> </td> </tr> </table> </form> i'm creating a ticketing system and i need some assistance. The code directly below displays the database records and the delete works fine. The edit however isn't picking the values in the various fields.
<?Php require "config.php"; $page_name="currentout.php"; $start=$_GET['start']; if(strlen($start) > 0 and !is_numeric($start)){ echo "Data Error"; exit; } $eu = ($start - 0); $limit = 10; $this1 = $eu + $limit; $back = $eu - $limit; $next = $eu + $limit; $nume = $dbo->query("select count(id) from receipt")->fetchColumn(); echo "<TABLE class='t1'>"; echo "<tr><th>ID</th><th>Name</th><th>Pass</th><th>Amount</th><th>Action</th></tr>"; $query=" SELECT * FROM receipt limit $eu, $limit "; foreach ($dbo->query($query) as $row) { @$m=$i%2; @$i=$i+1; echo "<tr class='r$m'><td>$row[id]</td><td>$row[name]</td><td>$row[phone_num]</td><td>$row[Amount]</td><td><a href='delete.php?id=$row[id]'>delete</a></td><td><a href='edit.php?id=$row[id]'>Edit</a></td></tr>"; } echo "</table>"; if($nume > $limit ){ echo "<table align = 'center' width='50%'><tr><td align='left' width='30%'>"; if($back >=0) { print "<a href='$page_name?start=$back'><font face='Verdana' size='2'>PREV</font></a>"; } echo "</td><td align=center width='30%'>"; $i=0; $l=1; for($i=0;$i < $nume;$i=$i+$limit){ if($i <> $eu){ echo " <a href='$page_name?start=$i'><font face='Verdana' size='2'>$l</font></a> "; } else { echo "<font face='Verdana' size='4' color=red>$l</font>";} $l=$l+1; } echo "</td><td align='right' width='30%'>"; if($this1 < $nume) { print "<a href='$page_name?start=$next'><font face='Verdana' size='2'>NEXT</font></a>";} echo "</td></tr></table>"; } ?>The code below is edit.php. It's supposed to display the various fields when clicked to allow for editing but it isn't picking any field, PLEASE assist. <?Php require "config.php"; $sql = "SELECT FROM receipt WHERE ID= :ID"; $stmt = $dbo->prepare($sql); $stmt->bindParam(':ID', $_GET['id'], PDO::PARAM_INT); $stmt->execute(); ?> <form action="update.php" method="post" enctype="multipart/form-data"> <table align="center"> <tr> <td> <label><strong>Full Names</strong></label></td> <td> <input type='text' name='name' value=" <?php echo $row['name']; ?>" /> <input type="hidden" name="id" value="<?php echo $id; ?> " /> <br /></td> </tr> <tr> <td><label><strong>ID/Passport No. </strong></label></td> <td> <input type="text" name="pass" value="<?php echo $row['id_passno']; ?> " /><br /></td> </tr> <tr> <td> <label><strong>Phone No. </strong></label></td> <td><input type="text" name="phone" value="<?php echo $row['phone_num']; ?>" /> <br /></td> </tr> <tr> <td> <label><strong>Amount (KShs.) </strong></label></td> <td><input type="text" name="amount" value="<?php echo $row['Amount']; ?> "/> <br /></td> </tr> <tr> <td> <input type="reset" name="Reset" value="CANCEL" onClick="return confirm('Discard changes?');" /> <br></td> <td> <input type="submit" name="Submit2" value="SUBMIT" /> </td> </tr> </table> </form> I made a private messaging system. There is a select all checkbox, but how do I create a function that says delete all of the selected messages? I'm just looking for some logic on this. Hi, ppl, my problem is that whenever the DELETE link is clicked, a javascript confirm box pops up and it should only delete the record with the ID from the $_GET global array if the user clicks the OK button, otherwise it should just redirect to the table of entries WITHOUT DELETION, but somehow it IS DELETING even when CANCEL button of javascript confirm box clicked. Here's my code below: <html> <head><title> </title> </head> <body> <?php require "bellConnect.inc.php"; $ID=$_GET['ID']; $result=mysql_query("SELECT * FROM bellProducts WHERE ID=$ID"); $row=mysql_fetch_assoc($result); $name=$row['Name']; $manufacturer=$row['Manufacturer']; print "Value of ID is $ID"; ?> <script type='text/javascript'> var confirmDelete=confirm("Are you sure you want to delete <?php echo "$name $manufacturer"?> ?"); if(confirmDelete) { <?php $deletedResult=mysql_query("DELETE FROM bellProducts WHERE ID=$ID"); ?> alert("<?php echo "$name $manufacturer" ?> has been deleted successfully."); window.location="http://localhost/index.php"; } else if(!confirmDelete) { window.location="http://localhost/index.php"; } </script> </body> </html> **please help me someone!!! thanks hello there.. im planning to create a simple Online Users that is integrated to Facebook sdk. So far, i have the ff codes: index.php (this is where the online users listed) Code: [Select] <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>Online Users</title> <link type="text/css" rel="stylesheet" href="style.css" /> <script type="text/javascript" src="js/jquery.js"></script> <script type="text/javascript" src="js/ouser.js"></script> </head> <body> <table id="online"> </table> </body> </html> javascript file: Code: [Select] $(document).ready( function() { setInterval (loadLog, 2500); }); function loadLog(){ $.ajax({ url: "onlineusers.html", cache: false, success: function(html){ $("#online").html(html); }, }); } test.php (This is my temporary file to test the Login authentication for FB.. THIS IS WORKING) Code: [Select] <?php session_start(); require_once("src/facebook.php"); $config = array( 'appId' => '285873338131549', 'secret' => '56b9f71b9fd307a033aeeb725893fc89', ); $facebook = new Facebook($config); $user_id = $facebook->getUser(); ?> <?php if($user_id) { try { $user_profile = $facebook->api('/me','GET'); $profile = $user_profile['name']; $_SESSION['user'] = $profile; //PUT USER TO SESSION $_SESSION['user_id'] = $user_id; $line = file_get_contents("onlineusers.html"); $line = trim($line); // removes leading/trailing blank lines $line = explode("\n", $line); $line[] = '<tr><td><img src="https://graph.facebook.com/' . $_SESSION['user_id'] . '/picture"width="25"height="25"/></td><td>' . $_SESSION['user'] . '</td><td><a href="http://www.fb.com/' . $_SESSION['user_id'] . '" target="_blank">View Profile</a></td></tr>'; $line = array_unique($line); $line = implode("\n", $line); file_put_contents("onlineusers.html", $line); echo 'OK'; } catch(FacebookApiException $e) { $login_url = $facebook->getLoginUrl(); echo '<a href="' . $login_url . '">LOGIN</a>'; error_log($e->getType()); error_log($e->getMessage()); } } else { $login_url = $facebook->getLoginUrl(); echo '<a href="' . $login_url . '">LOGIN</a>'; } echo "<a href='logout.php'>Logout</a>"; ?> What it does is, it simple insert the picture and name of the user in a flat html file.. http://www.barkadafm.org/onlineusers/index.php Now, my problem is,. I dont know how to delete the pic and name if a user logs out or disconnect.. Example, my name is Name5 and i will connect / login using http://www.barkadafm.org/onlineusers/test.php for the first connect, my name and picture will be inserted to my flat html file.. Let's assume that there'are already 4 users online.. and the 5th data will be mine. Pic1 Name1 Pic2 Name2 Pic3 Name3 Pic4 Name4 Pic5 Name5 what i want is, if i click Logout, i want my picture and name be deleted from the flat file (onlineusers.html) and destroy my 2 variables set at test.php Please help me.. Thank you! i have the below script but it doesn't work it just refreshes the page anyone know what is wrong Code: [Select] <?php $path = "../../gallery/gallery_files/gallery/"; if(isset($_POST['file']) && is_array($_POST['file'])) { foreach($_POST['file'] as $file) { $dirname = $path; //Recursive Delete Function function DELETE_RECURSIVE_DIRS($dirname) { // recursive function to delete // all subdirectories and contents: if(is_dir($dirname))$dir_handle=opendir($dirname); while($file=readdir($dir_handle)) { if($file!="." && $file!="..") { if(!is_dir($dirname."/".$file))unlink ($dirname."/".$file); else DELETE_RECURSIVE_DIRS($dirname."/".$file); } } closedir($dir_handle); rmdir($dirname); return true; } } } ?> |