Jump to content

UPDATE Query


greens85

Recommended Posts

Hi all,

 

Im trying to produce an edit form on my website.

 

I have the following code:

 

$sql="UPDATE edworld_jobs SET (contactname, emailaddress, telephone, jobref, jobtitle, startdate, deadline, category, jobdescription, location, hours, contract, salary)
VALUES
('$_POST[contactname]','$_POST[emailaddress]','$_POST[telephone]','$_POST[jobref]','$_POST[jobtitle]','$_POST[startdate]','$_POST[deadline]','$_POST[category]','$_POST[jobdescription]','$_POST[location]','$_POST[hours]','$_POST[contract]','$_POST[salary]') WHERE JobID=$job_id";

 

However it doesnt seem to want to update the appropriate row... can anyone tell me what im doing wrong?

 

thanks

Link to comment
https://forums.phpfreaks.com/topic/166673-update-query/
Share on other sites

change it to look like this (not doing the entire query)

 

<?php
$sql = "
UPDATE edworld_jobs SET (
  contactname = $_POST['contact_name'],
  emailaddress = $_POST['emailaddress'],
  etc = $_POST['etc...']
WHERE id = $id
";
?>

 

How does make it work? the id field in my database is called JobID so should this not be in the code anywhere?

Link to comment
https://forums.phpfreaks.com/topic/166673-update-query/#findComment-878869
Share on other sites

Hi tried that and got the following error:

 

Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in /path/to/file/confirmvacancyedit.php on line 15

 

The code is:

 

if(isset($_GET['id']) && is_numeric($_GET['id']))
{
    $job_id = (int) $_GET['id'];
}

$sql = "UPDATE edworld_jobs SET (
contactname = $_POST['contactname'], //THIS IS LINE 15
emailaddress = $_POST['emailaddress'],
telephone = $_POST['telephone'],
jobref = $_POST['jobref'],
jobtitle = $_POST['jobtitle'],
startdate = $_POST['startdate'],
deadline = $_POST['deadline'],
category = $POST['category'],
jobdescription = $_POST['jobdescription'],
location = $_POST['location'],
hours = $_POST['hours'],
contract = $_POST['contract'],
salary = $_POST['salary']
WHERE JobID=$job_id";
?>

 

Any ideas why this error is occuring?

 

thanks

Link to comment
https://forums.phpfreaks.com/topic/166673-update-query/#findComment-879335
Share on other sites

You need quotation marks:

 

<?php
if(isset($_GET['id']) && is_numeric($_GET['id']))
{
    $job_id = (int) $_GET['id'];
}

$sql = "UPDATE edworld_jobs SET (
contactname = \"$_POST['contactname']\", //THIS IS LINE 15
emailaddress = \"$_POST['emailaddress']\",
telephone = \"$_POST['telephone']\",
jobref = \"$_POST['jobref']\",
jobtitle = \"$_POST['jobtitle']\",
startdate = \"$_POST['startdate']\",
deadline = \"$_POST['deadline']\",
category = \"$POST['category']\",
jobdescription = \"$_POST['jobdescription']\",
location = \"$_POST['location']\",
hours = \"$_POST['hours']\",
contract = \"$_POST['contract']\",
salary = \"$_POST['salary']\"
WHERE JobID = $job_id";
?>

Link to comment
https://forums.phpfreaks.com/topic/166673-update-query/#findComment-879337
Share on other sites

You need quotation marks:

 

<?php
if(isset($_GET['id']) && is_numeric($_GET['id']))
{
    $job_id = (int) $_GET['id'];
}

$sql = "UPDATE edworld_jobs SET (
contactname = \"$_POST['contactname']\", //THIS IS LINE 15
emailaddress = \"$_POST['emailaddress']\",
telephone = \"$_POST['telephone']\",
jobref = \"$_POST['jobref']\",
jobtitle = \"$_POST['jobtitle']\",
startdate = \"$_POST['startdate']\",
deadline = \"$_POST['deadline']\",
category = \"$POST['category']\",
jobdescription = \"$_POST['jobdescription']\",
location = \"$_POST['location']\",
hours = \"$_POST['hours']\",
contract = \"$_POST['contract']\",
salary = \"$_POST['salary']\"
WHERE JobID = $job_id";
?>

 

Still getting the same error :(

Link to comment
https://forums.phpfreaks.com/topic/166673-update-query/#findComment-879343
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.