登录 | 注册 | FAQ
Anonymous

PHP + MySQL + CSS help needed

+ 发表回复

2 篇帖子 分页: 1 / 1


PHP + MySQL + CSS help needed

Oracle » 周六 2月 28, 2015 12:20 pm

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:
代码: 全选
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:
代码: 全选
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:
代码: 全选
<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:

代码: 全选
|        <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
头像

Oracle

  • 帖子: 1
  • 注册: 周六 2月 28, 2015 12:03 pm

Re: PHP + MySQL + CSS help needed

XainPro » 周二 3月 03, 2015 12:57 pm

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>
头像

XainPro

  • 帖子: 3933
  • 注册: 周五 2月 17, 2012 8:10 pm


+ 发表回复

分页: 1 / 1