By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
425,587 Members | 1,891 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 425,587 IT Pros & Developers. It's quick & easy.

Getting slew of errors when running php script

P: n/a
Hello! Curious if anyone could give me a hand. I wrote this PHP
script with makes a simple connection to a mysql database called
firstdb and just pulls back the results and displays on the webpage.

Here is the script.

I appreciate any light that could be shed on the script and why I would
get the errors.

Thank you,

Mike
---------------------------
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;
charset=iso-8859-1">
<title>Sample PHP Script</title>

</head>

<body style="font-family:Arial, Helvetica, sans-serif"
style="background-color:#CC9966">

<?php
// Define connection string
$host = "localhost";
$user = "root";
$pass = "*******";

//open a persistant connection to the database
$connect = mysql_connect($host, $user, $pass);

//Select the database
mysql_select_db("myfirstdb", $connect);

//Set and run the query
$sql = "Select Employee_no, Last_name, First_name, Commission from
Sales_Representative";
$result = mysql_query($sql, $connect);

$x = mysql_num_rows($result);

//If the tenth row exists, go straight to it
if ($x >= 10) {
mysql_data_seek($result, 9);
}

//Return the data from the 10th row
$row = mysql_fetch_array($result);
Print "Employee_no: " . $row["Employee_No"] . "<br>\n";
Print "Last_Name: " . $row["Last_Name"] . "<br>\n";
Print "First_Name: " . $row["First_Name"] . "<br>\n";
Print "Commission: " . $row["Commission"];

?>

</body>
</html>

Jul 17 '05 #1
Share this Question
Share on Google+
11 Replies


P: n/a
mikey_boy said the following on 07/06/2005 21:03:
Hello! Curious if anyone could give me a hand. I wrote this PHP
script with makes a simple connection to a mysql database called
firstdb and just pulls back the results and displays on the webpage.

Here is the script.

I appreciate any light that could be shed on the script and why I would
get the errors.


What are the error-messages you get? (if you post the error messages,
it'll be easier for people to work out the problem then having to go
through your code looking for syntax errors, etc.)

--
Oli
Jul 17 '05 #2

P: n/a
On 7 Jun 2005 13:03:54 -0700, "mikey_boy" <mb*****@gmail.com> wrote:
I appreciate any light that could be shed on the script and why I would
get the errors.


What errors?

--
Andy Hassall / <an**@andyh.co.uk> / <http://www.andyh.co.uk>
<http://www.andyhsoftware.co.uk/space> Space: disk usage analysis tool
Jul 17 '05 #3

P: n/a
>Hello! Curious if anyone could give me a hand. I wrote this PHP
script with makes a simple connection to a mysql database called
firstdb and just pulls back the results and displays on the webpage.

Here is the script.
WHERE ARE THE ERRORS?
I appreciate any light that could be shed on the script and why I would
get the errors.
WHERE ARE THE ERRORS? Well, I'll just have to guess what's wrong.
$host = "localhost";
This is wrong. Your hostname should be in the .nsa.gov top-level domain.
And if you don't have clearance, they'll kill you.
$user = "root";
Wrong. This should be "Administrator" or "Al Gore".
$pass = "*******";
Your password is incorrect, and too easy to guess.
//open a persistant connection to the database
mysql_connect() does not open a *PERSISTENT* connection.
$connect = mysql_connect($host, $user, $pass);

//Select the database
mysql_select_db("myfirstdb", $connect);
You don't check whether this worked. Also, it's MyFristDB (as in
the Senator).

//Set and run the query
$sql = "Select Employee_no, Last_name, First_name, Commission from
Sales_Representative";
Wrong. This query should be "delete from Sales_Representative where Spams_Sent > 0".
$result = mysql_query($sql, $connect);

$x = mysql_num_rows($result);

//If the tenth row exists, go straight to it
if ($x >= 10) {
mysql_data_seek($result, 9);
}

//Return the data from the 10th row
$row = mysql_fetch_array($result);
Print "Employee_no: " . $row["Employee_No"] . "<br>\n";
Print "Last_Name: " . $row["Last_Name"] . "<br>\n";
Print "First_Name: " . $row["First_Name"] . "<br>\n";
Print "Commission: " . $row["Commission"];
Isn't "print", not "Print" what you are trying to do here?
?>

</body>
</html>


Gordon L. Burditt
Jul 17 '05 #4

