-1

im getting the following syntax error can someone please help! im guessing it something soooo easy but i have been looking at it for ages and can see what im doing wrong

<?php
if(isset($_POST['delete']))
{
$dbhost = '';
$dbuser = '';
$dbpass = '';
$conn = mysql_connect($dbhost, $dbuser, $dbpass);
if(! $conn )
{
  die('Could not connect: ' . mysql_error());
}

$CourseId = $_POST['CourseId'];

$sql = "DELETE  course ".
       " WHERE CourseId = $CourseId" ;

mysql_select_db('d11os_projectdb');
$retval = mysql_query( $sql, $conn );
if(! $retval )
{
  die('Could not delete data: ' . mysql_error());
}
echo "Deleted data successfully\n";
mysql_close($conn);
}
else
{
?>`enter code here` 

2 Answers2

3
$sql = "DELETE FROM  course ".       --<-- Missing key word FROM
       " WHERE CourseId = $CourseId"
M.Ali
  • 67,945
  • 13
  • 101
  • 127
  • It could have taken this person 2 seconds to google this. But I guess when you dont even know what to google its a bit hard :) – M.Ali May 05 '14 at 21:32
  • Well we all have been there :) I am still there though lol :) – M.Ali May 05 '14 at 21:34
  • Cheers Rahul thank you for you input will keep this in mind for next time :P – M.Ali May 05 '14 at 21:35
  • 1
    just kidding, nice catch though +1 – Rahul May 05 '14 at 21:36
  • i have made the following changes $sql = "DELETE ROW FROM course WHERE CourseId = $CourseId"; but am now getting this error???? Could not delete data: Unknown column 'G4NC' in 'where clause' i need it to allow the user to type in a course id and then delete the row – user3605679 May 06 '14 at 00:12
0

You are missing the table name from the sql query

$sql = "DELETE  course FROM **table_name**".
       " WHERE CourseId = $CourseId" ;
user2998120
  • 23
  • 1
  • 5