Hi, I am very new to MySQL, but I do have a good understanding about PHP. I have a submission form, and I want the data transfered onto a SQL database, so that I could manage later on. What I ask for is the following:
a URL (http://...)
a short description (blah blah blah)
a long description (blah blah blah blah)
some keywords (blah;blah;blah;blah), however I plan on scripting it so that I could store it into an array. How do I use these with MySQL?
a picture (either URL or uploaded)
Those are what I get from the form. However I also want other things, like:
the date submitted
a rating
an ID
a number of hits
How will I create a table for these things? I am especially interested about how to put arrays into tables (with the keywords).
Thank you, and any help will be appreciated.
Newb Question: Submission Tables
Moderator: General Moderators
-
filthyjoker
- Forum Newbie
- Posts: 2
- Joined: Tue Jun 03, 2008 11:37 pm
- Frozenlight777
- Forum Commoner
- Posts: 75
- Joined: Wed May 28, 2008 12:59 pm
Re: Newb Question: Submission Tables
You have the form layed out correctly? You're form should look something like
form.html
since you're posting the input to a variable you can make a seperate php file that includes all of your database connection and sql queries.
The input for the short_description field would look something like this: $short = $_POST['short_description']; so that the variable $short has whatever was passed to the form when submitted.
sendtodb.php
as far as an array for the keywords. You're going to have to do things a little differently. You might just have to have seperate fields unless you want almost duplicate entries in the database. Also, for the number of hits, you need to do something else but hope this helps a little.
form.html
Code: Select all
<form action="sendtodb.php" method="POST">
<input name="short_description">
.......etc....
<input type="submit" value="Send to Database">
</form>since you're posting the input to a variable you can make a seperate php file that includes all of your database connection and sql queries.
The input for the short_description field would look something like this: $short = $_POST['short_description']; so that the variable $short has whatever was passed to the form when submitted.
sendtodb.php
Code: Select all
$host = "localhost";
$password="password";
$database="database";
mysql_connect($localhost, $password, $database) or die(mysql_error());
$short = $_POST['short_description'];
$url = $_POST['url'];
$long = $_POST['long_description'];
$keywords = $_POST['keywords'];
$picture = $_POST['picture_url'];
mysql_query("INSERT INTO table (id, url, short_desc, long_desc, keywords, picture_url, date)
VALUES ('" . NULL . "', '" . $url . "', '" . $short . "', " . $long. "', " . $keywords . "', " . $picture . "', " . NULL . "', NOW())");
echo "Form Submited";
as far as an array for the keywords. You're going to have to do things a little differently. You might just have to have seperate fields unless you want almost duplicate entries in the database. Also, for the number of hits, you need to do something else but hope this helps a little.
-
filthyjoker
- Forum Newbie
- Posts: 2
- Joined: Tue Jun 03, 2008 11:37 pm
Re: Newb Question: Submission Tables
Hey, thanks for the quick reply
Actually, I think I've got the form thing all right. I was curious about how to build my table, and what variables to use.
Also, how do I work with the picture? I was thinking about either having them put a URL or upload their own, but how do I work this out with SQL?
Thanks
Actually, I think I've got the form thing all right. I was curious about how to build my table, and what variables to use.
Also, how do I work with the picture? I was thinking about either having them put a URL or upload their own, but how do I work this out with SQL?
Thanks