# Need Quick PHP Help



## mixx941 (Dec 19, 2001)

Hello all. I'm new to PHP and I am making a computer help tutorial site with topics from building a computer, to flash, to photoshop, etc. .

I am wondering how I can have a system in PHP that would allow a user to submit a tutorial, but have it then go into a queue to be approved by an admin. Then, if we approved it, it would go to a specific category main listing page, and have it's own page. 

I am looking for the easiest, least time consuming way to do this, hopefully with a pre-packaged script that does not require shell access. 

Thanks

-Mark


----------



## brendandonhu (Jul 8, 2002)

To do this efficiently, it would be easiest if you have a database. Is this available?


----------



## mixx941 (Dec 19, 2001)

Yes PHP4 and the latest MySQL.

-Mark


----------



## brendandonhu (Jul 8, 2002)

Ok good.
Lets say in your MySQL table you have these columns:
ID||Status||Author||Category||Subject||Message
You could use Status to store whether the article is waiting approval, or approved, etc.
You could have an admin page that shows all articles waiting approval, with a button to change the status to approved.
Then in the page for each category, it would show all articles where status = approved and category = whatever category they are viewing.

Before I show some sample code, does that sound about right?


----------



## mixx941 (Dec 19, 2001)

Pretty much. 

The whole idea is to have them submit tutorials, and have them put into a queue to be approved. When they are approved by one of us admins, a link to that tutorial goes onto the main category page for that specific category, and that link would take them to the tutorial when clicked. 

I take it there's no pre-made package for this since you are talking about giving me sample code. I really appreciate your help. 

Also, my host is using phpMyAdmin for the MySQL management if that helps tell you anything.

THanks

-Mark


----------



## brendandonhu (Jul 8, 2002)

You could probably use PHP-Nuke or another content management system but I have never used them so I don't really know how.
This isn't too complicated though (I think).
You would have a form that the person fills out, and you would process it with something like this

```
<?php
$author = $_POST['author'];
$category = $_POST['category'];
$subject = $_POST['subject'];
$message = $_POST['message'];
mysql_connect(server,username,password);
mysql_select_db(database);
$sql = "INSERT INTO tutorials VALUES ('','NotApproved','$author','$category','$subject','$message')";
mysql_query($sql);
mysql_close()?>
```


----------



## mixx941 (Dec 19, 2001)

I looked at php-nuke but it says it requires shell access...which I dont have (please correct me if I read it wrong). 

Ok, so I have that form. Then how would I create the databases or access an adminCP? I would also need an email field, in case I needed to email them. 

Thanks for your ongoing help  

-Mark


----------



## brendandonhu (Jul 8, 2002)

You might want to check out this tutorial
http://www.mysql.com/articles/ddws/
Especially the Challenge Project code, it might help you out.


----------



## mixx941 (Dec 19, 2001)

OK. Thanks. I will have a look.

If anyone does think of any pre-made one, please let me know. 

Thanks

-Mark


----------



## brendandonhu (Jul 8, 2002)

You can create the database in phpMyAdmin.
With an E-Mail field, you would use this SQL to create the table.

```
CREATE TABLE `tutorials` (
`ID` INT NOT NULL AUTO_INCREMENT ,
`Status` TEXT,
`Author` TEXT,
`Category` TEXT,
`Subject` TEXT,
`Message` TEXT,
`Email` TEXT,
PRIMARY KEY ( `ID` ) 
);
```


----------



## mixx941 (Dec 19, 2001)

And that would be inputted where in phpMyAdmin? 

(Sorry this is my second day ever using phpMyAdmin, so I am a little new to this particular program). Also, any special options I need to select wherever I input that? 

Then, when I do input that, how do I make the front end. Front end meaning the updated submission form, the admincp, the list in the categories pages, and the articles themselves. 

Sorry I have so many questions... 

-Mark


----------



## brendandonhu (Jul 8, 2002)

Not sure what version of phpMyAdmin your using, but there should be an SQL tab somewhere where you can enter than into a textbox.

