Add function in php application does not work

I have a problem adding records to my database. When I try to add a record in the database, I get the following message: Parse error: syntax error, unexpected ‘$objUser’ (T_VARIABLE) in C:\xampp\htdocs\phpcrud… on line 9.

Can some please help me with this?

Here’s a snippet of the code:

$objUser = new User();

// GET
if(isset($_GET['edit_aid'])){
$aid = $_GET['edit_aid'];
$stmt = $objUser->runQuery("SELECT * FROM attendance WHERE aid = :aid");
$stmt->execute(array(":aid" => $aid));
$rowUser = $stmt-fetch(PDO::FETCH_ASSOC);
}else{
$aid = null;
$rowUser = null;
}

// POST
if(isset($_post['btn_save'])){
$total_attendance = strip_tags($_POST['total_attendance']);
$total_missed = strip_tags($_POST['total_missed']);
$total_escaped = strip_tags($_POST['total_escaped']);
$sid = strip_tags($_POST['sid']);

try{
	if($aid != null){
	  if($objUser->update($total_attendance, $total_missed, $total_escaped, $sid, 
$aid)){
		$objUser->redirect('index.php?updated')
	  }
	}else{
		if($objUser->insert($total_attendance, $total_missed, $total_escaped, $sid)){
		  $objUser->redirect('index.php?inserted')
		}else{
			$objUser->redirect('index.php?error')
		}
	}
}catch(PDOException $e{
	echo $e getMessge();
}
}

The posted code is filled with missing ‘;’, ‘)’, ‘->’, and ‘>’ syntax. The actual cause of the error is something before the first line of code that you did post, probably a missing ‘;’ on the previous line.

This code looks familiar. It looks like it is following a youtube/github project named pknowledge php_crud_base (I won’t post the actual link since we don’t want others to use this bad code.)

Please, don’t follow along with these junk programming videos. Instead, learn the fundamentals of the php/sql language, then design, write, test, and debug code and queries that do what you want.

Sponsor our Newsletter | Privacy Policy | Terms of Service