Forum Moderators: coopster
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?
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.
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]
$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]
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]
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]
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. :-)
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!
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!
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?
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
$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.