Connecting Tech Pros Worldwide Help | Site Map

Getting slew of errors when running php script

 
LinkBack Thread Tools Search this Thread
  #1  
Old July 17th, 2005, 01:30 PM
mikey_boy
Guest
 
Posts: n/a
Default Getting slew of errors when running php script

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>


  #2  
Old July 17th, 2005, 01:30 PM
Oli Filth
Guest
 
Posts: n/a
Default Re: Getting slew of errors when running php script

mikey_boy said the following on 07/06/2005 21:03:[color=blue]
> 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.
>[/color]

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
  #3  
Old July 17th, 2005, 01:30 PM
Andy Hassall
Guest
 
Posts: n/a
Default Re: Getting slew of errors when running php script

On 7 Jun 2005 13:03:54 -0700, "mikey_boy" <mbiehl2@gmail.com> wrote:
[color=blue]
>I appreciate any light that could be shed on the script and why I would
>get the errors.[/color]

What errors?

--
Andy Hassall / <andy@andyh.co.uk> / <http://www.andyh.co.uk>
<http://www.andyhsoftware.co.uk/space> Space: disk usage analysis tool
  #4  
Old July 17th, 2005, 01:30 PM
Gordon Burditt
Guest
 
Posts: n/a
Default Re: Getting slew of errors when running php script

>Hello! Curious if anyone could give me a hand. I wrote this PHP[color=blue]
>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.[/color]

WHERE ARE THE ERRORS?
[color=blue]
>I appreciate any light that could be shed on the script and why I would
>get the errors.[/color]

WHERE ARE THE ERRORS? Well, I'll just have to guess what's wrong.
[color=blue]
> $host = "localhost";[/color]

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.
[color=blue]
> $user = "root";[/color]

Wrong. This should be "Administrator" or "Al Gore".
[color=blue]
> $pass = "*******";[/color]

Your password is incorrect, and too easy to guess.
[color=blue]
> //open a persistant connection to the database[/color]

mysql_connect() does not open a *PERSISTENT* connection.
[color=blue]
> $connect = mysql_connect($host, $user, $pass);
>
> //Select the database
> mysql_select_db("myfirstdb", $connect);[/color]

You don't check whether this worked. Also, it's MyFristDB (as in
the Senator).
[color=blue]
>
> //Set and run the query
> $sql = "Select Employee_no, Last_name, First_name, Commission from
>Sales_Representative";[/color]

Wrong. This query should be "delete from Sales_Representative where Spams_Sent > 0".
[color=blue]
> $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"];[/color]

Isn't "print", not "Print" what you are trying to do here?[color=blue]
>
> ?>
>
>
>
></body>
></html>[/color]

Gordon L. Burditt
  #5  
Old July 17th, 2005, 01:30 PM
mikey_boy
Guest
 
Posts: n/a
Default Re: Getting slew of errors when running php script

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:

  #6  
Old July 17th, 2005, 01:30 PM
Andy Hassall
Guest
 
Posts: n/a
Default Re: Getting slew of errors when running php script

On 7 Jun 2005 14:48:59 -0700, "mikey_boy" <mbiehl2@gmail.com> wrote:
[color=blue]
>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[/color]

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

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

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

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.
[color=blue]
>Warning: mysql_select_db(): supplied argument is not a valid MySQL-Link
>resource in C:\development_site\Database.php on line 16[/color]

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

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

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

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.
[color=blue]
>Employee_no:
>Last_Name:
>First_Name:
>Commission:[/color]

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

--
Andy Hassall / <andy@andyh.co.uk> / <http://www.andyh.co.uk>
<http://www.andyhsoftware.co.uk/space> Space: disk usage analysis tool
  #7  
Old July 17th, 2005, 01:30 PM
Gordon Burditt
Guest
 
Posts: n/a
Default Re: Getting slew of errors when running php script

>Here is the errors that display. I work in the IT field, I should've[color=blue]
>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[/color]

I recommend fixing these, if necessary by using isset() on the variable
before using its value. But the big problem comes next:
[color=blue]
>Warning: mysql_pconnect() [function.mysql-pconnect]: Access denied for
>user 'ODBC'@'localhost' (using password: NO) in
>C:\development_site\Database.php on line 13[/color]

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.
[color=blue]
>Warning: mysql_select_db(): supplied argument is not a valid MySQL-Link
>resource in C:\development_site\Database.php on line 16[/color]

Your connect failed, so you can't select a database. Fix previous
error first.
[color=blue]
>Warning: mysql_query(): supplied argument is not a valid MySQL-Link
>resource in C:\development_site\Database.php on line 20[/color]

Your connect failed, so you can't do queries. Fix previous error first.
[color=blue]
>Warning: mysql_num_rows(): supplied argument is not a valid MySQL
>result resource in C:\development_site\Database.php on line 22[/color]

