benji87 Posted March 22, 2007 Share Posted March 22, 2007 Could some point me in the right direction or give me a code example to submit a form on the same page, so as i wont have to link the form to a processing script but have them on the same page. Im sure its simple but ive never done it before and i cant find any examples! :-\ Cheers Quote Link to comment Share on other sites More sharing options...
ToonMariner Posted March 22, 2007 Share Posted March 22, 2007 <?php if (isset($_POST['submit']) { //process form } ?> .... <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post"> ... </form> Quote Link to comment Share on other sites More sharing options...
benji87 Posted March 22, 2007 Author Share Posted March 22, 2007 Cheers, unexpected { on line 3 ??? <?php if (isset($_POST['submit']) { $topicid = $_POST['id']; $comment = $_POST['message']; $commentby = $_POST['commentby']; $date = date("j F"); $sql = mysql_query("INSERT INTO ssrfc_noticecomments (topicid, comment, commentby, date) VALUES('$topicid', '$comment', '$commentby', '$date')") or die (mysql_error()); if(!$sql){ echo 'There has been an error while trying to submit your post.'; } else { $id = mysql_insert_id(); } <? Dont see why that is unexpected?? Quote Link to comment Share on other sites More sharing options...
benji87 Posted March 26, 2007 Author Share Posted March 26, 2007 anyone??? Quote Link to comment Share on other sites More sharing options...
mmarif4u Posted March 26, 2007 Share Posted March 26, 2007 Try this code: <?php if (isset($_POST['submit']) { $topicid = $_POST['id']; $comment = $_POST['message']; $commentby = $_POST['commentby']; $date = date("j F"); $sql = mysql_query("INSERT INTO ssrfc_noticecomments (topicid, comment, commentby, date) VALUES('$topicid', '$comment', '$commentby', '$date')") or die (mysql_error()); if(!$sql){ echo 'There has been an error while trying to submit your post.'; } else { $id = mysql_insert_id(); } } ?> Quote Link to comment Share on other sites More sharing options...
benji87 Posted March 26, 2007 Author Share Posted March 26, 2007 No it doesnt like that either i really dont understand why it wont work Quote Link to comment Share on other sites More sharing options...
mjlogan Posted March 26, 2007 Share Posted March 26, 2007 if (isset($_POST['submit'])) ..... it was missing a ) Quote Link to comment Share on other sites More sharing options...
benji87 Posted March 28, 2007 Author Share Posted March 28, 2007 Here is my code, it all seems to process fine it just wont insert into the database :-\ can anyone help? <?php session_start(); include 'includes/db.php'; $username = $_SESSION['username']; $id = $_GET['id']; $query=("SELECT * FROM ssrfc_noticecomments WHERE topicid = $id ORDER BY date ASC LIMIT 0,10"); $result=mysql_query($query); $num=mysql_numrows($result); $i=0; while ($i < $num) { $commentby=mysql_result($result,$i,"commentby"); $date=mysql_result($result,$i,"date"); $comment=mysql_result($result,$i,"comment"); <table width="100%" border="0" cellpadding="2" cellspacing="2" bgcolor="eaeaea"> <tr> <td class="headers">Posted by: <? echo "$commentby" ?> Date: <? echo "$date" ?></td> </tr> <tr> <td class="navigation"><? echo "$comment" ?></td> </tr> </table> $i++; } mysql_close(); <form id="form1" name="form1" method="post" action="<?php $_SERVER['PHP_SELF'] ?>"> <table width="100%" border="0" cellspacing="2" bgcolor="eaeaea"> <tr> <td><div align="center"> <textarea name="message" cols="40" rows="10" class="navigation" id="message"></textarea> </div></td> </tr> <tr> <td><div align="center"> <input type="submit" name="Submit" value="Submit" /> </div></td> </tr> <tr> <td><div align="center"> <input name="id" type="hidden" id="id" value="<? echo "$id" ?>" /> <input name="commentby" type="hidden" id="commentby" value="<? echo "$username" ?>" /> </div></td> </tr> </table> </form> if (isset($_POST['submit'])) { $topicid = $_POST['id']; $comment = $_POST['message']; $commentby = $_POST['commentby']; $date = date("j F"); $sql = mysql_query("INSERT INTO ssrfc_noticecomments (topicid, comment, commentby, date) VALUES('$topicid', '$comment', '$commentby', '$date')") or die (mysql_error()); if(!$sql){ echo 'There has been an error while trying to submit your post.'; $id = mysql_insert_id(); } } ?> Quote Link to comment Share on other sites More sharing options...
per1os Posted March 28, 2007 Share Posted March 28, 2007 Are you getting an error? If so what error. $sql = mysql_query("INSERT INTO ssrfc_noticecomments (`topicid`, `comment`, `commentby`, `date`) VALUES('$topicid', '$comment', '$commentby', '$date')") or die (mysql_error()); Try that, date is usually reserved word in SQL. Quote Link to comment 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.