Jump to content

Recommended Posts

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 :D

 

					  <?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>");
}
	?>

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

I'm pretty sure it was this line,

 

$sql = mysql_query("SELECT * FROM jobs WHERE id = ".$editid." ") or die ('Error: '.mysql_error ());

 

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 '' at line 1

Right, i'm now using

					  <?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>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>");
}
	?>

 

The error has now gone, however it wont display any of the data from the query. Any help would be greatly thanked :D

The previous problem (the mysql error) was because $editid was empty and since the query expected a numeric value in $editid, the result was a sql syntax error.

 

Your code should be validating ALL external data, but more seriously, the code that is supposed to be putting a $_GET['editid'] onto the end of the URL is not working.

 

The latest problem is because you changed the query to begin and end with single-quotes and the php variable $editid inside that query is no longer being replaced with the value in $editid.

 

 

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.