Forum Moderators: coopster
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]
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");
?>
------------------------------------------------------------