-
Posts
86 -
Joined
-
Last visited
Everything posted by mat3000000
-
Absolutely perfect script, worked a treat. Thanks!
-
Hi, I think there should be a very easy way to do what I want to do. I just can't think of it! I have the number of pages returned in a variable called $pages. I want to add a link to every page like at the bottom of google. Example, there are three pages, links echoed like: 1 2 3 Thanks in advance
-
Using the 'Less Than' symbol in query problem
mat3000000 replied to mat3000000's topic in MySQL Help
Thank You, I am now using 'HAVING' and it seems to work fine. -
I have a query to search jobs. It also works out the distance from the user to the job: SELECT ((ACOS(SIN('$b_lat' * PI() / 180) * SIN(`lat` * PI() / 180) + COS('$b_lat' * PI() / 180) * COS(`lat` * PI() / 180) * COS(('$b_long' - `long`) * PI() / 180)) * 180 / PI()) * 60 * 1.1515) AS `distance`,username,sector,job,pay,reqexp, jobtime, hours, hourscat,days,description FROM `jobs` WHERE sector='$sector' AND job='$job' AND validated='1' AND `distance` < 80 ORDER BY `distance` DESC; I am getting an error when running this, however, when I remove the "AND `distance` < 80" clause it works fine. Whats the problem here??
-
It will add the 'FILES' folder if it isn't there, but just refreshes the page, displaying no errors, without adding anything to the folder??? As you can probably see I have three file slots for users, I want to fill the next available slot up, and if no slots, display error 2 ($e=2; - Delete a file to make space) //^^GET VARIABLES SUCH AS USERNAME ETC. if(isset($_POST['uploadfile'])){ if(is_dir("files/$username/FILES/")){}else{mkdir("files/$username/FILES/");} if (is_uploaded_file($_FILES['file']['tmp_name'])) { $name = $_FILES['file']['name']; if ($file != "application/pdf" || substr(strrchr($file, '.'), 1) != "pdf" || substr(strrchr($file, '.'), 1) != "jpg" || $file != "image/jpeg" || $file != "image/pjpeg") { $errors[] = 'File must be in PDF or JPEG format'; } else if($_FILES['file']['size'] > 256000){$errors[] = 'File must be under 250KB';} else { $name1 = substr($name, 0, strrpos($name, '.')); $ext = strtolower(substr(strrchr($name, '.'), 1)); $name = $name1.'.'.$ext; $res = mysql_query("SELECT username,file1,file2,file3 FROM `files` WHERE `username`='$username'"); $row = mysql_fetch_array($res); $f1 = $row['file1']; $f2 = $row['file2']; $f3 = $row['file3']; if($f1==''){ $result = move_uploaded_file($_FILES['file']['tmp_name'], "files/$username/FILES/$name"); if ($result == 1){ $time = time(); $t=1; mysql_query("UPDATE files SET file1='$name', file1_val='0', file1_added='$time' WHERE username='$username'"); }else $e=1; }else if(empty($f2)){ $result = move_uploaded_file($_FILES['file']['tmp_name'], "files/$username/FILES/$name"); if ($result == 1){ $time = time(); $t=1; mysql_query("UPDATE files SET file2='$name', file2_val='0', file2_added='$time' WHERE username='$username'"); }else $e=1; }else if(empty($f3)){ $result = move_uploaded_file($_FILES['file']['tmp_name'], "files/$username/FILES/$name"); if ($result == 1){ $time = time(); $t=1; mysql_query("UPDATE files SET file3='$name', file3_val='0', file3_added='$time' WHERE username='$username'"); }else $e=1; }else{$e=2;} } } }
-
Ahh, OK.
-
I'm guessing there isn't a way then?
-
Probably your best way is to just delete the whole folder with: public static function deleteDir($dirPath) { if (! is_dir($dirPath)) { throw new InvalidArgumentException('$dirPath must be a directory'); } if (substr($dirPath, strlen($dirPath) - 1, 1) != '/') { $dirPath .= '/'; } $files = glob($dirPath . '*', GLOB_MARK); foreach ($files as $file) { if (is_dir($file)) { self::deleteDir($file); } else { unlink($file); } } rmdir($dirPath); } Or something similar, then remake the folder using mkdir(); Sorry if this isn't the answer you were looking for, but I didn't understand your question really.
-
I have a site where a user can upload a PDF CV file. Before it is published I want it to be moderated using simple whiteout boxes. I want to page where an admin can view/edit the PDF and save it in one click (+ send user email + Set record in DB to '1') without downloading it, so obviously it has to be on my server. I have to use PHP. I have a linux server. I could do the solution in ASP using http://www.pdfescape.com/webmasters/ but is there a solution for PHP?
-
Getting This Error, anyone know why? (Line 410 is the line after my page code ends) Here is my code... function URL() { $pageURL = 'http'; if ($_SERVER["HTTPS"] == "on") {$pageURL .= "s";} $pageURL .= "://"; if ($_SERVER["SERVER_PORT"] != "80") { $pageURL .= $_SERVER["SERVER_NAME"].":".$_SERVER["SERVER_PORT"].$_SERVER["REQUEST_URI"]; } else { $pageURL .= $_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"]; } return $pageURL; } $url = URL(); if(empty($errors)){ $sort = $_GET['sort']; $s = $_GET['s']; $limit=15; if($sort == 'Distance') {$query = "SELECT ((ACOS(SIN('$b_lat' * PI() / 180) * SIN(`lat` * PI() / 180) + COS('$b_lat' * PI() / 180) * COS(`lat` * PI() / 180) * COS(('$b_long' - `long`) * PI() / 180)) * 180 / PI()) * 60 * 1.1515) AS `distance`,username,sector,job,description,pay,reqexp, jobtime, hours, hourscat FROM `staff` WHERE sector='$sector' AND job='$job' "; if(!$hrs==''){$query .= "AND hourscat='$hrs' "; if(!$pay==''){$query .= "AND pay>='$pay' "; if(!$jobtime==''){$query .= "AND jobtime='$jobtime' "; $query .= "ORDER BY `distance` DESC"; } $numresults=mysql_query($query); $numrows=mysql_num_rows($numresults); // If we have no results if ($numrows == 0) { $rslts = "<br /><tr><td>Sorry, there are currently no customer advertisements on our system</td></tr>"; } if ($numrows > 0){ // next determine if s has been passed to script, if not use 0 if (empty($s)) { $s=0; } //Get Results $query .= " limit $s,$limit"; $result = mysql_query($query) or die("The search failed"); // begin to show results set $count = 1 + $s ; $rslts = ''; // now you can display the results returned while ($row= mysql_fetch_array($result)) { $username = $row['username']; $sector = $row['sector']; $job = $row['job']; $desc = $row['decription']; $exp = $row['reqexp']; $pay = $row['pay']; $jobtime = $row['jobtime']; $hours = $row['hours']; $distance = round($row['distance'],1); $rslts .= "<br /><table class='profilebox' style='padding:10px;'> <tr> <td width='120' height='120' align='center'><a href='viewjob.php?user=$username' style='border:none;'> <img src='/bus/files/$username/profilepic/tn_profilepic.jpg'</td> <td width='40'> </td> <td width='190'> $sector - $job<br /><br /><br /> Experience Required: $exp years<br /><br /> Pay: £$pay /hr<br /></td> <td width='40'> </td> <td width='70'><br /><br /><br />Hours: £$hours<br />Job Time: $jobtime</td> <td width='40'> </td> <td valign='bottom' align='right' width='160'> Distance: $distance miles </td> </tr> </table> "; $count++ ; } $currPage = (($s/$limit) + 1); //break before paging $rslts .= "<br />"; // next we need to do the links to other results if ($s>=1) { // bypass PREV link if s is 0 $prevs=($s-$limit); $prree ="<b><a class='np' href='$url&s=$prevs'><< Previous Page</a></b>   "; } // calculate number of pages needing links $pages=intval($numrows/$limit); // $pages now contains int of pages needed unless there is a remainder from division if ($numrows%$limit) { // has remainder so add one page $pages++; } // check to see if last page if (!((($s+$limit)/$limit)==$pages) && $pages!=1) { // not last page so give NEXT link $news=$s+$limit; $nachste = "<b><a class='np' href='$url&s=$news'>Next Page >></a></b>"; } $a = $s + ($limit) ; if ($a > $numrows) { $a = $numrows ; } $b = $s + 1 ; $pages123 = "<table width='93%' align='center'><tr><td height='30' valign='bottom'><p class='np'> $prree $nachste </p><p style='font-size:10px;'>Showing results $b to $a of $numrows</p></td></tr></table>"; } echo $pages123 . $pageslist . $rslts . $pages123; }//end $numrows >0 ?>
-
mysql real escape sting HELP + Text area line break help???
mat3000000 replied to mat3000000's topic in PHP Coding Help
Thanks for your help. Just for the record I am using this to turn off magic quotes: if (get_magic_quotes_gpc()) { $process = array(&$_GET, &$_POST, &$_COOKIE, &$_REQUEST); while (list($key, $val) = each($process)) { foreach ($val as $k => $v) { unset($process[$key][$k]); if (is_array($v)) { $process[$key][stripslashes($k)] = $v; $process[] = &$process[$key][stripslashes($k)]; } else { $process[$key][stripslashes($k)] = stripslashes($v); } } } unset($process); } and I am using htmlentities() and nl2br() which seemed to work. Thank You!!!! -
mysql real escape sting HELP + Text area line break help???
mat3000000 replied to mat3000000's topic in PHP Coding Help
I do not host on my own server, is here a function I can use that will simulate it being off? -
I am having problems with these slashes. They keep showing up when I echo data.... The code is to update a field in a mysql database table. Here is my code: $query = mysql_query("SELECT * FROM `bus` WHERE username='$username'"); $row = mysql_fetch_array($query); $bio = $row['about']; $bio = str_replace("<br />","\r\n",$bio); if(isset($_POST['submit'])){ if(empty($errors)){ if($password == $pass){ $about1 = mysql_real_escape_string($_POST["about"]); $about1 = str_replace("\r\n","<br />",$about1); mysql_query("UPDATE bus SET about='$about1' WHERE username='$username'"); }else{$errors[] = 'Incorrect Password';} } } When I run this and put: About: I'm very tired today It's been very hard I get the about1 string as: I\\\'m very tired today\r\nIt\\\'s been very hard Why???
-
Reading Image Code And Storing In Database
mat3000000 replied to N-Bomb(Nerd)'s topic in PHP Coding Help
I looked into this a while ago and found it very annoying. I then reverted to the method I currently use on my site. Simply store the image in a directory on your server, if you are uploading the function you would use would be move_uploaded_file(), then you can get the images in one array from a whole directory using the glob() function with *.jpg Look up a file upload tutorial on google, they are everywhere and most will use this method. -
Sorry, I just don't know. That worked for me. Hope you find the answer though
-
Good Tut for PHP search results - Paged and Ordered
mat3000000 replied to mat3000000's topic in PHP Coding Help
Anyone? Please? -
I need to make a results page, which will display all the different results - paged. This is easy enough, however I need to calculate the distance between a postcode entered and the one stored in the database record, and order by this if the "Sort By:" drop down box is set to distance. I have been trying for a couple of days now and I can't figure anything out. The problem is that the results are obtained by a query and where clause, and in the where clause is where you get the second postcode from. This means, the query is already run and the results order has already been determined. I will post the script I have now (Not Finished). I would be very grateful if someone will take a look, or direct me to a good tutorial on this. $sector = mysql_real_escape_string(trim($_GET['sector'])); $job = mysql_real_escape_string(trim($_GET['job'])); $exp = mysql_real_escape_string(trim($_GET['exp'])); $postcode = mysql_real_escape_string(trim($_GET['postcode'])); if(!is_numeric($exp)){$errors[] = 'The Experience Field must contain only numbers';} //POSTCODE VAL function validatePostcode($str) {.......} if (!validatePostcode($postcode)) {$errors[] = 'Postcode is Invalid';} $postcode2 = strtoupper(str_replace(" ", "", trim($postcode))); $buspostcode = substr($postcode2, 0, -3); function calc_postcode_seperation($pcodeA,$pcodeB) {........} //Search Code if(isset($_GET['submit'])){ if(empty($errors)){ $limit=10; $query = "select * from staff where sector='$sector' AND job='$job' AND exp>='$exp' ORDER BY '????HELP????'"; $numresults=mysql_query($query); $numrows=mysql_num_rows($numresults); // If we have no results if ($numrows == 0) { echo "<br /><tr><td class='errorbox'>Sorry, your search returned no results</td></tr>"; } if ($numrows > 0){ // next determine if s has been passed to script, if not use 0 if (empty($s)) { $s=0; } //Get Results $query .= " limit $s,$limit"; $result = mysql_query($query) or die("Couldn't execute query"); // begin to show results set $count = 1 + $s ; // now you can display the results returned while ($row= mysql_fetch_array($result)) { $username = $row['username']; $fname = $row['fname']; $lname = $row['lname']; $sector = $row['sector']; $job = $row['job']; $exp = $row['exp']; $pay = $row['pay']; $town = $row['town']; $county = $row['county']; $theirpostcode = $row['postcode']; $postcode1 = strtoupper(str_replace(" ", "", trim($theirpostcode))); $theirpostcode = substr($postcode1, 0, -3); $distance = calc_postcode_seperation($buspostcode,$theirpostcode); echo "<tr class='profilebox' style='padding:10px; display:block;'> <td width='120' height='120' align='center'><img src='/staff/files/$username/profilepic/tn_profilepic.jpg'</td> <td width='40'> </td> <td width='190'>$fname $lname<br /> $sector - $job<br /><br /><br />Experience: $exp years<br /><br /> Expected Pay: £$pay /hr<br /></td> <td width='40'> </td> <td width='160' align='center'>Feedback Score:<br /><span style='font-size:15pt;'>?/10</span> </td> <td width='40'> </td> <td valign='bottom' align='right' width='160'> Distance: $distance<br />$town, $county </td> </tr> <tr><td height='20'></td></tr>"; $count++ ; } $currPage = (($s/$limit) + 1); //break before paging echo "<br />"; // next we need to do the links to other results if ($s>=1) { // bypass PREV link if s is 0 $prevs=($s-$limit); print " <a href=\"$PHP_SELF?s=$prevs&q=$var\"><< Prev</a>  "; } // calculate number of pages needing links $pages=intval($numrows/$limit); // $pages now contains int of pages needed unless there is a remainder from division if ($numrows%$limit) { // has remainder so add one page $pages++; } // check to see if last page if (!((($s+$limit)/$limit)==$pages) && $pages!=1) { // not last page so give NEXT link $news=$s+$limit; echo " <a href=\"$PHP_SELF?s=$news&q=$var\">Next >></a>"; } $a = $s + ($limit) ; if ($a > $numrows) { $a = $numrows ; } $b = $s + 1 ; echo "<tr><td height='30' valign='bottom'><p>Showing results $b to $a of $numrows</p></td></tr>"; } } }
-
You need to have the php right at the start of the file. Make sure there is no whitespace at all before your <?php tag. If it already is right at the start, download notepad++, copy all your code in there, save. Should sort it.
-
Hi, I have a website where users can log on and edit their profile pic, name, biography etc. I was wondering about the correct way to:- Add data to the database through forms (Register.php) Display the data on a page Using mysql escape sting, however, the way I am currently using will display a '\' before any ' symbol. So it's >> it\'s ... Here is a snippet of the code I am using... //insert data $about1 = mysql_real_escape_string($_POST['about']); //get $query = mysql_query("SELECT * FROM `staff` WHERE username='$username'"); $row = mysql_fetch_array($query); $about = $row['about']; echo $about;
-
Preg_replace help - Replace ' " \ and / ?
mat3000000 replied to mat3000000's topic in PHP Coding Help
Right, so how would you suggest I do what I want to do:- I have a form where user inputs data to DB. When user logs in, they can view all their info. If I use mysql_real_escape() then all the apostrophes end up with a slash before them? -
PHP generated gallery - Implementing Lightbox?
mat3000000 replied to mat3000000's topic in PHP Coding Help
Anyone? -
This question is PHP and javascript/jQuery so I wasn't sure where to post it, but anyway... Here is the code I am using so far. Currently it just displays a larger version of the image in a new window. I would like a lighbox instead. I have tried this with "FancyBox" but couldn't get it to work on all the images, just the first one. Any suggestions? <?php //GET PRODUCT VAR etc. ^^ $directory = "Images/items/$product/"; //get all image files with a .jpg extension. $images = glob($directory . "*.jpg"); $imgone = $images[0]; $gallery = ''; foreach($images as $image) { $tn = explode("/", $image); $tnname = $tn[3]; $gallery .= '<a href="#" rel="'.$image.'" class="image" title="Images/items/'.$product.'/large/'.$tnname.'" alt="'.$product.'"><img src="Images/items/'.$product.'/thumbs/'.$tnname.'" class="thumb" border="1" style="margin-bottom:7px;"/></a> '; } if(is_dir("Images/items/".$product)){ $gallery .= "<div id='image' class='bigimg' align='left'>"; $gallery .= '<a href="largeimg.php?id='.$product.'&i=Images/items/'.$product.'/large/0main_img.jpg" target="_new"> <img src="Images/items/'.$product.'/0main_img.jpg" border="0" alt='.$name.'/> <span class="more"><img src="Images/zoom.png" /></span></a></div>'; } ?> <!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><?php echo $name; ?></title> <script type="text/javascript" src="js/ddsmoothmenu.js"></script> <script type="text/javascript" src="js/jquery.js"></script> <link href="CSS/style.css" rel="stylesheet" type="text/css" /> <link rel="stylesheet" type="text/css" href="CSS/ddsmoothmenu.css" /> </head> <body> <div class="hidden"> <script type="text/javascript"> $(function() { $(".image").click(function() { var image = $(this).attr("rel"); var large = $(this).attr("title"); var product = $(this).attr("alt"); $('#image').hide(); $('#image').fadeIn('slow'); $('#image').html('<a href="largeimg.php?id='+ product +'&i=' + large + '" target="_new"><img src="' + image + '"/><span class="more"><img src="Images/zoom.png" /></span></a>'); return false; }); }); </script>
-
Thanks for the help, I knew it wasn't the PHP!
-
The mysql_error returns: