for some reason i am getting an error with my query statements here is my code

if ($_GET['mode'] == 'edit')
{	$c=$_GET['coursecode'];
	echo"$c";
	// editing an existing entity
 
	// check for value of id
	if (!$_GET['coursecode'])
	{
		echo "error: no coursecode specified, <a href=\"{$_SERVER['PHP_SELF']}\">click here to continue</a>";	
		exit;
	}
 
 
	if (!$_POST['submit'])
	{
		// first access to form
 
				// checking if the record is in the database 
		$query = "SELECT * FROM courses WHERE course_coode='$_GET[coursecode]'";	
		if (!$result=mysql_query($query))
			{
			echo '<p>nice</p>';
			echo "error: user with id {$_GET['coursecode']} does not exist, <a href=\"{$_SERVER['PHP_SELF']}\">click here to continue							 				</a>";	
			exit;	
			}
			else
			{
			echo 'good shit';	
				$row = mysql_fetch_assoc($result);
				extract($row);
 
				$_POST['coursecode']=$course_code;
				$_POST['coursename']=$course_name;
				$_POST['description']=$course_description;
			}
 
			print_form();
	}		
		// retrieve recored
		//$query = "SELECT * FROM courses WHERE course_coode =$_GET['coursecode']";
 
		//$result = ...;
 
		// if record does not exist
		/* if (... record not found ...)
		{
			echo "error: user with id {$_GET['id']} does not exist, <a href=\"{$_SERVER['PHP_SELF']}\">click here to continue</a>";	
			exit;
		}
		*/
 
		// put existing record into $_POST
		/* $_POST['name'] = $row[0];
		   $_POST['id'] = $row[1];
		*/
		//$_POST['name'] = "user";
		//$_POST['id'] = "1234";
 
	if ($_POST['submit'] == 'Save')
	{
		// user clicked save
 
		// validate submitted data
		$messages = validate_input();
		if (count($messages) > 0)
		{
			// invalid data, print form for resubmission
			print_form($messages);
		}
		else
		{
			// data was good, update entry
 
			/* code to save entry */
 
 
				$coursecode=$_POST['coursecode'];
				$coursename=$_POST['coursename'];
				$level=$_POST['level'];
				$optionnumber=$_POST['option_no'];
				$description=$_POST['description'];
				$comp=$_POST['comp'];
				$sem_no=$_POST['sem_no'];
				$credits=$_POST['credits'];
 
 
				$con = mysql_connect("$hostname","$username","$password");
				if (!$con)
				  {
				  die('Could not connect: ' . mysql_error());
				  }
 
				mysql_select_db("$database", $con);
 
				$sql="UPDATE courses SET course_name=$coursename,level_no=$level,option_no=$optionnumber,compulsory=$comp, 	 																												
				sem_no=$sem_no,course_description=$description,credits=$credits WHEREcourse_code=$coursecode ";	
 
				if (!mysql_query($sql,$con))
				  {
				  die('Error: ' . mysql_error());
				  }
				//quire_once('courses.php');
				//echo "1 record added";
				echo "user {$_POST['coursecode']} updated, <a href=\"{$_SERVER['PHP_SELF']}\">click here to continue</a>";
				mysql_close($con);
		}
	}
	else
	{
		// user clicked cancel (catch all)
		echo "operation cancelled, <a href=\"{$_SERVER['PHP_SELF']}\">click here to continue</a>";
 
	}
}

can someone help me with the query statement in line 19 please since with the flags that i have i am only getting "nice "on the screen which shows me that the query statement is wrong for what reason idk.

thanks

It seems that you have a typo in your query in line 19, unless your "course_code" column in the "courses" table is correctly spelled as "course_coode" with an extra o. Also in line 96 you have this: WHEREcourse_code=$coursecode

There should be a space between "WHERE" and "course".

Yes I too spotted the same 2 problems and was about to type it only to realise kokoro90 has already pointed that out.
Please check spellings and space issues and get back if you still face problems

thanks for the assistance now the query works well no i just have a small problem in the update query. the problem that i am having is that i am constantly getting an error and its not updating.

the error is
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 'to Electrical Energy Systems ,level_no=2,option_no=0,compulsory=yes, ' at line 1

if its not to much can u assist me with this error i am currently writing over that query hoping that its nothing to with my spelling this time

thanks for the assistance now the query works well no i just have a small problem in the update query. the problem that i am having is that i am constantly getting an error and its not updating.

the error is
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 'to Electrical Energy Systems ,level_no=2,option_no=0,compulsory=yes, ' at line 1

