Forum Moderators: coopster

Message Too Old, No Replies

mysql help.. please

         

Acternaweb

2:45 pm on Dec 16, 2003 (gmt 0)

10+ Year Member



I am using the mysportsdb script that was recommended and I am getting the following error

Warning: Access denied for user: 'apache@localhost' (Using password: NO) in /home/httpd/vhosts/my domain/httpdocs/mysportsdb/index.php on line 18

Warning: Supplied argument is not a valid MySQL-Link resource in /home/httpd/vhosts/my domain/httpdocs/mysportsdb/index.php on line 20

Using phpadmin supplied by my host I have added user "apache" and password "password" beause the password "no" was not allowed.

Is this script valid? Any ideas?

caspita

2:56 pm on Dec 16, 2003 (gmt 0)

10+ Year Member



well .. did u change also the password in the scrip? also check because some times the ISPs does not let you define the usercode like you are showing .. they use to put your user account at front. ei:

you user account is 'testuser'

usually your mysql users will be defined as :

testuser_user1
testuser_user2
testuser_user3 ... and so on.

also if you paste here the connection script I can take a quick look.

Acternaweb

3:14 pm on Dec 16, 2003 (gmt 0)

10+ Year Member



Thanks Caspita, in the phpadmin I added added my username/password as listed below. I greatly appreciate your help.

Here is the CFG file:

<?
// Configuration definitions
// ALWAY MAKE SURE that there are no characters (including spaces and empty lines)
// before or after the PHP opening and closing tags.

//// Database connection stuff
// host to connect to (usually "localhost" or your hostname:port)
$msd_db["host"] = "localhost";
// username for inventory database
$msd_db["user"] = "realusername";
// password for inventory database
$msd_db["pass"] = "realpass";
// database name (where all data is stored)
$msd_db["db"] = "mysportsdb";

//// HTML/HTTP stuff
// Base URL for inventory, usually "/mysportsdb/", if you've made a virtual-host
// for inventory it can be the vhost name or simply "/"
// in any case, it needs a leading and trailing "/"
$inv_data["base"] = "/mysportsdb/";

// Logon to the db

$db = mysql_pconnect($msd_db["host"],$msd_db["user"],$msd_db["pass"]);

mysql_select_db($msd_db["db"],$db);

This is the php on the index.php page

<?php
// Logon to the db

include("cfg.php");
$db = mysql_pconnect($inv_db["localhost"],$inv_db["realusername"],$inv_db["realpass"]);

mysql_select_db($inv_db["db"],$db);

?>

[edited by: jatar_k at 5:15 pm (utc) on Dec. 16, 2003]
[edit reason] removed specific user/pass [/edit]

caspita

3:47 pm on Dec 16, 2003 (gmt 0)

10+ Year Member



Let's see ... I'm bit confuse here because looks like your opening the db in the .cfg file and then trying to open another one in the index.php. If you just need one db then take out those lines from index :


$db = mysql_pconnect($inv_db["localhost"],$inv_db["pmgreen"],$inv_db["jetsfan"]);

mysql_select_db($inv_db["db"],$db);

Now, if you are trying to open a second db then you need specify the parameters ... I don't know if you are doinf it but if that is all the code in your index.php before the connection then that $inv_db array looks empty, you need to feed the array before use it like it is being done in the .cfg, something like:


$inv_db["host"] = "localhost";
$inv_db["user"] = "pmgreen";
$inv_db["pass"] = "jetsfan";
$inv_db["db"] = "second_db";

then you can use the :


$db = mysql_pconnect($inv_db["localhost"],$inv_db["pmgreen"],$inv_db["jetsfan"]);
mysql_select_db($inv_db["db"],$db);

And finally php will try to reuse the $db pointer so the second pconnect could get you lost the first connection, then if you need both open use a different name for the secon connect like $db2 and take a look of the php connect syntax in the php manual because you need to make explicit that this will be a new connection.. I learned that in the hard way after a day of looking why php was messing up the pointers :-;

Keep posting if still does not work.

[edited by: jatar_k at 5:15 pm (utc) on Dec. 16, 2003]
[edit reason] removed code, it is in above post [/edit]

Acternaweb

4:24 pm on Dec 16, 2003 (gmt 0)

10+ Year Member



HI again,

Thanks for the help, sorry for the novice level questions. This isn't my script, but rather one that was recommended to me.

I removed the code from the index.php page and no longer get the errors. However the script is not working right.

I went to the phpadmin tool and saw the "sport" and "manufacter" that I entered there but it is not showing up on the site.

It is a personal site with not commerece or business related content so I hope it is ok to post here.

[edited by: jatar_k at 5:16 pm (utc) on Dec. 16, 2003]
[edit reason] no personal urls thanks [/edit]

caspita

4:43 pm on Dec 16, 2003 (gmt 0)

10+ Year Member



