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 'desc = '', duration = '', avail = ''' at line 4
I'm a student who need to submit the project in 12 hours. My lecturer will not help to solve the prob as i took few hours with no soloution found. This is my 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 'desc = '', duration = '', avail = ''' at line 4
THis is my php script for SQL as below:
<?php
include 'db.php';
//Start Delete Contact
if(isset($_POST["action"]) and $_POST["action"]=="delete"){
$id = (isset($_POST["ci"])? $_POST["ci"] : '');
$sql = "delete from tblcourseinfo
where regid = $id";
$result = mysqli_query($link, $sql);
if(!$result)
{
echo mysqli_error($link);
exit();
}
}
//End Delete Contact
//Insert or Update course information
if(isset($_POST['action_type']))
{
if ($_POST['action_type'] == 'add' or $_POST['action_type'] == 'edit')
{
//Sanitize the data and assign to variables
$regid = mysqli_real_escape_string($link, strip_tags($_POST['regid']));
$coursename = mysqli_real_escape_string($link, strip_tags($_POST['coursename']));
$price = mysqli_real_escape_string($link, strip_tags($_POST['price']));
$desc = mysqli_real_escape_string($link, strip_tags($_POST['desc']));
$duration = mysqli_real_escape_string($link, strip_tags($_POST['duration']));
$avail = mysqli_real_escape_string($link, strip_tags($_POST['avail']));
if ($_POST['action_type'] == 'add')
{
$sql ="insert into tblcourseinfo set
coursename = '$coursename',
price = '$price',
desc = '$desc',
duration = '$duration',
avail = '$avail'";
}else{
$sql ="update tblcourseinfo set
coursename = '$coursename',
price = '$price',
desc = '$desc',
duration = '$duration',
avail = '$avail'
where regid = $regid";
}
if (!mysqli_query($link, $sql))
{
echo 'Error Saving Data. ' . mysqli_error($link);
exit();
}
}
header('Location: courselist.php');
exit();
} // End Insert or update information
//Start of edit contact read
$gresult = ''; //declare global variable
if(isset($_POST["action"]) and $_POST["action"]=="edit"){
$id = (isset($_POST["ci"])? $_POST["ci"] : '');
$sql = "select regid, coursename,
price, desc,
duration, avail from tblcourseinfo
where regid = $id";
$result = mysqli_query($link, $sql);
if(!$result)
{
echo mysqli_error($link);
exit();
}
$gresult = mysqli_fetch_array($result);
include 'update.php';
exit();
}
//Read registrants information from database : Stage 1
$sql = "select * from tblcourseinfo";
$result = mysqli_query($link, $sql);
if(!$result)
{
echo mysqli_error($link);
exit();
}
//Loop through each row on array and store the data to $reg_list[] : Stage 2
while($rows = mysqli_fetch_array($result))
{
$reg_list[] = array('regid' => $rows['regid'],
'coursename' => $rows['coursename'],
'price' => $rows['price'],
'desc' => $rows['desc'],
'duration' => $rows['duration'],
'avail' => $rows['avail']);
}
include 'courselist.php';
exit();
?>
Subject
Written By
Posted
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 'desc = '', duration = '', avail = ''' at line 4
September 01, 2015 09:06AM
September 01, 2015 09:39AM
September 01, 2015 11:22AM
September 01, 2015 04:37PM