Click here to Skip to main content
15,913,333 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
PHP
<?php
include_once('connection.php');
if(isset($_POST['submit']))
{
$name= $_POST['name'];
$email=$_POST['email'];
$add=$_POST['address'];
$adm=$_POST['admission'];
if(mysql_query("insert into student_record(name,email,address,joining_date) VALUES

('$name','$email','$add','$adm',)")
{
	echo "values has been submitted";
}
}
?>


<!DOCTYPE html>

<title>niraj php

<p>Name:<br></p>
<p>Email:<br></p>
<p>Address : <br> </p>
<p>Admission Date: <br></p>
<p>
</p>


What I have tried:

I have tried to remove the curly bracket but it didn't work.
Posted
Updated 28-Aug-17 23:06pm
v2

The problem is:
PHP
if(mysql_query("insert into student_record(name,email,address,joining_date) VALUES ('$name','$email','$add','$adm',)")
{

You have one ) after your string, and that closes the ( after mysql_query. However, your ( of the if statement is still open, so you need another ) to close that as well:
PHP
if(mysql_query("insert into student_record(name,email,address,joining_date) VALUES ('$name','$email','$add','$adm',)"))
{
That aside, I'm not sure if that comma after '$adm' is supposed to be there; I think you have to remove that as well (although that would be a MySQL syntax error, not a PHP one)

Also, this way of executing a query is very bad. You are simply putting all POST values into your query; you have an SQL Injection[^] vulnerability. Learn about parameterized queries to overcome this.
 
Share this answer
 
v2
Comments
CPallini 29-Aug-17 4:20am    
5.
Not a solution to your question, but another problem you have.
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[^]
SQL Injection Prevention Cheat Sheet - OWASP[^]
 
Share this answer
 

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