The submission form you would do in regular HTML and the action would be the PHP I gave above. But in that PHP change the line
('','NotApproved','$author','$category','$subject','$message')";
to
('','NotApproved','$author','$category','$subject','$message',$email')";
and add at the beginning
$email = $_POST['email']

I'm thinking about the best way for an admin page to approve submissions. The category pages will be pretty easy after that.


----------



## mixx941 (Dec 19, 2001)

It's phpMyAdmin 2.4.0.

I did that, and it worked out easy . Cool.

My database name is:

"brainsto_tutorials" and the table is "tutorials"

I'll see if I can make sense of that php you gave me 

-Mark

EDIT: I made that php page and went ahead and uploaded it. (here: http://www.brain-storm.us/submit.php)

I specified my database, and now I have a blank page. Then how would I make the form for people to fill out?

Also, could someone view source and see my password by doing this? I changed it to "password" for now so that if so, nobody could see it.


----------



## brendandonhu (Jul 8, 2002)

No-in PHP its safe to have your password in a file like that.
Your HTML form would be like this.

```
Author: 
Email: 
Subject: 
Category: Category1">Category2
Tutorial
```
Note that I haven't tested any of this code so there may be errors/bugs at first.


----------



## mixx941 (Dec 19, 2001)

OK, I made the proper modifications and added a submit and reset button.

http://www.brain-storm.us/submit.html

It posted correctly, but obviously no confirmation page. I looked at my phpMyAdmin after I submitted a form and there was a (1) next to the database that wasn't there before! 

-Mark


----------



## brendandonhu (Jul 8, 2002)

A confirmation page? Ok. Name it thanks.html and add this line to the end of the PHP Code

```
header('Location: thanks.html');
```
Hit browse on the phpMyAdmin and you should be able to see if the data was entered correctly.


----------



## mixx941 (Dec 19, 2001)

Well, I typed a whole long reply and my attachment was too big. Here I try again:

I tried adding that code inside and outside the "?>" at the end of the php.

When it was inside, I got parse errors. Outside I just saw the code as text.

As for the phpMyAdmin browse thing, I see the tables when I go to browse, but I do not see the data I have input (see screenshot)

THanks

-Mark


----------



## brendandonhu (Jul 8, 2002)

Ok to view the data click the "Go" button just below that textarea in the screenshot.
And here is what the php code should be now

```
<?php
$email = $_POST['email'];
$author = $_POST['author'];
$category = $_POST['category'];
$subject = $_POST['subject'];
$message = $_POST['message'];
mysql_connect(server,username,password);
mysql_select_db(database);
$sql = "INSERT INTO tutorials VALUES ('','NotApproved','$author','$category','$subject','$message',$email');
mysql_query($sql);
mysql_close();
header('Location: thanks.html')?>
```


----------



## mixx941 (Dec 19, 2001)

Here is what I see when I click that go button:










I'll try that PHP in a sec.

-Mark

EDIT: That PHP gives me this:



> Parse error: parse error, unexpected $ in /home/brainsto/public_html/submit.php on line 13


----------



## brendandonhu (Jul 8, 2002)

You also have to change the database. 
That would mean there is no data in the database, which would be because of the parse errors. Upload the latest version of the PHP and it should work. Make sure you have the correct database/username/password.


----------



## mixx941 (Dec 19, 2001)

Here is how I have the code:


```
<?php
$email = $_POST['email'];
$author = $_POST['author'];
$category = $_POST['category'];
$subject = $_POST['subject'];
$message = $_POST['message'];
mysql_connect(localhost,brainsto,password);
mysql_select_db(brainsto_tutorials);
$sql = "INSERT INTO tutorials VALUES ('','NotApproved','$author','$category','$subject','$message',$email');
mysql_query($sql);
mysql_close();
header('Location: thanks.html')?>
```
It says



> Parse error: parse error, unexpected $ in /home/brainsto/public_html/submit.php on line 12


The webhost has the latest version of MySQL, PHP, and just updated Cpanel (not that cpanel matters).

Now, I have the database set as "brainsto_tutorials". Should it just be "tutorials" because it already knows its in brainsto?

-Mark


----------



## mixx941 (Dec 19, 2001)

I played around with the code some and came up with this...it works now:


```
<?php
$email = $_POST['email'];
$author = $_POST['author'];
$category = $_POST['category'];
$subject = $_POST['subject'];
$message = $_POST['message'];
mysql_connect("localhost","brainsto","PASSWORD");
mysql_select_db(brainsto_tutorials);
$sql = "INSERT INTO tutorials VALUES ('','NotApproved','$author','$category','$subject','$message','$email')";
mysql_query($sql);
mysql_close();
header('Location: thanks.html'); ?>
```
Also, it now shows up in the DB.

I will need to create categories like "Computers" "Flash" "Photoshop" etc as well.

What's next? 

THanks

-Mark


----------



## brendandonhu (Jul 8, 2002)

Ok good now you've got it working.
Next I would do the admin page. This will show the tutorials, and a button to Accept them or Delete them.
Well it will when I'm finished with it hopefully


----------



## brendandonhu (Jul 8, 2002)

Ok heres something to start with for admin.php. It will display the tutorial, and allow you to Accept or Delete it.
I have not tested it, and there will undoubtedly be bugs in it, so post what errors it gives and I'll have to correct em 1 at a time.

```
<?php
mysql_connect(server,username,password);
mysql_select_db(database) or die( "Unable to select database");
#Detect if a tutorial is being deleted
#If yes, delete it
if (isset($_GET['delete'])) {
$delete = $_GET['delete'];
mysql_query("DELETE FROM tutorials WHERE id=$delete");
echo("Submission Removed");}
#Detect if a tutorial is being approved
#If yes, change status to approved
if (isset($_GET['approve'])) {
$accept = $_GET['approve'];
mysql_query("UPDATE tutorials SET status="approved" WHERE id=$delete");
echo("Submission Accepted");}
$query = "SELECT * FROM tutorials WHERE status = 'NotApproved'";
$result = mysql_query($query);
$num=mysql_numrows($result);
echo "[B]Waiting Approval[/B]

";
while ( $row = mysql_fetch_array($result) )
{
$id = $row['ID'];
$status = $row['status'];
$author = $row['author'];
$email = $row['email'];
$subject = $row['subject'];
$category = $row['category'];
$message = $row['message'];
echo "From:  [URL]$author[/URL]  Subject: $subject  Category:  $category
[URL]Don't Approve[/URL]  [URL]Approve[/URL]
$message

";
}
?>
```


----------



## mixx941 (Dec 19, 2001)

First Error So Far:



> Parse error: parse error, unexpected T_STRING in /home/brainsto/public_html/admin.php on line 14


Also, what do I need to do to the forum or phpMyAdmin to add categories like "Computers" "Flash" "Photoshop" etc?

Thanks A Lot 

-Mark


----------



## brendandonhu (Jul 8, 2002)

Try changing
echo("Submission Accepted");}
to 
echo "Submission Accepted";}
If that doesn't work, maybe put a ; at the end of the line.


