Hi,
I am trying to create a simple form submission using php and mysql. I am stuck at very basic level of mysql and php code.
Here is what i am trying to do.
index page where name and email data is shown.
add-data.php page where i am adding the email and name using the form.
send the data to database and update the page index.php.
I am not planning to use ajax but just want to redirect to the index page after the successful submission.
Not sure how to submit the data to the database and redirect to the index page. Any help?
Here is my code.
index.php
<?php
//Code to connect to database
$con=mysql_connect("localhost","xxx","xxx") or die(mysql_error());
echo "Connected to database";
//select database
$select=mysql_select_db("test") or die(mysql_error());
//get the result from database
$result=mysql_query("SELECT* from demo");
//display result by looping through each row
while($row=mysql_fetch_array($result))
{
echo "<br/>";
//use row to fetch the element of each column
echo "<br/>"."ID : ".$row['id']."<br/>"." Name :".$row['name']. "<br/>"." Email :".$row['email']."<br/>";
}
mysql_close($con);
?>
add-data.php
<form method="post" action="index.php">
<label>Name :</label><input type="text" name="name" id="name"><br/>
<label>Email: </label><input type="text" name="email" id="email"><br/>
<br/><input type="submit" name="Add">
<br/>
</form>
I have managed to add the form. But not sure how to get the data from the form and add into the database and redirect to index.php
Any help with code to guide me in right direction is appreciated.