if its not to much can u assist me with this error i am currently writing over that query hoping that its nothing to with my spelling this time

It seems that you need to give a space between WHERE and your condition in your update query

WHERE course_code=$coursecode

Due to the way line 96 wraps I cannot see if there is a space between "credits=$credits" and "WHERE". If there is no space there, you need to insert one, otherwise it will not be valid SQL. Also check the previous line (95) to ensure you have a space between "SET" and "course_name", as there is again no way to tell due to the line wrapping.

for some reason i am getting an error with my query statements here is my code

if ($_GET['mode'] == 'edit')
{	$c=$_GET['coursecode'];
	echo"$c";
	// editing an existing entity
 
	// check for value of id
	if (!$_GET['coursecode'])
	{
		echo "error: no coursecode specified, <a href=\"{$_SERVER['PHP_SELF']}\">click here to continue</a>";	
		exit;
	}
 
 
	if (!$_POST['submit'])
	{
		// first access to form
 
				// checking if the record is in the database 
		$query = "SELECT * FROM courses WHERE course_coode='$_GET['coursecode']'";	
		if (!$result=mysql_query($query))
			{
			echo '<p>nice</p>';
			echo "error: user with id {$_GET['coursecode']} does not exist, <a href=\"{$_SERVER['PHP_SELF']}\">click here to continue							 				</a>";	
			exit;	
			}
			else
			{
			echo 'good shit';	
				$row = mysql_fetch_assoc($result);
				extract($row);
 
				$_POST['coursecode']=$course_code;
				$_POST['coursename']=$course_name;
				$_POST['description']=$course_description;
			}
 
			print_form();
	}		
		// retrieve recored
		//$query = "SELECT * FROM courses WHERE course_coode =$_GET['coursecode']";
 
		//$result = ...;
 
		// if record does not exist
		/* if (... record not found ...)
		{
			echo "error: user with id {$_GET['id']} does not exist, <a href=\"{$_SERVER['PHP_SELF']}\">click here to continue</a>";	
			exit;
		}
		*/
 
		// put existing record into $_POST
		/* $_POST['name'] = $row[0];
		   $_POST['id'] = $row[1];
		*/
		//$_POST['name'] = "user";
		//$_POST['id'] = "1234";
 
	if ($_POST['submit'] == 'Save')
	{
		// user clicked save
 
		// validate submitted data
		$messages = validate_input();
		if (count($messages) > 0)
		{
			// invalid data, print form for resubmission
			print_form($messages);
		}
		else
		{
			// data was good, update entry
 
			/* code to save entry */
 
 
				$coursecode=$_POST['coursecode'];
				$coursename=$_POST['coursename'];
				$level=$_POST['level'];
				$optionnumber=$_POST['option_no'];
				$description=$_POST['description'];
				$comp=$_POST['comp'];
				$sem_no=$_POST['sem_no'];
				$credits=$_POST['credits'];
 
 
				$con = mysql_connect("$hostname","$username","$password");
				if (!$con)
				  {
				  die('Could not connect: ' . mysql_error());
				  }
 
				mysql_select_db("$database", $con);
 
				$sql="UPDATE courses SET course_name=$coursename,level_no=$level,option_no=$optionnumber,compulsory=$comp, 	 																												
				sem_no=$sem_no,course_description=$description,credits=$credits WHEREcourse_code=$coursecode ";	
 
				if (!mysql_query($sql,$con))
				  {
				  die('Error: ' . mysql_error());
				  }
				//quire_once('courses.php');
				//echo "1 record added";
				echo "user {$_POST['coursecode']} updated, <a href=\"{$_SERVER['PHP_SELF']}\">click here to continue</a>";
				mysql_close($con);
		}
	}
	else
	{
		// user clicked cancel (catch all)
		echo "operation cancelled, <a href=\"{$_SERVER['PHP_SELF']}\">click here to continue</a>";
 
	}
}

can someone help me with the query statement in line 19 please since with the flags that i have i am only getting "nice "on the screen which shows me that the query statement is wrong for what reason idk.

thanks

you try running with the variable enclosed in ' ' quotes

Can I know what method you are using in your form.

If you are using method = get
use $_GET to read the form data.

If you are using method = post
use $_POST to read the form data.

And don't use $_GET and $_POST in your code, If you are don't want to use those to then directly use

$_REQUEST

which will gives you the data even if it is a Get or Post

If you are using $_GET or $_POST in your queries..

use like this

$query = "SELECT * FROM students WHERE id_no = ".$_GET['formdata'];

OR

$query = "SELECT * FROM students WHERE id_no = ".$_POST['formdata'];
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.