runnerjp Posted November 7, 2008 Share Posted November 7, 2008 ok im trying to add error code to my script... <link rel="stylesheet" type="text/css" href="http://www.runningprofiles.com/css/login.css"> <link rel="stylesheet" type="text/css" href="http://www.runningprofiles.com/members/include/style.css"> <script> function setColor(color) { var textbox = document.getElementById('inputforum'); textbox.value += "[color=" + color + "][/color]"; } function setsize(size) { var textbox = document.getElementById('inputforum'); textbox.value += "[size=" + size + "][/size]"; } function initialise() { var element = document.getElementById('element-id'); if (element && element.style) element.style.display = 'none'; } function toggleDisplay(element) { var style; if (typeof element == 'string') element = document.getElementById(element); if (element && (style = element.style)) style.display = (style.display == 'none') ? '' : 'none'; } if (!document.getElementById) document.getElementById = function() {return null;}; function wrapText(el, openTag, closeTag) { if (el.setSelectionRange) { // W3C/Mozilla el.value = el.value.substring(0,el.selectionStart) + openTag + el.value.substring(el.selectionStart,el.selectionEnd) + closeTag + el.value.substring(el.selectionEnd,el.value.length); } else if (document.selection && document.selection.createRange) { // IE code goes here el.focus(); //or else text is added to the activating control var range = document.selection.createRange(); range.text = openTag + range.text + closeTag; } } </script> <?php session_start(); //connection string require_once '../settings.php'; include "../BBClass.php"; //store the BBClass.php in the same place as settings.php or change the path. include "connect.php"; $id = $_SESSION['user_id']; $puser = get_username($id); $timestamp = time(); $timeout = $timestamp - 180; $username= get_username($_SESSION['user_id']); function selfURL() { $s = empty($_SERVER["HTTPS"]) ? '' : ($_SERVER["HTTPS"] == "on") ? "s" : ""; $protocol = strleft(strtolower($_SERVER["SERVER_PROTOCOL"]), "/").$s; $port = ($_SERVER["SERVER_PORT"] == "80") ? "" : (":".$_SERVER["SERVER_PORT"]); return $protocol."://".$_SERVER['SERVER_NAME'].$port.$_SERVER['REQUEST_URI']; } function strleft($s1, $s2) { return substr($s1, 0, strpos($s1, $s2)); } $filename = (selfURL()); //Insert User $insert = mysql_query("REPLACE INTO `useronline` SET `timestamp`='$timestamp', `ip`='".$_SERVER['REMOTE_ADDR']."', `file`='$filename',`user`='$username',`user_id`='".$_SESSION['user_id']."'") or die(mysql_error()); $uid = $_SESSION['user_id']; //never use the same varible name twice. $forum=$_GET['forum']; $forumid=$_GET['id']; session_start(); $query = "SELECT * FROM users WHERE ID = '$id' LIMIT 1"; if ($result = mysql_query($query)){ if (mysql_num_rows($result)) { $array = mysql_fetch_assoc($result); $puser = $array['Username']; $pimage = $array['image']; ?> <p><table width="100%" class="loggedin"> <tr> <td > <div class="c1"> <div align="center"><em> <script type='text/javascript'> var date=new Date(); // Gets the full date! var day=date.getHours(); // Gets the hours! if(day<=11) { document.write('Good Morning,'); // If it's before 12 PM then display this! } else if(day<18){ document.write('Good Afternoon,'); // After 12 PM display this! } else { document.write('Good Evening,'); // After 6 PM display this! } </script> You are logged in as <?php echo ucwords(strtolower($username)) ?>.Your ip address is <?php echo $_SERVER["REMOTE_ADDR"]; ?>; this is stored for security reasons.</em> </div> </div> </td> </tr> </table> <table class='maintables'> </p> <p> </p> </div> <tr class='headline'><td>Post a message</td></tr> <tr class='maintables'><td> <? $errMsg=""; if(isset($_POST['submit'])) { $name=$puser; $yourpost=$_POST['yourpost']; $forum=$_GET['forum']; $subject=$_POST['subject']; if(strlen($yourpost)<1) { $errMsg= "You did not type in a post."; //no post entered } else if(strlen($subject)<1) { $errMsg="You did not enter a subject."; //no subject entered } else { $thedate=date("U"); //get unix timestamp $displaytime=date("F j, Y, g:i a"); //we now strip HTML injections $subject=strip_tags($subject); $name=strip_tags($name); $yourpost=strip_tags($yourpost); $insertpost="INSERT INTO forumtutorial_posts(forum,author,title,post,showtime,realtime,lastrepliedto,lastposter) values('$forum','$name','$subject','$yourpost','$thedate','$thedate','$thedate','$name')"; mysql_query($insertpost) or die("Could not insert post"); //insert post $updatep="UPDATE `users` SET `post_count`=`post_count`+'1' WHERE `Username`='$name'"; mysql_query($updatep) or die("Could not update post"); print "Message posted, go back to <A href='index.php?page=forum&forum=$forum'>Forum</a>."; print "</td></tr></table>"; exit; } } //else //{ ?> <form action='<?php "$_SERVER[php_SELF]" ?>' method='post'> <div align="center"><br> Subject: <input class='inputinbox' type='text' name='subject' size='20'> <span style="color:red;"><?php echo $errMsg; ?></span> <br> </div> <tr class='maintables'> <td align="center"> <?php $id=$_GET['id']; if(isset($_POST['submit'])) { $name=$puser; $yourpost=$_POST['yourpost']; $subject=$_POST['title']; if(strlen($yourpost)<1) { print "You did not type in a post."; //no post entered } else { $thedate=date("U"); //get unix timestamp $displaytime = time(); //we now strip HTML injections $subject=strip_tags($subject); $name=strip_tags($name); //This is where the bbcode come in. $message = new BBCode; $message->selection = $yourpost; $message->parseCode(); // set to 1 if you want to disable bbcode $message->parseEmoticons(); $yourpost = $message->parsed; $insertpost="INSERT INTO `forumtutorial_posts` (`author`,`forum`,`title`,`post`,`showtime`,`realtime`,`lastposter`,`parentid`) values('$name','$forum','$subject','$yourpost','$thedate','$thedate','$name','$id')"; mysql_query($insertpost) or die("Could not insert post"); //insert post $updatepost="UPDATE `forumtutorial_posts` SET `numreplies`=`numreplies`+'1', `lastposter`='$name', `lastrepliedto`='$thedate' WHERE `postid`='$id'"; mysql_query($updatepost) or die("Could not update post"); $updatep="UPDATE `users` SET `post_count`=`post_count`+'1' WHERE `Username`='$name'"; mysql_query($updatep) or die("Could not update post"); print "Message posted, go back to <A href='index.php?page=message&id=$id&forum=$forum'>Message</a>."; } } else { $gettopic="SELECT * FROM `forumtutorial_posts` WHERE `postid`='$id'"; $gettopic2=mysql_query($gettopic) or die("Could not get topic"); $gettopic3=mysql_fetch_array($gettopic2); $message=strip_tags($getreplies3['post']); $message=nl2br($message); ?><br> <form action='index.php?page=reply&forum=<? echo $forum; ?>&id=<? echo $_GET['id']; ?>' method='post' name='myform'> <div style='padding-left: 5px; padding-top:5px;'></div> <input name="title" type="hidden" value="<?php echo $gettopic3['title'];?>" /> <textarea id="inputforum" class="inputforum" name='yourpost' rows='5' cols='40'></textarea> <br> <input type='submit'class="submit-btn" name='submit' value=''> </p> </form> <? } ?> </td> </tr></form> <? //} print "</td></tr></table>"; }} ?> the thing is if i dont type in either topic or i dont type in the message box then it goes from this where i would expect the error to show along side where the error was made to this where not matter where the error was made it displays it in the subject area! Link to comment https://forums.phpfreaks.com/topic/131780-adding-validation-to-current-code/ Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.