Architect Posted February 28, 2015 Share Posted February 28, 2015 Hey you all! I'm sorry if it's in the wrong topic, but couldn't find a more suitable one.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; } <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> I have a header with a textarea in it, CODE: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. All the imported divs should be on a new line.I believe I have tried almost everything and now I'm out of ideas. Sorry if my poor skill in English messed something up.Thanks in advance!Architect Link to comment Share on other sites More sharing options...
Architect Posted March 1, 2015 Author Share Posted March 1, 2015 Hey! I have solved two problems:First: I changed my sql table so it includes "id" row, i'm sorting all the posts by id value (descending). Second: I managed to play around with the jsfiddle and figure out all the divs. (YAY!) Now only one problem left: how to loose the "submit" button and submit text via "enter" from the <textarea>? Thanks you all! Link to comment Share on other sites More sharing options...
justsomeguy Posted March 2, 2015 Share Posted March 2, 2015 Now only one problem left: how to loose the "submit" button and submit text via "enter" from the <textarea>?Why would you want to change that? People have been conditioned to know that pressing enter in a text area will go to the next line, not submit the form. Why change that behavior? Link to comment Share on other sites More sharing options...
thescientist Posted March 2, 2015 Share Posted March 2, 2015 Some browser may automatically submit a form if enter is pressed while focused inside of an element inside a <form>. However, I would never remove the Submit button. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now