PHP Code for Submitting details into a Database

Asked By 10 points N/A Posted on -
qa-featured

Hello everyone.

I am a beginner when it comes to PHP programming.

I would like to ask some experts to help me with this.

What is the PHP code that I will be using to submit input information into a database?

I hope I'll be able to get your answers soon. Thank you.

SHARE
Best Answer by Chung Opi
Best Answer
Best Answer
Answered By 5 points N/A #99401

PHP Code for Submitting details into a Database

qa-featured

Everyone is new in some field and learn the different techniques with time, no matter you will learn PHP with time.

In order to get complete code you can refer to http://www.blazonry.com/scripting/linksdb/insert_data.php, this link will provide complete code and also give description of those code. You can also use html code in PHP so this tutorial will also helpful in defining that area.

This link will guide you how you can submit data in data bases, Hope this will be helpful and your problem will be resolved soon. Have a good day and enjoy PHP. There are many different codes related to PHP on this site.

Answered By 0 points N/A #99402

PHP Code for Submitting details into a Database

qa-featured

Hello, thank you for your question. I am sanjoy, and I'll do my best to help you.

Let us see how submit inputted information into a database. I'll create a php application that collect student information and store into a database. At first, create a database (say, studentinfo) using phpmyadmin. Now create a table (say, student_name) with there fileds, such as, roll_no, name, phone under "studentinfo" database. Create two files named form.php and post.php .

Open the file form.php and write down the below code,

<html>

<body>

<form action="post.php" method="post">

Student Name: <input type="text" name="name" /><br>

Roll No: <input type="text" name="roll_no" /><br>

Phone: <input type="text" name="phone" /><br>

<input type="submit" />

</form>

</body>

</html>

Now Open the file post.php and write down the below code,

<?php

$connection = mysql_connect("localhost","root","123456"); // change "root" with your mysql database user name and "123456" with your database password.

if (!$connection)

  {

  die('Could not connect: ' . mysql_error());

  }

mysql_select_db("studentinfo", $connection);

$sql="INSERT INTO student_name (roll_no, name, phone) VALUES ('$_POST[roll_no]','$_POST[name]','$_POST[phone]')";

if (!mysql_query($sql,$connection))

  {

  die('Error: ' . mysql_error());

  }

echo "Student Info Successfully Inserted into Database";

mysql_close($connection);

?>

Open any browser and run form.php, fill the form and enter "Submit" button.

I think, it solve your problem. I'd be waiting for your reply.

Thanks

Related Questions