Jump to content

Recommended Posts

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!

Link to comment
https://forums.phpfreaks.com/topic/127628-n00b-how-to-show-the-mysql-database/
Share on other sites

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.

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 :D

 

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.

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.

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...

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?

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?

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

 

 

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?

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.

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.

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 8)

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.