----------



## brendandonhu (Jul 8, 2002)

To add a category to the form you change the HTML there.
find 
After that you can add categories like
Category3 
would add a 3rd category


----------



## mixx941 (Dec 19, 2001)

Hi. I tried both and I still get:



> Parse error: parse error, unexpected T_STRING in /home/brainsto/public_html/admin.php on line 14


Also, on the adding options would I need to add them to the MySQL?

-Mark


----------



## brendandonhu (Jul 8, 2002)

Change
mysql_query("UPDATE tutorials SET status="approved" WHERE id=$delete");
to
sql = "UPDATE tutorials SET status='approved' WHERE id=$delete";
mysql_query($sql);


----------



## brendandonhu (Jul 8, 2002)

Oh and yes, if you want to add another element to the field, you have to add it to MySQL as well as the PHP scripts.


----------



## mixx941 (Dec 19, 2001)

> Parse error: parse error, unexpected '=' in /home/brainsto/public_html/admin.php on line 14


When it's like this:


```
<?php
mysql_connect(localhost,brainsto,password);
mysql_select_db(brainsto_tutorials) or die( "Unable to select database");
#Detect if a tutorial is being deleted
#If yes, delete it
if (isset($_GET['delete'])) {
$delete = $_GET['delete'];
mysql_query("DELETE FROM tutorials WHERE id=$delete");
echo("Submission Removed");}
#Detect if a tutorial is being approved
#If yes, change status to approved
if (isset($_GET['approve'])) {
$accept = $_GET['approve'];
sql = "UPDATE tutorials SET status='approved' WHERE id=$delete";
mysql_query($sql);
echo "Submission Accepted";};
$query = "SELECT * FROM tutorials WHERE status = 'NotApproved'";
$result = mysql_query($query);
$num=mysql_numrows($result);
echo "[B]Waiting Approval[/B]

";
while ( $row = mysql_fetch_array($result) )
{
$id = $row['ID'];
$status = $row['name'];
$author = $row['email'];
$email = $row['country'];
$subject = $row['age'];
$category = $row['title'];
$message = $row['gender'];
echo "From:  [URL]$author[/URL]  Subject: $subject  Category:  $category
[URL]Don't Approve[/URL]  [URL]Approve[/URL]
$message

";
}
?>
```
-Mark


----------



## brendandonhu (Jul 8, 2002)

Oops I made a tiny mistake.
The line
sql = "UPDATE tutorials SET status='approved' WHERE id=$delete";

needs to have a $ at the beginning


----------



## mixx941 (Dec 19, 2001)

Well that worked!  I was just going over it and was gonna add it when I saw your new message.

Now if someone were to enter a big long tutorial in the text area, would it show up there? I haven't tried posting one and then deleting it yet, so...

I have to go to a job here in a few minutes, but whatever's next I will do when I get back. Also maybe an "example" on how to add those other categories like "Flash" "Computers" "Graphic Design" "Linux" "Internet" etc in my existing MySQL, so I dont screw that up !

Thanks for your ongoing help. 

-Mark










*EDIT: I submitted a forum and it showed up like the one in the screenshot, but with none of the info filled in. Just thought I'd say that before I left.*


----------



## brendandonhu (Jul 8, 2002)

Since its not showing in there-can you take a screenshot of what the data looks like from within phpMyAdmin? Its probably something like a typo or capitalization error in the script.


----------



## mixx941 (Dec 19, 2001)

Sure. I believe it is all showing up in phpMyAdmin here:










-Mark


----------



## brendandonhu (Jul 8, 2002)

Ok lets try narrowing the problem down-does this show both records in the admin page?

```
<?php
mysql_connect(localhost,brainsto,password);
mysql_select_db(brainsto_tutorials) or die( "Unable to select database");
#Detect if a tutorial is being deleted
#If yes, delete it
if (isset($_GET['delete'])) {
$delete = $_GET['delete'];
mysql_query("DELETE FROM tutorials WHERE id=$delete");
echo("Submission Removed");}
#Detect if a tutorial is being approved
#If yes, change status to approved
if (isset($_GET['approve'])) {
$accept = $_GET['approve'];
$sql = "SELECT * FROM tutorials";
mysql_query($sql);
echo "Submission Accepted";};
$query = "SELECT * FROM tutorials WHERE status = 'NotApproved'";
$result = mysql_query($query);
$num=mysql_numrows($result);
echo "[B]Waiting Approval[/B]

";
while ( $row = mysql_fetch_array($result) )
{
$id = $row['ID'];
$status = $row['name'];
$author = $row['email'];
$email = $row['country'];
$subject = $row['age'];
$category = $row['title'];
$message = $row['gender'];
echo "From:  [URL]$author[/URL]  Subject: $subject  Category:  $category
[URL]Don't Approve[/URL]  [URL]Approve[/URL]
$message

";
}
?>
```


