PHP - My Php Script Works At School But Not At Home?!
My school is running PHP 4.3.2 on its network, and I'm running PHP 5.3.1 on my localhost machine using Xampp/Apache.
My login system works perfectly at school, however $_SESSION["LoggedIn"] does not register, recognise nor acknowledge on my home system. It's not the script itself as I've copied the files across, so in theory it should work exactly the same? I've compared phpinfo()'s and within the session category all values are the same. The database/MySQL works fine on both networks so it's not a problem to do with this. Any ideas? Thanks. Similar TutorialsHi. I had some trouble getting the mail function to work, I guess because I'm developing on LAMP (localhost), but I got it working at the office yesterday by configuring things as outlined here http://mattsk.blogspot.com/2010/09/configure-lamp-on-ubuntu-1004-to-send.html This got it working fine. But today I'm trying it from home and it's not working (mail is not getting sent). I don't know how the network is set up at work, but at home I'm on wireless lan through a d-link router. I have a feeling it has something to do with the smtp_port = 465 (see link above), and that port maybe being blocked by the firewall or something. I'm not really sure how all this stuff works though. I tried contacting d-link, but they want some money before they'll help me out. I followed some instructions I found online to forward port 465, which seemed to work (at lease the router told me so). But the mail is still not sending. A also tried the "fix-almost-any-computer-problem-ever" solution (i.e. I restarted my computer). But still nothing. I hope I've come to the right place for help. Any help would be great. Thanks. I have the following 2 scripts. One adds to the database and the other deletes a record from the database. Code: [Select] <form action="deletebidder.php" method="post"> <table> <tr> <td><font face ="calibri" size="4"> Add Bidder:</td> </tr> <tr> <td><input type="text" name="biddersId" /></td> </tr> <tr> <td><input type="hidden" name="addedbidder" /></td> </tr> <tr> <td><input type="Submit" value="Add"></td> </tr> </table> Second from: Code: [Select] <form name="deletebidder" action="process_bidders2.php" method="post"> <table> <tr> <td><font face= "calibri" size= "3"> Delete Bidder</font></td> </tr> <tr> <td><input type= "text" name="deletebidder" /></td> </tr> <tr> <td><input type= "hidden" name="deletebidder1" /></td> </tr> <tr> <td><input type= "submit" value= "submit" /></td> </tr> </table> </form> Both forms are on the same page. Now I have tried separate processing pages with the same results (If i get one to work the other doesn't, it's either one or the other, but they won't work together. If i have the add bidder working, the delete bidder doesn't work and visa versa?? Also, ONE IMPORTANT note is, if i try to process each form on separate pages, no matter what action "name" i give the form, it will only go to the action page that is working. Example is, I tried to process one form on deletebidder.php and the other on process_bidders2.php but it didn't matter. Both forms were processed by the deletebidder.php page. How is this even possible if I gave them both seperate action "paths"?? Code: [Select] <?php ob_start(); error_reporting(E_ALL); ini_set("display_errors", 1); $biddersId= $_POST['biddersId']; if (isset($addedbidder)) \\hidden form field { mysql_connect("$host", "$db_user", "$db_password")or die("cannot connect to server"); mysql_select_db("$db_name")or die("cannot select DB"); $sql="SELECT * FROM bidders WHERE biddersId='$biddersId'"; $result=mysql_query($sql); // Mysql_num_row is counting table row $count=mysql_num_rows($result); if($count==0){ // Add $biddersId to DB and redirect to anypage mysql_Query("INSERT INTO bidders (biddersId) VALUES ('$biddersId')"); header("Location: attendance.php"); exit(); } } if (isset($deletebidder1)) \\hidden form field { $biddersId= $deletebidder; mysql_connect("$host", "$db_user", "$db_password")or die("cannot connect to server"); mysql_select_db("$db_name")or die("cannot select DB"); mysql_query("DELETE FROM bidders WHERE biddersId='$biddersId'"); header("Location: attendance.php"); exit(); } ob_flush(); echo "<font color= \"red\" face=\"calibri\" size=\"4\">That bidder is already logged, Please press your browsers back button and try again.</font>"; ?> I am just helping out a friend with his online store that he would like to add multiple currencies to. I made this script to help him out: $price = 99.95; $default_currency = 20; // displays all the file nodes if(!$xml=simplexml_load_file('http://www.ecb.int/stats/eurofxref/eurofxref-daily.xml')){ trigger_error('Error reading XML file',E_USER_ERROR); } else { $array['currency'][1] = 'EUR'; $array['value'][1] = 1.00; $i = 2; foreach ($xml->Cube->Cube->children() as $node) { $arr = $node->attributes(); // returns an array $array['currency'][$i] = $arr['currency']; $array['value'][$i] = $arr['rate']; $i++; } } if (isset($_POST['currency'])){ $currency = $_POST['currency']; } else { $currency = $default_currency; } $price = $array['value'][$currency] / $array['value'][$default_currency] * $price; $price = round($price, 2); $currency_name = $array['currency'][$currency]; echo '<p>Price is '.$currency_name.$price.'<br /> To change currency, select from dropdown box below.</p>'; echo '<form action="currency.php" method="post"><select name="currency">'; $i = 1; foreach ($array['currency'] as $value){ echo '<option value="'.$i.'">'.$value.'</option>'; $i++; } echo '</select><br /><input type="submit" /></form><br />'; $i = 1; foreach ($array['currency'] as $value){ echo '<p>'.$value.' = '.$array['value'][$i].'</p>'; $i++; } But for some reason it only works some of the time and I can't work out why for the life of me. If I could get some help in the matter, that would be greatly appreciated. A link to the above example can be found here. Regards, I. I have created a script (single file) that works fine when testing it alone, but when included it doesn't and rest of page is blank. What could cause this? Is this because of some "mismatch" between the queries, variables used on the included file and the existing file? This is mind bender. I recently upgraded from a VPS to a Dedicated server. The script is a data mining tool that primarily uses cURL. It worked flawlessy on the the VPS. Because it was the same hosting company everything was migrated and done so smoothly to the new dedicated. Now, the program hangs for no reason at all. The times vary but I'll usually get about an hour of the script before it hangs. It used to run for hours at a time on the VPS. While I do see some 'notices' and cURL timeouts - there are no error messages echoed out when the program hangs and there is nothing within the error log on the server to indicate anything in terms of why. The program simply 'freezes'. I think I've spent the last three days modifying the php.ini file. Here are some settings which may be of interest? post_max_size = 16M log_errors = On max_execution_time = 0; (From what I understand is unlimited). max_input_time = 0 ; memory_limit = 128M; At the top of every page within my script: set_time_limit(0); error_reporting(E_ALL); The dedicated is an 8 gig Linux box running Apache. Speaking of which, here are some settings within WHM for Apache: Max Clients 500 Max Requests Per Child - 0 (unlimited) Keep-Alive - On Keep-Alive Timeout - 50 Max Keep-Alive Requests - Unlimited Timeout - 1000 Because the script works on another VPS that I have within the same hosting company can someone direct me with what I should be looking for and/or comparing between both servers? What are the most common reasons for a PHP script to freeze from a server setting standpoint? Well the subject line is pretty explicit. I found this script that uploads a picture onto a folder on the server called images, then inserts the the path of the image on the images folder onto a VACHAR field in a database table. Code: [Select] <?php //This file inserts the main image into the images table. //address error handling ini_set ('display_errors', 1); error_reporting (E_ALL & ~E_NOTICE); //authenticate user //Start session session_start(); //Connect to database require ('config.php'); //Check whether the session variable id is present or not. If not, deny access. if(!isset($_SESSION['id']) || (trim($_SESSION['id']) == '')) { header("location: access_denied.php"); exit(); } else{ // Check to see if the type of file uploaded is a valid image type function is_valid_type($file) { // This is an array that holds all the valid image MIME types $valid_types = array("image/jpg", "image/jpeg", "image/bmp", "image/gif"); if (in_array($file['type'], $valid_types)) return 1; return 0; } // Just a short function that prints out the contents of an array in a manner that's easy to read // I used this function during debugging but it serves no purpose at run time for this example function showContents($array) { echo "<pre>"; print_r($array); echo "</pre>"; } // Set some constants // This variable is the path to the image folder where all the images are going to be stored // Note that there is a trailing forward slash $TARGET_PATH = "images/"; // Get our POSTed variable $image = $_FILES['image']; // Sanitize our input $image['name'] = mysql_real_escape_string($image['name']); // Build our target path full string. This is where the file will be moved to // i.e. images/picture.jpg $TARGET_PATH .= $image['name']; // Make sure all the fields from the form have inputs if ( $image['name'] == "" ) { $_SESSION['error'] = "All fields are required"; header("Location: member.php"); exit; } // Check to make sure that our file is actually an image // You check the file type instead of the extension because the extension can easily be faked if (!is_valid_type($image)) { $_SESSION['error'] = "You must upload a jpeg, gif, or bmp"; header("Location: member.php"); exit; } // Here we check to see if a file with that name already exists // You could get past filename problems by appending a timestamp to the filename and then continuing if (file_exists($TARGET_PATH)) { $_SESSION['error'] = "A file with that name already exists"; header("Location: member.php"); exit; } // Lets attempt to move the file from its temporary directory to its new home if (move_uploaded_file($image['tmp_name'], $TARGET_PATH)) { // NOTE: This is where a lot of people make mistakes. // We are *not* putting the image into the database; we are putting a reference to the file's location on the server $sql = "insert into images (member_id, image_cartegory, image_date, image) values ('{$_SESSION['id']}', 'main', NOW(), '" . $image['name'] . "')"; $result = mysql_query($sql) or die ("Could not insert data into DB: " . mysql_error()); header("Location: images.php"); echo "File uploaded"; exit; } else { // A common cause of file moving failures is because of bad permissions on the directory attempting to be written to // Make sure you chmod the directory to be writeable $_SESSION['error'] = "Could not upload file. Check read/write persmissions on the directory"; header("Location: member.php"); exit; } } //End of if session variable id is not present. ?> The script seems to work fine because I managed to upload a picture which was successfully inserted into my images folder and into the database. Now the problem is, I can't figure out exactly how to write the script that displays the image on an html page. I used the following script which didn't work. Code: [Select] //authenticate user //Start session session_start(); //Connect to database require ('config.php'); $sql = mysql_query("SELECT* FROM images WHERE member_id = '".$_SESSION['id']."' AND image_cartegory = 'main' "); $row = mysql_fetch_assoc($sql); $imagebytes = $row['image']; header("Content-type: image/jpeg"); print $imagebytes; Seems to me like I need to alter some variables to match the variables used in the insert script, just can't figure out which. Can anyone help?? I have a very weird problem. On my website i have a script that takes random pages and displays them on the homepage. It works without a problem on its own but when i have it included in the homepage using include('webmaster fav.php'); i get this error: Warning: Cannot use a scalar value as an array in /mnt/w0210/d28/s25/b02a8bb2/www/webmaster fav.php on line 18 and this error: Warning: array_unique() [function.array-unique]: The argument should be an array in /mnt/w0210/d28/s25/b02a8bb2/www/webmaster fav.php on line 20 and this error: Warning: array_unique() [function.array-unique]: The argument should be an array in /mnt/w0210/d28/s25/b02a8bb2/www/webmaster fav.php on line 21 and this error: Warning: Cannot use a scalar value as an array in /mnt/w0210/d28/s25/b02a8bb2/www/webmaster fav.php on line 23 I am kindof new to php but i think its a good script and it works without errors when it isn't included on the homepage it works. what could be the problem? heres the code: <?php $directory = "/mnt/w0210/d28/s25/b02a8bb2/www/data/"; //the list of pages i want to be random on the site $directory = (!strstr($directory,"*") || $directory =="./" ) ? $directory."*" : $directory; //Checks if the wildcard operator is present, and if not it adds it by default at the end; $files = glob($directory); //Yes, it was that easy to get all the files; $size=sizeof($files); for($i=0;$i<sizeof($files) ; $i++){ //Loop through the files and adds to array; $fp = fopen($files[$i],"r"); $contents[$i]=fgets($fp,999); fclose($fp); } for($x=0;$x<15;$x++){ $numb[$x]=rand(1, sizeof($files)); } $x=count($numb)-count(array_unique($numb)); $num = array_unique ($numb); for($q=0;$x<15;$x++){ $numb[$x]=rand(1, sizeof($files)); } //$imploded = implode(" ", $contents); //get rid of spaces //$newcontent=explode("~", $imploded); // sort into chucks so i can display the data. for($i=0;$i<15; $i++){ $number=$num[$i]; if($contents[$number]==""||$contents[$number]==" "||$contents[$number]==null){ } else{ echo "<li>"; $replacedcontent=str_replace(' ', '-',$contents[$number]); echo "<br/><a href='games/$replacedcontent'>"; $newrcontent=str_replace('-', ' ',$replacedcontent); echo "<img src='$newrcontent.jpg' border='2'></img>"; echo "<br/>$newrcontent</a></li>"; } } ?> i copied and pasted it from many sites examples so thats why some comments are weird... but basically it gets all the data files. reads the title and puts them in an array, then chooses some random ones and puts them in with their image so they can be displayed on the homepage. I have a really weird problem. I'm trying to run a mysql query that works fine in phpmyadmin but in php script is giving me an error. The query is: Code: [Select] (SELECT DISTINCT art.`TEMPLATE`,gal.`ARTICLE_ID`,art.`TITLE`,art.`DESCRIPTION`,MATCH(art.`TITLE`,art.`DESCRIPTION`,gal.`CONTENT`) AGAINST ('WORD*' IN BOOLEAN MODE) AS score FROM articles art,galeries gal WHERE gal.`ARTICLE_ID`=art.`ARTICLE_ID` AND MATCH(art.`TITLE`,art.`DESCRIPTION`,gal.`CONTENT`) AGAINST ('WORD* ' IN BOOLEAN MODE)) UNION (SELECT DISTINCT `TEMPLATE`,`ARTICLE_ID`,`TITLE`,`DESCRIPTION`,MATCH(`TITLE`,`DESCRIPTION`,`CONTENT`) AGAINST ('WORD* ' IN BOOLEAN MODE) AS score FROM articles WHERE (MATCH(`TITLE`,`DESCRIPTION`,`CONTENT`) AGAINST ('WORD* ' IN BOOLEAN MODE))) ORDER BY score DESC LIMIT 0,30 Snipset from php script code: function search($start_row,$ammount,$search_key,$pages){ $start_row = intval($start_row) * $ammount; $return_val = ""; $symbols = array('/','\\','\'','"',',','.','<','>','?',';',':','[',']','{','}','|','=','+','-','_',')','(','*','&','^','%','$','#','@','!','~','`' );//this will remove punctuation $pattern = "#[^(\w|α|β|γ|δ|ε|ζ|η|θ|ι|κ|λ|μ|ν|ξ|ο|π|ρ|σ|τ|υ|φ|χ|ψ|ω|Α|Β|Γ|Δ|Ε|Ζ|Η|Θ|Ι|Κ|Λ|Μ|Ν|Ξ|Ο|Π|Ρ|Σ|Τ|Υ|Φ|Χ|Ψ|Ω|ς|ά|έ|ό|ί|ύ|ώ|ή|ϊ|ϋ|ΐ|ΰ|Ά|Έ|Ό|Ί|Ύ|Ώ|Ή|Ϊ|Ϋ|\d|\'|\"|\.|\!|\?|;|,|\\|\/|\-|:|\&|@)]+#"; $search_key = greek_text::to_upper($search_key); $wc = strip_tags($search_key); $wc = preg_replace($pattern, " ", $wc); for ($i = 0; $i < sizeof($symbols); $i++) { $wc = str_replace($symbols[$i],' ',$wc); } $wc = str_replace("΄", " ", $wc); $wc = str_replace(chr(162), " ", $wc); if( !$keep_numbers ) { $wc = preg_replace('#(^|\s+)[\d\s]+(\s+|$)#',' ',$wc); $pattern = '#(^|\s+)([0-9]+[a-zA-ZαβγδεζηθικλμνξοπρστυφχψωΑΒΓΔΕΖΗΘΙΚΛΜΝΞΟΠΡΣΤΥΦΧΨΩςάέόίύώήϊϋΐΰΆΈΌΊΎΏΉΪΫ]+\s*)+(\s+|$)#'; preg_match($pattern,$wc,$aa); $wc = preg_replace($pattern, " ", $wc); } $wc = trim(preg_replace("/\s\s+/", " ", $wc)); $wc = explode(" ", $wc); $cleaned_keyword = array_filter($wc); $cleaned_keyword = greek_text::removeStopWordsFromArray($cleaned_keyword); $stemmed_keywords = greek_text::stemWordsArray($cleaned_keyword); $query = "(SELECT DISTINCT art.`TEMPLATE`,gal.`ARTICLE_ID`,art.`TITLE`,art.`DESCRIPTION`,MATCH(art.`TITLE`,art.`DESCRIPTION`,gal.`CONTENT`) AGAINST ('"; while(list($key,$val)=each($stemmed_keywords)){ if($val<>" " and strlen($val) > 1){ $query .= $val."*"; $search_keys .= $val."* "; } } $query .= "' IN BOOLEAN MODE) AS score FROM articles art,galeries gal WHERE gal.`ARTICLE_ID`=art.`ARTICLE_ID` AND MATCH(art.`TITLE`,art.`DESCRIPTION`,gal.`CONTENT`) AGAINST ('".$search_keys."' IN BOOLEAN MODE))"; $query .= " UNION (SELECT DISTINCT `TEMPLATE`,`ARTICLE_ID`,`TITLE`,`DESCRIPTION`,MATCH(`TITLE`,`DESCRIPTION`,`CONTENT`) AGAINST ('".$search_keys."' IN BOOLEAN MODE) AS score FROM articles WHERE (MATCH(`TITLE`,`DESCRIPTION`,`CONTENT`) AGAINST ('".$search_keys."' IN BOOLEAN MODE))) ORDER BY score DESC LIMIT ".intval($start_row).",".$ammount; $rs = $this->dbActions->execQuery($query); $this->dbActions->execQuery("INSERT INTO searches (`KEY`,`DATE`,`RESULTS`) VALUES ('".$search_key."',NOW(),".$pages.")"); $search_results = "<div id='results'>"; while($row = mysql_fetch_array($rs)){ $search_results.= "<div id='result'>"; $search_results.= "<div class='result_title'><h4><a href='article.php?articleId=".$row["ARTICLE_ID"]."'>".$row['TITLE']."</a></h4></div>"; $search_results.= "<div class='result_description'>".$row['DESCRIPTION']."</div>"; $search_results.= "</div>"; $search_results.= "<div class='result_seperator'></div>"; } $search_results .= "</div>"; $return_val = $search_results; return $return_val; } dbactions class: require 'includes/errors.php'; error_reporting(0); class DBActions{ var $dbCon; var $errorHandler; function DBActions(){ $this->dbCon = $this->dbCon(); $errorHandler = new errors(1); } private function dbCon(){ require 'conf/configuration.php'; $dbcon = mysql_connect($dbUrl,$dbUser,$dbPass); if(!$dbcon)trigger_error("Unable to connect to database $dbUrl for user $dbUser",E_USER_ERROR); mysql_select_db($dbName); mysql_query("SET NAMES 'UTF8'"); mysql_query('set character set utf8'); return $dbcon; } function dbClose(){ if($this->dbCon) mysql_close($this->dbCon); } function execQuery($query){ $result = mysql_query($query,$this->dbCon); $msg = "Unable to execute query ".$query; if(mysql_num_rows($result) > 0) return $result; else if($result == false) trigger_error($msg,E_USER_ERROR); else return $result; } function send_error_mail(){ $this->errorHandler->sendErrorEmail(); } } I've try everything but can't get this working.. Any healp whould be really appreciated. Thanks in advance. I am moving my website to a new Service Provider. The script I use for multiple updating worked on the older server but not on the new one. It shows the information but does not update the records. Any help would be greatly appreciated. Old Server : PHP 5.2.11 MYSQL: 5.0.92-community New Server : PHP 5.2.17 MYSQL: 5.1.47-community Script: <?php include("head.php"); $host="localhost"; // Host name $username="xxxxxxx"; // Mysql username $password="xxxxxxx"; // Mysql password $db_name="xxxxxxx"; // Database name $tbl_name="xxxxxxx"; // Table name // Connect to server and select databse. mysql_connect("$host", "$username", "$password")or die("cannot connect"); mysql_select_db("$db_name")or die("cannot select DB"); $sql="SELECT * FROM $tbl_name limit 20"; $result=mysql_query($sql); // Count table rows $count=mysql_num_rows($result); ?> <title>PowerMan South Africa</title> <META HTTP-EQUIV="Pragma" CONTENT="no-cache"> <META HTTP-EQUIV="Expires" CONTENT="-1"> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <link rel="stylesheet" href="style.css" type="text/css" media="screen" /> <style type="text/css" media="screen,projection"> @import url(calendar.css); </style> </head> <table width="500" border="0" cellspacing="1" cellpadding="0"> <form name="form1" method="post" action=""> <tr> <td> <table width="500" border="0" cellspacing="1" cellpadding="0"> <tr> <td align="center"><strong>ID</strong></td> <td align="center"><strong>Company</strong></td> <td align="center"><strong>contact</strong></td> <td align="center"><strong>Email</strong></td> <td align="center"><strong>Telephone</strong></td> <td align="center"><strong>Type</strong></td> </tr> <?php while($rows=mysql_fetch_array($result)){ ?> <tr> <td align="center"><? $id[]=$rows['id']; ?><? echo $rows['id']; ?></td> <td align="center"><input name="company[]" type="text" id="company" value="<? echo $rows['company']; ?>"></td> <td align="center"><input name="contact[]" type="text" id="contact" value="<? echo $rows['contact']; ?>"></td> <td align="center"><input name="email[]" type="text" id="email" value="<? echo $rows['email']; ?>"></td> <td align="center"><input name="telephone[]" type="text" id="telephone" value="<? echo $rows['telephone']; ?>"></td> <td align="center"><input name="type[]" type="text" id="type" value="<? echo $rows['type']; ?>"></td> </tr> <?php } ?> <tr> <td colspan="4" align="center"><input type="submit" name="Submit" value="Submit"></td> </tr> </table> </td> </tr> </form> </table> <?php // Check if button name "Submit" is active, do this if($Submit){ for($i=0;$i<$count;$i++){ $sql1="UPDATE $tbl_name SET company='$company[$i]', contact='$contact[$i]', email='$email[$i]',type='$type[$i]', telephone='$telephone[$i]' WHERE id='$id[$i]'"; $result1=mysql_query($sql1); } } if($result1){ header("location:update_multiple.php"); echo "<meta http-equiv=Refresh content=0;url=update_multiple.php>"; } mysql_close(); ?> Good Afternoon Team, Am sitting with something simple using the language below. If I copy the echo output of my query as included below it works perfectly in phpmyadmin but doesn't work on a website. Variables all seem to echo consistently/correctly and POST checks seem to verify this is working correctly as well. I worry the error comes with the syntax I used in combining the sql queries. That, or perhaps LAST_INSERT_ID does not work in the php script as well as it does in phpmyadmin. All help appreciated.
if(isset($_POST[`region_id`])) {
Hey guys,
I'm using the following pagination script from a website I found. I'ts basically a pagination script that takes data from a MySQL database and displays a certain number of sets before placing the next set on a new page.
This script works great if I substitute a static value for the data I want returned but If the request is stored in a $POST variable like from an HTML form the data refuses to paginate. It will render the first set of data but will not paginate the rest and only shows blank pages
I'm thinking it has something to do with the $POST variable not being set or carrying over to each page but I'm not sure.
I truly appreciate the help!
<?php /* Place code to connect to your DB here. */ include('config.php'); // include your code to connect to DB. $tbl_name=""; //your table name // How many adjacent pages should be shown on each side? $adjacents = 3; /* First get total number of rows in data table. If you have a WHERE clause in your query, make sure you mirror it here. */ $query = "SELECT COUNT(*) as num FROM $tbl_name"; $total_pages = mysql_fetch_array(mysql_query($query)); $total_pages = $total_pages[num]; /* Setup vars for query. */ $targetpage = "filename.php"; //your file name (the name of this file) $limit = 2; //how many items to show per page $page = $_GET['page']; if($page) $start = ($page - 1) * $limit; //first item to display on this page else $start = 0; //if no page var is given, set start to 0 /* Get data. */ $sql = "SELECT column_name FROM $tbl_name LIMIT $start, $limit"; $result = mysql_query($sql); /* Setup page vars for display. */ if ($page == 0) $page = 1; //if no page var is given, default to 1. $prev = $page - 1; //previous page is page - 1 $next = $page + 1; //next page is page + 1 $lastpage = ceil($total_pages/$limit); //lastpage is = total pages / items per page, rounded up. $lpm1 = $lastpage - 1; //last page minus 1 /* Now we apply our rules and draw the pagination object. We're actually saving the code to a variable in case we want to draw it more than once. */ $pagination = ""; if($lastpage > 1) { $pagination .= "<div class=\"pagination\">"; //previous button if ($page > 1) $pagination.= "<a href=\"$targetpage?page=$prev\">� previous</a>"; else $pagination.= "<span class=\"disabled\">� previous</span>"; //pages if ($lastpage < 7 + ($adjacents * 2)) //not enough pages to bother breaking it up { for ($counter = 1; $counter <= $lastpage; $counter++) { if ($counter == $page) $pagination.= "<span class=\"current\">$counter</span>"; else $pagination.= "<a href=\"$targetpage?page=$counter\">$counter</a>"; } } elseif($lastpage > 5 + ($adjacents * 2)) //enough pages to hide some { //close to beginning; only hide later pages if($page < 1 + ($adjacents * 2)) { for ($counter = 1; $counter < 4 + ($adjacents * 2); $counter++) { if ($counter == $page) $pagination.= "<span class=\"current\">$counter</span>"; else $pagination.= "<a href=\"$targetpage?page=$counter\">$counter</a>"; } $pagination.= "..."; $pagination.= "<a href=\"$targetpage?page=$lpm1\">$lpm1</a>"; $pagination.= "<a href=\"$targetpage?page=$lastpage\">$lastpage</a>"; } //in middle; hide some front and some back elseif($lastpage - ($adjacents * 2) > $page && $page > ($adjacents * 2)) { $pagination.= "<a href=\"$targetpage?page=1\">1</a>"; $pagination.= "<a href=\"$targetpage?page=2\">2</a>"; $pagination.= "..."; for ($counter = $page - $adjacents; $counter <= $page + $adjacents; $counter++) { if ($counter == $page) $pagination.= "<span class=\"current\">$counter</span>"; else $pagination.= "<a href=\"$targetpage?page=$counter\">$counter</a>"; } $pagination.= "..."; $pagination.= "<a href=\"$targetpage?page=$lpm1\">$lpm1</a>"; $pagination.= "<a href=\"$targetpage?page=$lastpage\">$lastpage</a>"; } //close to end; only hide early pages else { $pagination.= "<a href=\"$targetpage?page=1\">1</a>"; $pagination.= "<a href=\"$targetpage?page=2\">2</a>"; $pagination.= "..."; for ($counter = $lastpage - (2 + ($adjacents * 2)); $counter <= $lastpage; $counter++) { if ($counter == $page) $pagination.= "<span class=\"current\">$counter</span>"; else $pagination.= "<a href=\"$targetpage?page=$counter\">$counter</a>"; } } } //next button if ($page < $counter - 1) $pagination.= "<a href=\"$targetpage?page=$next\">next �</a>"; else $pagination.= "<span class=\"disabled\">next �</span>"; $pagination.= "</div>\n"; } ?> <?php while($row = mysql_fetch_array($result)) { // Your while loop here } ?> <?=$pagination?> Hello, The following is my situation where I seem to get a 500 error code from the linux server: i have an 'index' file like this: Code: [Select] <?php require("includes/config.php"); $a = $_REQUEST['a']; switch ($a) { case "home": include("frontpage/main.php"); case "user-process": include("user-process.php"); } ?> config.php is something like this: Code: [Select] <?php require(includes/classes/session.class.php); require(includes/classes/user.class.php); require(includes/classes/db.class.php); ... ?> Now if we fall into the case "home" it works fine. Instead, if we fall into user-process it writes to the logs file Fatal Error: Class User does not exist bla bla bla. Why doesn't it exist ? every class is included in the config.php file then index.php includes first config.php ( which has all the classes) and then includes the requested page. I also have a .htaccess file which is as follows: Code: [Select] RewriteEngine On RewriteRule ^([^/\.]+)?/?([^/\.]+)?/?([^/\.]+)?/?([^/\.]+)?/?([^/\.]+)?/?([^/\.]+)?/?([^/\.]+)?$ index.php?a=$1&b=$2&c=$3&d=$4&e=$5&f=$6&g=$7 [NC,L] which is used to access in a SEO friendly way the pages that users request. So this script did work in previous versions oh php but in php5 I get the error, "Sorry, uploaded images must be of type jpg or jpeg, (not )." So it looks like it's not recognizing my file as a jpeg?? Any contributions towards a fix are GREATLY appreciated!!! If there are clean, nice (EASY) php5 scripts available for this simple image uploading and thumbnail creation I would consider starting this over. //Listing page code: echo "<form name=\"addCat\" enctype=\"multipart/form-data\" action=\"preview.php\" method=\"post\">"; <INPUT type="file" name="pic1" size="50" value=""> <INPUT type="file" name="pic2" size="50" value=""> <INPUT type="file" name="pic3" size="50" value=""> <INPUT type="file" name="pic4" size="50" value=""> <input type="submit" value="Upload Images"> //preview.php page code: $pic1 = $_FILES['pic1']; $pic2 = $_FILES['pic2']; $pic3 = $_FILES['pic3']; $pic4 = $_FILES['pic4']; function ResizeImage($im,$maxwidth,$maxheight,$name){ $width = imagesx($im); $height = imagesy($im); if(($maxwidth && $width > $maxwidth) || ($maxheight && $height > $maxheight)){ if($maxwidth && $width > $maxwidth){ $widthratio = $maxwidth/$width; $RESIZEWIDTH=true; } if($maxheight && $height > $maxheight){ $heightratio = $maxheight/$height; $RESIZEHEIGHT=true; } if($RESIZEWIDTH && $RESIZEHEIGHT){ if($widthratio < $heightratio){ $ratio = $widthratio; }else{ $ratio = $heightratio; } }elseif($RESIZEWIDTH){ $ratio = $widthratio; }elseif($RESIZEHEIGHT){ $ratio = $heightratio; } $newwidth = $width * $ratio; $newheight = $height * $ratio; if(function_exists("imagecopyresampled")){ $newim = imagecreatetruecolor($newwidth, $newheight); imagecopyresampled($newim, $im, 0, 0, 0, 0, $newwidth, $newheight, $width, $height); }else{ $newim = imagecreate($newwidth, $newheight); imagecopyresized($newim, $im, 0, 0, 0, 0, $newwidth, $newheight, $width, $height); } ImageJpeg (($newim),$name . ".jpg"); ImageDestroy ($newim); }else{ ImageJpeg ($im,$name . ".jpg"); } } // Set up some variables flush(); set_time_limit(210); // set process page limit to 3.5 minutes $maxfilesize = "102400"; //# individual file size limit - in bytes (102400 bytes = 100KB) $path="2012images"; $thumbpath="thumbs"; // two data pulls to rename images - would be easier to have a permanent counter...fix later $mysql[getpicname] = mysql_query("select pic from picname"); $z = mysql_fetch_array($mysql[getpicname]); $new_filename=$z[pic]; $new_z[pic]=$z[pic]+$total_pics; if(@mysql_query("UPDATE picname SET pic = '$new_z[pic]' ")) echo ""; // Create thumbnail from imgurl and store in thumbs // Height to reszie image to (in pixels) $RESIZEHEIGHT=200; // Width to reszie image to (in pixels) $RESIZEWIDTH=200; //thumbnail to thumbs folder, named same as 1st image $FILENAME=$thumbpath."/".$new_filename; $thumb_name=$thumbpath."/".$new_filename.".jpg"; // create a thumbnail from the first image only $im = imagecreatefromjpeg($_FILES['pic1']['tmp_name']); if($im) { if(file_exists("$pic_1.jpg")) { unlink("$pic_1.jpg"); } if (ResizeImage($im,$RESIZEWIDTH,$RESIZEHEIGHT,$FILENAME)) ImageDestroy ($im); } //now upload the images..... for ($i=1;$i<5;$i++) { //check if blank or image $xpic="pic".$i; if (($$xpic<>"none") and ($$xpic<>"")) { // check if jpg $cert1 = "image/pjpeg"; //jpg $cert2 = "image/jpeg"; //jpg (for MAC) $xtype =$HTTP_POST_FILES[$xpic]['type']; $xsize =$HTTP_POST_FILES[$xpic]['size']; if (($xtype <> $cert1) AND ($xtype <> $cert2)) { echo "<DIV class=\"errorsubheading\"><br><br>Alert - Missing or Invalid Information</DIV><br>"; echo "<DIV class=\"requiredtext\">Sorry, uploaded images must be of type jpg or jpeg, (not $xtype).</DIV><BR>"; echo "<BR><br><br>"; include ("footer.php"); exit(); } if ($xsize > $maxfilesize) { echo "<DIV class=\"errorsubheading\"><br><br>Alert - Missing or Invalid Information</DIV><br>"; echo "<DIV class=\"requiredtext\">Sorry, uploaded images must be under the maximum size requirements.</DIV><BR>"; echo "<BR><br><br>"; include ("footer.php"); exit(); } else { // upload to server $dest=$path."/".$new_filename.".jpg"; If (move_uploaded_file($$xpic, $dest)) { $photo[$i]=$dest; $new_filename+=1; } else { echo "<DIV class=\"errorsubheading\"><br><br>Alert - Upload Failed!</DIV><br>"; echo "<BR><br><br>"; include ("footer.php"); exit(); } // upload sucessful } // end type check } // end check if blank } hi i have the script below which copies data from one table to another but will only insert new data update current data or delete old data from tempproducts to products then it will delete the tempproducts from the db however i keep getting this error: Warning: mssql_query() [function.mssql-query]: Query failed in E:\UpdateProducts.php on line 33 updateproducts.php Code: [Select] <?php include('../../otherscripts/functions.php'); $log = new Logging(); // create DB connection $host = "localhost"; $user = "user"; $pass = "pass"; $mydb = "db"; $db = mssql_connect($host,$user,$pass); //Select Database mssql_select_db($mydb); // delete all old data $sql0 = "SELECT * FROM tempproduct"; $sql1 = "INSERT INTO products SELECT * FROM tempproduct WHERE manf_part_no NOT IN (SELECT manf_part_no FROM products) AND supp_id NOT IN (SELECT supp_id FROM products)"; $sql2 = "DELETE FROM products WHERE manf_part_no NOT IN (SELECT manf_part_no FROM tempproduct) AND supp_id NOT IN (SELECT supp_id FROM tempproduct)"; $sql3 = "UPDATE p1 SET p1.avail_qty = t1.avail_qty, p1.cost_price = t1.cost_price, p1.rrp = t1.rrp, p1.date_added = t1.date_added, p1.description = t1.description FROM Products p1 INNER JOIN tempproduct t1 ON (p1.manf_part_no = t1.manf_part_no AND p1.supp_id = t1.supp_id)"; $sql4 = "TRUNCATE TABLE tempproduct"; //If tempproduct is empty done Execute Commands if it is full then execute commands $query = mssql_query($sql0) or die($log->lwrite('Failed to select for count from db')); $rowcount = mssql_num_rows($query); if($rowcount == 0){ $log->lwrite('Teh tempproduct am emptyish'); } else{ mssql_query($sql1) or die($log->lwrite('Failed to insert to db'.$sql1)); mssql_query($sql2) or die($log->lwrite('Failed to Delete from db')); mssql_query($sql3) or die($log->lwrite('Failed to Update db')); mssql_query($sql4) or die ($log->lwrite('Failed to TRUNCATE db')); } ?> if i run $sql1 command in the sql manager it runs fine and no errors occur? Hello,
I want to create and display school time table like
timetable.jpg 45.66KB
2 downloads
I have created my database like this
CREATE TABLE IF NOT EXISTS `time_table` ( `id` int(10) NOT NULL AUTO_INCREMENT, `class` varchar(20) NOT NULL, `section` varchar(10) NOT NULL, `subject` varchar(20) NOT NULL, `teacher` varchar(30) NOT NULL, `monday` varchar(10) NOT NULL, `tuesday` varchar(10) NOT NULL, `wednsday` varchar(10) NOT NULL, `thursday` varchar(10) NOT NULL, `friday` varchar(10) NOT NULL, `saturday` varchar(10) NOT NULL, PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;Columns' Monday', 'Tuesday' will store starting hour of a period But i don't know how to display it as above format. I even do not know whether i am using proper format of table. Somebody please suggest me how can i create this time table Hello house, I am new to coding, I have a project about generating school terminal results and using pin to check results in codeigniter framework. Any help will be appreciated. Thanks
Hi guys and girls im a new guy on this forums and im here to beg for a favor, for my school assignment i have to make a simple php script and i have no idea how to do that so, here i am what i need is basically a video store rental application that store staff would use. Nothing fancy just that it works. We also got sakila-db to work with and use witch is 30% of my problem if a got to make my own db i would not be quite as confused right now. Can any1 help me because im starting to panic. i apologize if i posted in the wrong place. im including small dijagram of how this thing is supposed to look any help would be appreciated. [attachment deleted by admin] Hello, I'm a cs student (2nd year) this year has been a disaster for us the students(studying over zoom and shit), I have a tiny tiny project that a have to finish in the next 24 hours, we made a small sample website using html and js, and now we need to switch it to php language and make the site responsive and later on add SQL. I would very much appreciate if someone can help me for couple of minutes over zoom and help me complete it. All I have left is echo the products from an array with a loop and make a php table that will put my items to my cart. It's my first time here..hope there is some good people here Edited July 21, 2020 by requinixadded thread title err, dunno if i managed to put it in the right thread but if i didn't, please tell me. thank you.
getting back on topic, my father asked me to create a website for a school. i know how to make a website but the problem is, how do i start? should i ask about their objectives or something? color of the webpage etc? in short, i don't know the practicalities and processes used in making a website for a certain client. you could say this would be my first time in doing this (kind of like an on-the-job training) so...any ideas? i would very much appreciate any help given.
|