[PHP]Fetching from MySQL error..

Joined
Oct 9, 2008
Messages
572
Reaction score
14
Well, I got this from w3school, and I adjusted the username and password after my settings..
The thing is the page is empty, doesn't show anything.
(I started yesterday to learn PHP)
PHP:
<html>
<body>
<?php
$con = mysql_connect("localhost","root","root");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }

mysql_select_db("mb7_ne", $con);

$result = mysql_query(SELECT * FROM mind7);

while($row = mysql_fetch_array($result))
  {
echo $row['name'];
  }
  mysql_close($con);	
	
	
?>
</body>
</html>

If you can help me out, it would be great =]
 
Try this.

PHP:
$dbc = mysql_connect('localhost','root','root');
mysql_select_db('mb7_ne',$dbc) or die('Database Connection Error!');
while ($row = mysq_fetch_array(mysql_query("SELECT * FROM mind7"))) {
	echo 'Name :'.$row['name'].'<br />';
}
 
You could be selecting a unknown table or the database isint workin... Try
PHP:
mysql_connect("localhost","root","root");
mysql_select_db("mb7_ne");

$result = mysql_query("SELECT * FROM mind7") or die(mysql_error());;

while($row = mysql_fetch_array($result) or die(mysql_error()))
  {
echo $row['name'];
  }
?>
 
Okay this is embarrasing, found out that my DB didn't have a password on it, so I tried to delete it and set it to nothing (the password in my .php file) and also tried with lordvladek's script, didn't help either, Nothing comes up, not even an error..
 
Okay this is embarrasing, found out that my DB didn't have a password on it, so I tried to delete it and set it to nothing (the password in my .php file) and also tried with lordvladek's script, didn't help either, Nothing comes up, not even an error..
Are you fetching an existing table? O_o
There's no reason why their code's shouldn't work.
 
Mindblaster7 - [PHP]Fetching from MySQL error.. - RaGEZONE Forums

http://img37.picoodle.com/img/img37/3/2/2/f_eerrowsm_5989e86.png

=.=

Its up and running..
 
I beg of you, please indent;
PHP:
<html>
<body>
<?php
    $con = mysql_connect("localhost", "root", "root");
    $sql = mysql_select_db("mb7_ne", $con);
    if (!$sql)
    {
        die('Could not connect: ' . mysql_error());
    }

    $result = mysql_query("SELECT * FROM `mind7`");
    while($row = mysql_fetch_array($result))
    {
        echo $row['name'];
    }
    mysql_close($con);
?>
</body>
</html>
 
I beg of you, please indent;
PHP:
<html>
<body>
<?php
    $con = mysql_connect("localhost", "root", "root");
    $sql = mysql_select_db("mb7_ne", $con);
    if (!$sql)
    {
        die('Could not connect: ' . mysql_error());
    }

    $result = mysql_query("SELECT * FROM `mind7`");
    while($row = mysql_fetch_array($result))
    {
        echo $row['name'];
    }
    mysql_close($con);
?>
</body>
</html>

*Copy/paste'd*
No Sorry didn't work =/...

I don't get it. I even edited the password to "" (nothing) and deleted it because it didn't work, but that didn't work either.. I think I'll speak with my dad.. He have had made some webshops in the past and working with software daily.. But last time I asked him about java, he knew nothing =P.. *waiting for him to get home*
 
PHP:
<html>
<body>
<?php
    $con = mysql_connect("localhost", "root", "root");
    $sql = mysql_select_db("mb7_ne", $con);
    if (!$sql)
    {
        die('Could not connect: ' . mysql_error());
    }

    $result = mysql_query("SELECT * FROM `mind7`");
    while($row = mysql_fetch_array($result))
    {
        echo $row['name'];
    }
    echo mysql_error();
    mysql_close($con);
?>
</body>
</html>
What does it say now?
 
PHP:
<html>
<body>
<?php
    $con = mysql_connect("localhost", "root", "root");
    $sql = mysql_select_db("mb7_ne", $con);
    if (!$sql)
    {
        die('Could not connect: ' . mysql_error());
    }

    $result = mysql_query("SELECT * FROM `mind7`");
    while($row = mysql_fetch_array($result))
    {
        echo $row['name'];
    }
    echo mysql_error();
    mysql_close($con);
?>
</body>
</html>
What does it say now?

Still nothing =.=

Note that I said earlier that my DB doesn't have root as password, it has nothing, but I tried to set the password to "" (nothing) but still didn't come up with anything, so I tried to just delete the password quote, didn't help either. Still blank!
 
PHP:
echo mysql_error();
Would echo the errors.

I know, but it doesn't come up with anything.. Thats just completely mindfuck, even thought I installed php 5.2.4 (I thinks its that) yesterday =S..

I should upload it to my website and make a database in phpMyAdmin.. Just to see, if its just my computer.
 
Code:
<html>
<head>
	<title>Test</title>
</head>
<body>
<?php

	$con = mysql_connect("localhost","root","root");
	if (!$con)
	{
		die('Could not connect: ' . mysql_error());
	}

	mysql_select_db("mb7_ne", $con) or die(mysql_error());

	$result = mysql_query("SELECT * FROM `mind7`;") or die(mysql_error());

	if(mysql_num_rows($result) == 0)
	{
		echo "There were no entries in the database";
	}

	while($row = mysql_fetch_array($result))
	{
		echo $row['name'];
	}
	
	mysql_close($con);    
        
?>
</body>
</html>

this should work or throw you an error
 
Back