Forum Moderators: coopster

Message Too Old, No Replies

supplied argument is not a valid MySQL-Link resource

         

caveman28

1:31 pm on Oct 23, 2003 (gmt 0)

10+ Year Member



I am trying to run some shopping cart code I wrote and cannot get my pages to connect to my database. I have mysql 3.x running and am using php3. I setup the database tables and fields with the sql command line and know they are correct. I have a folder called "includes" which houses my config.inc file (with database info) and it is called correctly with the require_once code in each file. But everytime I click the link to go to the database connection, I get this error:

Warning: mysql_query(): supplied argument is not a valid MySQL-Link resource in /var/www/html/add_item.php on line 23
Unable to select requested database.

Here is my config.inc file, I edited out the username and password of course:

<?php

$db_info[username] = "*******";
$db_info[password] = "*******";
$db_info[host] = "127.0.0.1";
$db_info{dbname] = "mysite_com_-_db";
$db_connection = mysql_connect ($db_info[host], $db_info[username], $db_info[password]) or die (mysql_error());
mysql_select_db ($db_info[dbname], $db_connection) or die (mysql_error());

?>

and here is line 23 of add_item.php:

mysql_query ($query, $db_connection) or die ("Unable to select requested database.");

What the hell am I doing wrong?

-caveman

[edited by: jatar_k at 1:37 pm (utc) on Oct. 23, 2003]
[edit reason] emails in profile thanks [/edit]

Paul in South Africa

2:05 pm on Oct 23, 2003 (gmt 0)

10+ Year Member



If this is correct and not a typo when you made your post

$db_info{dbname] = "mysite_com_-_db";

should be

$db_info[dbname] = "mysite_com_-_db";

caveman28

7:36 pm on Oct 23, 2003 (gmt 0)

10+ Year Member



Ok, one of my brackets was wrong, I got a better editor. Now for the more serious errors. I have an admin_index page with a link that I can click to add a new product to my catalog. When I click the link, it loads add_product.pgp with this error:

Unknown table 'product' in where clause

Can someone point out my error to me? I am new to php and building this site for my girlfriend for her birthday present! I do not see any table refered to as 'product' except where 's' is truncated to the end of it when specifying the $tablename variable on line 15. Here is my code.

------------------------------------------------------------
<?php

$page_title = 'Add product';
require_once ("includes/admin_header.inc");
require_once ("includes/config.inc");

function make_product_select_row ($which) {

global $db_connection;

echo '<tr><td align="right">product ' . ucfirst ($which) . ':</td><td align="left">
<select name="' . $which . '_id">
';

$tablename = 'product_' . $which . 's';
$columnname = 'product_' . $which . '_id';
$query = "select * from $tablename order by $columnname";
$db_query = mysql_query ($query, $db_connection) or die (mysql_error());

while ($row = mysql_fetch_array ($db_query)) {
echo "<option value=\"$row[0]\">$row[1]</option>\n";
}

echo '</select></td></tr>
';
}

if (isset($HTTP_POST_VARS['submit'])) {
$query = "insert into products values ('0', $HTTP_POST_VARS[name_id]',
'$HTTP_POST_VARS[size_id]', $HTTP_POST_VARS[format_id]', $HTTP_POST_VARS[price]',
'$HTTP_POST_VARS[available]', '')";
mysql_query ($query, $db_connection) or die (mysqlerror());
}

echo '<table>
<tr>
<td align="center"><b>SKU</b></td>
<td align="center"><b>Product name</b></td>
<td align="center"><b>product Size</b></td>
<td align="center"><b>product Format</b></td>
<td align="center"><b>Price per unit</b></td>
<td align="center"><b>availability</b></td>
</tr>
';

$query = "select products.product_id, product_names.product_name AS NAME, product_sizes.product_size AS SIZE, product_formats.product_format AS FORMAT, products.price, products.available from products, product_names, product_sizes, product_formats where product.name_id = product_names.product_name_id and products.size_id = product_sizes.product_size_id and products.format_id = product_formats.product_format_id order by product_id";
$db_query = mysql_query ($query, $db_connection) or die (mysql_error());

while ($row = mysql_fetch_array ($db_query)) {
echo "<tr>
<td align=\"center\">$row[product_id]</td>
<td align=\"center\">$row[NAME]</td>
<td align=\"center\">$row[SIZE]</td>
<td align=\"center\">$row[FORMAT]</td>
<td align=\"center\">$row[price]</td>
<td align=\"center\">$row[available]</td>
</tr>\n";
}

echo '</table>';
echo '<br />
<table>
<tr><td align="center">Add a new product:</td></tr>
<form action="add_product.php" method="post">
';

make_product_select_row ('name');
make_product_select_row ('size');
make_product_select_row ('format');

echo '<tr><td align="right">Price per unit:</td><td align="left"><input type="text" name="price" size="10"></td></tr>
<tr><td align="right">Available:</td><td align="left"><select name="available"><option value="yes">Yes</option>
<option value="no">No</option></td></tr>
<tr><td align="center" colspan="2"><input type="submit" name="submit" value="add product"></td></tr>
</form>
</table>';

require_once ("includes/admin_footer.inc");
?>
------------------------------------------------------------

lorax

7:56 pm on Oct 23, 2003 (gmt 0)

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



>> where product.name_id = product_names.product_name_id

Is this really correct or should it be where products.name_id instead?