----------



## mixx941 (Dec 19, 2001)

That shows what it did in the above screenshot. The categories, the Approve or Disapprove buttons, but the data is not there. Also, is there a way to get the actual message or tutorial to show up there?

Thanks

-Mark


----------



## brendandonhu (Jul 8, 2002)

It is supposed to show the message.
Well, try this.

```
<?php
mysql_connect(localhost,brainsto,password);
mysql_select_db(brainsto_tutorials) or die( "Unable to select database");
#Detect if a tutorial is being deleted
#If yes, delete it
if (isset($_GET['delete'])) {
$delete = $_GET['delete'];
mysql_query("DELETE FROM tutorials WHERE id=$delete");
echo("Submission Removed");}
#Detect if a tutorial is being approved
#If yes, change status to approved
if (isset($_GET['approve'])) {
$accept = $_GET['approve'];
$sql = "SELECT * FROM tutorials";
mysql_query($sql);
echo "Submission Accepted";};
$query = "SELECT * FROM tutorials";
$result = mysql_query($query);
$num=mysql_numrows($result);
echo "[B]Waiting Approval[/B]

";
while ( $row = mysql_fetch_array($result) )
{
$id = $row['ID'];
$status = $row['status'];
$author = $row['author'];
$email = $row['email'];
$subject = $row['subject'];
$category = $row['category'];
$message = $row['message'];
echo "From:  [URL]$author[/URL]  Subject: $subject  Category:  $category
[URL]Don't Approve[/URL]  [URL]Approve[/URL]
$message

";
}
?>
```


----------



## mixx941 (Dec 19, 2001)

Another Screenshot:










Maybe my computer is messed up! The address is:

http://www.brain-storm.us/admin2.php

-Mark


----------



## brendandonhu (Jul 8, 2002)

Ok thats progress! If you add another entry to the database, I bet you it will repeat that 3 times.
Im working on getting the content in there.


----------



## brendandonhu (Jul 8, 2002)

Yes it is somewhat working now. I added another entry and it repeated that part again.


----------



## brendandonhu (Jul 8, 2002)

I feel stupid  This ought to work, I had posted the code setup for the database on MY website and forgot to change it to yours!

```
<?php
mysql_connect(localhost,brainsto,password);
mysql_select_db(brainsto_tutorials) or die( "Unable to select database");
#Detect if a tutorial is being deleted
#If yes, delete it
if (isset($_GET['delete'])) {
$delete = $_GET['delete'];
mysql_query("DELETE FROM tutorials WHERE ID = $delete");
echo("Submission Removed");}
#Detect if a tutorial is being approved
#If yes, change status to approved
if (isset($_GET['approve'])) {
$accept = $_GET['approve'];
$sql = "UPDATE tutorials SET status = 'Approved' WHERE ID = $approve";
mysql_query($sql);
echo "Submission Accepted";};
$query="SELECT * FROM tutorials";
$result=mysql_query($query);
$num=mysql_numrows($result);
echo "[B]Waiting Approval[/B]

";
while ( $row = mysql_fetch_array($result) )
{
$id = $row['ID'];
$status = $row['status'];
$author = $row['author'];
$email = $row['email'];
$subject = $row['subject'];
$category = $row['category'];
$message = $row['message'];
echo "From:  [URL]$author[/URL]  Subject: $subject  Category:  $category
[URL]Don't Approve[/URL]  [URL]Approve[/URL]
$message

";
}
?>
```


----------



## mixx941 (Dec 19, 2001)

The screenshot is the same as before, except with 3 entries. Still no data though. 

Thanks

-Mark


----------



## brendandonhu (Jul 8, 2002)

Ok I tested and the Accept/Don't links work now. (Thats why theres only 1 entry showing now).
The latest script there should work-I'll take another look.


----------



## mixx941 (Dec 19, 2001)

OK, Now I refreshed that page (admin2.php) and two of the entries disappeared! 

-Mark

EDIT: Whoops, didnt see your post.


----------



## brendandonhu (Jul 8, 2002)

Ok I edited my post above, try the script now.
If it doesn't work, I will have to try it on my server and figure it out probably.


----------



## mixx941 (Dec 19, 2001)

Now its showing the two entries, but only the Approve/Disapprove buttons...but the info that is entered in the form isn't there. 

Thanks

-Mark


----------



## brendandonhu (Jul 8, 2002)

Ok this should just show all the data in the database, unformatted. If it works, then I can add the Approve/Don't Approve functions back in.

```
<?php
mysql_connect(localhost,brainsto,password);
mysql_select_db(brainsto_tutorials) or die( "Unable to select database");
$query="SELECT * FROM tutorials";
$result=mysql_query($query);
$num=mysql_numrows($result);
while ( $row = mysql_fetch_array($result) )
{
$id = $row['ID'];
$status = $row['status'];
$author = $row['author'];
$email = $row['email'];
$subject = $row['subject'];
$category = $row['category'];
$message = $row['message'];
echo "$id $status $author $email $subject $category $message";
}
?>
```


