Jump to content

Recommended Posts

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

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,

<?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! :)

Link to comment
https://forums.phpfreaks.com/topic/233356-edit-function/
Share on other sites

it looks like your edit mode only pre fills the form, and doesnt actually update the database on submission.

 

perhaps add a hidden field in the edit form called update and set it to true, or =1 ,whatever really

 

then under the ($action=='edit') part you can either update the submitted data (because update is true), or show the prefilled form with the data (because update isnt true)

you could also do it by checking if $_POST is true instead of $_GET.

 

 

Link to comment
https://forums.phpfreaks.com/topic/233356-edit-function/#findComment-1200013
Share on other sites

try echoing put the $row[] data before you pass to variables, just to be sure that it is pulling out the data from the database?

 

also your hidden field is borked, its got a name that probably (im not 100'%) got illegal characters, and no value.

 

does teh form  itself display? if it does it means something is found in the database as its echoed inside the while loop

Link to comment
https://forums.phpfreaks.com/topic/233356-edit-function/#findComment-1200021
Share on other sites

Right, here's what i've got now

 

if ($action == "edit"){
print("<strong>Editing a Job:</strong>");
$editid = $_GET['editid'];
$s = "SELECT * FROM jobs WHERE id=".$editid." LIMIT 1";
$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_title',job_description='$job_description',job_type='$job_type',job_area='$job_area','hot_job'='$hot_job' WHERE id=$id"; echo("<form name='add' method='post' action='?action=edit'>");
echo("<table class=main cellspacing=0 cellpadding=5 width=50%>");
echo("<input type='hidden' name='id' value='$id'>");
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>");
}

 

The when selecting a job to edit /add_jobs.php?action=edit&editid=75

it prefills all forms with the correct details, once i edit the job and press submit i'm getting

Editing a Job:Error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'LIMIT 1' at line 1 IN SELECT * FROM jobs WHERE id= LIMIT 1

Link to comment
https://forums.phpfreaks.com/topic/233356-edit-function/#findComment-1200045
Share on other sites

thats because when you post its still executing the prepopulation part too.

 

 

also you are using 2 variables for the same value $editid and $id are the same thing, chose one and stick to that throughout

 

if(action=="edit")
{
if ($_POST)
   {
     //do the updating stuff
   }
   else 
   {
      //show prepopulated form
    }
}

Link to comment
https://forums.phpfreaks.com/topic/233356-edit-function/#findComment-1200179
Share on other sites

Right i think im getting there, i've tidyed the code up abit for you :)

 

<?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"];
////DELETE A JOB ////
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> ]");
}
////EDIT A JOB ////
if ($action == "edit"){
print("<strong>Editing a Job:</strong>");
if ($_POST) {
$editid = $_GET['editid'];
$job_title = $_POST['job_title'];
$job_description = $_POST['job_description'];
$job_type = $_POST['job_type'];
$job_area = $_POST['job_area'];
$hot = $_POST['hot'];
$nurse_vet = $_POST['nurse_vet'];
$query2 = "UPDATE jobs SET job_title='$job_title',job_description='$job_description',job_type='$job_type',job_area='$job_area','hot_job'='$hot_job','nurse_vet'='$nurse_vet' WHERE id=$editid"; 
$sql = mysql_query($query2) or die ('Error: '.mysql_error () . " IN $s");
}else {
$editid = $_GET['editid'];
$s = "SELECT * FROM jobs WHERE id=".$editid." LIMIT 1";
$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'];
$hot = $row['hot'];
$nurse_vet = $row['nurse_vet'];
echo("<table class=main cellspacing=0 cellpadding=5 width=50%>");
echo("<input type='hidden' name='id' value='$id'>");
echo("<form name='add' method='post' action='?action=edit'>");
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' checked></td></tr>");
echo("<tr><td>Nurse or Vet job? </td><td align='center'>Vet <input type='radio' name='nurse_vet' value='Vet'> Nurse <input type='radio' name='nurse_vet' value='Nurse' 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>");
}
}
}
////ADD A JOB ////
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'];
$nurse_vet = $_POST['nurse_vet'];
$id = mysql_insert_id();
$query = "INSERT INTO jobs (id, job_title, job_description, job_type, job_area, hot_job, nurse_vet) VALUES ('$id', '$job_title', '$job_description', '$job_type', '$job_area', '$hot', '$nurse_vet')";
$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>Nurse or Vet job? </td><td align='center'>Vet <input type='radio' name='nurse_vet' value='Vet'> Nurse <input type='radio' name='nurse_vet' value='Nurse' 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'></form></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>Nurse/Vet Job:</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'];
$nurse_vet = $row['nurse_vet'];
$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><strong>$nurse_vet</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';?>

 

Right now, it's populating the form but when i'm submitting, the error i'm now getting is

 

