Forum Moderators: coopster

Message Too Old, No Replies

mysql error

I am new to php/mysql.The error after execution is---------

         

chacko

9:13 am on Feb 23, 2006 (gmt 0)

10+ Year Member



Warning: mysql_numrows(): supplied argument is not a valid MySQL result resource in e:\phpdev\www\database\main.php on line 7
Filename Type Size Description

my code for that is as---

$sql = "SELECT * FROM tbl_Files ";
$sql .= "ORDER BY filename ASC";
$result = mysql_query($sql, $db);
$num = mysql_numrows($result);
for ($i = 0; $i < $num; $i++) {
$data = mysql_fetch_object($result);

what should I do to solve the problem?

physics

3:04 pm on Feb 23, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You should try checking that you're getting a valid result with something like:

if (!$result) {
die('Could not query:' . mysql_error());
}

From: [php.net...]
After your mysql_query() call to make sure you are getting a valid result.

Also, I think

 
mysql_query($sql, $db);

should be:

mysql_query($sql);

See: [us3.php.net...]

chacko

6:30 am on Feb 24, 2006 (gmt 0)

10+ Year Member



Warning: Access denied for user: 'ODBC@127.0.0.1' (Using password: NO) in e:\phpdev\www\book.php on line 5

Warning: MySQL Connection Failed: Access denied for user: 'ODBC@127.0.0.1' (Using password: NO)
in e:\phpdev\www\book.php on line 5

Warning: mysql_select_db(): supplied argument is not a valid MySQL-Link resource in e:\phpdev\www\book.php on line 6

Warning: mysql_query(): supplied argument is not a valid MySQL-Link resource in e:\phpdev\www\book.php on line 7

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in e:\phpdev\www\book.php line 9

This error comes for the php-code below during execution. what should I do?

<html>
<body>
<pre>
<?php
$connection=mysql_connect("localhost","","");
mysql_select_db("manisha",$connection);
$result=mysql_query("select * from manu",$connection);
while($row=mysql_fetch_array($result,MYSQL_NUM))
{
foreach($row as $attribute)
print"{$attribute}";
print"\n";
}
?>
</pre>
</body>
</html>

chacko

6:48 am on Feb 24, 2006 (gmt 0)

10+ Year Member



<html>
<body>
<pre>

<?php

function showerror()
{
die("Error".mysql_errorno() .":" . mysql_error());
}

if(!($connection = @ mysql_connect("localhost","coder","password")))
die("Could not connect");

if(!(@ mysql_select_db("manisha",$connection)))
showerror();

if(!($result= @ mysql_query("select * from manu",$connection)))
showerror();

while($row= @ mysql_fetch_array($result,MYSQL_NUM))
{
foreach($row as $attribute)
print"{$attribute}";
print"\n";
}

?>

</pre>
</body>
</html>

this the php-code for connection but it replies-

could not connect.

what goes wrong in such a connection?

chacko

11:00 am on Feb 25, 2006 (gmt 0)

10+ Year Member



Warning: main(library/config.php): failed to open stream: No such file or directory in c:\program files\easyphp1-8\www\database\upload.php on line 30

Warning: main(): Failed opening 'library/config.php' for inclusion (include_path='.;C:/Program Files/EasyPHP1-8\php\pear\') in c:\program files\easyphp1-8\www\database\upload.php on line 30

Warning: main(library/opendb.php): failed to open stream: No such file or directory in c:\program files\easyphp1-8\www\database\upload.php on line 31

Warning: main(): Failed opening 'library/opendb.php' for inclusion (include_path='.;C:/Program Files/EasyPHP1-8\php\pear\') in c:\program files\easyphp1-8\www\database\upload.php on line 31

Warning: mysql_query(): Access denied for user 'ODBC'@'localhost' (using password: NO) in c:\program files\easyphp1-8\www\database\upload.php on line 36

Warning: mysql_query(): A link to the server could not be established in c:\program files\easyphp1-8\www\database\upload.php on line 36
Error, query failed

This error happens during execution of following code.What can I do for this.

<form method="post" enctype="multipart/form-data">
<table width="350" border="0" cellpadding="1" cellspacing="1" class="box">
<tr>
<td width="246">
<input type="hidden" name="MAX_FILE_SIZE" value="2000000">
<input name="userfile" type="file" id="userfile">
</td>
<td width="80"><input name="upload" type="submit" class="box" id="upload" value=" Upload "></td>
</tr>
</table>

<?php
if(isset($_POST['upload']) && $_FILES['userfile']['size'] > 0)
{
$fileName = $_FILES['userfile']['name'];
$tmpName = $_FILES['userfile']['tmp_name'];
$fileSize = $_FILES['userfile']['size'];
$fileType = $_FILES['userfile']['type'];

$fp = fopen($tmpName, 'r');
$content = fread($fp, filesize($tmpName));
$content = addslashes($content);
fclose($fp);

if(!get_magic_quotes_gpc())
{
$fileName = addslashes($fileName);
}

include 'library/config.php';
include 'library/opendb.php';

$query = "INSERT INTO `upload` (`name`, `size`, `type`, `content`, `group`, `comment`) ".
"VALUES ('$fileName', '$fileSize', '$fileType', '$content')";

mysql_query($query) or die('Error, query failed');
include 'library/closedb.php';

echo "<br>File $fileName uploaded<br>";
}
?>

physics

5:44 pm on Feb 26, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I recommend you try to do something simpler first. Just connect to the database using mysql_connect() :
[us3.php.net...]

Then do a simple query like "SELECT * FROM tbl_Files" and display the results.

phparion

6:10 pm on Feb 26, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



You mixed two questions in one thread, I am confused how to answer both efficiently :(