----------



## mixx941 (Dec 19, 2001)

Here is what I see on a page:



> 1 2 4 5


(http://www.brain-storm.us/admin3.php)

-Mark


----------



## deuce868 (Nov 2, 2000)

I think it might be case sensitive. Make sure to capitalize the first letter of each where you say
$status = $row[Status']; etc...

I think you are only getting the ID's because there is no field called status =)


----------



## brendandonhu (Jul 8, 2002)

Yea thats it! OMG I had like a dream where I was posting the code with the capitalization! It was soooo weird.
There is a status in the database though deuce.
Try this

```
<?php
mysql_connect(localhost,brainsto,password);
mysql_select_db(brainsto_tutorials) or die( "Unable to select database");
#Detect if a tutorial is being deleted
#If yes, delete it
if (isset($_GET['delete'])) {
$delete = $_GET['delete'];
mysql_query("DELETE FROM tutorials WHERE ID = $delete");
echo("Submission Removed");}
#Detect if a tutorial is being approved
#If yes, change status to approved
if (isset($_GET['approve'])) {
$accept = $_GET['approve'];
$sql = "UPDATE tutorials SET Status = 'Approved' WHERE ID = $approve";
mysql_query($sql);
echo "Submission Accepted";};
$query="SELECT * FROM tutorials WHERE Status = 'NotApproved'";
$result=mysql_query($query);
$num=mysql_numrows($result);
echo "[B]Waiting Approval[/B]

";
while ( $row = mysql_fetch_array($result) )
{
$id = $row['ID'];
$status = $row['Status'];
$author = $row['Author'];
$email = $row['Email'];
$subject = $row['Subject'];
$category = $row['Category'];
$message = $row['Message'];
echo "From:  [URL]$author[/URL]  Subject: $subject  Category:  $category
[URL]Don't Approve[/URL]  [URL]Approve[/URL]
$message

";
}
?>
```


----------



## deuce868 (Nov 2, 2000)

I meant that there is no status with a lowercase...there is one with a cap Status...That was where I grabbed the example from.


----------



## brendandonhu (Jul 8, 2002)

Ahh ok.
I'm still wondering why I had a dream about capitalizing php code, it was a rather bazaar experience


----------



## deuce868 (Nov 2, 2000)

did you eat too much chocolate before you weant to bed? I have heard that causes the cap php condition. =)


----------



## brendandonhu (Jul 8, 2002)

Could be, I did have ice cream last night


----------



## mixx941 (Dec 19, 2001)

YES! That worked! I got the entries. 

Now, the main things left are to add categories to the DB, add them to the form, and make it so when they submit a tutorial it goes to the proper category main page, and then has its own page. 

Thanks again for your ongoing help brendandonhu, and thanks deuce for solving our mystery! 

-Mark


----------



## brendandonhu (Jul 8, 2002)

Ok lets start by adding them to the form.
Open the HTML page.Find
Category1">Category2
and remove it.
To add Computers, Photoshop, and Flash, would go something like this
ComputersPhotosFlash
Once you have that done, we will add them in phpMyAdmin.


----------



## mixx941 (Dec 19, 2001)

OK, I talked about it and thought it through, and here are the categories:

1) Upgrading
2) Flash
3) Photoshop
4) PHP
5) HTML
6) Windows
7) Linux
8) Macintosh

Here is the HTML I came up with, tell me if it's wrong:



> Submit A Tutorial
> 
> Author:
> Email:
> ...


Thanks

-Mark


----------



## brendandonhu (Jul 8, 2002)

Looks fine to me. On second thought, there is no need to add the categories to the database.
SO I will come up with a script to list the subject of each tutorial within a category, and when they click on it, it will bring up the full tutorial.


----------



## brendandonhu (Jul 8, 2002)

Put this in showcategory.php
If you wanted to view the Flash tutorials, you would go to
showcategory.php?cat=Flash

```
mysql_connect(localhost,brainsto,password);
mysql_select_db(brainsto_tutorials) or die( "Unable to select database");
if(!isset($_GET['cat'])
{header('Location: index.html')};
$cat = $_GET['cat']
$query="SELECT * FROM tutorials WHERE Status = 'Approved' & Category = $cat";
$result=mysql_query($query);
$num=mysql_numrows($result);
while ( $row = mysql_fetch_array($result) )
{
$id = $row['ID'];
$status = $row['Status'];
$author = $row['Author'];
$email = $row['Email'];
$subject = $row['Subject'];
$category = $row['Category'];
$message = $row['Message'];
echo "[URL]$subject<a/>    Author:  <a href=mailto:$email>$author[/URL]";
}
```


----------



## mixx941 (Dec 19, 2001)

Here is what I see when I look at "showcategory.php"