Well .. does not help to much looking the url .. I can not see the php code in that way because all gets parsed to html and is what i see. However it doesn't look too complicated so you may post here the whole index.php and add.php scripts so I can take a look... also after we are done be sure to change you user/password because is not very good to have that info listed here :-)

Acternaweb

5:17 pm on Dec 16, 2003 (gmt 0)

10+ Year Member



Wasn't sure, but you are a brain so thought I would give it a shot:

Here is all the index.php page:

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN">

<HTML>
<HEAD>
<META name="generator" content=
"HTML Tidy for Linux/x86 (vers 1st March 2002), see www.w3.org">

<TITLE>Sports Collection</TITLE>
<LINK type="text/css" rel="stylesheet" href="http://www.mysite.com/css/style.css">
</HEAD>

<BODY>
<?php
// Logon to the db

include("cfg.php");

?>

<font face class="title"> Paul's SportsDB</font>

<UL>
<LI STYLE="list-style-type: circle"> <A href="view.php">View the DB</A></LI>

<LI STYLE="list-style-type: circle"> <A href="add.php">Add an entry to the DB</A></LI>

<LI STYLE="list-style-type: circle"> <A href="edit.php">Edit an entry</A></LI>

<LI STYLE="list-style-type: circle"> <A href="doc.php">View Documentation</A></LI>

<LI STYLE="list-style-type: circle"> <A href="stats.php">DB Stats</A></LI>

<LI STYLE="list-style-type: circle"> <A href="admin.php"><font class="text">DB Admin</A></LI>
</UL>
</BODY>
</HTML>

Here is the admin page:
<?php
include("cfg.php");

if ($action == "") {

?>
<HTML>
<HEAD>
<TITLE>MySportsDB Admin Page</TITLE>
<LINK type="text/css" rel="stylesheet" href="style.css">
</HEAD>

<BODY>

<H1 class="center">MySportsDB Admin</H1>

<UL>
<LI><A href="admin.php?action=insertm">Insert a manufacturer</A></LI>

<LI><A href="admin.php?action=removem">Remove a manufacturer</A></LI>

<LI><A href="admin.php?action=inserts">Insert a sport</A></LI>

<LI><A href="admin.php?action=removes">Remove a sport</A></LI>

<LI><A href="admin.php?action=removec">Remove a card from the DB</A></LI>

<LI><A href="index.php">Back to the main menu</A></LI>

</UL>
</BODY>
</HTML>

<?php
}

if ($action == insertm) {
// Insert a new card manufacturer

?>
<form method=post action="<? echo $SCRIPT_NAME;?>" target="_top">

<table border=0 cellspacing=0 cellpadding=5>
<tr><td colspan=2 align=center><b>Manufacturer Insert</b></td></tr>
<tr><td><b>Manufacturer:</b></td>
<td class=text3><input type=text name=imanufacturer size=25 maxlength=25></td></tr>
<tr><td colspan=2 align=center>
<input type=submit name=submit value="Add Manufacturer"></td></tr>
</table>
</form>

<?php

}

if ($action == removem) {

// Remove a manufacturer

echo "Not yet implemented<BR>\n";
echo "<A href=\"admin.php\">Back to DB Admin</A><BR>\n";

}

if ($action == inserts) {
// Insert a new sport

?>

<form method=post action="<? echo $SCRIPT_NAME;?>" target="_top">
<table border=0 cellspacing=0 cellpadding=5>
<tr><td colspan=2 align=center><b>Sport Insert</b></td></tr>
<tr><td><b>Sport:</b></td>
<td class=text3><input type=text name=isport size=25 maxlength=25></td></tr>
<tr><td colspan=2 align=center>
<input type=submit name=submit value="Add Sport"></td></tr>
</table>
</form>

<?php

}

if ($action == removes) {
// Remove a sport

echo "Not yet implemented<BR>\n";
echo "<A href=\"admin.php\">Back to DB Admin</A><BR>\n";
}

if ($action == removec) {
// Remove a card from the database
echo "Not yet implemented<BR>\n";
echo "<A href=\"admin.php\">Back to DB Admin</A><BR>\n";

}

if ($imanufacturer!= "") {
mysql_query("INSERT INTO `manufacturer` (`id`, `name`) VALUES ('', '$imanufacturer')");

echo "$imanufacturer has been inserted into the database.<BR>\n";
}

if ($isport!= "") {
mysql_query("INSERT INTO `sport` (`num`, `sport`) VALUES ('', '$isport')");
echo "$isport has been inserted into the database.<BR>\n";
}

?>

The add page is just text that says "Nothing yet" Permissions are set to 777

Thanks again, not sure where you are located but I owe you many many drinks, lol

[edited by: jatar_k at 5:21 pm (utc) on Dec. 16, 2003]
[edit reason] removed specifics [/edit]

caspita

9:47 pm on Dec 16, 2003 (gmt 0)

10+ Year Member



The add page is just text that says "Nothing yet" Permissions are set to 777

