0

I am using wampserver php version 5.6.16, I trying to collect the data from form submission:

//First create database
CREATE DATABASE 'college';
Then create table
CREATE TABLE 'students' (
'student_id' int(11) NOT NULL AUTO_INCREMENT,
'student_name' varchar(255) NOT NULL,
'student_email' varchar(255) NOT NULL,
'student_city' varchar(255) NOT NULL,
PRIMARY KEY ('student_id') )

After that I create the page code:

<html>
<head>
<title>insert data in database using mysqli</title>
</head>
<body>

<div id="main">
<h1>Insert data into database using mysqli</h1>
<div id="login">
    <h2>Student's Form</h2>
    <hr/>
    <form action="kiri.php" method="POST">
        <label>Student Name :</label>
        <input type="text" name="stu_name" id="name" required="required" placeholder="Please Enter Name"/><br /><br />
        <label>Student Email :</label>
        <input type="email" name="stu_email" id="email" required="required" placeholder="john123@gmail.com"/><br/><br />
        <label>Student City :</label>
        <input type="text" name="stu_city" id="city" required="required" placeholder="Please Enter Your City"/><br/><br />
        <input type="submit" value=" Submit " name="submit"/><br />
    </form>
</div>


</div>
<?php
if(isset($_POST["submit"])){
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "college";

// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
    die("Connection failed: " . $conn->connect_error);
}

$sql = "INSERT INTO students (student_name, student_email, student_city)
VALUES ('".$_POST["stu_name"]."','".$_POST["stu_email"]."','".$_POST["stu_city"]."')";

if ($conn->query($sql) === TRUE) {
    echo "<script type= 'text/javascript'>alert('New record created successfully');</script>";
} else {
    echo "<script type= 'text/javascript'>alert('Error: " . $sql . "<br>" . $conn->error."');</script>";
}

$conn->close();
}
?>
</body>
</html>

But I get this error:

Deprecated: Automatically populating $HTTP_RAW_POST_DATA is deprecated and will be removed in a future version. To avoid this warning set 'always_populate_raw_post_data' to '-1' in php.ini and use the php://input stream instead. in Unknown on line 0

Warning: Cannot modify header information - headers already sent in Unknown on line 0

Community
  • 1
  • 1
Mehran
  • 137
  • 3
  • 9
  • 1
    you used regular quotes `'` for your table creation and therefore, it never got created, that's IF that is your actual codes for it. – Funk Forty Niner Jun 28 '16 at 13:06
  • 2
    There is no `header` in the provided code. You are open to SQL injections as well. – chris85 Jun 28 '16 at 13:07
  • [Little Bobby](http://bobby-tables.com/) says ***[your script is at risk for SQL Injection Attacks.](http://stackoverflow.com/questions/60174/how-can-i-prevent-sql-injection-in-php)*** Learn about [prepared](http://en.wikipedia.org/wiki/Prepared_statement) statements for [MySQLi](http://php.net/manual/en/mysqli.quickstart.prepared-statements.php). Even [escaping the string](http://stackoverflow.com/questions/5741187/sql-injection-that-gets-around-mysql-real-escape-string) is not safe! – Jay Blanchard Jun 28 '16 at 13:09
  • 1. go and change setting in php.ini file and then restart server. 2. No header is shown in your code – Alive to die - Anant Jun 28 '16 at 13:10
  • Thank you for reply,I created the SQL manually through phpmyadmin – Mehran Jun 28 '16 at 13:12

0 Answers0