runnerjp Posted May 12, 2008 Share Posted May 12, 2008 hey guys i have done this for a comment box on my website <?php session_start(); { // Sign the guestbook require_once("../settings.php"); $id = $_SESSION['user_id']; $get_username_value = get_username($id); $username = $_GET['user']; $from = $get_username_value; $message = $_POST["message"]; $time = date("F j, Y, g:i a"); $db = new DbConnector(); $db->connect(); $query = "INSERT INTO guestbook(owner,postedby,post,time) VALUES('$username','$from','$message','$time')"; $db->query($query); echo "Your message has been posted"; } $owner = $get_username_value; $query = "SELECT * FROM guestbook WHERE owner= $get_username_value ORDER BY ID DESC"; $result = $db->query($query); while($gbrows = mysql_fetch_array($result)) { echo "Posted by: <a href=\"member.php?id=".$gbrows["postedby"]."\">".$gbrows["postedby"]."</a> - ".$gbrows["time"]."<br/>".$gbrows["post"]."<br><br>"; } echo "<center><br/><b>Sign $owner:s guestbook</b><br/> <form action=\"member.php?sign=$owner&from=$get_username_value method='POST'> <textarea name='message' rows='5' cols='30' align='left'>Your message</textarea><br/> <input type='submit' value='Update' name='submit'> </form> </center> ";?> but i just get a blank page... any reason why?> Link to comment https://forums.phpfreaks.com/topic/105245-comment-box/ Share on other sites More sharing options...
Cobby Posted May 12, 2008 Share Posted May 12, 2008 Whats with the open curly bracket straight after session_start()? Link to comment https://forums.phpfreaks.com/topic/105245-comment-box/#findComment-538899 Share on other sites More sharing options...
runnerjp Posted May 12, 2008 Author Share Posted May 12, 2008 for this $id = $_SESSION['user_id']; $get_username_value = get_username($id); $username = $_GET['user']; $from = $get_username_value; $message = $_POST["message"]; $time = date("F j, Y, g:i a"); $db = new DbConnector(); $db->connect(); $query = "INSERT INTO guestbook(owner,postedby,post,time) VALUES('$username','$from','$message','$time')"; $db->query($query); echo "Your message has been posted"; as its different to the rest of code Link to comment https://forums.phpfreaks.com/topic/105245-comment-box/#findComment-538909 Share on other sites More sharing options...
beboo002 Posted May 12, 2008 Share Posted May 12, 2008 i think plz check this function get_username($id) and what is the value of $username,$from and $owner; all are same or different. becouse u insert value in database owner is $username and when fetch then u use owner=$owner and here action=\"member.php?sign=$owner&from=$get_username_value both sign and $get_username_value are same i think Link to comment https://forums.phpfreaks.com/topic/105245-comment-box/#findComment-538918 Share on other sites More sharing options...
runnerjp Posted May 12, 2008 Author Share Posted May 12, 2008 sorry i dont undertsand ?? Link to comment https://forums.phpfreaks.com/topic/105245-comment-box/#findComment-538983 Share on other sites More sharing options...
Fadion Posted May 12, 2008 Share Posted May 12, 2008 Try to echo $get_username_value, $username and the other variables to see if ure getting any values. Place an "or die(mysql_error())" after the query to check if theres any possible error in it. Check if the session has got a value. And if $get_username_value isnt an int, the following query $query = "SELECT * FROM guestbook WHERE owner= $get_username_value ORDER BY ID DESC"; should be (added single quotes in $get_username_value): $query = "SELECT * FROM guestbook WHERE owner='$get_username_value' ORDER BY ID DESC"; Link to comment https://forums.phpfreaks.com/topic/105245-comment-box/#findComment-539015 Share on other sites More sharing options...
runnerjp Posted May 12, 2008 Author Share Posted May 12, 2008 Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/runningp/public_html/members/include/box.php on line 25 <?php session_start(); // Sign the guestbook require_once("../settings.php"); { $id = $_SESSION['user_id']; $get_username_value = get_username($id); $username = $_GET['user']; $from = $get_username_value; $message = $_POST["message"]; $time = date("F j, Y, g:i a"); $query = "INSERT INTO guestbook(owner,postedby,post,time) VALUES('$username','$from','$message','$time')"; $db->query($query); echo "Your message has been posted"; } $owner = $get_username_value; $query = $query = "SELECT * FROM guestbook WHERE owner='$get_username_value' ORDER BY ID DESC"; $result = $db->query($query); while($grab = mysql_fetch_array($result)) { echo "Posted by: <a href=\"member.php?id=".$grab["postedby"]."\">".$grab["postedby"]."</a> - ".$grab["time"]."<br/>".$grab["post"]."<br><br>"; } echo "<center><br/><b>Sign $owner:s guestbook</b><br/> <form action=\"member.php?sign=$owner&from=$get_username_value method='POST'> <textarea name='message' rows='5' cols='30' align='left'>Your message</textarea><br/> <input type='submit' value='Update' name='submit'> </form> </center>"; ?> basicly i cant undestand whats up with while($grab = mysql_fetch_array($result)) { echo "Posted by: <a href=\"member.php?id=".$grab["postedby"]."\">".$grab["postedby"]."</a> - ".$grab["time"]."<br/>".$grab["post"]."<br><br>"; } to fetch all the results for the comment area also if there is an easyer way of making a comment box for each profile im open to suggestions lol but this is the way iv thought about going about it Link to comment https://forums.phpfreaks.com/topic/105245-comment-box/#findComment-539064 Share on other sites More sharing options...
runnerjp Posted May 12, 2008 Author Share Posted May 12, 2008 hummm ok iv been thinkin ... if i got a normal shoutbox, how would i do it so each user has there own shoutbox?? asign each shoutbox with sum id in the db and call the id or something?> Link to comment https://forums.phpfreaks.com/topic/105245-comment-box/#findComment-539083 Share on other sites More sharing options...
revraz Posted May 12, 2008 Share Posted May 12, 2008 Because you are not reporting errors. but i just get a blank page... any reason why?> Link to comment https://forums.phpfreaks.com/topic/105245-comment-box/#findComment-539087 Share on other sites More sharing options...
runnerjp Posted May 12, 2008 Author Share Posted May 12, 2008 humm but revraz iv been thinkin and is my way going to product a good comment area.... would it be possible to use a shout box for each page?? Link to comment https://forums.phpfreaks.com/topic/105245-comment-box/#findComment-539095 Share on other sites More sharing options...
BlueSkyIS Posted May 12, 2008 Share Posted May 12, 2008 what is a shout box? Link to comment https://forums.phpfreaks.com/topic/105245-comment-box/#findComment-539116 Share on other sites More sharing options...
runnerjp Posted May 12, 2008 Author Share Posted May 12, 2008 here is an example of a shout box --- http://example.freeshoutbox.net/ Link to comment https://forums.phpfreaks.com/topic/105245-comment-box/#findComment-539124 Share on other sites More sharing options...
runnerjp Posted May 12, 2008 Author Share Posted May 12, 2008 ok atting at from scratch and i have got an error im not famillia with <?php session_start(); // starts sessions $id = $_SESSION['user_id']; $query = "SELECT * FROM guestbook WHERE id = '$id' LIMIT 1"; if ($result = mysql_query($query)){ if (mysql_num_rows($result)) { $array = mysql_fetch_assoc($result); $message = $array['message']; }} echo $message; echo (" <form method='POST' action='?page=updatepost'> <table width="523" border="0" align="center" cellpadding="0" cellspacing="2"> <tr><td width="150"><div align="right"> <label for="events">Message</label> </div> </td> <td colspan="2"><textarea class="input" id="message" name="message" rows="4" cols="40">type your message here</textarea></td> </tr> <tr> <td width="150"></td> <td width="112"><input name="submitButtonName" type="submit" class="submit-btn" value=""></td> <td width="253"> </td> </tr> </table> </form>"); case 'updatepost': $id = $_POST['id']; $message = $_POST['message']; $update = "INSERT guestbook SET message='$message', id = '$id' WHERE id='$id' "; $rsUpdate = mysql_query($update); if ($rsUpdate)?> unexpected T_LNUMBER on this line <table width="523" border="0" align="center" cellpadding="0" cellspacing="2"> Link to comment https://forums.phpfreaks.com/topic/105245-comment-box/#findComment-539175 Share on other sites More sharing options...
BlueSkyIS Posted May 12, 2008 Share Posted May 12, 2008 the problem is your double-quotes around those numbers. either escape them or do what i do: use single-quotes instead. Link to comment https://forums.phpfreaks.com/topic/105245-comment-box/#findComment-539180 Share on other sites More sharing options...
radar Posted May 12, 2008 Share Posted May 12, 2008 Replace all that with this.. <?php session_start(); // starts sessions $id = $_SESSION['user_id']; $query = "SELECT * FROM guestbook WHERE id = '$id' LIMIT 1"; if ($result = mysql_query($query)){ if (mysql_num_rows($result)) { $array = mysql_fetch_assoc($result); $message = $array['message']; }} echo $message; echo (' <form method="POST" action="?page=updatepost"> <table width="523" border="0" align="center" cellpadding="0" cellspacing="2"> <tr><td width="150"><div align="right"> <label for="events">Message</label> </div> </td> <td colspan="2"><textarea class="input" id="message" name="message" rows="4" cols="40">type your message here</textarea></td> </tr> <tr> <td width="150"></td> <td width="112"><input name="submitButtonName" type="submit" class="submit-btn" value=""></td> <td width="253"> </td> </tr> </table> </form>'); case 'updatepost': $id = $_POST['id']; $message = $_POST['message']; $update = "INSERT guestbook SET message='$message', id = '$id' WHERE id='$id' "; $rsUpdate = mysql_query($update); if ($rsUpdate)?> All your HTML wasnt getting sent out.. if you look at your syntax highlighting shown here, everything in blue was not encapsilated.. It's been a long time since ive had to echo out HTML so if my code doesnt work change the first and last ' to " then everything in between to ' and it should work... if your syntax is right it should ALL be red inside the entire echo. Link to comment https://forums.phpfreaks.com/topic/105245-comment-box/#findComment-539184 Share on other sites More sharing options...
runnerjp Posted May 12, 2008 Author Share Posted May 12, 2008 ahh yes that help thanks... but for this line case 'updatepost': how comes im getting unexpected t_case? Link to comment https://forums.phpfreaks.com/topic/105245-comment-box/#findComment-539483 Share on other sites More sharing options...
runnerjp Posted May 13, 2008 Author Share Posted May 13, 2008 humm i dont think im using my switch statement properly <?php session_start(); // starts sessions $id = $_SESSION['user_id']; $query = "SELECT * FROM guestbook WHERE id = '$id' LIMIT 1"; if ($result = mysql_query($query)){ if (mysql_num_rows($result)) { $array = mysql_fetch_assoc($result); $message = $array['message']; echo $message; {switch($_GET )} default: echo (' <form method="POST" action="?page=updatepost"> <table width="523" border="0" align="center" cellpadding="0" cellspacing="2"> <tr><td width="150"><div align="right"> <label for="events">Message</label> </div> </td> <td colspan="2"><textarea class="input" id="message" name="message" rows="4" cols="40">type your message here</textarea></td> </tr> <tr> <td width="150"></td> <td width="112"><input name="submitButtonName" type="submit" class="submit-btn" value=""></td> <td width="253"> </td> </tr> </table> </form>'); case 'updatepost': $id = $_POST['id']; $message = $_POST['message']; $update = "INSERT guestbook SET message='$message', id = '$id' WHERE id='$id' "; $rsUpdate = mysql_query($update); if ($rsUpdate)}}?> also im missing some {} out sum where but for the life of me can see where abouts Link to comment https://forums.phpfreaks.com/topic/105245-comment-box/#findComment-539712 Share on other sites More sharing options...
runnerjp Posted May 13, 2008 Author Share Posted May 13, 2008 would a swtich statement be the best way to go for this or would there be something alot easyer? Link to comment https://forums.phpfreaks.com/topic/105245-comment-box/#findComment-539771 Share on other sites More sharing options...
runnerjp Posted May 13, 2008 Author Share Posted May 13, 2008 ok i have progressed alot so far but for some reaosn my code will not add the users username.. it leaves the field blank <html> <head> <title>Shoutbox!</title> <style type="text/css"> <!-- .message { color: #000000; font-family: Verdana; font-size: 10px;} .username { color: #FF9900 font-family: Verdana; font-size: 10px; font-weight: bold} .date { color: #707070; font-family: Verdana; font-size: 9px;} .forms { font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 10 px; color: #6CA05A; text-decoration: none; background-color: #CCCCCC; border-color: #6CA05A; border-style: solid; border: 1px} .submit { background-color: #CCCCCC; border-color: #6CA05A; color: #2A343C; font-family: Verdana; font-size: 10px; border-style: solid; border 1 px;} --> </style> </head> <body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0" style="padding: 2px"> <?php // If submitted if($_POST['submit']) { // Verify if the fields were filled. if(!$_POST['message']) { echo 'Error, You need to post a Message!'; die; } // Date format $date = date("d/m/y"); // http://www.php.net/date // Assign variables of the forms $id = $_SESSION['user_id']; $username = $id; $message = $_POST['message']; $ip = $_SERVER['REMOTE_ADDR']; // Connect to the database include('../../settings.php'); // Insert the info in the shoutbox table. $query = "INSERT INTO shoutbox ( username, message, date, ip) VALUES ('$username','$message','$date','$ip')"; mysql_query($query); // close connection // Show message to let them return to the shoutbox ?> <div align="center">Thank you for submitting.<br> Return to the <a href="shoutbox.php">shoutbox</a>! <?php // If NOT submitted } else { $query = "SELECT * FROM shoutbox ORDER BY id DESC LIMIT 10"; $result = mysql_query($query); // Create a table ?> <table width="100%" cellpadding="0" cellspacing="0" border="0"> <? // Run a While loop for the rows while($c = mysql_fetch_array($result)) { ?> <tr> <td> <? echo $c[author] ?></a> says: <div align="justify"><? echo $c[message] ?></div> </td> </tr> <tr><td>on <? echo $c[date] ?> <hr noshade="noshade" size="1" style="border-style: dashed" color="#000000" /></td></tr> <? } ?> </table> <form method="post" action="box.php"> <table width="100%" border="0" cellpadding="0" cellspacing="0"> <tr> <td>Message :</td> <td><input type="text" name="message" class="forms"></td> </tr> <tr> <td colspan="2"><input type="submit" name="submit" value="Speak!" class="subtmit"></td> </tr> </table> </form> <?php } ?> </body> </html> also i was wondering.. whats th best way to go now with assigning each user their own chatbox ?? so on profile 1 it has chatbox 1 come up on profile 2 it has chatbox 2 ect ect Link to comment https://forums.phpfreaks.com/topic/105245-comment-box/#findComment-539980 Share on other sites More sharing options...
runnerjp Posted May 13, 2008 Author Share Posted May 13, 2008 bmp Link to comment https://forums.phpfreaks.com/topic/105245-comment-box/#findComment-540241 Share on other sites More sharing options...
runnerjp Posted May 13, 2008 Author Share Posted May 13, 2008 any 1 Link to comment https://forums.phpfreaks.com/topic/105245-comment-box/#findComment-540294 Share on other sites More sharing options...
runnerjp Posted May 13, 2008 Author Share Posted May 13, 2008 ok i have tried everything... the table updates everythin but username... and its set to username i thought it was $id = $_SESSION['user_id']; $username = $id; but i even tried $username = 'bob'; lol and it does not even record that :S Link to comment https://forums.phpfreaks.com/topic/105245-comment-box/#findComment-540391 Share on other sites More sharing options...
BlueSkyIS Posted May 13, 2008 Share Posted May 13, 2008 where is session_start()? and always use or die: mysql_query($query) or die(mysql_error()); Link to comment https://forums.phpfreaks.com/topic/105245-comment-box/#findComment-540401 Share on other sites More sharing options...
runnerjp Posted May 13, 2008 Author Share Posted May 13, 2008 >< dang...session_start(); would be the key to it all Link to comment https://forums.phpfreaks.com/topic/105245-comment-box/#findComment-540402 Share on other sites More sharing options...
runnerjp Posted May 13, 2008 Author Share Posted May 13, 2008 sorry i had to re open because i found anouther little thing.... include('../../settings.php'); $id = $_SESSION['user_id']; $username = get_username($id); $user = $_GET['user']; $message = $_POST['message']; $ip = $_SERVER['REMOTE_ADDR']; // Insert the info in the shoutbox table. $query = "INSERT INTO shoutbox ( user, username, message, date, ip) VALUES ('{$_GET[user]}','$username','$message','$date','$ip')"or die(mysql_error()); mysql_query($query); ok so im using $_GET['user']; to get the username out of the url soo members/bob i have used it before to set friends to be friends,,, but it does not seem to be working in this case ?? here is my htaccess to show you that user is in there... RewriteEngine on RewriteBase / RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^([^/.]+)/?$ members/index.php?page=profile&username=$1 Link to comment https://forums.phpfreaks.com/topic/105245-comment-box/#findComment-540421 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.