WDjoe
-
Posts
13 -
Joined
-
Last visited
Posts posted by WDjoe
-
-
Hi, yes I did notice the comma and removed the comma at the end of the query (no difference).
$q = "SELECT *, DATE_FORMAT(payment_date, '%M %D, %Y') AS formatted_date FROM item_payments WHERE username = 'benm' AND item_name='Invitations' " ;
And this is what the database looks like:
CREATE TABLE IF NOT EXISTS `item_payments` (
`payment_id` int(11) NOT NULL AUTO_INCREMENT,
`item_name` varchar(30) DEFAULT NULL,
`budget_id` int(50) DEFAULT NULL,
`amount` decimal(10,2) DEFAULT NULL,
`payment_date` date DEFAULT NULL,
`username` varchar(50) DEFAULT NULL,
`notes` varchar(200) NOT NULL,
`invoice_number` varchar(50) NOT NULL,
PRIMARY KEY (`payment_id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=227 ;--
-- Dumping data for table `item_payments`
--INSERT INTO `item_payments` (`payment_id`, `item_name`, `budget_id`, `amount`, `payment_date`, `username`, `notes`, `invoice_number`) VALUES
(226, 'Invitations', 728, '32.00', '2015-01-01', 'benm', '', 'abc123'),
(225, 'Invitations', 728, '36.77', '2015-01-08', 'benm', ' test notes in invitations', 'test invoice number varchar ABCD12345'); -
$item_name = 'Invitations';
$q = "SELECT *, DATE_FORMAT(payment_date, '%M %D, %Y') AS formatted_date FROM item_payments WHERE username='$user' AND item_name='$item_name',"; -
Tried it and I get the following. But I still don't see what is wrong with it:
#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '$item_name="Invitations" ' at line 1
-
Ok, I have pounded my head long enough (literally hours working on this) and I just can't figure this one out. I am hoping someone can solve this issue for me.
Hopefully I can explain myself well enough to be understood.
I have a database table ("items") with a column named "item_name", inside this column I have "Invitations" as a category name.
I am doing a simple query like this;
--------------------------------------------------------------------------------------------------------------------------
$category = "Invitations"
Query ="SELECT * FROM items WHERE username='$user' AND item_name='$category' ";
--------------------------------------------------------------------------------------------------------------------------
The problem is it will not return the rows where item_name = "Invitations".
I checked and rechecked making sure all letters are correct and that there are no spacing , etc.
If I edit that column and replace the text ("Invitations") with numbers, i.e."1234" and change $category ="1234" it returns the rows exactly as I would expect. I tried changing the column type to VARCHAR, CHAR, TEXT.
So what's going on?? Any ideas?
-
I figured it out and would like to share my solution.
I knew it had to be a sessions issue but all the "session_start()" was correctly placed on all my pages.
But in Chapter 12 there is a mention that you can put the "session_start()" in the php.ini folder.
That's what I did. Just make a folder and name it php.ini and inside it just place "session_start ()" (without the quotation marks).
Everything now works as it should. :-)
- 1
-
Hi, I am implementing the login script in chapter 12 but I don't understand something and hope someone can give me an answer.
Every time I enter my credentials into the login form and press "Login" it automatically transfers me to my index.php page.
Can anyone help please?
Thanks
-
Hi every, can someone help me out with this problem that I have concerning zero's showing up in fields that I want to show blank if there is no value being called from the database. I read various topics on this issue but I just don't get it.
To keep it simple lets say I have a form that has an optional FAX telephone number. If someone that fills in the form does not have a FAX number he or she will omit this field, but when the form is summited to the database a zero gets placed into the fax_telephone field in the database. I would like it to have nothing placed in the database. The way the fax number shows now has the fax number as "0", I would like it not to show anything at all.
This is a very simplified query with everything else removed but the fax telephone field that I am using:
$q = "INSERT INTO users (fax_telephone) VALUES ('$fax_telephone')";/code]
On my database I have set up like this:
[b]Field:[/b] fax_telephone
[b]Type[/b]:INT
[b]Lenngth[/b]:10
[b]Default:[/b] NULL
[b]Collation:[/b] utf8_general_ci
[b]Attributes:[/b]
[b]Null:[/b] (CHECKED)
Can anyone tell me what I am have to do to correct this?
Many thanks in advance.
-
In the top of the footer.html page of the CMS script what file is the footer.html referring to that is listed as
<!--<?php include ('./includes/comments.inc.php'); ?>-->
I don't see any explanation about this line of code in the book nor is it in the includes folder.
If I erase this line the pages gets scrambled so I would image it is important.
-
During the loop that creates the select options you need to compare $row[0] against that ID and add the selected="selected" snippet if that is the case. You'll need to use an if else to cater for form stickiness too.
Hi Stuart, thank you for your help.
I have tried different combinations with no luck. I noticed something though, I only had one table selected (categories) I think I would need also to select the other table (pages) so a comparison could be made. But when I did add the other table I got multiple choices of the same item in the drop down menu. That is I have three of everything in the drop-down menu. And even that did not get the category selected. Here is the updated code I used thinking it would work but didn't.
<select name="category_id"<?php if (array_key_exists('category', $add_page_errors)) echo ' class="error"'; ?>> <option>Select One</option> <?php // Retrieve all the categories and add to the pull-down menu: $q = "SELECT categories.id, categories.category, pages.category_id FROM categories, pages ORDER BY category ASC"; $r = mysqli_query ($dbc, $q); while ($row = mysqli_fetch_array ($r, MYSQLI_NUM)) { echo "<option value=\"$row[0]\""; // Check for stickyness: if (isset($_POST['categories.id']) && ($_POST['pages.category_id'] == $row[0]) ) echo ' selected="selected"'; echo ">$row[1]</option>\n"; } ?> </select>
This is how the two table are set up :
TABLE 'categories'
('id', 'category')
TABLE 'pages'
(id, category_id, title, description, content, date_created)
Any thoughts?
thanks again.
-
I am wondering if anyone can help me out with this.
On the CMS script I now have the capability to edit any page or category. I have a drop-down menu where the administrator can change the category that the page will be placed under. My problem is when I edit a page I would like the category drop-down menu to have the category of the page that it is under (from the database) already selected. I copied the code from the "add_page.php" file to my new "edit_page.php" file but when I go to edit the page the category is not selected only the text "Select One" is. Though I am able to click on a category from the drop-down menu to choose a category I would like the one that page is classified under to show automatically. If I forget to enter a category when I edit a page a "0" is automatically placed under the "category_id" column in the database and the page is unable to be viewed.
Here is the drop-down menu code that retrieves the categories from the database.
<p><label for="category"><strong>Category</strong></label><br /> <select name="category_id"<?php if (array_key_exists('category', $add_page_errors)) echo ' class="error"'; ?>> <option>Select One</option> <?php // Retrieve all the categories and add to the pull-down menu: $q = "SELECT id, category FROM categories ORDER BY category ASC"; $r = mysqli_query ($dbc, $q); while ($row = mysqli_fetch_array ($r, MYSQLI_NUM)) { echo "<option value=\"$row[0]\""; // Check for stickyness: if (isset($_POST['category_id']) ) echo ' selected="selected"'; echo ">$row[1]</option>\n"; } ?> </select><?php if (array_key_exists('category', $add_page_errors)) echo ' <span class="error">' . $add_page_errors['category'] . '</span>'; ?></p>
Many thanks for any help in advance.
-
Hi Larry, thank you for your reply. That did the trick :-)
- 1
-
I am working to on the first script in the book "Effortless E-Commerce with PHP and MySQL" and have it working the way I want it to work.I am customizing it to fit my particular needs. I have added pages where the administrator can also add or delete pages and categories from the database. I also made it where only the administrator can add the users to the database (no one can register).
There is only one problem I am having and it's driving me nuts and I am hoping that someone can help me.
First, I have added the TinyMCE html editor per instructions in the book ( I love this feature) and it works as it should, the problem I have is how do I edit a page that is already in the database so when I call it to be edited the original text from this page is automatically placed in the TinyMCE editor for easy editing?
- 1
Baffle With A Simple Query
in PHP and MySQL for Dynamic Web Sites: Visual QuickPro Guide (4th Edition)
Posted
It's working now.
I had to go line by line by line and follow every step of the code in extreme detail and analyze after comma and semi-colon and so forth.
I had an "else" statement in my code where if any records were found to display the table and if no records were found to display a message. Unfortunately for me the message was nothing ( I had not yet written the message I wanted to display) and I had the "if" statement reversed, so when I ran the query it found records but because the "if" statement was reversed nothing was shown on the webpage.
No problem, only spend 3 days trying to get it to work, lots of coffee and aspirin and a huge learning experience for me! ...lol
Thank you for your help HartleySan for helping me out.