Well here is the sad answer to your questions :-( ... I was asking you for the add.php because when I looked the url I saw that was the one adding the record to the DB but if you say that it has nothing else in there that "Notig yet" that means whoever wrote the code didn't finish it ... Basically you have everything except for the scripts to add/modify/delete the record for the DB (I'm assuming here because if add.php has nothing for sure the other actions either) ... So this module will never work for you at least you code those actions and for that you need to learn a little more ;-)

permisions have nothing to do here and 777 is not good for a php file (not unix expert here but I know that one :-) ).

try to look if you can find out more files having SQL sentences like $sql = "INSERT INTO ..." and using mysql functions like mysql_query($sql,$db) ... those could be the phps we are looking for.

I'm in US by the way and those drinks could motivate me ;-)

c u later. :-)

Acternaweb

1:11 pm on Dec 17, 2003 (gmt 0)

10+ Year Member



HI,

Where in the States are you, I am in Virginia. So if I am understanding correctly, the script isn't finished. So I will get to understand the script better thanks to you :-)

I found INSERT INTO in the admin for:

if ($imanufacturer!= "") {
mysql_query("INSERT INTO `manufacturer` (`id`, `name`) VALUES ('', '$imanufacturer')");

echo "$imanufacturer has been inserted into the database.<BR>\n";
}

if ($isport!= "") {
mysql_query("INSERT INTO `sport` (`num`, `sport`) VALUES ('', '$isport')");
echo "$isport has been inserted into the database.<BR>\n";
}

But nothning to add a card. I assume this was meant to be done on the index.php. I don't really care where the act is done as long as I can do it :-)

Again many thanks!

caspita

3:05 pm on Dec 17, 2003 (gmt 0)

10+ Year Member



form method=post action="<? echo $SCRIPT_NAME;?>" target="_top">

HI, I'm in NJ.

I just noticed also (look at the quote) that the script 'admin.php' is trying to call it self to execute the actions, which is fine acording to you note that you found the mysql sentences in the admin.php in self, but I think the way it is using the evironment variable is not good, you may need to use $_SERVER['SCRIPT_NAME'] instead of $SCRIPT_NAME (what is trying to do is to use a predefined variable).

I think if you change that and try to create a manufacturer or a sport it should work.

Good luck!

Acternaweb

3:24 pm on Dec 17, 2003 (gmt 0)

10+ Year Member



HI

I am from NJ orginally. Essex county area. I changed the script like you recommended and still no success. When I view the DB via phpadmin I see the entries. I also entered a BS record that I can see in the DB but no on the site.

Do you know of any scripts that could do what I want or atleast work enough that I can try to fake it?

caspita

3:58 pm on Dec 17, 2003 (gmt 0)

10+ Year Member



I'm in NJ but was born far away in south american country, that is why my english in not good ;-).

Here the firts tutorial I followed to learns php,mysql scripting... I has some good example and is a very good base

Links are not allowed here, so replace the * by /, # by :, and! by .

http#**hotwired.lycos.com*webmonkey*programming*php*tutorials*tutorial4!html

Acternaweb

4:02 pm on Dec 17, 2003 (gmt 0)

10+ Year Member



Your English is fine. I am not one to give up so after I take this tut, hopefully I can get back to scripts with your help.

I started taking that tut, but they must not be using phpadmin or have direct access to the server via telnet. I don't have that available.

Thanks again

Where in NJ are you?

caspita

8:22 pm on Dec 17, 2003 (gmt 0)

10+ Year Member



North of NJ. Ramsey.

You don't need to see the installation tutorial, just assume that is done for you. Go directly to the php coding examples.

I'll try to look a good example for you into my library.

Acternaweb

9:09 pm on Dec 17, 2003 (gmt 0)

10+ Year Member



Even the programing looks like it uses telnet protocal and I don't see how I replicate it via phpmyadmin.

I beleive the script that we were trying to do earily is not nearly done.

Thanks

Acternaweb

6:56 pm on Dec 18, 2003 (gmt 0)

10+ Year Member



OK, call me stubborn but I can't give up. I entered some data via phpmyadmin. Now how do I get it out?

I figure at worst this would be a good introduction.

My folks are in Livingston, ever hear of it?

caspita

9:27 pm on Dec 19, 2003 (gmt 0)

10+ Year Member



Ok here a generic php to display data from a table:

$db = mysql_connect('localhost','<user here>','<password here>') or die('I cannot connect to the database because: ' . mysql_error());

mysql_select_db('<db here>',$db);

$ssql = "SELECT <field-1>,<field-2>,<field-n> FROM <table here>";

echo "ssql=$ssql<br>";

$result = mysql_query($ssql, $db);

while ($result and mysql_num_rows($result) and ($row = mysql_fetch_assoc($result)))
{
echo ($row['<field-1'] . ", " . $row['<field-2'] . ", " .
$row['<field-n']);
}

that all!

enjoy it.