runnerjp
-
Posts
2,214 -
Joined
-
Last visited
Posts posted by runnerjp
-
-
well really i just want to get the error, find out who caused it and where and just show them a message like "you have made an error" without showing the actuall error.
-
hum i still would'nt mind adding a log to my database Thorpe.
-
Hi,
I need to create a PHP script that writes php errors (Warning notices etc.) to MySQLdatabase. I know PHP has a built in error log function but im on a shared hosting site and cant chnage these types of files nor have any access ot them. Any ideas where I could start?
I already have error reporting enabled at the start of my scripts,
PHP Code:
<?php ini_set('display_errors', 1); error_reporting(E_ALL & ~E_NOTICE); ?>
The data i was thinkin of is:
Date/time
Page
error
Error line in code?
Ip of user
username
then if an error is added to db send me an email so i know.
Then rather then disply " there is an error in you syntax" ect it just prompts them to an error page of my own choosing.
This way i wont show information which could lead to security holes!
Thanks!
Jarratt.
-
Ok guys i have a page where im echoing a count number in a loop...
$counter2= '1';
$counter2++;
How can i make it so on ach page of the pagination it adds 5 to the previous value??
so on each page it will start with these numbers.
page1 = 2, page 2 = 7 , page3 = 12, page4 = 17, page5 = 22, page6 = 27
To get the page number i use this
$pagenum =(is_numeric($pagenum) && $pagenum >= 1) ? (int)$pagenum : 1;
-
how is the date stored in db?
-
Im tryign to number the posts on my forum. These numbers only refer to posts under a topic. Im not counting how many posts are under a topic but just giving them a number.
At the moment i have this script in place:
$counter2 = 1; $counter2++;
The problem is when a go to page 2 it starts from 2 again.
here is the full forum code so you can get an idea how it works
<?php require_once '../settings.php'; checkLogin('1 2'); include "../info.php"; // sets username/id ect include "../getuser.php"; // records user view on page include "checkinfo.php"; //Your ip address is...; include "../BBClass.php"; //class for bbcode $gettopic3=mysql_fetch_assoc(mysql_query("SELECT * from forumtutorial_posts where postid='$forumpostid'")); include "forumnav.php"; // shows where you are on the forum $getuser = mysql_fetch_assoc(mysql_query("SELECT * from users where Username='$username'")); if ($notify == "yes") { $updateemail="DELETE FROM forum_email WHERE topic_id='$forumpostid' AND user_id = '$id'"; mysql_query($updateemail) or die(mysql_error()); } //Here we count the number of results //Edit $data to be your query $data =mysql_query("SELECT * from forumtutorial_posts where parentid='$forumpostid'") or die(mysql_error()); $rows =mysql_num_rows($data); //This is the number of results displayed per page $page_rows= 5; //This sets the range to display in our query if ($pagenum === "last") { $query ="Select COUNT(*) as C from forumtutorial_posts where parentid='$forumpostid'"; $result=mysql_query($query); $data =mysql_fetch_array($result); if ($data['C'] == 0) $pagenum=1; else $pagenum=ceil($data['C'] / $page_rows); } $pagenum =(is_numeric($pagenum) && $pagenum >= 1) ? (int)$pagenum : 1; $max ='limit ' . ($pagenum - 1) * $page_rows . ',' . $page_rows; //This is your query again, the same one... the only difference is we add $max into it $start = (($pagenum-1) * $page_rows)+1; { } ?> <table width = "80%" align="center"> <tr> <td width = "36%" height = "21"> <?php $getusersonline ="SELECT user_id,user FROM useronline WHERE (file LIKE 'http://www.runningprofiles.com/members/index.php?page=message&forum=$forum&id=$forumpostid' or file LIKE 'http://www.runningprofiles.com/members/index.php?page=message&forum=$forum&id=$forumpostid&forum=general' or file LIKE 'http://www.runningprofiles.com/members/index.php?page=message&forum=$forum&id=$forumpostid' or file LIKE 'http://www.runningprofiles.com/members/index.php?page=message&forum=$forum&id=$forumpostid&pagenum=$pagenum' or file LIKE 'http://www.runningprofiles.com/members/index.php?page=message&forum=$forum&id=$forumpostid¬ify=yes' or file LIKE 'http://www.runningprofiles.com/members/index.php?page=message&forum=$forum&id=$forumpostid&pagenum=last' ) AND timestamp > " . (time() - 900); //grab from sql users on in last 15 minutes $getusersonline2=mysql_query($getusersonline) or die("Could not get users"); $num =mysql_num_rows($getusersonline2); echo " <b>Currently Viewing: </b>"; $tmp=array(); while ($getusersonline3=mysql_fetch_array($getusersonline2)) { $tmp[]="<a href='$getusersonline3[user]'>$getusersonline3[user]</a>"; } echo implode(',', $tmp); ?> </td> <td width = "64%" align = "right" valign = "bottom"> <div align = "right"><a href = "index.php?page=mainforums"> <img src = "/images/homeforum.gif" alt = "home" border = "0"/></a> <?php echo ' <a href="index.php?page=forum&forum= $forum">' ?><img src = "/images/backforum.gif" border = "0" alt = "back"/> </a> <?php if ($gettopic3['forumlock'] == 0) { ?> <?php echo ' <a href="index.php?page=reply&id=$forumpostid&forum=$forum">' ?> <img src = "/images/post_reply.gif" border = "0" alt = "reply"/> </a> </div> <? } ?></td> </tr> <?php if ($pagenum == 1) { ?> </table> <table width = "90%" align="center" cellpadding = "0" cellspacing = "0" > <tr> <td> <table width = "100%" align = "center" cellpadding = "0" cellspacing = "0" class="loggedin"> <tr> <td colspan="3" align="right" class = 'border'><table width="100%" style = "height:auto" > <tr> <td width="15%" align="left"><font size="2" color="white"> <a name="<?php echo $gettopic3['postid'] ?>" href = 'http://www.runningprofiles.com/members/index.php?page=message&forum=<?php echo $forum ?>&id=<?php echo $forumpostid ?>#<?php echo $gettopic3['postid'] ?>'><strong>#1</strong></a></font></td> <td width="32%" align="left"></td> <td width="33%" align="right"><font size="2" color="white">» Posted <? $dbtime=$gettopic3['showtime']; $time =date("F j Y, g:i a", $dbtime); $time =date("F j, Y, g:i a", $dbtime); gettheTime($dbtime, $time); ?> « </font></td> </tr> </table></td> </tr> <tr> <td width = "20%" align = "center" valign = "middle" class = "forum_view_topic_header_2_b" ><a href = '/members/<? echo $getreplies3['author']; ?>'> <span class = "style5"><? echo "<b>". $gettopic3['author']." </b>" ?></span></a> <?php $result = mysql_query( "SELECT * FROM useronline WHERE(user='" . $gettopic3['author'] . "')"); while ($row=mysql_fetch_array($result)) { $last_active=time() - $row['timestamp']; } echo ($last_active < 300) ? '<img src="http://www.runningprofiles.com/images/useron.gif" width="12" height="11" alt= "usron" />' : '<img src="http://www.runningprofiles.com/images/useroff.gif" width="12" height="11" alt= "usroff" />'; ?> <br /> <? $query="SELECT * FROM users WHERE Username = '" . $gettopic3['author'] . "' LIMIT 1"; if ($result=mysql_query($query)) { if (mysql_num_rows($result)) { $array =mysql_fetch_assoc($result); $image =$array['image']; $postnum=$array['post_count']; echo "<img src=\"http://www.runningprofiles.com/members/images/mini/$image\" border=\"1\" alt =\"mini\" />"; ?> <br /> <span class = "style7"> Posts: <?php echo $postnum; ?> </span> <? } } ?> </td> <td width = "85%" colspan="2" style="background-color:white"> <table width = "100%" border = "0" cellpadding = "5" cellspacing = "0"> <tr> <td width="96%" valign = "top"><span class="style1"> <?php $message =nl2br($gettopic3['post']); $b =new BBCode(); $b->selection=nl2br($message); $b->parseCode(); echo nl2br($b->parsed); ?> </span></td> </tr> <tr> <td align = "left" valign = "top"></td> </tr> <tr> <td height = "27" colspan = "2" align = "right" > </td> </tr> <tr> <td height = "28" align = "right" valign = "top"> <a href = "index.php?page=reply&forum=<?php echo $forum; ?>&id=<? echo $forumpostid ?>&pid=<? echo $gettopic3['postid']; ?>"><img src = "/images/quote.gif" border = "0" height="16" width="16" alt = "Quote"/></a> <?php $dbtime =$gettopic3['showtime']; $intTime=time(); $intDiff=$intTime - $dbtime; if ($intDiff < 7200 && $gettopic3['author'] != $username) { ?> <?php include "include/editmessage.php"; // shows where you are on the forum ?> <a href = "index.php?page=editmessage&forum=<?php echo $forum; ?>&id=<? echo $forumpostid ?>&pid=<? echo $gettopic3['postid']; ?>"><img src = "/images/edit.bmp" border = "0" alt = "Edit"/></a> <?php } ?> <?php //Now increase it: $CONT_ID++; ; ?> </td> <td width = "4%" align = "right" valign = "bottom"> </td> </tr> </table></td> </tr> </table></td> </tr> </table> <?php } $getreplies = "Select * from forumtutorial_posts where parentid='$forumpostid' ORDER BY showtime $max"; //getting replies $getreplies2=mysql_query($getreplies) or die(mysql_error() . "Could not get replies"); $counter2 = 1; while ($getreplies3=mysql_fetch_array($getreplies2)) { ?><br /> <table width = "90%" align="center" cellpadding = "0" cellspacing = "0" > <tr> <td> <table width = "100%" align = "center" cellpadding = "0" cellspacing = "0" class="loggedin"> <tr> <td colspan="3" align="right" class = 'border'> <table width="100%"> <tr> <td width="15%" align="left"><font size="2" color="white"> <?php $counter2++; ?> <a name="<?php echo $getreplies3['postid'] ?>"> </a><a href ='http://www.runningprofiles.com/members/index.php?page=message&forum=<?php echo $forum ?>&id=<?php echo $forumpostid ?>#<?php echo $getreplies3['postid'] ?>'><strong>#<?php echo $counter2;?></strong></a></font></td> <td width="32%" align="left"> </td> <td width="33%" align="right"><font size="2" color="white">» Replied <? $dbtime=$getreplies3['showtime']; $time =date("F j Y, g:i a", $dbtime); $time =date("F j, Y, g:i a", $dbtime); gettheTime($dbtime, $time); ?> « </font></td> </tr> </table></td> </tr> <tr> <td class = "forum_view_topic_header_2_b" width = "20%" align = "center" valign = "middle" ><a href = '/members/<? echo $getreplies3['author']; ?>'> <span class = "style5"><? echo "<b>". $getreplies3['author']." </b>" ?></span></a> <?php $result = mysql_query( "SELECT * FROM useronline WHERE(user='" . $getreplies3['author'] . "')"); while ($row=mysql_fetch_array($result)) { $last_active=time() - $row['timestamp']; } echo ($last_active < 300) ? '<img src="http://www.runningprofiles.com/images/useron.gif" width="12" height="11" alt= "usron" />' : '<img src="http://www.runningprofiles.com/images/useroff.gif" width="12" height="11" alt= "usroff" />'; ?> <br /> <? $query="SELECT * FROM users WHERE Username = '" . $getreplies3['author'] . "' LIMIT 1"; if ($result=mysql_query($query)) { if (mysql_num_rows($result)) { $array =mysql_fetch_assoc($result); $image =$array['image']; $postnum=$array['post_count']; echo "<img src=\"http://www.runningprofiles.com/members/images/mini/$image\" border=\"1\" alt =\"mini\" />"; ?> <br /> <span class = "style7"> Posts: <?php echo $postnum; ?> </span> <? } } ?> </td> <td width = "85%" colspan="2" style="background-color:white"> <table width = "100%" border = "0" cellpadding = "5" cellspacing = "0"> <tr> <td width="96%" valign = "top"> <?php $message =nl2br($getreplies3['post']); $b =new BBCode(); $b->selection=nl2br($message); $b->parseCode(); echo nl2br($b->parsed); ?> </td> </tr> <tr> <td align = "left" valign = "top"></td> </tr> <tr> <td height = "27" colspan = "2" align = "right" > </td> </tr> <tr> <td height = "28" align = "right" valign = "top"> <a href = "index.php?page=reply&forum=<?php echo $forum; ?>&id=<? echo $forumpostid ?>&pid=<? echo $getreplies3['postid']; ?>"><img src = "/images/quote.gif" border = "0" height="16" width="16" alt = "Quote"/></a> <?php $dbtime =$getreplies3['showtime']; $intTime=time(); $intDiff=$intTime - $dbtime; if ($intDiff < 7200 && $getreply3['author'] != $username || $getuser = 'Admin') { include 'editmessage.php'; //Now increase it: $CONT_ID++; } ; ?> </td> <td width = "4%" align = "right" valign = "bottom"> </td> </tr> </table></td> </tr> </table></td> </tr> </table> <? } ?> <? echo "<br /><center>"; // Find out the total number of pages depending on the limit set $numofpages=$rows / $page_rows; $totalpages=ceil($numofpages); // Start links for pages $maxpage =$totalpages == 0 ? 1 : $totalpages; // add this line echo "Page " . $pagenum . " of " . $maxpage . "</center>"; // change this // Sets link for previous 25 and return to page 1 if ($pagenum != 1) { $pageprev=($pagenum - 1); echo "<center><a href=\"" . $_SERVER['PHP_SELF'] . "?page=message&forum=$forum&id=$forumpostid&pagenum=1\"><<</a> "; echo "<a href=\"" . $_SERVER['PHP_SELF'] . "?page=message&forum=$forum&id=$forumpostid&pagenum=$pageprev\">PREV </a> "; } else { echo "<center>PREV "; } // Loop thru all the pages and echo out the links for ($i=1; $i <= $numofpages; $i++) { if ($i == $pagenum) { echo "[" . $i . "] "; } else { echo "<a href=\"" . $_SERVER['PHP_SELF'] . "?page=message&forum=$forum&id=$forumpostid&pagenum=$i\">$i</a> "; } } // Check for straglers after the limit blocks if (($rows % $page_rows) != 0) { if ($i == $pagenum) { echo "[" . $i . "] "; } else { echo "<a href=\"" . $_SERVER['PHP_SELF'] . "?page=message&forum=$forum&id=$forumpostid&pagenum=$i\">$i</a> "; } } // Print out the Next 25 and Goto Last page links if (($rows - ($page_rows * $pagenum)) > 0) { $pagenext=$pagenum++; echo "<a href=\"" . $_SERVER['PHP_SELF'] . "?page=message&forum=$forum&id=$forumpostid&pagenum=$pagenext\">NEXT </a> "; echo "<a href=\"" . $_SERVER['PHP_SELF'] . "?page=message&forum=$forum&id=$forumpostid&pagenum=$totalpages\">>></a> </center>"; } else { echo("NEXT </center> <br />"); } ?>
As you can see if on pahe 1 it echos the topic starter.... anything more it doesnt and thats why i start it from number 2.
-
ok i forgot ''
the issue i now have is after this i have if ($getthreads3['date'] == $getdate3['date']){echo 'yes';} }
how would i make it so it echos only 1 yes and not the amount of yesys compared to dates in db
-
what about posting the html? without any thing to view we cannot do anything
-
the code below does not echo yes. If i add the date manually () if echos yes... $date123 also echos out the date!
where am i going wrong?
<?php $getthreads = "Select * from daddiary ORDER BY DATE (STR_TO_DATE( `date`, '%d/%m/%Y ' )) ASC"; $getthreads2=mysql_query($getthreads) or die("Could not get threads"); while ($getthreads3=mysql_fetch_array($getthreads2)) { ?><tr <? if ( $getthreads3['date'] == date("d/m/Y") ) { echo 'bgcolor="#CAD9D9"'; }?> > <td width="10%" height="39" align="center" valign="middle"><?php echo $getthreads3['date'];?> </td> <td width="15%" align="center" valign="middle"> <?php echo $getthreads3['am']; $date123=$getthreads3['date']; $getdate= "Select * from dadreps where date = $date123"; $getdate2=mysql_query($getdate) or die("Could not get threads"); while ($getdate3=mysql_fetch_array($getdate2)) {
Also when it does work it echos yes the amount of times that there are rows with same date. How could i echo yes no matter how many rows it shows?
-
Can u provide you site name so we can see where this is occuring
-
i have even tired changing to distance as there is only 1 date but many distances!
didnt work
-
I tried that and its still not looping through the data!
-
but im only wanting these to go through the array
var cell1 = row.insertCell(0); var str1 = document.createTextNode("Distance: "); cell1.appendChild(str1); var input = document.createElement('input'); input.name = 'distance[]' + lastRow; input.id = 'distance' + lastRow; input.style.width = "187px" cell1.appendChild(input); var theBR = document.createElement('br'); cell1.appendChild(theBR); var str1 = document.createTextNode("Time: "); cell1.appendChild(str1); var input2 = document.createElement('input'); input2.value = '00'; input2.name = 'hours[]' + lastRow; input2.id = 'hours' + lastRow; input2.style.width = "25px" input2.setAttribute('maxlength', 1); cell1.appendChild(input2); var str2 = document.createTextNode(" Hours"); cell1.appendChild(str2); var input3 = document.createElement('input'); input3.value = '00'; input3.name = 'min[]' + lastRow; input3.id = 'min' + lastRow; input3.style.width = "25px" cell1.appendChild(input3); var str3 = document.createTextNode(" Minutes"); cell1.appendChild(str3); var input4 = document.createElement('input'); input4.value = '00'; input4.name = 'seconds[]' + lastRow; input4.id = 'seconds' + lastRow; input4.style.width = "25px" cell1.appendChild(input4); var str4 = document.createTextNode(" Seconds"); cell1.appendChild(str4);
and as you can see they are allready in an array ver.
Or do i need them ALL to be like this to have just these work?
-
I have added a function so i can add more textboxes to the form if needed
<script language="javascript1.2" type="text/javascript"> function addRow() { var tbl = document.getElementById('thetable'); var lastRow = tbl.rows.length; var row = tbl.insertRow(lastRow); var cell1 = row.insertCell(0); var str1 = document.createTextNode("Distance: "); cell1.appendChild(str1); var input = document.createElement('input'); input.name = 'distance[]' + lastRow; input.id = 'distance' + lastRow; input.style.width = "187px" cell1.appendChild(input); var theBR = document.createElement('br'); cell1.appendChild(theBR); var str1 = document.createTextNode("Time: "); cell1.appendChild(str1); var input2 = document.createElement('input'); input2.value = '00'; input2.name = 'hours[]' + lastRow; input2.id = 'hours' + lastRow; input2.style.width = "25px" input2.setAttribute('maxlength', 1); cell1.appendChild(input2); var str2 = document.createTextNode(" Hours"); cell1.appendChild(str2); var input3 = document.createElement('input'); input3.value = '00'; input3.name = 'min[]' + lastRow; input3.id = 'min' + lastRow; input3.style.width = "25px" cell1.appendChild(input3); var str3 = document.createTextNode(" Minutes"); cell1.appendChild(str3); var input4 = document.createElement('input'); input4.value = '00'; input4.name = 'seconds[]' + lastRow; input4.id = 'seconds' + lastRow; input4.style.width = "25px" cell1.appendChild(input4); var str4 = document.createTextNode(" Seconds"); cell1.appendChild(str4); } function delRow() { var tbl = document.getElementById('thetable'); var lastRow = tbl.rows.length; if (lastRow > 2) tbl.deleteRow(lastRow - 1); } </script>
The whole form is below
<link rel = "stylesheet" href = "http://www.runningprofiles.com/dad/Form.Send/demo.css" type = "text/css"/> <script type = "text/javascript" src = "http://www.runningprofiles.com/dad/mootools.js"></script> <script type = "text/javascript" src = "http://www.runningprofiles.com/dad/Form.Send/demo.js"></script> <?php $getthreads = "Select * from dad where id='".$_GET["id"]."' ORDER BY date ASC"; $getthreads2=mysql_query($getthreads) or die("Could not get threads"); while ($getthreads3=mysql_fetch_array($getthreads2)) { ?> <center> <form id = "myForm" action = "include/addlog.php" method = "post"> <table style="BORDER-COLLAPSE: collapse"> <tbody> <tr> <td> <p align="right">Date:</p></td> <td> <p align="left"><?php echo $getthreads3['date'];?></p> <input type="hidden" name="date" value="<?php echo $getthreads3['date'];?>" > </td> </tr> <tr> <td> <br /> <p align="right">Am Run:</p></td> <td> <p align="left"><br /> <input style="WIDTH: 186px;" value="<?php echo $getthreads3['am'];?>" name="am" /></p></td> </tr> <tr> <td> <p align="right">Duration:</p></td> <td> <p align="left"> <input maxlength="2" style="WIDTH: 20px;" name="hoursam" /> Hours<input maxlength="2" style="WIDTH: 20px;" name="minam" /> Minutes<input maxlength="2" style="WIDTH: 25px; " name="secam" />Seconds</p></td> </tr> <tr> <td><br /> <p align="right">Pm Run:</p></td> <td> <p align="left"><br /> <input style="WIDTH: 186px;" value="<?php echo $getthreads3['pm'];?>" name="pm" /></p></td> </tr> <tr> <td> <p align="right">Duration:</p></td> <td> <p align="left"> <input maxlength="2" style="WIDTH: 25px; " name="hourspm" /> Hours<input maxlength="2" style="WIDTH: 25px;" name="minpm" /> Minutes<input maxlength="2" style="WIDTH: 25px;" name="secpm" /> Seconds</p></td> </tr> <tr> <td><br /> <p align="right">Weather:</p></td> <td> <p align="left"><br /> <input style="WIDTH: 187px;" name="weather" /></p></td> </tr> <tr> <td><br /> <p align="right">Comments:</p></td> <td> <p align="left"><br /> <input style="WIDTH: 187px;" name="comments" /></p></td> </tr> <tr> <td> </td> <td> <p align="center"> </p></td> </tr> </tbody> </table> <table id="thetable" align="center"> <tr> <td> </td> </tr> </table> <script language="javascript1.2" type="text/javascript"> function addRow() { var tbl = document.getElementById('thetable'); var lastRow = tbl.rows.length; var row = tbl.insertRow(lastRow); var cell1 = row.insertCell(0); var str1 = document.createTextNode("Distance: "); cell1.appendChild(str1); var input = document.createElement('input'); input.name = 'distance[]' + lastRow; input.id = 'distance' + lastRow; input.style.width = "187px" cell1.appendChild(input); var theBR = document.createElement('br'); cell1.appendChild(theBR); var str1 = document.createTextNode("Time: "); cell1.appendChild(str1); var input2 = document.createElement('input'); input2.value = '00'; input2.name = 'hours[]' + lastRow; input2.id = 'hours' + lastRow; input2.style.width = "25px" input2.setAttribute('maxlength', 1); cell1.appendChild(input2); var str2 = document.createTextNode(" Hours"); cell1.appendChild(str2); var input3 = document.createElement('input'); input3.value = '00'; input3.name = 'min[]' + lastRow; input3.id = 'min' + lastRow; input3.style.width = "25px" cell1.appendChild(input3); var str3 = document.createTextNode(" Minutes"); cell1.appendChild(str3); var input4 = document.createElement('input'); input4.value = '00'; input4.name = 'seconds[]' + lastRow; input4.id = 'seconds' + lastRow; input4.style.width = "25px" cell1.appendChild(input4); var str4 = document.createTextNode(" Seconds"); cell1.appendChild(str4); } function delRow() { var tbl = document.getElementById('thetable'); var lastRow = tbl.rows.length; if (lastRow > 2) tbl.deleteRow(lastRow - 1); } </script> <table style="WIDTH: 100%; BORDER-COLLAPSE: collapse"> <tr> <td> <p align="center"> <input type="button" value="Add Interval" onclick="addRow()" /> <input type="button" value="Subtract Interval" onclick="delRow()" /> </p> </td> </tr> </table> <center> <input type = "submit" name = "button" id = "submitter"/></center> <span class = "clr"> <!-- spanner --></span> </div> </form> <?php } ?> <center> <div id = "log"> <center><h3>Added diary</h3> <div id = "log_res"> <!-- spanner --></center> </div> </div> </center>
Now when i come to try add the data to the db it only adds the 1st result from the loop...why??
<?php include '../../settings.php'; $mydate=$_POST['date']; $am=mysql_real_escape_string($_POST['am']); $minam=mysql_real_escape_string($_POST['minam']); $hoursam=mysql_real_escape_string($_POST['hoursam']); $secam=mysql_real_escape_string($_POST['secam']); $pm=mysql_real_escape_string($_POST['pm']); $minpm=mysql_real_escape_string($_POST['minpm']); $hourspm=mysql_real_escape_string($_POST['hourspm']); $secpm=mysql_real_escape_string($_POST['secpm']); $weather=mysql_real_escape_string($_POST['weather']); $comments=mysql_real_escape_string($_POST['comments']); if($am != ""){$amtime = $hoursam . ":" . $minam. ".". $secam;} if($pm != ""){$pmtime = $hourspm . ":" . $minpm. ".". $secpm;} mysql_query("INSERT INTO daddiary (`date`,`am`,`pmtime`,`pm`,`amtime`,`weather`,`comment`) VALUES ('$mydate','$am' , '$amtime','$pm','$pmtime' , '$weather','$comments') ") or die(mysql_error()); $i=-1; $limit=count($_POST['date']); while(++$i<$limit) { if ($_POST['distance'] != "") { $mydate=$_POST['date']; $distance=mysql_real_escape_string($_POST['distance'][$i]); $min=mysql_real_escape_string($_POST['min'][$i]); $hours=mysql_real_escape_string($_POST['hours'][$i]); $sec=mysql_real_escape_string($_POST['seconds'][$i]); $time = $hours . ":" . $min. ".". $sec; echo $time; mysql_query("INSERT INTO dadreps (`date`,`distance`,`time`) VALUES ('$mydate','$distance' , '$time') ") or die(mysql_error()); } } echo 'Your diary entry has been added'; ?>
-
how would i chnage this 15/03/2010 to a time stamop and chnage it back to 15/03/2010 when out of db>
-
23/05/2010 10,000m Track BMAF 10k - Oxford Set a PB
15/05/2010 Other Road BMAF Road Relays - Sutton Park, Birmingham Get in the team!
06/06/2010 10,000m Road 10km Road Championship - Bispham, Blackpool Set a PB!
Is how its showing it... im using a query $getthreads ="Select * from races ORDER BY DATE_FORMAT(date, '%d-%m-%Y') ASC";
what am i doing wrong??
-
$getthreads ="Select * from races WHERE date >= 'date("d/m/Y")' ORDER BY date ASC";
how do i use the function is this does not work
-
ver dump gets me
Array
(
[date] => 14/03/2010
[venue] => 1
[goals] => 1
[date2] => 14/03/2010
[venue2] => 2
[goals2] => 2
[date3] => 14/03/2010
[venue3] => 3
[goals3] => 3
[distance] => 5000m
[terrain] => Road
[distance2] => 3000m
[terrain2] => Track
[distance3] => 10,000m
[terrain3] => Cross Country
)
if that helps at all
-
Below is the full code to add races to my db.
<link rel="stylesheet" href="http://www.runningprofiles.com/dad/Form.Send/demo.css" type="text/css" /> <script type="text/javascript" src="http://www.runningprofiles.com/dad/mootools.js"></script> <script type="text/javascript" src="http://www.runningprofiles.com/dad/Form.Send/demo.js"></script> <script> function addRow() { var tbl = document.getElementById('thetable'); var lastRow = tbl.rows.length; var row = tbl.insertRow(lastRow); var cell1 = row.insertCell(0); cell1.setAttribute('align','center') var input = document.createElement('input'); input.name = 'date' + lastRow; input.id = 'date' + lastRow; cell1.appendChild(input); var cell2 = row.insertCell(1); cell2.setAttribute('align','center') input = document.createElement('input'); input.name = 'goals' + lastRow; input.id = 'goals' + lastRow; cell2.appendChild(input); var cell3 = row.insertCell(1); cell3.setAttribute('align','center') input = document.createElement('input'); input.name = 'venue' + lastRow; input.id = 'venue' + lastRow; cell3.appendChild(input); var cell4 = row.insertCell(1); cell4.setAttribute('align','center'); input = document.createElement('select'); input.name = 'terrain' + lastRow; input.id = 'terrain' + lastRow; var s = "Road/Track/Multi Terrain/Cross Country".split("/"); for(var i=0;i<s.length;i++) { var o = document.createElement("option"); o.value = s[i]; o.text = s[i]; input.add(o); } cell4.appendChild(input); var cell5 = row.insertCell(1); cell5.setAttribute('align','center'); input = document.createElement('select'); input.name = 'distance' + lastRow; input.id = 'distance' + lastRow; var s = "3000m/5000m/10,000m/5 Miles/10 Miles/20 Miles/Half Marathon/Marathon /Other".split("/"); for(var i=0;i<s.length;i++) { var o = document.createElement("option"); o.value = s[i]; o.text = s[i]; input.add(o); } cell5.appendChild(input); } function delRow() { var tbl = document.getElementById('thetable'); var lastRow = tbl.rows.length; if (lastRow > 2) tbl.deleteRow(lastRow - 1); } </script> <br /> <center> Here is a list of you up and coming races. Use the form below to add them so then <b>I</b> know which races you have gone for! </center> <br /> <table width = "99%" class = 'forum'> <tr> <td> <table width="100%" class = 'maintable'> <tr class = 'headline'> <td width = "12%" bgcolor="#003366"> <div align = "center">Date</div></td> <td width = "14%" bgcolor="#003366"> <div align = "center">Terrain</div></td> <td width = "12%" bgcolor="#003366"> <div align = "center">Distance</div> </td> <td width = "43%" bgcolor="#003366"> <div align = "center">Venue </div></td> <td width = "19%" bgcolor="#003366"> <div align = "center">Goals</div></td> </tr> <?php //$query="DELETE FROM dad WHERE id = '22' "; //$result=mysql_query($query); $getthreads = "Select * from races ORDER BY date ASC"; $getthreads2=mysql_query($getthreads) or die("Could not get threads"); while ($getthreads3=mysql_fetch_array($getthreads2)) { ?><tr <? if ( $getthreads3['date'] == date("d/m/Y") ) { echo 'bgcolor="#CAD9D9"'; }?> > <td width="10%" height="39" align="center" valign="middle"><?php echo $getthreads3['date'];?> </td> <td width="15%" align="center" valign="middle"> <?php echo $getthreads3['distance']; ?> </td> <td width="15%" align="center" valign="middle"><?php echo $getthreads3['terrain']; ?> </td><td align = "center" valign = "middle"><?php echo $getthreads3['venue']?> </td> <td align="center" valign = "middle"> <?php echo $getthreads3['goals']?> </td> </tr> <?php } ?> </table></td> </tr> </table> <form id="myForm" action="Form.Send/ajax.form.php" method="post"> <table align="center" style="WIDTH: 100%;BACKGROUND: #C0C0C0; BORDER-COLLAPSE: collapse" id="thetable"> <tbody> <tr> <td> <p align="center">Date</p></td> <td> <p align="center">Distance</p></td> <td> <p align="center">Terrain</p></td> <td> <p align="center">place</p></td> <td> <p align="center">Goals</p></td> </tr> <tr> <td align="center"> <input name="date" value="<?php echo date("d/m/Y");?> " /></td> <td align="center"> <select name="distance"> <option value="3000m">3000m</option> <option value="5000m">5000m</option> <option value="10,000m">10,000m</option> <option value="5 Miles">5 Miles</option> <option value="10 Miles">10 Miles</option> <option value="20 Miles">20 Miles</option> <option value="Half Marathon">Half Marathon</option> <option value="Marathon">Marathon</option> <option value="Other">Other</option> </select> </td> <td align="center"> <select name="terrain"> <option value="Road">Road</option> <option value="Track">Track</option> <option value="Multi Terrain">Multi Terrain</option> <option value="Cross Country">Cross Country</option> </select> </td> <td align="center"> <input name="venue" /></td> <td align="center"> <input name="goals" /></td> </tr> </tbody> </table> <table style="WIDTH: 100%; BORDER-COLLAPSE: collapse"> <tr> <td> <p align="center"> <input type="button" value="Add Anouther" onclick="addRow()" /> <input type="button" value="Subtract Row" onclick="delRow()" /> </p> </td> </tr> </table> <center> <input type="submit" name="button" id="submitter" /></center> <span class="clr"><!-- spanner --></span> </div> </form> <center> <div id="log"> <center><h3>Ajax Response</h3> <div id="log_res"><!-- spanner --></center></div> </div> </center> <span class="clr"><!-- spanner --></span>
As you can see there is an option to add a number of rows so you can add more than 1 race... what would i need to do to add all races the user inputs?? a loop of some kind?
-
so if i did this
function check_input($data) { $data = trim($data); $data = stripslashes($data); $data = htmlspecialchars($data); $data = mysql_real_escape_string($data) ; return $data; }
would that work to prevent both sql and cross site??
mysql_real_escape_string()
-
Ok i have come across this function...
function check_input($data) { $data = trim($data); $data = stripslashes($data); $data = htmlspecialchars($data); return $data; }
Would this have any other advantages then mysql_real_escape_string ??
-
Hey guys i have a script below where i can add other input boxes if needed.... these are then numberd plusing 1 to each one.
How can i make sure they are all added to my db?
An output might look liek this
Array ( [date] => 1 [am] => 1 [pm] => 1 [comment] => 1 [date2] => w [am2] => w [pm2] => w [comment2] => w [date3] => 1 [am3] => 1 [pm3] => 1 [comment3] => 1 [date4] => g [am4] => g [pm4] => g [comment4] => g )
<script> function addRow() { var tbl = document.getElementById('thetable'); var lastRow = tbl.rows.length; var row = tbl.insertRow(lastRow); var cell1 = row.insertCell(0); var input = document.createElement('input'); input.name = 'date' + lastRow; input.id = 'date' + lastRow; cell1.appendChild(input); var cell2 = row.insertCell(1); input = document.createElement('input'); input.name = 'am' + lastRow; input.id = 'am' + lastRow; cell2.appendChild(input); var cell3 = row.insertCell(2); input = document.createElement('input'); input.name = 'pm' + lastRow; input.id = 'pm' + lastRow; cell3.appendChild(input); var cell4 = row.insertCell(3); input = document.createElement('input'); input.name = 'comment' + lastRow; input.id = 'comment' + lastRow; cell4.appendChild(input); } function delRow() { var tbl = document.getElementById('thetable'); var lastRow = tbl.rows.length; if (lastRow > 2) tbl.deleteRow(lastRow - 1); } </script> <form action="javascript:get(document.getElementById('myform'));" name="myform" id="myform"> <table style="WIDTH: 100%; BORDER-COLLAPSE: collapse" id="thetable"> <tbody> <tr> <td> <p align="center">Date</p></td> <td> <p align="center">Am</p></td> <td> <p align="center">Pm</p></td> <td> <p align="center">Comment</p></td> </tr> <tr> <td> <input name="date" /> </td> <td> <input name="am" /> </td> <td> <input name="pm" /></td> <td> <input name="comment" /></td> </tr> </tbody> </table> <table style="WIDTH: 100%; BORDER-COLLAPSE: collapse"> <tr> <td> <p align="center"> <input type="button" value="Add Row" onclick="addRow()" /> <input type="button" value="Subtract Row" onclick="delRow()" /> </p> </td> </tr> </table>
-
Below is a script to edit a forum post but the issue is it edits all the forums posts to the same message e.g
b4
post1 = hey
post2= how
post3= are
post4= you
Now i select post 1 to be changed to 123
it should look like this:
post1 = 123
post2= how
post3= are
post4= you
but looks like this
post1 = 123
post2= 123
post3= 123
post4= 123
<?php if (isset($_POST['edit'])) { $message = mysql_real_escape_string($_POST['message']); $query = "UPDATE forumtutorial_posts SET post = '$message' WHERE postid=".$getreplies3['postid']." "; mysql_query($query) or die('Error, query failed'); } else { echo $getreplies3['postid'] ; $threadid = $CONT_ID; ?> <script src="../../css/SpryCollapsiblePanel.js" type="text/javascript"></script> <link href="http://www.runningprofiles.com/css/SpryCollapsiblePanel.css" rel="stylesheet" type="text/css" /> <div id="CollapsiblePanel<?PHP // I had to add $CONT_ID that is set in the script that includes this. and ive done it again for the "tabindex" just to ensure it works! echo $CONT_ID; ?>" class="CollapsiblePanel"> <div class="CollapsiblePanelTab" tabindex="<?PHP echo $CONT_ID; ?>"> Edit</div> <div class="CollapsiblePanelContent"> <form name='input' action='<?php echo $filename ;?>' method='post'> <div align="center"> <label> <textarea class='inputforum' name="message" id="message" cols="500" rows="5"><? echo $message; ?></textarea> </label> <input type="checkbox" name="deletepost" value="deletepost" /> delete post <br/> <br/> <input type='submit' name='edit' class="submit-btn" value='' /> </div> </form> <? } ?></div> </div> <script type="text/javascript"> <!-- <?PHP //Ive added the variable $CONT_ID here aswell. THIS IS REQUIRED FOR THE //JS to work! ?> var CollapsiblePanel<?PHP echo $CONT_ID; ?> = new Spry.Widget.CollapsiblePanel("CollapsiblePanel<?PHP echo $CONT_ID; ?>", {contentIsOpen:false}); //--> </script>
-
Sure thing
// Find out the total number of pages depending on the limit set $numofpages=$rows / $page_rows; $totalpages=ceil($numofpages); // Start links for pages $maxpage =$totalpages == 0 ? 1 : $totalpages; // add this line echo "Page " . $pagenum . " of " . $maxpage . "</center>"; // change this // Sets link for previous 25 and return to page 1 if ($pagenum != 1) { $pageprev=($pagenum - 1); echo "<center><a href=\"" . $_SERVER['PHP_SELF'] . "?page=message&forum=$forum&id=$forumpostid&pagenum=1\"><<</a> "; echo "<a href=\"" . $_SERVER['PHP_SELF'] . "?page=message&forum=$forum&id=$forumpostid&pagenum=$pageprev\">PREV </a> "; } else { echo "<center>PREV "; } // Loop thru all the pages and echo out the links for ($i=1; $i <= $numofpages; $i++) { if ($i == $pagenum) { echo "[" . $i . "] "; } else { echo "<a href=\"" . $_SERVER['PHP_SELF'] . "?page=message&forum=$forum&id=$forumpostid&pagenum=$i\">$i</a> "; } } // Check for straglers after the limit blocks if (($rows % $page_rows) != 0) { if ($i == $pagenum) { echo "[" . $i . "] "; } else { echo "<a href=\"" . $_SERVER['PHP_SELF'] . "?page=message&forum=$forum&id=$forumpostid&pagenum=$i\">$i</a> "; } } // Print out the Next 25 and Goto Last page links if (($rows - ($page_rows * $pagenum)) > 0) { $pagenext=$pagenum++; echo "<a href=\"" . $_SERVER['PHP_SELF'] . "?page=message&forum=$forum&id=$forumpostid&pagenum=$pagenext\">NEXT </a> "; echo "<a href=\"" . $_SERVER['PHP_SELF'] . "?page=message&forum=$forum&id=$forumpostid&pagenum=$totalpages\">>></a> </center>"; } else { echo("NEXT </center> <br />"); }
Forum code not allowing new lines!
in PHP Coding Help
Posted
Hey guys,
If i add text like so into a reply on my forum
It shows it like this
The code here adds bbcode to the text
----------------------------------------------------
----------------------------------------------------
Is it the way im outputting the code?
and below is the bbcode.
", "", $m); // Remove [/code] tag.
$m = highlight_string($m,true); // Highlight string and encode.
$selection = str_ireplace("
", $selection); // Add highlighted code back with tags for later parsing.
}
#### End
" => "</p>" ,"
" => "</p>");
// BBCode array including their replacement.
break;
}
}
function parseEmoticons($noBBCode=0) { // noBBCode variable defaults to 0. If set to one the parser will not parse be able to parse BBCode.
if(!$this->selection) { // Check if the user has set the selection.
$this->debug .= "You must set a value for the selection before parsing! "; // Set the Debug variable if not.
}else{
$error = 0; // Default to no errors.
if($this->parsed) { // If something has already been parsed.
$selection = str_replace("\n", '', $this->parsed); // Set the parsed value in order to not reset the already parsed selection.
}elseif($noBBCode==1) { // If nothing has been parsed and the noBBCode variable has been set to one.
$selection = str_replace("\n", '', $this->selection); // Set the selection value to variable selection.
$error = 2; // Set the error variable to 2 so that it will not look for
Regards,
Jarratt[/code]