Hello everyone:
I'm trying to learn PHP and I'm using this book to help me "PHP, MYSQL and Apache all in one" They have an example which is listed below. I'm using Dreamweaver to write the PHP and XAMPP to write the db.
I have set up the db connection with Dreamweaver.
My db is located in the default folder under XAMPP.
I get this error:
Incorrect database name 'storefront_db '
[PHP] <?php
session_start();
//connect to database
$conn = mysql_connect("localhost", "nomad", "nomad") or die(mysql_error());
mysql_select_db("storefront_db ",$conn) or die(mysql_error());
if ( POST[sel_item_id] != "") {
//validate item and get title and price
$get_iteminfo = "select item_title from store_items where id = POST[sel_item_id]";
$get_iteminfo_res = mysql_query($get_iteminfo) or die(mysql_error());
if (mysql_num_rows($get_iteminfo_res) < 1) {
//invalid id, send away
header("Location: seestore.php");
exit;
} else {
//get info
$item_title = mysql_result($get_iteminfo_res,0,'item_title');
//add info to cart table
$addtocart = "insert into store_shoppertrack values ('', '$PHPSESSID', ' POST[sel_item_id]', ' POST[sel_item_qty]', ' POST[sel_item_size]', ' POST[sel_item_color]', now())";
mysql_query($addtocart);
//redirect to showcart page
header("Location: showcart.php");
exit;
}
} else {
//send them somewhere else
header("Location: seestore.php");
exit;
}
?>
[/PHP]
Any help would be great
nomad
9 1582
have you setup a database in mysql yet?
if you have, please check for misspelling, if you haven't created a database yet, this is the cause of your problem :)
uhhh just noticed you have a space in the database name on line 5 - mysql_select_db("storefront_db ",$conn) or die(mysql_error());
this is probably why, erase the space so it looks like: - mysql_select_db("storefront_db",$conn) or die(mysql_error());
uhhh just noticed you have a space in the database name on line 5 - mysql_select_db("storefront_db ",$conn) or die(mysql_error());
this is probably why, erase the space so it looks like: - mysql_select_db("storefront_db",$conn) or die(mysql_error());
The correction you suggested did not work. I get this error now Object not found!
The requested URL was not found on this server. If you entered the URL manually please check your spelling and try again.
If you think this is a server error, please contact the webmaster Error 404
localhost
06/27/07 08:59:52
Apache/2.2.4 (Win32) DAV/2 mod_ssl/2.2.4 OpenSSL/0.9.8e mod_autoindex_color PHP/5.2.1
You're other question about the db being made. Yes it is created which is called storefront_db.Do I have to call up the directory to get to the storefront_db?
Nomad
The correction you suggested did not work. I get this error now Object not found!
The requested URL was not found on this server. If you entered the URL manually please check your spelling and try again.
If you think this is a server error, please contact the webmaster Error 404
localhost
06/27/07 08:59:52
Apache/2.2.4 (Win32) DAV/2 mod_ssl/2.2.4 OpenSSL/0.9.8e mod_autoindex_color PHP/5.2.1
You're other question about the db being made. Yes it is created which is called storefront_db.Do I have to call up the directory to get to the storefront_db?
Nomad
This means it's working :) cause you're being redirected to another page, which probably doesn't exist yet :)
(a 404 error means exactly that the document you are trying to see cannot be found on the server, it has nothing to do with database connectivity)
try commenting out your header('Location .....); statements and make it echo something like 'redirect to thispage', 'redirect to thatpage' instead. So you can see where it's going :)
This means it's working :) cause you're being redirected to another page, which probably doesn't exist yet :)
(a 404 error means exactly that the document you are trying to see cannot be found on the server, it has nothing to do with database connectivity)
try commenting out your header('Location .....); statements and make it echo something like 'redirect to thispage', 'redirect to thatpage' instead. So you can see where it's going :)
Thanks for the help
I found out that one of my php files was in the wrong directory.
I have another problem when I click a link on the main page it get this error
Unknown column 'id' in 'field list'
Here is the code -
-
<?php
-
//connect to database
-
$conn = mysql_connect("localhost", "nomad", "nomad") or die(mysql_error());
-
mysql_select_db("storefront_db",$conn) or die(mysql_error());
-
$display_block = "<h1>My Categories</h1>
-
<P>Select a category to see its items.</p>";
-
//show categories first
-
$get_cats = "select id, cat_title, cat_desc from store_categories order by cat_title";
-
$get_cats_res = mysql_query($get_cats) or die(mysql_error());
-
if (mysql_num_rows($get_cats_res) < 1) {
-
$display_block = "<P><em>Sorry, no categories to browse.</em></p>";
-
} else {
-
while ($cats = mysql_fetch_array($get_cats_res)) {
-
$cat_id = $cats[id];
-
$cat_title = strtoupper(stripslashes($cats[cat_title]));
-
$cat_desc = stripslashes($cats[cat_desc]);
-
$display_block .= "<p><strong><a href=\" [PHP]%4$s[/PHP] SERVER[PHP_SELF]?cat_id=$cat_id\">$cat_title</a></strong><br>$cat_desc</p>";
-
if ( [PHP]%4$s[/PHP] GET[cat_id] == $cat_id) {
-
//get items
-
$get_items = "select id, item_title, item_price from store_items where cat_id = $cat_id order by item_title";
-
$get_items_res = mysql_query($get_items) or die(mysql_error());
-
if (mysql_num_rows($get_items_res) < 1) {
-
$display_block = "<P><em>Sorry, no items in this category.</em></p>";
-
} else {
-
$display_block .= "<ul>";
-
while ($items = mysql_fetch_array($get_items_res)) {
-
$item_id = $items[id];
-
$item_title = stripslashes($items[item_title]);
-
$item_price = $items[item_price];
-
$display_block .= "<li><a href=\"showitem.php?item_id=$item_id\">$item_title</a></strong> (\$item_price)";
-
}
-
$display_block .= "</ul>";
-
}
-
}
-
}
-
}
-
?>
-
<HTML>
-
<HEAD>
-
<TITLE>My Categories</TITLE>
-
</HEAD>
-
<BODY>
-
<?php echo $display_block; ?>
-
</BODY>
-
</HTML>
-
I looked at my fields in my db and them seemed to be same as my php.
code.
nomad
this is from your sql query
$get_cats = "select id, cat_title, cat_desc from store_categories order by cat_title";
again make sure that no spaces have sneaked in to your code, this time it might be in the database setup.
It's pretty dangerous to use just "id", i would prefer calling it cat_id. with multiple tables it can be confusing to have a column named id in each table, if it's not foreign keys.
you could try using backqoutes in the statement making it look like
$get_cats = "select `id`, `cat_title`, `cat_desc` from `store_categories` order by `cat_title`";
but this probably won't help, check out the database and see if you haven't accidentally sneaked a space before or after id
this is from your sql query
$get_cats = "select id, cat_title, cat_desc from store_categories order by cat_title";
again make sure that no spaces have sneaked in to your code, this time it might be in the database setup.
It's pretty dangerous to use just "id", i would prefer calling it cat_id. with multiple tables it can be confusing to have a column named id in each table, if it's not foreign keys.
you could try using backqoutes in the statement making it look like
$get_cats = "select `id`, `cat_title`, `cat_desc` from `store_categories` order by `cat_title`";
but this probably won't help, check out the database and see if you haven't accidentally sneaked a space before or after id
Thanks for the all help.
and I will try to rewrite the code, this is an exercise out of the book.
The id are PK with auto_increments with not null.
nomad
this is from your sql query
$get_cats = "select id, cat_title, cat_desc from store_categories order by cat_title";
again make sure that no spaces have sneaked in to your code, this time it might be in the database setup.
It's pretty dangerous to use just "id", i would prefer calling it cat_id. with multiple tables it can be confusing to have a column named id in each table, if it's not foreign keys.
you could try using backqoutes in the statement making it look like
$get_cats = "select `id`, `cat_title`, `cat_desc` from `store_categories` order by `cat_title`";
but this probably won't help, check out the database and see if you haven't accidentally sneaked a space before or after id
well I'm still getting the same error code
Unknown column 'id' in 'field list'
I think it has to deal with these line of code
while ($cats = mysql_fetch_array($get_cats_res)) {
$cat_id = $cats[id];
the next lines below that seem to work.
I even tried draging the fields into dreamweaver so I know I got the right fields names. It might be the id field itself because there are least 4 tables that use the same name.
nomad
well I'm still getting the same error code
Unknown column 'id' in 'field list'
I think it has to deal with these line of code
while ($cats = mysql_fetch_array($get_cats_res)) {
$cat_id = $cats[id];
the next lines below that seem to work.
I even tried draging the fields into dreamweaver so I know I got the right fields names. It might be the id field itself because there are least 4 tables that use the same name.
nomad
found the problem. Boy do I feel dumb
I had a field called int when it should have been id.
Thanks for the tip ronnil.
nomad
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Mudge |
last post by:
Hi,
My hosting provider only allows me to use 50 connections to my MySQL
database that my Web site will use.
I don't know what this 50 connections means exactly. Does this mean that
only 50...
|
by: Bob |
last post by:
After adding a Data Connection everything appears to be fine but when
I right-click on Tables to add a table the option is not there, only
refresh & properties are showing. I can see and review...
|
by: KL |
last post by:
Well, I am back.
This time our assignment has us filling a vector and then timing how
long it takes to find a spot in the vector to insert a new item, and
the time required to insert the item...
|
by: Angelos |
last post by:
I get this error mysql_pconnect Too many connections ... every now and
then.
Does anyone knows where it comes from ?
There are a lot of sites running on the server and all of them use the...
|
by: Lior |
last post by:
Hi, I have an ASP.NET website that crashes under heavy load.
I use a SQL Server DB. I get around 5500 hits per day. I keep getting the
timeout expieried connection pool error. Sometimes it even...
|
by: dave m |
last post by:
I need to be able to retrieve a unique ID from a users PC. I needs to be
something a user could not easily change, like the computer name. Could
someone point me in the right direction to find ...
|
by: Paul |
last post by:
I am trying to create a log of certain events on the website by writing them
to a text file. The logging code is in an "included" file that is inserted
into the pages that need to be monitored....
|
by: t.mitchell |
last post by:
Hi,
I have a python gtk app that allows users to have one project open at a
time. I have recently discovered that projects are not being freed
when they are closed - the refcount is not hitting...
|
by: U S Contractors Offering Service A Non-profit |
last post by:
This Sunday the 26th 2006 there will
be Music @ Tue Nov Inbox
Reply
Craig Somerford
to me
show details
9:54 pm (26 minutes ago)
#1St "CLICK" HeAt frOm A blanket...
|
by: Usman Jamil |
last post by:
Hi
I've a class that creates a connection to a database, gets and loop on a
dataset given a query and then close the connection. When I use netstat
viewer to see if there is any connection open...
|
by: CloudSolutions |
last post by:
Introduction:
For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
|
by: ryjfgjl |
last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
| |