Your query failed, so you didn't get a result. Fix previous error first.
[color=blue]
>Warning: mysql_fetch_array(): supplied argument is not a valid MySQL
>result resource in C:\development_site\Database.php on line 30[/color]

Your query failed, so you didn't get a result. Fix previous error first.
[color=blue]
>Employee_no:
>Last_Name:
>First_Name:
>Commission:
>[/color]

Gordon L. Burditt
  #8  
Old July 17th, 2005, 01:30 PM
glakk@potatoradio.f2s.com
Guest
 
Posts: n/a
Default Re: Getting slew of errors when running php script




<<<< 13 >>>>

  #9  
Old July 17th, 2005, 01:30 PM
R. Rajesh Jeba Anbiah
Guest
 
Posts: n/a
Default Re: Getting slew of errors when running php script

Gordon Burditt wrote:
<snip>[color=blue][color=green]
> > Print "Commission: " . $row["Commission"];[/color]
>
> Isn't "print", not "Print" what you are trying to do here?[/color]

Isn't PHP case-insensitive?

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

  #10  
Old July 17th, 2005, 01:30 PM
Oli Filth
Guest
 
Posts: n/a
Default Re: Getting slew of errors when running php script

R. Rajesh Jeba Anbiah said the following on 08/06/2005 17:18:[color=blue]
> Gordon Burditt wrote:
> <snip>
>[color=green][color=darkred]
>>> Print "Commission: " . $row["Commission"];[/color]
>>
>>Isn't "print", not "Print" what you are trying to do here?[/color]
>
>
> Isn't PHP case-insensitive?[/color]

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
  #11  
Old July 17th, 2005, 01:30 PM
R. Rajesh Jeba Anbiah
Guest
 
Posts: n/a
Default [OT] Re: Getting slew of errors when running php script

Oli Filth wrote:[color=blue]
> R. Rajesh Jeba Anbiah said the following on 08/06/2005 17:18:[/color]
<snip>[color=blue][color=green]
> > Isn't PHP case-insensitive?[/color]
>
> Indeed. PHP is case-insensitive for function names. But case-sensitive
> for variable names.[/color]

Yeah, thanks:)
[color=blue]
> P.S. Please fix your signature. It should start dash-dash-space to be
> automatically trimmed.[/color]

It's not me, but GG.

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

  #12  
Old July 17th, 2005, 01:45 PM
mikey_boy
Guest
 
Posts: n/a
Default Re: Getting slew of errors when running php script

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:[color=blue]
> On 7 Jun 2005 14:48:59 -0700, "mikey_boy" <mbiehl2@gmail.com> wrote:
>[color=green]
> >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[/color]
>
> This didn't come from the script you posted. It didn't contain "$discovery".
>[color=green]
> >Notice: Undefined variable: root in C:\development_site\Database.php on
> >line 13[/color]
>
> This didn't come from the script you posted. It didn't contain "$root".
>[color=green]
> >Notice: Undefined variable: killer in C:\development_site\Database.php
> >on line 13[/color]
>
> This didn't come from the script you posted. It didn't contain "$killer".
>[color=green]
> >Warning: mysql_pconnect() [function.mysql-pconnect]: Access denied for
> >user 'ODBC'@'localhost' (using password: NO) in
> >C:\development_site\Database.php on line 13[/color]
>
> 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.
>[color=green]
> >Warning: mysql_select_db(): supplied argument is not a valid MySQL-Link
> >resource in C:\development_site\Database.php on line 16[/color]
>
> Because you didn't check for errors on the mysql_pconnect.
>[color=green]
> >Warning: mysql_query(): supplied argument is not a valid MySQL-Link
> >resource in C:\development_site\Database.php on line 20[/color]
>
> Because you didn't check for errors on the mysql_pconnect nor on the
> mysql_select_db.
>[color=green]
> >Warning: mysql_num_rows(): supplied argument is not a valid MySQL
> >result resource in C:\development_site\Database.php on line 22[/color]
>
> Because you didn't check for errors on the mysql_pconnect nor on the
> mysql_select_db nor on the mysql_query.
>[color=green]
> >Warning: mysql_fetch_array(): supplied argument is not a valid MySQL
> >result resource in C:\development_site\Database.php on line 30[/color]
>
> 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.
>[color=green]
> >Employee_no:
> >Last_Name:
> >First_Name:
> >Commission:[/color]
>
> You haven't got any data so they're all blank.
>
> --
> Andy Hassall / <andy@andyh.co.uk> / <http://www.andyh.co.uk>
> <http://www.andyhsoftware.co.uk/space> Space: disk usage analysis tool[/color]

 

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Popular Articles

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over 220,989 network members.