jon4433 Posted March 4, 2012 Share Posted March 4, 2012 For the past day I have been trying to get my comment box to insert the message into the user comment column (the user that is currently signed in). But it doesn't seem to be doing that? Which leads to another problem. I'm not able to get the users 'name' beside the message since they message isn't inserting into their comment column. The comment when it goes into the database just goes into the comment column, but on a new line... and i'm wanting it to go into the users comment column. If that made sense, sorry if it never. Am I doing anything wrong? <?php session_start(); if($_SESSION['username']){ $connect = mysql_connect("****","****","****") or die("Could not connect to database."); mysql_select_db("****") or die ("Could not find database!"); $comment=$_POST['comment']; $user = $_SESSION['username']; $q="INSERT INTO login (comment) VALUES ('$comment')"; mysql_query($q); echo "<p>"; } else header("location: suggestion.html"); ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Untitled Document</title> <link href="css/style.css" rel="stylesheet" type="text/css" /> <style type="text/css"> body { background-image: url(images/sky.png); background-size:100% 100%; background-attachment: fixed; background-repeat: repeat-x; background-position: left top; background-color: #999999; } body,td,th { color: #000; font-family: "MS Serif", "New York", serif; } </style> </head> <body> <div id="wrap"> <!--Header--> <div id="header_member" align="center"> <a href="membersarea.php"><img src="images/member_header.png" width="700" height="100" /></a></div> <!--Log out and time--> <div id="info"> <div id="date"><script type="text/javascript"> var currentDate = new Date() var day = currentDate.getDate() var month = currentDate.getMonth() + 1 var year = currentDate.getFullYear() document.write("<b>" + day + "/" + month + "/" + year + "</b>") var currentTime = new Date() var hours = currentTime.getHours() var minutes = currentTime.getMinutes()</script> </div> <div id="time"><script type="text/javascript"> var suffix = "AM"; if (hours >= 12) { suffix = "PM"; hours = hours - 12; } if (hours == 0) { hours = 12; } if (minutes < 10) minutes = "0" + minutes document.write("<b>" + hours + ":" + minutes + " " + suffix + "</b>")</script> </div> </div> <div id="logout"><center><?php echo "<a href='logout.php'>Log out.</a>";?></center></div> <!--Main section which will contain everything else--> <div id="member_main"> <!--Display user information from the database--> <div id="member_right"><center> <form method="Post"> <textarea name="comment" rows=4 cols=50></textarea><br /><br /> <input type="submit" name="submit" value="Post"> </form></center> <?php $q="SELECT comment FROM login"; $result=mysql_query($q); while($row=mysql_fetch_array($result)){ //list the comments echo $row['comment']."<br /><br>"; } ?> </div> <!--Welcome message--> <div id="member_top" align="center"><?php echo "Welcome, ".$_SESSION['username'];?></div> <div id="member_left" align="center"><img src="images/navigation.png" width="105" height="30" /><a href="membersarea.php"><img src="images/home_member.png" width="105" height="30" /></a><a href="account.php"><img src="images/account.png" width="105" height="30" /></a><a href="chat.php"><img src="images/chat.png" width="105" height="30" /></a></div> </div> <!--About us--> <div id="about" align="center"><a href="membersarea.php">Home</a> | <a href="">About Us</a> | <a href="">Contact Us</a> | <a href="">FeedBack</a></div> <!--Footer--> <div align="center" id="footer_member" style="color: #FFF">Dawncraftmc© 2011 - 2012</div> </div> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/258243-abit-stuck/ Share on other sites More sharing options...
litebearer Posted March 4, 2012 Share Posted March 4, 2012 This may help... http://www.tizag.com/mysqlTutorial/mysqlwhere.php Quote Link to comment https://forums.phpfreaks.com/topic/258243-abit-stuck/#findComment-1323742 Share on other sites More sharing options...
S3cr3t Posted March 4, 2012 Share Posted March 4, 2012 I dont really understand that but I would save an userID and username too. Table users - userID - username - password Table comments - commentID - userID - message - timestamp Associate the userID in comments table with the userID in the login table. Probably make a $_SESSION['userID']; . And then do it with that WHERE statement. Quote Link to comment https://forums.phpfreaks.com/topic/258243-abit-stuck/#findComment-1323744 Share on other sites More sharing options...
Anon-e-mouse Posted March 4, 2012 Share Posted March 4, 2012 I dont really understand that but I would save an userID and username too. Table users - userID - username - password Table comments - commentID - userID - message - timestamp Associate the userID in comments table with the userID in the login table. Probably make a $_SESSION['userID']; . And then do it with that WHERE statement. Going on what I've read if you were to store the users ID instead of their username as the session (not that you couldn't do both) you could then use that as your variable to differentiate when querying the tables. <?php $sql = "UPDATE `table1` SET `column1` = '".$toset."' WHERE `userID` = '".$_SESSION['userID']."'"; ?> So you then update the table with your information using the session you set when they first logged in, no reason to say you could assign the session to another variable as you have above and then use it in the query but thats just a quick example.. Hope it helps! Quote Link to comment https://forums.phpfreaks.com/topic/258243-abit-stuck/#findComment-1323771 Share on other sites More sharing options...
jon4433 Posted March 5, 2012 Author Share Posted March 5, 2012 It has all helped, their comment now stores in the comment column of their row. But I now have another problem of not being able to post more than 1 comment, as it updates the one in the database. But thank you for the help Quote Link to comment https://forums.phpfreaks.com/topic/258243-abit-stuck/#findComment-1324208 Share on other sites More sharing options...
Anon-e-mouse Posted March 5, 2012 Share Posted March 5, 2012 It has all helped, their comment now stores in the comment column of their row. But I now have another problem of not being able to post more than 1 comment, as it updates the one in the database. But thank you for the help Well that is easily solved. If you had a page you could have an icon on each "comment" that would take you to an edit page and then do that for that specific comment, whilst at the bottom (as its usually done) you could have a form which allows you to then post a new comment regardless of whether they have one or not? Quote Link to comment https://forums.phpfreaks.com/topic/258243-abit-stuck/#findComment-1324224 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.