Hello guys I want to show the database on my website using this code which is given below but it's giving me annoying error again and again. I have tried everything but nothing is working it give me same error notice
Here is the error Notice
Notice: Undefined index: name in C:\xampp\htdocs\test3\index.php on line 15
Here is the PHP Code
<?php
$connect = mysql_connect("localhost","root","123");
if(!$connect) {
die("Failed to Connect: " . mysql_error());
}
if (!mysql_select_db ("login")){
die("Failed to Select DB: ". mysql_error());
}
$results = mysql_query ("Select * from users ");
while($row = mysql_fetch_array($results)){
echo $row['name'];
}
?>
I have also tried to replace mysql_fetch_array($results)
with this mysqli_fetch_assoc($result)
and it's also not working please run this code yourself and then give me that code. Thanks
You can also simply do it this way to avoid confusion on the if's
mysql_connect("localhost","root","123") or die("Failed to Connect");
mysql_select_db ("login") or die ("cannot connect to db");
$results = mysql_query ("Select * from users ");
while($row = mysql_fetch_assoc($results))
{
echo $row['name'];
}
Since the error refers to the name, you might want to check your users table if the column name exists.
you can use var_dump()
to check the result
while($row = mysql_fetch_array($results)){
var_dump($row);
}
check the output, whether field name
exists
<?php
$host="localhost"; // Host name
$username=""; // Mysql username
$password=""; // Mysql password
$db_name="test"; // Database name
$tbl_name="members"; // Table name
// Connect to server and select databse.
mysql_connect("localhost", "root", "abcd")or die("cannot connect");
mysql_select_db("testDB")or die("cannot select DB");
$sql="SELECT * FROM login WHERE userid='$myusername' and password='$mypassword'";
$result=mysql_query($sql);
//you can then mysql_fetch_array or mysql_fetch_ob
...
?>
this will surely help you
Your database "login", table "users" doesn't have a column "name". That could be because of a typo with CaSe sEnsitivitY or other just missing.