Sangha-08 Posted October 8, 2008 Share Posted October 8, 2008 Ok, I'm new im php & MySql, but I've managed to create a database, connected it and even managed to make an insert form, but now I would like to know how to display my data? I have database called "video1" and a table called "stuff" and in that table I have 4 fields - -Name -Code -Uploader -Description Now, I want to know how to display the database like :- http://www.mydomain.com/video.php?id=((RANDOM-NUMBER-HERE)) any ideas? Thanks in advance. I love you guys! Quote Link to comment https://forums.phpfreaks.com/topic/127628-n00b-how-to-show-the-mysql-database/ Share on other sites More sharing options...
trq Posted October 9, 2008 Share Posted October 9, 2008 Theres many tutorials covering this stuff on the net. Do we really need to write you another? Theres a link in my sig to a book (Hudzilla), it has an entire chapter dedicated to databases and php. Quote Link to comment https://forums.phpfreaks.com/topic/127628-n00b-how-to-show-the-mysql-database/#findComment-660400 Share on other sites More sharing options...
Sangha-08 Posted October 9, 2008 Author Share Posted October 9, 2008 I looked for it on google and altavista for bout an hour.. could you please explain? Cheers m8. Quote Link to comment https://forums.phpfreaks.com/topic/127628-n00b-how-to-show-the-mysql-database/#findComment-660405 Share on other sites More sharing options...
trq Posted October 9, 2008 Share Posted October 9, 2008 I looked for it on google and altavista for bout an hour.. could you please explain? Cheers mate. So, you've read the chapter in the book I pointed you too? Quote Link to comment https://forums.phpfreaks.com/topic/127628-n00b-how-to-show-the-mysql-database/#findComment-660407 Share on other sites More sharing options...
Maq Posted October 9, 2008 Share Posted October 9, 2008 Try something like this (not tested): $user="root"; // usually $host="localhost"; // usually $password="your_password"; $database = "video1"; $connection = mysql_connect($host,$user,$password) or die ("couldn't connect to server"); $db = mysql_select_db($database,$connection) or die ("Couldn't select database"); $query = "SELECT Name, Code, Uploader, Description FROM stuff "; $results = mysql_query ($query) ; while ( $row = mysql_fetch_array($results)) { echo $row['Name']; echo $row['Code']; echo $row['Uploader']; echo $row['Description']; } Of course you have to create the HTML part. Quote Link to comment https://forums.phpfreaks.com/topic/127628-n00b-how-to-show-the-mysql-database/#findComment-660409 Share on other sites More sharing options...
Sangha-08 Posted October 9, 2008 Author Share Posted October 9, 2008 Try something like this (not tested): <?php $user="root"; // usually $host="localhost"; // usually $password="your_password"; $database = "video1"; $connection = mysql_connect($host,$user,$password) or die ("couldn't connect to server"); $db = mysql_select_db($database,$connection) or die ("Couldn't select database"); $query = "SELECT Name, Code, Uploader, Description FROM stuff "; $results = mysql_query ($query) ; while ( $row = mysql_fetch_array($results)) { echo $row['Name']; echo $row['Code']; echo $row['Uploader']; echo $row['Description']; } Of course you have to create the HTML part. Thank you very much for that code, I had to edit it a bit, but it works But, how do i get pages like http://www.mysite.com/play.php?id=(NUMBER) Is there something I have to change in the database? because it doesn't contain any numbers at the moment. PS - I only started php 2 weeks ago and I'm only 13, please don't be harsh, thanks. Quote Link to comment https://forums.phpfreaks.com/topic/127628-n00b-how-to-show-the-mysql-database/#findComment-660427 Share on other sites More sharing options...
Maq Posted October 9, 2008 Share Posted October 9, 2008 First of all that link is 404'd. Do you have any knowledge of HTML? Quote Link to comment https://forums.phpfreaks.com/topic/127628-n00b-how-to-show-the-mysql-database/#findComment-660430 Share on other sites More sharing options...
trq Posted October 9, 2008 Share Posted October 9, 2008 I posted an example of this a long while ago. here. Read that thread, and in particular my reply. Quote Link to comment https://forums.phpfreaks.com/topic/127628-n00b-how-to-show-the-mysql-database/#findComment-660433 Share on other sites More sharing options...
Sangha-08 Posted October 9, 2008 Author Share Posted October 9, 2008 First of all that link is 404'd. Do you have any knowledge of HTML? Haha, I obviously have knowledge of html, if I'm learning php. That's common sense. It was an example that i made up, I mean stuff like http://uk.youtube.com/watch?v=AuK2A1ZqoWs Where "AuK2A1ZqoWs" is the database id. Quote Link to comment https://forums.phpfreaks.com/topic/127628-n00b-how-to-show-the-mysql-database/#findComment-660437 Share on other sites More sharing options...
Maq Posted October 9, 2008 Share Posted October 9, 2008 Yes, thorpe is right, as always. Look at the link it shows you how to do this. This is something that needs to be self taught. These forums are for help here and there, unless you want to post in the freelance section and have someone do it for you... Quote Link to comment https://forums.phpfreaks.com/topic/127628-n00b-how-to-show-the-mysql-database/#findComment-660439 Share on other sites More sharing options...
Maq Posted October 9, 2008 Share Posted October 9, 2008 Haha, I obviously have knowledge of html, if I'm learning php. That's common sense. Then you need to $_GET a variable which isn't safe because you're passing your database via HTTP. You should $_POST it in a hidden type, which is basic HTML. I don't see your problem, can you post your code? Quote Link to comment https://forums.phpfreaks.com/topic/127628-n00b-how-to-show-the-mysql-database/#findComment-660442 Share on other sites More sharing options...
trq Posted October 9, 2008 Share Posted October 9, 2008 Haha, I obviously have knowledge of html, if I'm learning php. That's common sense. Then you need to $_GET a variable which isn't safe because you're passing your database via HTTP. You should $_POST it in a hidden type, which is basic HTML. I don't see your problem, can you post your code? What gives you the impression $_POST is any safer than $_GET? Quote Link to comment https://forums.phpfreaks.com/topic/127628-n00b-how-to-show-the-mysql-database/#findComment-660444 Share on other sites More sharing options...
Maq Posted October 9, 2008 Share Posted October 9, 2008 It's hidden from the URL. Quote Link to comment https://forums.phpfreaks.com/topic/127628-n00b-how-to-show-the-mysql-database/#findComment-660447 Share on other sites More sharing options...
trq Posted October 9, 2008 Share Posted October 9, 2008 And that does what? Quote Link to comment https://forums.phpfreaks.com/topic/127628-n00b-how-to-show-the-mysql-database/#findComment-660449 Share on other sites More sharing options...
Maq Posted October 9, 2008 Share Posted October 9, 2008 I don't want people knowing the names of my databases, especially hackers? Quote Link to comment https://forums.phpfreaks.com/topic/127628-n00b-how-to-show-the-mysql-database/#findComment-660452 Share on other sites More sharing options...
Sangha-08 Posted October 9, 2008 Author Share Posted October 9, 2008 Well, as far as I'm aware, if you use something like <?php $_GET print['whatever']; ?> Then the url will be http://www.yomama.com/yomama.php?whatever=yomama Where as, using something like <?php $_POST print['whatever']; ?> from a page with the from to the page its sent to the url would look like this http://www.yomama.com/yomama.php Quote Link to comment https://forums.phpfreaks.com/topic/127628-n00b-how-to-show-the-mysql-database/#findComment-660455 Share on other sites More sharing options...
Maq Posted October 9, 2008 Share Posted October 9, 2008 Yep, if you use GET to pass your database name via URL and you're prone for SQL injections. Plus, people have more information about your database, which in my opinion, isn't bad. Quote Link to comment https://forums.phpfreaks.com/topic/127628-n00b-how-to-show-the-mysql-database/#findComment-660457 Share on other sites More sharing options...
Sangha-08 Posted October 9, 2008 Author Share Posted October 9, 2008 Damn its 1:44 am .. lol I've been tryin to make this since 6pm lol anyways, back to the topic. CREATE TABLE users ( id INT PRIMARY KEY, uname VARCHAR(80), hobby TEXT ) ok, thats the code to make the database, but I'm using phpMyAdmin and i don't know how to input the most crucial part there INT PRIMARY KEY got any ideas? Quote Link to comment https://forums.phpfreaks.com/topic/127628-n00b-how-to-show-the-mysql-database/#findComment-660464 Share on other sites More sharing options...
trq Posted October 9, 2008 Share Posted October 9, 2008 I don't want people knowing the names of my databases, especially hackers? The term is crackers thankyou, and knowone should be passing around the names of there databases through any request. Anyway, I think we've gone off track. I'll leave it at that. Quote Link to comment https://forums.phpfreaks.com/topic/127628-n00b-how-to-show-the-mysql-database/#findComment-660467 Share on other sites More sharing options...
trq Posted October 9, 2008 Share Posted October 9, 2008 Damn its 1:44 am .. lol I've been tryin to make this since 6pm lol anyways, back to the topic. CREATE TABLE users ( id INT PRIMARY KEY, uname VARCHAR(80), hobby TEXT ) ok, thats the code to make the database, but I'm using phpMyAdmin and i don't know how to input the most crucial part there INT PRIMARY KEY got any ideas? That thread is simply an example, you should be able to use your current database scheme. I believe the code in my example may have been for sqlite, not mysql, not that it matters much. Quote Link to comment https://forums.phpfreaks.com/topic/127628-n00b-how-to-show-the-mysql-database/#findComment-660469 Share on other sites More sharing options...
Sangha-08 Posted October 9, 2008 Author Share Posted October 9, 2008 Ok, I implemented the stuff to which you gave me the link to and now I have Table.php <html> <body> <form action="insert.php" method="post"> Name: <input type="text" name="name" /> Embed Code: <input type="text" name="code" /> Uploader/Your Name: <input type="text" name="uploader" /> Description/comments: <input type="text" name="description" /> <input type="submit" /> </form> </body> </html> Insert.php <?php $con = mysql_connect("localhost","arorifjffd9i90","y45747547tsger"); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("video1", $con); $sql="INSERT INTO stuff (name,code, uploader, description) VALUES ('$_POST[name]','$_POST[code]','$_POST[uploader]','$_POST[description]')"; if (!mysql_query($sql,$con)) { die('Error: ' . mysql_error()); } echo "Added Successfully"; mysql_close($con) ?> & working.php <?php $user="dfgdg"; // usually $host="localhost"; // usually $password="fdhdfhfg"; $database = "video1"; $connection = mysql_connect($host,$user,$password) or die ("couldn't connect to server"); $db = mysql_select_db($database,$connection) or die ("Couldn't select database"); $query = "SELECT Name, Code, Uploader, Description FROM stuff "; $results = mysql_query ($query) ; while ( $row = mysql_fetch_array($results)) { echo $row['Name']; echo $row['Code']; echo $row['Uploader']; echo $row['Description']; } mysql_close($con); ?> So, what do I have to do next to make it working.php?id=1 to show just the #1 inupt? Also, I changed the database names and the passwords for security purposes Quote Link to comment https://forums.phpfreaks.com/topic/127628-n00b-how-to-show-the-mysql-database/#findComment-660476 Share on other sites More sharing options...
Maq Posted October 9, 2008 Share Posted October 9, 2008 The term is crackers thankyou, and knowone should be passing around the names of there databases through any request. Anyway, I think we've gone off track. I'll leave it at that. agreed. Quote Link to comment https://forums.phpfreaks.com/topic/127628-n00b-how-to-show-the-mysql-database/#findComment-660501 Share on other sites More sharing options...
Lodius2000 Posted October 9, 2008 Share Posted October 9, 2008 not to feed the fire but some html-developer firefox addons allow you to covert post's to get's, I tried it once, there was my password in cleartext in the url, kinda pissed me off Quote Link to comment https://forums.phpfreaks.com/topic/127628-n00b-how-to-show-the-mysql-database/#findComment-660521 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.