Editing a Job:Error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''hot_job'='','nurse_vet'='Nurse' WHERE id=' at line 1 IN 

Link to comment
https://forums.phpfreaks.com/topic/233356-edit-function/#findComment-1200214
Share on other sites

you are still muddling editid and id variables, and now you are asking for an editid via $_GET inside a $_POST so it wont work

change this bit

if ($_POST) {
$editid = $_GET['editid'];

 

to

if ($_POST) {
$editid = $_POST['id'];

 

showing exactly why you should stick to 1 variable through a process, in your script you have $delid,$editid $id and they all carry the same value (ID from the database table)

I cannot urge you enough to stop doing this

you are using action to decide what $action to take, not $id, its so not needed and only proving to make things more complicated for you unnesscessarily

 

TIP:

a very good way to check the sql is to echo out the sql statement into the page whilst you develop

 

$query2 = "UPDATE jobs SET job_title='$job_title',job_description='$job_description',job_type='$job_type',job_area='$job_area','hot_job'='$hot_job','nurse_vet'='$nurse_vet' WHERE id=$editid"; 
echo $query2;

 

 

Link to comment
https://forums.phpfreaks.com/topic/233356-edit-function/#findComment-1200217
Share on other sites

Thankyou for all your help so far,

 

Editing a Job:UPDATE jobs SET job_title='', job_description='', job_type='Permanent', job_area='East Anglia', 'hot_job'='', 'nurse_vet'='Nurse' WHERE id=Add A New Job!

 

That's what i get when echo'ing out the sql, i can't see why the hot_job enum isn't being filled in =/

 

<?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"];
////DELETE A JOB ////
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> ]");
}
////EDIT A JOB ////
if ($action == "edit"){
print("<strong>Editing a Job:</strong>");
if ($_POST) {
$editid = $_POST['id'];
$job_title = $_POST['job_title'];
$job_description = $_POST['job_description'];
$job_type = $_POST['job_type'];
$job_area = $_POST['job_area'];
$hot = $_POST['hot'];
$nurse_vet = $_POST['nurse_vet'];
$query2 = "UPDATE jobs SET job_title='$job_title', job_description='$job_description', job_type='$job_type', job_area='$job_area', 'hot_job'='$hot_job', 'nurse_vet'='$nurse_vet' WHERE id=$editid"; 
echo $query2;
//////$sql = mysql_query($query2) or die ('Error: '.mysql_error () . " IN $s");
}else {
$editid = $_GET['editid'];
$s = "SELECT * FROM jobs WHERE id=".$editid." LIMIT 1";
$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'];
$hot = $row['hot'];
$nurse_vet = $row['nurse_vet'];
echo("<table class=main cellspacing=0 cellpadding=5 width=50%>");
echo("<input type='hidden' name='id' value='$id'>");
echo("<form name='add' method='post' action='?action=edit'>");
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' checked></td></tr>");
echo("<tr><td>Nurse or Vet job? </td><td align='center'>Vet <input type='radio' name='nurse_vet' value='Vet'> Nurse <input type='radio' name='nurse_vet' value='Nurse' 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>");
}
}
}
////ADD A JOB ////
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'];
$nurse_vet = $_POST['nurse_vet'];
$id = mysql_insert_id();
$query = "INSERT INTO jobs (id, job_title, job_description, job_type, job_area, hot_job, nurse_vet) VALUES ('$id', '$job_title', '$job_description', '$job_type', '$job_area', '$hot', '$nurse_vet')";
$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>Nurse or Vet job? </td><td align='center'>Vet <input type='radio' name='nurse_vet' value='Vet'> Nurse <input type='radio' name='nurse_vet' value='Nurse' 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'></form></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>Nurse/Vet Job:</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'];
$nurse_vet = $row['nurse_vet'];
$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><strong>$nurse_vet</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';?>

Link to comment
https://forums.phpfreaks.com/topic/233356-edit-function/#findComment-1200243
Share on other sites

Thankyou, i think i'm almost there :D,

 

Error,

Editing a Job:Error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''hot_job'='no', 'nurse_vet'='Nurse' WHERE id='78' LIMIT 1' at line 1 IN UPDATE jobs SET job_title='', job_description='', job_type='Permanent', job_area='East Anglia', 'hot_job'='no', 'nurse_vet'='Nurse' WHERE id='78' LIMIT 1

Query,

$query2 = "UPDATE jobs SET job_title='$job_title', job_description='$job_description', job_type='$job_type', job_area='$job_area', 'hot_job'='$hot', 'nurse_vet'='$nurse_vet' WHERE id='$editid' LIMIT 1"; 
$sql = mysql_query($query2) or die ('Error: '.mysql_error () . " IN $query2");

Link to comment
https://forums.phpfreaks.com/topic/233356-edit-function/#findComment-1200255
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.