I am trying to get a input from user which will then pull data from table and display it .
My code is
$ini = $_GET["ini_id"];
$con=mysqli_connect("localhost","root","","globalgoals");
// Check connection
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
else
{
$country = array();
//country
$sql="";
//!mysqli_query($con,$sql))
$result = mysqli_query($con,"SELECT * FROM country WHERE metrics="$ini");/*table name*/
while($row = mysqli_fetch_array($result))
{
array_push($country,$row['country']);/*column name*/
}
//
When I enter the url http://localhost/xampp/testing/Int/table.php?ini=C2C
I get the error
Notice: Undefined index: ini_id in C:\xampp\htdocs\xampp\Testing\Int\table.php on line 2
In here your trying to get like this $_GET['ini'];
http://localhost/xampp/testing/Int/table.php?ini=C2C
If your trying to get it like $_GET['ini_id']
http://localhost/xampp/testing/Int/table.php?ini_id=C2C //change here
Get $ini = $_GET["ini"];
because you did not passed ini_id
.
Second
$result = mysqli_query($con,"SELECT * FROM country WHERE metrics='".$ini."'");
one more thing,
$result = mysqli_query($con,"SELECT * FROM country WHERE metrics='".$ini."'");
You missed the dot before and after the variable.
Use isset...
$ini = (isset($_GET['ini_id'])) ? $_GET['ini_id'] : null;
But perhaps more importantly, you need to secure that variable before you use it as part of a database query. Since your id is alphanumeric use mysqli_real_escape_string():
$ini = (isset($_GET['ini_id']) ? $_GET['ini_id'] : null;
$ini = mysqli_real_escape_string($con, $ini);