how to insert data into mysql database using a textbox in php?

Member Avatar for diafol

how to use Google?
how to use php.net?
how to use forum search?
how to show us your code so far?

To insert data into Mysql DB using PHP yop should have to use Mysql insert statement.
An Example of this
HTML page script .
<form action ="next.php" method="post" >
<input type ="text" name="name" />
</form>

page next.php
$link = mysql_connect("Server name","username","passwd");
mysql_select_db("db name"):
$result = mysql_query("insert into tablenmae values($_POST[name])");
if($result)
echo "Record inserted.";

Member Avatar for diafol

mysqli even?

So to insert value to mysql there are following steps

1. make connectio to mysql using
$con=mysql_connect("[server ip/address]","[user]","[password]")
eg:-

$con=mysql_connect("localhost","root","");

2. select the database
$db=mysql_select_db("database_name",$con);
eg:-

$db=mysql_select_db("employee",$con);

3. insert the data into database using mysql query
$res=mysql_query("Insert into abc values('field1'...);
eg:

$query=mysql_query("Insert into abc values('iim','manager')");

Hopefully it's clear...
If you have any doubt just click here

thankz both 3 of you :)....i know how to use google but i only post here to have a second option in case i cant find anything in google...

@ardav.....if you cant answer nicely ... just dont reply ...... and btw thanks for the
effort :)

Member Avatar for diafol

You waste everybody's time with inane questions like this.

how to insert data into mysql database using a textbox in php?

and this statement:

i only post here to have a second option in case i cant find anything in google

Why don't you just search Google and get a script, fiddle with it and come back when you hit a problem.

.if you cant answer nicely ... just dont reply

That's rich, if you can't be bothered to do some work for yourself, don't post. Read the guidelines. You should show some effort yourself.

wasting time? ....what is daniweb made for? ...actually i just pass by and drop some thread to see if somebody is replying and yeah they reply ..


Why don't you just search Google and get a script, fiddle with it and come back when you hit a problem.

thats what i said ..then i hit the thing called problem and i need some clear tuts


oh yeah you dont know what your talking .........


well yeah overall you win ... my fault :)

how to insert data into mysql database using a textbox in php?

Dear valued member, any body please send me code to INSEETDATAQUERY IN OOP PHPWITH MYSQL

<form action ="#" method="post" >
<input type ="text" name="name" />
<input type ="submit" name="submit" value="submit" />
</form>
<?php
if(isset($_POST['submit']))
$link = mysql_connect("localhost","root","") or die(mysql_error());
mysql_select_db("db_name") or die(mysql_error());
$result = mysql_query("insert into tablenmae values('".$_POST[name]."')") or die(mysql_error());
if($result)
{
  echo "values inserted.";
}
else
{
  echo'Not inserted';
}

Try this code:

Processor.php

<?php
$con=mysqli_connect("example.com","peter","abc123","my_db");
// Check connection
if (mysqli_connect_errno()) {
  echo "Failed to connect to MySQL: " . mysqli_connect_error();
}

mysqli_query($con,"INSERT INTO Persons (FirstName, LastName, Age)
VALUES ('Peter', 'Griffin',35)");

mysqli_query($con,"INSERT INTO Persons (FirstName, LastName, Age) 
VALUES ('Glenn', 'Quagmire',33)");

mysqli_close($con);
?>

Registration.php


<html>
<body>

<form action="insert.php" method="post">
Firstname: <input type="text" name="firstname">
Lastname: <input type="text" name="lastname">
Age: <input type="text" name="age">
<input type="submit">
</form>

</body>
</html>
Member Avatar for diafol

Dear new members, could you please stop necroposting to this thread. It died a natural death, but has now been resurrected. There are many similar threads in DW that were satisfactory answered.

The OP did not show any effort himself and did not think to read our guidelines. Therefore, he didn't really deserve a 'full solution'. In addition, providing solutions to dead threads like this only serves to clutter up our forum thread list with this nonsense. If you wish to show off your ability, then consider writing a cope snippet or a tutorial.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.