Click here to Skip to main content
15,848,264 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I am new OOP PHP learner.I just wanted to create a table and insert my posts.Then I've faced Parse error above.

What I have tried:

include "db.php";
include "config.php";

$db = new database();

if (isset($_POST['submit'])){
	$title = $_POST['title'];
	$content = $_POST['content'];
$query = "INSERT INTO posts(title,content) VALUES('$title',$content')"




<!DOCTYPE html>


<form action="insert_post.php" method="post" enctype="multipart/form-data">
	<div class="form-group">
	<center><table width="800" align="center" border="2">
		<tr bgcolor="orange">
		<td colspan="6"><h1 style="text-align:center">Post EDIT</h1></td>
			<td align="right" bgcolor="orange">Post title:</td>
			<td><input type="text" name="title" size="60"></td>
			<td align="right" bgcolor="orange">Post Content:</td>
			<td><textarea name="Content" rows="15" cols="40"></textarea></td>

	<td colspan="6" align="center" bgcolor="orange"><input type="Submit" name="submit" value="Publish Now"  /></td>


Updated 29-Apr-22 1:43am

There is no semicolon at the end of the previous line:
$query = "INSERT INTO posts(title,content) VALUES('$title',$content')";
//                                       This is missing in your code ^
See also PHP: Instruction separation - Manual[^]
Share this answer
In addition to solution 1, I suspect
$query = "INSERT INTO posts(title,content) VALUES('$title','$content')";
// a single quote was missing                         here ^

Never build an SQL query by concatenating strings. Sooner or later, you will do it with user inputs, and this opens door to a vulnerability named "SQL injection", it is dangerous for your database and error prone.
A single quote in a name and your program crash. If a user input a name like "Brian O'Conner" can crash your app, it is an SQL injection vulnerability, and the crash is the least of the problems, a malicious user input and it is promoted to SQL commands with all credentials.
SQL injection - Wikipedia[^]
SQL Injection[^]
SQL Injection Attacks by Example[^]
PHP: SQL Injection - Manual[^]
How can I explain SQL injection without technical jargon? - Information Security Stack Exchange[^]
Share this answer
CHill60 29-Apr-22 10:40am    
Did you notice the date of the OP?
Patrice T 29-Apr-22 13:08pm    
No Missed it. Thank you
$hasil = mysqli_query($con,"SELECT * FROM MURID
WHERE NOKP= '".$nokp."'") ;
$row = mysqli_fetch_array($hasil);
$nama = htmlspecialchars($row['NAMA'],ENT_QUOTES);
$notel = $row['NOTEL'];
$emel =$row['EMEL'];
$idmurid =$row['IDMUIRD'];
Share this answer
Dave Kreskowiak 1-Jul-22 11:49am    
Whatever this is it's getting removed as a non-answer to a five year old question.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900