My gurus, please help with my mysql
Posted: Thu Jan 30, 2003 1:38 pm
My dear gurus,
i'm a graphic designer trying to create a site giving Photoshop, CorelDraw, 3DMax... tutorials. But for now, i got some troubles on creating, controlling, querying mysql database (In this field, i'm just a newbie).
If you have some spare times, please help.
First, the site requests are
- Adding, editing, deleting (Hope i won't delete any) tutorials to database
- Displaying tutorials to site visitors
- Allowing people to submit tutorials to my site so that we can share them
- A protected admin area for me to check new submitted tutorials, adding, editing my tutorials <<< I may use .htaccess if there is no better solution
As simply as that!
Consider i have only one section of tutorials (e.g. Photoshop), then i create one table for them
Yes, that's the table i have created and below is the tutorials.php
The show_tutorial.php is here
The add_tutorial.php like this
Some questions
- Do those codes correct. i mean if i use those codes, are there any errors?
- Can my script support line break (The <p> and <br>) automatically? If not, how to?
- Can my script support HTML? I mean if i supply HTML into the textarea, do they work when displayed in show_tutorial.php
- What should I do to make the scripts support BBCode insteads of HTML
- If i want to stop people hacking my site, how can i stop them supply HTML into the add_tutorial.php
- Does any better solution you want to show me?
- Any comments or suggestions?
I know this topic will take you lots of times. Thus, if you are not free, answer me later, i will wait.
And if you answer me soon, that will be more than happiness.
Thanks for reading
Caroline
i'm a graphic designer trying to create a site giving Photoshop, CorelDraw, 3DMax... tutorials. But for now, i got some troubles on creating, controlling, querying mysql database (In this field, i'm just a newbie).
If you have some spare times, please help.
First, the site requests are
- Adding, editing, deleting (Hope i won't delete any) tutorials to database
- Displaying tutorials to site visitors
- Allowing people to submit tutorials to my site so that we can share them
- A protected admin area for me to check new submitted tutorials, adding, editing my tutorials <<< I may use .htaccess if there is no better solution
As simply as that!
Consider i have only one section of tutorials (e.g. Photoshop), then i create one table for them
Code: Select all
CREATE TABLE tutorial_photoshop (
id int not null auto_increment,
author_name varchar(50),
author_email varchar(),
postdate DATE,
tutorial_title varchar(255),
short_description TEXT,
tutorial MEDIUMTEXT,
primary key (id), // I'm still wondering what PRIMARY & UNIQUE are and what they are for.
unique id (id)
);Code: Select all
<?
// My server host support short_tag, so i don't need <?php
// Connect to database
mysql_connect('db_host','db_user','db_pass'); // What should be here to print out somthing if error?
mysql_select_db('db_name');
// Do some stuffs
// As i only need 5 records displays with full information, i do this
$result = mysql_query("SELECT * FROM tutorial_photoshop ORDER BY DATE() LIMIT 5");
echo "<b>Newest Tutorials</b>";
while($row = mysql_fetch_array($result)) {
echo "<a href="show_tutorial.php?id=".$rowїid].""><b>$rowїtutorial_title]</b></a><br>";
echo "By <b><a href='mailto: $rowїauthor_email]'>$rowїauthor_name]</a></b> on $rowїpostdate]";
echo "<p>$rowїshort_description]";
echo "<p>$rowїtutorial]";
}
?>
<?
// We need some more tutorials if people want them
// They are not the latest but the next 5
$result = mysql_query("SELECT * FROM tutorial_photoshop ORDER BY DATE() LIMIT 6,10");
echo "<p><b>New Tutorials</b>";
while($row = mysql_fetch_array($result)) {
echo "<a href="show_tutorial.php?id=".$rowїid].""><b>$rowїtutorial_title]</b></a> by $rowїauthor_name]";
}
?>
<p><a href='displayall.php'>All tutorials</a>Code: Select all
<?
mysql_connect('db_host','db_user','db_pass');
mysql_select_db('db_name');
$result = mysql_query("SELECT * FROM tutorial_photoshop WHERE id=$id");
$row = mysql_fetch_array($result);
echo "<b>$rowїtutorial_title]</b><br>";
echo "By <a href='mailto: $rowїauthor_email]'>$rowїauthor_name]</a> on $rowїpostdate]";
echo "<p>$rowїshort_description]";
echo "<p>$rowїtutorial]";
?>Code: Select all
<?
// Inserting data into table
if ($submit) {
mysql_connect('db_host','db_user','db_pass');
mysql_select_db('db_name');
$result = mysql_query("INSERT INTO tutorial_photoshop VALUES ('','$author_name','$author_email','$postdate','$tutorial_title','$short_description','$tutorial') ");
echo "Thank you! Tutorial added!";
}
?>
<?
// Print out the form to supply data
echo "<form method=post action='$PHP_SELF'>";
echo "<input type=text name=author_name> Author Name<br>";
echo "<input type=text name=author_email> Author Email<br>";
echo "<input type=hidden name=postdate value="$date('d-M-Y')">"; // This may be error. Confused!
echo "<input type=text name=tutorial_title> Tutorial Title<br>";
echo "<input type=text name=short_description> Short Description";
echo "<p>Content of the tutorial<br><textarea name=tutorial></textarea>";
echo "<input type=submit name=submit value=Send>";
?>- Do those codes correct. i mean if i use those codes, are there any errors?
- Can my script support line break (The <p> and <br>) automatically? If not, how to?
- Can my script support HTML? I mean if i supply HTML into the textarea, do they work when displayed in show_tutorial.php
- What should I do to make the scripts support BBCode insteads of HTML
- If i want to stop people hacking my site, how can i stop them supply HTML into the add_tutorial.php
- Does any better solution you want to show me?
- Any comments or suggestions?
I know this topic will take you lots of times. Thus, if you are not free, answer me later, i will wait.
And if you answer me soon, that will be more than happiness.
Thanks for reading
Caroline