pwamly
January 3, 2019, 10:13pm
1
I have my form html form, i want to display success or failure message to the page…when data is inserted to the database… i am using php to connect and send data to the database…
need your help bellow are my codes:
html page
A small example page to insert some data in to the MySQL database using PHP
Firstname:
Lastname:
Click Me!
inse.php
<?php
if (isset($_POST['submit'])) {
require "init.php";
$name=$_POST["fname"];
$password=$_POST["lname"];
$hash =password_hash($password, PASSWORD_DEFAULT);
$sql_query="insert into name values('$name','$hash');";
if(mysqli_query($con,$sql_query))
{
$posted = false;
if( $_POST ) {
$posted = true;
// Database stuff here...
// $result = mysql_query( ... )
$sql = "SELECT * FROM $name";
$result2 = mysqli_query($con, $sql);
while ($row = mysqli_fetch_array($result2)) {
$result3 = $_POST['name'] == $row["name"]; // Dummy result
if( $posted ) {
if( $result3 )
echo "";
echo "";
echo "";
echo "";
echo "";
echo "";
}
}
}
else
{
echo "
data insertion error..";
}
}
}
?>
This would be the code processing the POST action, whatever that is???
pwamly
January 3, 2019, 10:22pm
3
sorry can you explain it please
pwamly
January 3, 2019, 10:30pm
5
thank you for your help… i have got a reason that i have to study the page u gave me… but for now if u can help to display the message which will pop up and die soon after submission it will be good…
This is handled by the action page the form is posting to.
1 Like
pwamly
January 3, 2019, 10:43pm
7
okay and for my case that page i called inse.php as shown above can u try to look at friend…
I don’t really do PHP anymore. I do Javascript now.
You should format your code:
<?php
echo "My first PHP script!";
?>
1 Like
Xiija
January 4, 2019, 8:29pm
9
FOR OTHERS TO READ MORE EASILY…
<?php
if (isset($_POST['submit']) )
{
require "init.php";
$name = $_POST["fname"];
$password = $_POST["lname"];
$hash = password_hash($password, PASSWORD_DEFAULT);
$sql_query = "insert into name values('$name','$hash');";
if (mysqli_query($con, $sql_query))
{ $posted = false;
if ($_POST)
{ $posted = true;
// Database stuff here...
//
$result = mysql_query( ... )
$sql = "SELECT * FROM $name";
$result2 = mysqli_query($con, $sql);
while ($row = mysqli_fetch_array($result2))
{ $result3 = $_POST['name'] == $row["name"];
// Dummy result
if( $posted )
{
if( $result3 )
echo "";
}
}
}
else
{ echo "datainsertionerror . . ";
}
}
}
?>
1 Like
pwamly
January 4, 2019, 8:57pm
10
okay thanks lot for your idea actually they ll see now