> mysql_connect(localhost,brainsto,password); mysql_select_db(brainsto_tutorials) or die( "Unable to select database"); if(!isset($_GET['cat']) {header('Location: index.html')}; $cat = $_GET['cat'] $query="SELECT * FROM tutorials WHERE Status = 'Approved' & Category = $cat"; $result=mysql_query($query); $num=mysql_numrows($result); while ( $row = mysql_fetch_array($result) ) { $id = $row['ID']; $status = $row['Status']; $author = $row['Author']; $email = $row['Email']; $subject = $row['Subject']; $category = $row['Category']; $message = $row['Message']; echo "
> $subject Author: $author";
> }


-Mark


----------



## mixx941 (Dec 19, 2001)

I see the <php and ?> tags weren't included. So I put those there, and then I stopped getting all that code.

But nothing shows up when I do "cat=Flash". But my password was visible 

-Mark


----------



## brendandonhu (Jul 8, 2002)

Yea you need the PHP tags.
Are there any tutorials in the flash category in the database?


----------



## mixx941 (Dec 19, 2001)

I submitted one...amybe it didn't go through. Let me try again.


----------



## mixx941 (Dec 19, 2001)

Yes. I submitted one and it didn't show up. Also when I view source my pass is visible.  That cannot be. Nobody can know my pass even if it's only admins who see this. 

Thanks

-Mark


----------



## brendandonhu (Jul 8, 2002)

I checked, it did go through, but it wasn't approved. I approved it, check now.


----------



## brendandonhu (Jul 8, 2002)

Your password is not supposed to show.
Its because you forgot the space after <?php
Add a space there and the password won't be in the source.


----------



## mixx941 (Dec 19, 2001)

Nope. I confirmed one as well, it still doesn't show up. Note that I am changing my password every time it doesn't work to "password" because it shows it...is there any way to prevent that? 

-Mark


----------



## brendandonhu (Jul 8, 2002)

Change
<phpmysql_connect(localhost,brainsto,password);t
to 
<?php
mysql_connect(localhost,brainsto,password);
Am I correct in saying password is not your actual password?


----------



## mixx941 (Dec 19, 2001)

No, password is not my password. Now I get this:



> Parse error: parse error, unexpected '{' in /home/brainsto/public_html/showcategory.php on line 5


-Mark


----------



## brendandonhu (Jul 8, 2002)

Change
if(!isset($_GET['cat'])
to
if(!isset($_GET['cat']))


----------



## mixx941 (Dec 19, 2001)

> Parse error: parse error, unexpected '}' in /home/brainsto/public_html/showcategory.php on line 5


-Mark


----------



## brendandonhu (Jul 8, 2002)

{header('Location: index.html')};
becomes
{header('Location: index.html');};
If that doesnt work, try
{header('Location: index.html');}


----------



## mixx941 (Dec 19, 2001)

The first one gave me:



> Parse error: parse error, unexpected T_VARIABLE in /home/brainsto/public_html/showcategory.php on line 7


The second one same thing.

-Mark


----------



## brendandonhu (Jul 8, 2002)

Ok use the 1st one and
$cat = $_GET['cat']
becomes
$cat = $_GET['cat'];


----------



## mixx941 (Dec 19, 2001)

> Warning: mysql_numrows(): supplied argument is not a valid MySQL result resource in /home/brainsto/public_html/showcategory.php on line 9
> 
> Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/brainsto/public_html/showcategory.php on line 10


-Mark


----------



## brendandonhu (Jul 8, 2002)

Not sure if this is it, but change
$query="SELECT * FROM tutorials WHERE Status = 'Approved' & Category = $cat";

to
$query="SELECT * FROM tutorials WHERE Status = 'Approved' && Category = $cat";


----------



## mixx941 (Dec 19, 2001)

> Warning: mysql_numrows(): supplied argument is not a valid MySQL result resource in /home/brainsto/public_html/showcategory.php on line 9
> 
> Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/brainsto/public_html/showcategory.php on line 10


-Mark


----------



## deuce868 (Nov 2, 2000)

$query="SELECT * FROM tutorials WHERE Status = 'Approved' AND Category = '$cat'";

Keyworkd is AND and you need single quotes around the cat


----------



## deuce868 (Nov 2, 2000)

best way to check queries is to plug them into phpmyadmin sql section. It will often help you debug them easier than the generic php messages you get back.


----------



## brendandonhu (Jul 8, 2002)

Ok thanks, I checked and you can use && so maybe its the quotes issue, didn't realize you needed them around a variable.


----------



## deuce868 (Nov 2, 2000)

you have to remember that the variable is going to be replaced with text...so you need quotes around all text.


----------



## brendandonhu (Jul 8, 2002)

Ok that makes sense.


----------



## mixx941 (Dec 19, 2001)

OK, I do not get errors anymore, but I dont think it's working properly. Below is a screenshot of what I see. I submitted another one in the Flash category but it didn't show up.










Thanks

-Mark


----------



## deuce868 (Nov 2, 2000)

use this line after the query
$echo ($query);
exit;

and it should output the query you are running


Then copy and paste that query into phpmyadmin and see how many rows you get back. If you get back more than two rows then the problem is the php code in the while loop...if it only returns what you see on the page then you have a query/database problem.


----------



## mixx941 (Dec 19, 2001)

So That would be like this?


```
<?php
mysql_connect(localhost,brainsto,password);
mysql_select_db(brainsto_tutorials) or die( "Unable to select database");
if(!isset($_GET['cat']))
{header('Location: index.html');};
$cat = $_GET['cat'];
$query="SELECT * FROM tutorials WHERE Status = 'Approved' AND Category = '$cat'";
$echo ($query);
exit;
$result=mysql_query($query);
$num=mysql_numrows($result);
while ( $row = mysql_fetch_array($result) )
{
$id = $row['ID'];
$status = $row['Status'];
$author = $row['Author'];
$email = $row['Email'];
$subject = $row['Subject'];
$category = $row['Category'];
$message = $row['Message'];
echo "[URL]$subject<a/>    Author:  <a href=mailto:$email>$author[/URL]";
}
?>
```
Thanks

-Mark

P.S. "Paste that query in phpMyAdmin" Where? As I said I have never really used phpMyAdmin before this week


----------



## deuce868 (Nov 2, 2000)

yep, then it should print it on the screen for you to copy and paste


----------



## deuce868 (Nov 2, 2000)

sorry, missed the bottom half at first

Once you go into the database there should be a box for sql query. You want to paste it in there.


----------



## mixx941 (Dec 19, 2001)

> Fatal error: Call to undefined function: () in /home/brainsto/public_html/showcategory2.php on line 8


-Mark


----------



## mixx941 (Dec 19, 2001)

Paste What There ?


----------



## brendandonhu (Jul 8, 2002)

I'm not sure exactly where deuce is going with this, but I think
$echo ($query);
should be
$echo($query);


----------



## deuce868 (Nov 2, 2000)

the space should not matter. It is the $ in front of echo...it should just be echo($query) (no $ before echo)

Where I am going is this:
he says he only gets two rows to display...so there must have only been two rows returned then. 

If he puts the query directly into phpmyadmin then he can see how many rows get returned. If the #$ is more than two...then there is a problem in the php while loop. If he only gets two rows back in phpmyadmin...then either the data in the database is bad...or the query is bad.


----------



## brendandonhu (Jul 8, 2002)

Ok I get it. I'll bet its not the database, its my script though


----------



## brendandonhu (Jul 8, 2002)

Wait a sec-It is working properly almost! Its gettings all the data except the ID, because I made a capitalization error again. Use this for showcategory.php and it will be working.
Next I have to do showtuturial.php.

```
<?php
mysql_connect(localhost,brainsto,password);
mysql_select_db(brainsto_tutorials) or die( "Unable to select database");
if(!isset($_GET['cat']))
{header('Location: index.html');};
$cat = $_GET['cat'];
$query="SELECT * FROM tutorials WHERE Status = 'Approved' AND Category = '$cat'";
$echo ($query);
exit;
$result=mysql_query($query);
$num=mysql_numrows($result);
while ( $row = mysql_fetch_array($result) )
{
$id = $row['ID'];
$status = $row['Status'];
$author = $row['Author'];
$email = $row['Email'];
$subject = $row['Subject'];
$category = $row['Category'];
$message = $row['Message'];
echo "[URL]$subject<a/>    Author:  <a href=mailto:$email>$author[/URL]
";
}
?>
```


----------



## mixx941 (Dec 19, 2001)

Here is my updated code for "showcategory2.php"


```
<?php
mysql_connect(localhost,brainsto,password);
mysql_select_db(brainsto_tutorials) or die( "Unable to select database");
if(!isset($_GET['cat']))
{header('Location: index.html');};
$cat = $_GET['cat'];
$query="SELECT * FROM tutorials WHERE Status = 'Approved' AND Category = '$cat'";
echo($query)
exit;
$result=mysql_query($query);
$num=mysql_numrows($result);
while ( $row = mysql_fetch_array($result) )
{
$id = $row['ID'];
$status = $row['Status'];
$author = $row['Author'];
$email = $row['Email'];
$subject = $row['Subject'];
$category = $row['Category'];
$message = $row['Message'];
echo "[URL]$subject<a/>    Author:  <a href=mailto:$email>$author[/URL]";
}
?>
```
And I get this error now with the updated code: 


> Fatal error: Call to undefined function: () in /home/brainsto/public_html/showcategory2.php on line 8


-Mark


----------



## brendandonhu (Jul 8, 2002)

Use the code in my last post-I don't see anything wrong with the latest screenshot, and I went to the page and it seemed fine.


----------



## mixx941 (Dec 19, 2001)

OK I used that code and it looks like this:










-Mark


----------



## brendandonhu (Jul 8, 2002)

Yea thats what its supposed to do, list all the tutorials in that category. Now use this in showtutorial.php and clicking the tutorial subject will bring up the whole thing.

```
<?php
mysql_connect(localhost,brainsto,password);
mysql_select_db(brainsto_tutorials) or die( "Unable to select database");
if(!isset($_GET['tut']))
{header('Location: index.html');};
$tut = $_GET['tut'];
$query="SELECT * FROM tutorials WHERE Status = 'Approved' AND ID = '$tut'";
$result=mysql_query($query);
$num=mysql_numrows($result);
while ( $row = mysql_fetch_array($result) )
{
$id = $row['ID'];
$status = $row['Status'];
$author = $row['Author'];
$email = $row['Email'];
$subject = $row['Subject'];
$category = $row['Category'];
$message = $row['Message'];
echo "[URL]$subject<a/>    Category: <a href=showcategory.php?cat=$category>$cat[/URL]  Author:  [URL]$author[/URL]
$message";
}
?>
```


----------



## mixx941 (Dec 19, 2001)

OK I updated the code and when I go to "http://www.brain-storm.us/showcategory2.php?cat=Flash" it redirects me to "http://www.brain-storm.us" 

-Mark


----------



## brendandonhu (Jul 8, 2002)

The code above is for showtutorial.php-did you put it into showcategory2?
It has error handling built in so if they don't choose a category/tutorial to view, it redirects to your main page.


----------



## mixx941 (Dec 19, 2001)

Oh God. I screwed up big time. 

Yes I put it in showcategory2.php. 

What is the correct code for showcategory2.php again? 

-Mark


----------



## brendandonhu (Jul 8, 2002)

```
<?php
mysql_connect(localhost,brainsto,password);
mysql_select_db(brainsto_tutorials) or die( "Unable to select database");
if(!isset($_GET['cat']))
{header('Location: index.html');};
$cat = $_GET['cat'];
$query="SELECT * FROM tutorials WHERE Status = 'Approved' AND Category = '$cat'";
$echo ($query);
exit;
$result=mysql_query($query);
$num=mysql_numrows($result);
while ( $row = mysql_fetch_array($result) )
{
$id = $row['ID'];
$status = $row['Status'];
$author = $row['Author'];
$email = $row['Email'];
$subject = $row['Subject'];
$category = $row['Category'];
$message = $row['Message'];
echo "[URL]$subject<a/>    Author:  <a href=mailto:$email>$author[/URL]
";
}
?>
```


----------



## mixx941 (Dec 19, 2001)

> Fatal error: Call to undefined function: () in /home/brainsto/public_html/showcategory.php on line 8


with code


```
<?php
mysql_connect(localhost,brainsto,password);
mysql_select_db(brainsto_tutorials) or die( "Unable to select database");
if(!isset($_GET['cat']))
{header('Location: index.html');};
$cat = $_GET['cat'];
$query="SELECT * FROM tutorials WHERE Status = 'Approved' AND Category = '$cat'";
$echo ($query);
exit;
$result=mysql_query($query);
$num=mysql_numrows($result);
while ( $row = mysql_fetch_array($result) )
{
$id = $row['ID'];
$status = $row['Status'];
$author = $row['Author'];
$email = $row['Email'];
$subject = $row['Subject'];
$category = $row['Category'];
$message = $row['Message'];
echo "[URL]$subject<a/>    Author:  <a href=mailto:$email>$author[/URL]
";
}
?>
```
When I visit:

http://www.brain-storm.us/showcategory.php?cat=Flash


----------



## brendandonhu (Jul 8, 2002)

Oops, remove the lines
$echo ($query);
exit;


----------



## mixx941 (Dec 19, 2001)

OK Now I got the screenshot again.

When I visit www.brain-storm.us/showtutorial.php or add the "?cat=Flash" it does the redirect.

-Mark


----------



## brendandonhu (Jul 8, 2002)

To show a category its
showcategory.php?cat=Flash
showtutorial.php is to show a specific tutorial.
That URL ends in ?tut=Number


----------



## brendandonhu (Jul 8, 2002)

Example:
http://www.brain-storm.us/showtutorial.php?tut=2
http://www.brain-storm.us/showcategory.php?cat=Flash


----------



## mixx941 (Dec 19, 2001)

Oh ok. That tut=2 worked  I saw an earlier tutorial. 

OK Ready for the next step. Thanks again for all your ongoing help on this. 

-Mark


----------



## brendandonhu (Jul 8, 2002)

Well, we can add/approve/remove tutorials, view them in categories, and view the tutorial.
What else do you need?
BTW my scripts are just the barebones PHP-they look ugly. you will probably want to make em look pretty.


----------



## mixx941 (Dec 19, 2001)

Well how would I make it so that if I approved one that was in the "Flash" category, the title would show up on a main category listing page, and so when they clicked it on the main category listing it would take them to the full article. 

-Mark


----------



## brendandonhu (Jul 8, 2002)

Thats what showtutorial.php is.
Or did you want one that shows all of them from all categories.


----------



## deuce868 (Nov 2, 2000)

I don't mean to sound rude...but Comp...it doesn't sound like you know much, if any, php. Maybe you should read up a bit first and then come back to this. Some of these errors you need to know to debug like missing ; and extra $ and such.


----------



## mixx941 (Dec 19, 2001)

> _Originally posted by deuce868:_
> *I don't mean to sound rude...but Comp...it doesn't sound like you know much, if any, php. Maybe you should read up a bit first and then come back to this. Some of these errors you need to know to debug like missing ; and extra $ and such. *


Deuce, you're absolutely right. I know *NO* PHP other than the tags to start and end a PHP document.

That's why I came here to TSG looking for a pre-made package that would do what I need, so I didn't need to bother anyone here, or waste a whole bunch of time reading a book or online docs when the site hosting plan and domain are already up, and time is ticking.

brendandonhu was nice enough do do all this for me, and I appreciate that one million percent.

-Mark


----------