P: n/a
Here is the errors that display. I work in the IT field, I should've
know to post the errors...MY BAD!!
---------------------------------------------------------------------------------------------------------
Notice: Undefined variable: discovery in
C:\development_site\Database.php on line 13

Notice: Undefined variable: root in C:\development_site\Database.php on
line 13

Notice: Undefined variable: killer in C:\development_site\Database.php
on line 13

Warning: mysql_pconnect() [function.mysql-pconnect]: Access denied for
user 'ODBC'@'localhost' (using password: NO) in
C:\development_site\Database.php on line 13

Warning: mysql_select_db(): supplied argument is not a valid MySQL-Link
resource in C:\development_site\Database.php on line 16

Warning: mysql_query(): supplied argument is not a valid MySQL-Link
resource in C:\development_site\Database.php on line 20

Warning: mysql_num_rows(): supplied argument is not a valid MySQL
result resource in C:\development_site\Database.php on line 22

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL
result resource in C:\development_site\Database.php on line 30
Employee_no:
Last_Name:
First_Name:
Commission:

Jul 17 '05 #5

P: n/a
On 7 Jun 2005 14:48:59 -0700, "mikey_boy" <mb*****@gmail.com> wrote:
Here is the errors that display. I work in the IT field, I should've
know to post the errors...MY BAD!!
---------------------------------------------------------------------------------------------------------
Notice: Undefined variable: discovery in
C:\development_site\Database.php on line 13
This didn't come from the script you posted. It didn't contain "$discovery".
Notice: Undefined variable: root in C:\development_site\Database.php on
line 13
This didn't come from the script you posted. It didn't contain "$root".
Notice: Undefined variable: killer in C:\development_site\Database.php
on line 13
This didn't come from the script you posted. It didn't contain "$killer".
Warning: mysql_pconnect() [function.mysql-pconnect]: Access denied for
user 'ODBC'@'localhost' (using password: NO) in
C:\development_site\Database.php on line 13
How about posting either:

(a) The errors from the script you posted, or
(b) The script that produced these errors.

Because they aren't the same. The one you posted used mysql_connect, and on a
different line number.
Warning: mysql_select_db(): supplied argument is not a valid MySQL-Link
resource in C:\development_site\Database.php on line 16
Because you didn't check for errors on the mysql_pconnect.
Warning: mysql_query(): supplied argument is not a valid MySQL-Link
resource in C:\development_site\Database.php on line 20
Because you didn't check for errors on the mysql_pconnect nor on the
mysql_select_db.
Warning: mysql_num_rows(): supplied argument is not a valid MySQL
result resource in C:\development_site\Database.php on line 22
Because you didn't check for errors on the mysql_pconnect nor on the
mysql_select_db nor on the mysql_query.
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL
result resource in C:\development_site\Database.php on line 30
Because you didn't check for errors on the mysql_pconnect nor on the
mysql_select_db nor on the mysql_query nor mysql_num_rows.
Employee_no:
Last_Name:
First_Name:
Commission:


You haven't got any data so they're all blank.

--
Andy Hassall / <an**@andyh.co.uk> / <http://www.andyh.co.uk>
<http://www.andyhsoftware.co.uk/space> Space: disk usage analysis tool
Jul 17 '05 #6

P: n/a
>Here is the errors that display. I work in the IT field, I should've
know to post the errors...MY BAD!!
---------------------------------------------------------------------------------------------------------
Notice: Undefined variable: discovery in
C:\development_site\Database.php on line 13

Notice: Undefined variable: root in C:\development_site\Database.php on
line 13

Notice: Undefined variable: killer in C:\development_site\Database.php
on line 13
I recommend fixing these, if necessary by using isset() on the variable
before using its value. But the big problem comes next:
Warning: mysql_pconnect() [function.mysql-pconnect]: Access denied for
user 'ODBC'@'localhost' (using password: NO) in
C:\development_site\Database.php on line 13
Here you have a serious problem: you can't connect to your
database. Test the login information using a command-line
client. And you really ought to have a password on your database,
even if it's only accessible via localhost.
Warning: mysql_select_db(): supplied argument is not a valid MySQL-Link
resource in C:\development_site\Database.php on line 16
Your connect failed, so you can't select a database. Fix previous
error first.
Warning: mysql_query(): supplied argument is not a valid MySQL-Link
resource in C:\development_site\Database.php on line 20
Your connect failed, so you can't do queries. Fix previous error first.
Warning: mysql_num_rows(): supplied argument is not a valid MySQL
result resource in C:\development_site\Database.php on line 22
Your query failed, so you didn't get a result. Fix previous error first.
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL
result resource in C:\development_site\Database.php on line 30
Your query failed, so you didn't get a result. Fix previous error first.
Employee_no:
Last_Name:
First_Name:
Commission:


