Jump to content

MySql Memo To Webpage.


Phsycoslaya

Recommended Posts

Hello, im kinda new to the whole thing. Well not really I Got the basics. But this shouldn't be to hard..


http://razrwow.game-host.org I set up the database and all that stuff I know how to do that much so I can work the admin stuff but I wanna make my own site like that cause I downloaded that whole setup I just setup the database in MySql and stuff..

So first of all.

I want to beable to type in this memo and make it show up on my webpage.

[URL=http://imageshack.us][IMG]http://img155.imageshack.us/img155/3728/tableft8.jpg[/img][/URL]



The Database is called, phpsite
The password is Password
the UserName is root
the Host name is Localhost

Please setup a PhP thingy for me to look at so I can find out how to do it.. like..

<?php echo '$memofromthemysqlthing' ?> or w/e you have to do. Just right it all out, doesnt have to be fancy just something to link the two.. Thanks.
Link to comment
Share on other sites

This will display the contents of that field, but you'll have to specify an 'id' (from the first column) or some other clause.  This should get you started though.

[code]
<?php 

// Specify the id here, or pass it in a $_POST or $_GET variable
$id = 1;

// Connect to the MySQL database, returning a connection link id
// in $conn, or abort displaying an error message if can't connect
$conn = mysql_connect('Localhost', 'root', 'Password')
  or die('Could not connect: ' . mysql_error());

// Before running any queries, we must select the database to use
// or abort if we can't
mysql_select_db('phpsite', $conn) or die('Could not select database');

// Next, select only the 'body' field from the table 'notes' for
// the row with the given id.  This data is then stored in $result
// which can be accessed with functions below
$sql = "SELECT body FROM notes WHERE id=$id";
$result = mysql_query($sql) or die (mysql_error());

// Next fetch the returned row as an array with key-names that
// correspond to the field names of the table
$row = mysql_fetch_array($result, MYSQL_ASSOC);

// Display the contents of the field 'body'
echo $row['body'];

// Free up MySQL resources
mysql_free_result($result);
mysql_close($conn);
?>
[/code]
Link to comment
Share on other sites

I've edited the code and added comments.  Also, you might want to look at [url=http://uk.php.net/manual/en/ref.mysql.php]the MySQL section[/url] from the PHP manual, and if you're not familiar with SQL, you can check out some tutorials on this site or do a google.

HTH :)
Link to comment
Share on other sites

Hm howcome the title doesnt wanna show?

I typed this

[code]<?php

$id = 1;

$conn = mysql_connect('Localhost', 'root', 'password')
or die('Could not connect: ' . mysql_error());

mysql_select_db('phpsite', $conn) or die('Could not select database');

$sql = "SELECT body FROM notes WHERE id=$id";
$sqll = "SELECT title FROM notes WHERE id=$id";
$resultt = mysql_query($sqll) or die(mysql_error());
$result = mysql_query($sql) or die(mysql_error());


$row = mysql_fetch_array($result, MYSQL_ASSOC);
$roww = mysql_fetch_array($result, MYSQL_ASSOC);

echo $row['body'];
echo $roww['title'];

mysql_free_result($result);
mysql_close($conn);[/code]
Link to comment
Share on other sites

No worries.

BTW, instead of

[code]
$sql = "SELECT body FROM notes WHERE id=$id";
$sqll = "SELECT title FROM notes WHERE id=$id";
$resultt = mysql_query($sqll) or die(mysql_error());
$result = mysql_query($sql) or die(mysql_error());


$row = mysql_fetch_array($result, MYSQL_ASSOC);
$roww = mysql_fetch_array($result, MYSQL_ASSOC);

echo $row['body'];
echo $roww['title'];
[/code]
you could just have
[code]
$sql = "SELECT body, title FROM notes WHERE id=$id";
$result = mysql_query($sql) or die(mysql_error());

$row = mysql_fetch_array($result, MYSQL_ASSOC);

echo $row['body'];
echo $row['title'];
[/code]
Link to comment
Share on other sites

Can anybody link me a tutorial, on how to add an Edit / New / Delete button onto it and stuff.. I wanna get technical. Thanks hope to see your reply.



*To be more specific*

I want it so I can click edit to edit a news thing or w/e
or clikc New to make a new news paragraph
or click Delete to delete that news thingy. Help.
Link to comment
Share on other sites

Can anybody link me a tutorial, on how to add an Edit / New / Delete button onto it and stuff.. I wanna get technical. Thanks hope to see your reply.



*To be more specific*

I want it so I can click edit to edit a news thing or w/e
or clikc New to make a new news paragraph
or click Delete to delete that news thingy. Help.
Link to comment
Share on other sites

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.