Not getting prefect output


#1

following is the code for inserting the data into database code and output

<? 
include ("init.php");
$bus_no=$_POST["bus_no"];
$pwd=$_POST["pwd"];
$lon=$_POST["lon"];
$lat=$_POST["lat"];

$sql="INSERT INTO `bus` (`bus_no`, `pwd`, `longitude`, `latitude`) VALUES ('23', '1', '34', '34')";

if(mysqli_query($con,$sql))
{
	print ("<br><h3>one row inserted.....</h3>") ;
}
else
{
	print ("error in insertion....".mysqli_error($con)) ;
}

?>

the init.php code is as follows and output

<?
$host="files.000webhost.com";
$user="id6648536_jeevan";
$password="*************";
$db="id6648536_bus_tracker";

$con=mysqli_connect($host,$user,$password,$db);

if(!$con)
{
	die("error in connection".mysqli_error());
}
else
{
	echo("<br><h3>connection success...</h3>") ;
}

can anyone plzz tell me why i am getting output in this way and my data is not getting inserted into database.
Thank you.


#2

input is

output is


#3

An expert will assist you soon @ckhawand . :smile:


#4

It’s because the host is localhost, not files.000webhost.com

So instead of
$host="files.000webhost.com";
Use
$host="localhost";


#5

@ckhawand it is not inserting still and in output also some part of program is getting printed.


#6

Try this instead

<?php
include ("init.php");
$bus_no = $_POST["bus_no"];
$pwd = $_POST["pwd"];
$lon = $_POST["lon"];
$lat = $_POST["lat"];

$sql="INSERT INTO `bus` (`bus_no`, `pwd`, `longitude`, `latitude`) VALUES ('23', '1', '34', '34')";

if(mysqli_query($con,$sql)){
	echo "<br><h3>one row inserted.....</h3>";
}else{
	echo "error in insertion...." . mysqli_error($con);
}
?>