Gordon L. Burditt
Jul 17 '05 #7

P: n/a

<<<< 13 >>>>

Jul 17 '05 #8

P: n/a
Gordon Burditt wrote:
<snip>
Print "Commission: " . $row["Commission"];


Isn't "print", not "Print" what you are trying to do here?


Isn't PHP case-insensitive?

--
<?php echo 'Just another PHP saint'; ?>
Email: rrjanbiah-at-Y!com Blog: http://rajeshanbiah.blogspot.com

Jul 17 '05 #9

P: n/a
R. Rajesh Jeba Anbiah said the following on 08/06/2005 17:18:
Gordon Burditt wrote:
<snip>
Print "Commission: " . $row["Commission"];


Isn't "print", not "Print" what you are trying to do here?

Isn't PHP case-insensitive?


Indeed. PHP is case-insensitive for function names. But case-sensitive
for variable names.
P.S. Please fix your signature. It should start dash-dash-space to be
automatically trimmed.
--
Oli
Jul 17 '05 #10

P: n/a
Oli Filth wrote:
R. Rajesh Jeba Anbiah said the following on 08/06/2005 17:18: <snip>
Isn't PHP case-insensitive?


Indeed. PHP is case-insensitive for function names. But case-sensitive
for variable names.


Yeah, thanks:)
P.S. Please fix your signature. It should start dash-dash-space to be
automatically trimmed.


It's not me, but GG.

--
<?php echo 'Just another PHP saint'; ?>
Email: rrjanbiah-at-Y!com Blog: http://rajeshanbiah.blogspot.com

Jul 17 '05 #11

P: n/a
Andy-

I made the mistake and posted the wrong error message. I altered the
script a bit, but posted the orginal error message. I will post the
new error message that I get when I try running the new altered script.
Again sorry for the hassle.

I will keep you all posted.

Thanks for everyone's assistance.

Mike

Andy Hassall wrote:
On 7 Jun 2005 14:48:59 -0700, "mikey_boy" <mb*****@gmail.com> wrote:
Here is the errors that display. I work in the IT field, I should've
know to post the errors...MY BAD!!
---------------------------------------------------------------------------------------------------------
Notice: Undefined variable: discovery in
C:\development_site\Database.php on line 13


This didn't come from the script you posted. It didn't contain "$discovery".
Notice: Undefined variable: root in C:\development_site\Database.php on
line 13


This didn't come from the script you posted. It didn't contain "$root".
Notice: Undefined variable: killer in C:\development_site\Database.php
on line 13


This didn't come from the script you posted. It didn't contain "$killer".
Warning: mysql_pconnect() [function.mysql-pconnect]: Access denied for
user 'ODBC'@'localhost' (using password: NO) in
C:\development_site\Database.php on line 13


How about posting either:

(a) The errors from the script you posted, or
(b) The script that produced these errors.

Because they aren't the same. The one you posted used mysql_connect, and on a
different line number.
Warning: mysql_select_db(): supplied argument is not a valid MySQL-Link
resource in C:\development_site\Database.php on line 16


Because you didn't check for errors on the mysql_pconnect.
Warning: mysql_query(): supplied argument is not a valid MySQL-Link
resource in C:\development_site\Database.php on line 20


Because you didn't check for errors on the mysql_pconnect nor on the
mysql_select_db.
Warning: mysql_num_rows(): supplied argument is not a valid MySQL
result resource in C:\development_site\Database.php on line 22


Because you didn't check for errors on the mysql_pconnect nor on the
mysql_select_db nor on the mysql_query.
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL
result resource in C:\development_site\Database.php on line 30


Because you didn't check for errors on the mysql_pconnect nor on the
mysql_select_db nor on the mysql_query nor mysql_num_rows.
Employee_no:
Last_Name:
First_Name:
Commission:


You haven't got any data so they're all blank.

--
Andy Hassall / <an**@andyh.co.uk> / <http://www.andyh.co.uk>
<http://www.andyhsoftware.co.uk/space> Space: disk usage analysis tool


Jul 17 '05 #12

This discussion thread is closed

Replies have been disabled for this discussion.