PHP + MySQL + CSS help needed
Posty: 2 Strona 1 z 1
PHP + MySQL + CSS help needed
Hey you all!I've struggled with my code for the past two days, but somehow can't get it to work.
First off HTML+PHP+MySQL code:
- Kod: Zaznacz cały
if($_POST){
$name = $fgmembersite->UserFullName();
$comment = $_POST['comment'];
$connect = mysql_connect("random", "ranom", "random", "random") or die(mysql_error());
if($connect){
mysql_select_db("random",$connect);
$query = "INSERT INTO data(Name, Comment, date) VALUES (\"" . $name . "\",\"" . $comment . "\",'DATETIME: Auto CURDATE()')";
if(mysql_query($query)){
}
} else {
die ("Error: " . mysql_error());
}
}
$connect = mysql_connect("random", "random", "random", "random");
if($connect){
mysql_select_db("random",$connect);
$query7 = "SELECT * FROM data ORDER BY date DESC";
$result = mysql_query($query7);
while ($row = mysql_fetch_array($result)){
echo '<br />' . $row['Name'] . ': ';;
echo $row['Comment'];
}
} else {
die ("Error: " . mysql_error());
}
?>
CSS code:
- Kod: Zaznacz cały
body{
background:#FFFFFF;
font:bold 12px Arial, Helvetica, sans-serif;
margin:0;
padding:0;
min-width:960px;
color:#303030;
text-align: center;
}
#header {
background-color:#FFFFFF;
color:#303030;
padding:5px;
list-style-type: none;
margin-left:0px;
padding-left:0px;
min-width: 960px;
}
#section {
margin-left: 80%;
width:350px;
padding:10px;
}
#vasak {
line-height:30px;
background-color:#eeeeee;
height:300px;
width:100px;
float:left;
padding:5px;
}
#parem {
width:350px;
float:left;
padding:10px;
}
.logo img
{
float: left;
margin-left: 10%;
}
.logo p {
float: right;
text-align: right;
display:inline-block;
padding: 0;
}
.kastike {
text-align: center;
}
.container {width: 960px; margin: 0 auto; overflow: hidden;}
#content { float: left; width: 100%;}
.tervitus {
margin-left: 10%;
margin-top: 0;
}
.sein {
margin-left: 10%;
margin-top: 0%;
}
.ptekst {
float: none;
margin-left: 600px;
}
I have a header with a textarea in it, CODE:
- Kod: Zaznacz cały
<div id="header">
<div class="kastike">
<form action = "" method = "POST">
<textarea style="resize:none" name = "comment" rows = "5" cols = "60"></textarea>
<input type = "submit" value = "Postita">
</form>
</div>
</div>
This is what I have this far:
When I type something in the textarea and click "submit" - it is sent to MySQL database, after that my code reads from the table and echoes it back on the page.
My 1st problem: My table has three rows: "Name - varchar" ; "Comment - varchar" ; "date - timestamp".
I'd like to print all the messages in reverse order (newest post are on the top). My code at the moment sometimes works, sometimes messes it all up.
Second problem - I can't make the textarea "submit" work via 'Enter'. Things I have tried this far: jQuery and JS.
Third problem (with CSS). I'd like my page to look something like that:
- Kod: Zaznacz cały
| <textbox> |
| |
|side| |$name 1 :| |$comment1|
| | |$name 2 :| |$comment2|
| | |$name 3 :| |$comment3|
I'd like to read from the MySQL table and but the $name and $comment in separate <div>s.
I believe I have tried almost everything and now I'm out of ideas.
Thanks in advance!
Oracle
Re: PHP + MySQL + CSS help needed
try it like this<html>
<head>
<title>Title of the document</title>
<style>
div.box {
margin-right:10px;
height: 500px;
border: 1px solid black;
background: orange;
}
</style>
</head>
<body>
<div class="box">
<div id="header">
<div class="kastike">
<form action = "" method = "POST">
<input required style="resize:none" name="comment" >
<input type = "submit" value = "Postita">
</form>
</div>
</div>
<?php
$connect = mysql_connect("localhost", "root", "") or die(mysql_error());
mysql_select_db("test",$connect);
if($_POST){
// $name = $fgmembersite->UserFullName();
$name = 'ABC';
$comment = $_POST['comment'];
$query = "INSERT INTO data(Name, Comment) VALUES ('$name' , '$comment')";
if(!mysql_query($query)){
die ("Error: " . mysql_error());
}
}
$query = "SELECT * FROM data ORDER BY date DESC";
$result = mysql_query($query);
echo '<ul>';
while ($row = mysql_fetch_array($result)){
echo '<li>' . $row['name'] . ': ' . $row['comment']. '</li>';
}
?>
</div>
</body>
</html>
Strona 1 z 1