PHP - Script Works Fine Alone, But Not When Included - What Could Be The Cause?
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? Similar TutorialsI 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. 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? Code: [Select] <?php $objConnect = mysql_connect("localhost","","cgdfgdfg") or die(mysql_error()); $objDB = mysql_select_db("ffdfvbbd"); $pic2 = "SELECT * FROM images"; if (!isset($_GET['Page'])) $_GET['Page']='0'; $pic1 = mysql_query($pic2); $Num_Rows = mysql_num_rows($pic1); $Per_Page = 16; // Per Page $Page = $_GET["Page"]; if(!$_GET["Page"]) {$Page=1;} $Prev_Page = $Page-1; $Next_Page = $Page+1; $Page_Start = (($Per_Page*$Page)-$Per_Page); if($Num_Rows<=$Per_Page) {$Num_Pages =1;} else if(($Num_Rows % $Per_Page)==0) {$Num_Pages =($Num_Rows/$Per_Page) ;} else {$Num_Pages =($Num_Rows/$Per_Page)+1; $Num_Pages = (int)$Num_Pages;} $pic2 .="ORDER by thumbnailID DESC LIMIT $Page_Start , $Per_Page" ; $pic1 = mysql_query($pic2); $cell = 0; $link1 = "SELECT * FROM images"; echo ' <div id="tablediv"> <table border="0" cellpadding="17" cellspacing="0" class="table"> <tr>'; while($pic = mysql_fetch_array($pic1)) { if($cell % 4 == 0) { echo '</tr><tr>'; } if($cell == 2) { echo ' <td> filler </td>'; } elseif ($cell == 3) { echo ' <td> filler </td>'; } else { echo ' <td> <a href="/' . $pic["link"] . '.php"> <div class="image"> <img src="https://s3.amazonaws.com/images/' . $pic["pic"] . '.png" alt="' . $pic["alt"] . '" height="200" width="200" /> </div> </a> </td>'; } $cell++; } echo '</tr></table></div>'; ?>The code above works just fine. However, once I add a WHERE function,as shown below, I get a "Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource" error. Code: [Select] <?php $objConnect = mysql_connect("localhost","","cgdfgdfg") or die(mysql_error()); $objDB = mysql_select_db("ffdfvbbd"); $pic2 = "SELECT * FROM images WHERE folder = 'blog' "; //WHERE FUNCTION IS HERE if (!isset($_GET['Page'])) $_GET['Page']='0'; $pic1 = mysql_query($pic2); $Num_Rows = mysql_num_rows($pic1); $Per_Page = 16; // Per Page $Page = $_GET["Page"]; if(!$_GET["Page"]) {$Page=1;} $Prev_Page = $Page-1; $Next_Page = $Page+1; $Page_Start = (($Per_Page*$Page)-$Per_Page); if($Num_Rows<=$Per_Page) {$Num_Pages =1;} else if(($Num_Rows % $Per_Page)==0) {$Num_Pages =($Num_Rows/$Per_Page) ;} else {$Num_Pages =($Num_Rows/$Per_Page)+1; $Num_Pages = (int)$Num_Pages;} $pic2 .="ORDER by thumbnailID DESC LIMIT $Page_Start , $Per_Page" ; $pic1 = mysql_query($pic2); My mysql table includes column thumbnailID folder link pic alt time The folder column is there so I can specify what I want in the page. Anyhow, why won't it work? Hello everyone, I'm having this problem which is really annoying, tried to solve it but couldn't, I write that code in PHPMyAdmin and it works great, but it doesn't work in the website it self ok long story short, there are three tables, hotels, cities, countries hotels include in addition to hotel info, 2 columns (city_id) and (country_id) Cities include id and name and also countries include id and name what I was trying to do, that when a person inputs a city or country name in the search form, it should get the hotels that exists in this city or country, but unfortunately it shows all the hotels in all cities and countries, although the pagination code for number of pages works just fine, it count the number of hotels in that city or country and show the number of pages correctly so here is the code for both for hotel search Code: [Select] class hotelManager { public function getHotel($where) { $where = isset($_POST['where']) ? $_POST['where'] : ""; $dbObj = new DB(); $sql = "select * from hotels where city_id = (select id from cities where name = '$where' ) or country_id = (select id from countries where name = '$where' )"; $result = MYSQL_QUERY($sql); $arr = array(); echo "<table>"; while($row = mysql_fetch_array($result)) { echo "<tr>"; echo "<td valign=\"top\" width=\"120px\">"; $rowid = $row['id']; $imageqry=mysql_query("SELECT * FROM `hotelphotos` where hotel_id='$rowid' LIMIT 1"); $image=mysql_fetch_array($imageqry); $imagename=$image['attachmentName']; echo "<img src=\"foxmaincms/webroot/files/small/$imagename\"/>"; echo "</td>"; echo "<td valign=\"top\">"; echo "<table> <tr> <td valign=\"top\"> <a href=\"hotels.php?id=".$row['id']."\" class=\"titleslink\">".$row['name']."</a> </td> </tr> <tr> <td class=\"text\" valign=\"top\"> ".$row['location']." </td> </tr> </table>"; echo "</td>"; echo "</tr>"; } echo "</table>"; for hotel pagination Code: [Select] <?php include("includes/hotelsManager.php"); $hotelObj = new hotelManager(); $where = isset($_POST['where']) ? $_POST['where'] : ""; if(isset($_POST['where'])) { $hotelObj -> getHotel($where); $per_page = 9; //Calculating no of pages $sql = "select * from hotels where city_id = (select id from cities where name = '$where' ) or country_id = (select id from countries where name = '$where' )"; $result = MYSQL_QUERY($sql) or die("<br />No Hotels found in this city, please check the city name and try again"); $count = mysql_num_rows($result); $pages = ceil($count/$per_page) ?> <div id="loading" ></div> <div id="maincontent" ></div> <ul id="pagination"> thank you in advance Good day dear community. I need to build a function which parses the domain from a url. I have used various ways to parse html sources. But this one is is a bit tricky! See the target i want to parse - it has some invaild Markup: http://www.schulministerium.nrw.de/BP/SchuleSuchen?action=644.0013008534253&SchulAdresseMapDO=194190 well what do you think - can i apply this code here <?php require_once('config.php'); // call config.php for db connection $filename = "url.txt"; // Include the txt file which have urls $each_line = file($filename); foreach($each_line as $line_num => $line) { $line = trim($line); $content = file_get_contents($line); //echo ($content)."<br>"; $pattern = '/<td>(.*?)<\/td>/si'; preg_match_all($pattern,$content,$matches); foreach ($matches[1] as $match) { $match = strip_tags($match); $match = trim($match); //var_dump($match); $sql = mysqli_query("insert into tablename(contents) values ('$match')"); //echo $match; } } ?> well i have to rework the parser-part of this script. I need to parse somway different - since i have other site here. Can anybody help me here to get a better regex - or a better way to parse this site ... Any and all help will be greatly apprecaited. regards db1 FOR the CMS go to http://sandeepthapa.com.np/project/admin and login in username: user pasword: 123456 with both Chrome and IE. pleease and site is http://sandeepthapa.com.np/project/ it works fine with Chrome, but not with IE. please help me this is my first CMS . i am learning.. it i use joommla templetefor design. oz i am not a designer //..here is the code for process_login.php page <?php require_once("includes/session.php"); ?><?php require_once("includes/connection.php"); ?><?php require_once("includes/functions.php"); ?><?php if (logged_in()) { redirect_to("content.php"); } if (isset($_POST['submit'])) { if(!$_POST['username']) { echo ' Make sure u type in username'; } if( !$_POST['password']) { echo 'make sure you type password'; } $username = trim(mysql_prep($_POST['username'])); $password = trim(mysql_prep($_POST['password'])); $hashed_password = sha1($password); // Check database to see if username and the hashed password exist there. $query = "SELECT id, username "; $query .= "FROM users "; $query .= "WHERE username = '{$username}' "; //$query .= "AND hashed_password = '{$hashed_password}' "; $query .= "AND hashed_password = '{$hashed_password}' "; $query .= "LIMIT 1"; $result_set = mysql_query($query) or die(mysql_error()); if(!$result_set) {die("Database connection failed: " . mysql_error());} confirm_query($result_set); if (mysql_num_rows($result_set) == 1) { // username/password authenticated // and only 1 match $found_user = mysql_fetch_array($result_set); //echo $found_user['id']; $_SESSION['user_id'] = $found_user['id']; $_SESSION['username'] = $found_user['username']; //echo 'test query'; redirect_to("content.php"); } } else { echo 'error'.mysql_error(); } ?> </body> </html> I am having a very difficult time working out what to look at next. I have a page and it will not fopen a new file or an existing one to write. Even though I have a couple of other pages that copy into the same location without trouble. My PHP is 5.2.13 on W2k3 IIS. Here is the code that works; copy($myDir.$file, "\\\\Eeyore\\TempEDI\\".$file); Here is the code that fails; $fileN = "\\\\Eeyore\\TempEDI\\alley.txt"; $fh1 = fopen($fileN, 'wb'); I have tried with and without the new file already existing. I have checked NTFS permissions and the Share permissions. The webserver in use is remote to the files. I have turned on File level object access auditing on the Eeyore server (also win2k3) and the fopen call does not even hit the Eeyore server, I can see all other access to the file and folder but nothing from the page in question. Safe_mode and Opendirbase are both unset in php.ini. All I want to do is make a text file and add some lines of text, this problem is absolutely infuriating. Hi all, I wonder if any of you have this problem before.. I have a login page with "checked box remember me" - It is working fine in my localhost machine I can see the COOKIE in my browser's option setting (Firefox). But now the problem is: When I run the script in my test server; and do exactly the same thing..the COOKIE did not seem know. When I logged in as an admin and checked the box. And closed all the browser. Then, open the browser (Firefox)and go to the index page (landing page) then it redirect me to the login page instead. I looked the at COOKIE setting in my Firefox and I can it is stored there. Any ideas whats wrong? I have strange problem with SOAP. My file SchoolAPI look like that: <?php require_once('../require/constants.php'); require_once('../require/connection.inc.php'); class SchoolAPI{ private $dbh; public function __construct() { $this->dbh = new PDO(DRIVER.':host='.HOST.';dbname='.DB, USER, PASSWORD); } //function return all subcjects public function getSubjects(){ $sth = $this->dbh->prepare(' SELECT id, nazwa ROM subjects'); $sth->execute(); return $sth->fetchAll(PDO::FETCH_NUM); //return array(array("1", "subject1"),array("2", "subject2")); } //function return all classes public function getClasses(){ $sth = $this->dbh->prepare(' SELECT id, nazwa FROM classes'); $sth->execute(); return $sth->fetchAll(PDO::FETCH_NUM); //return array(array("1", "class1"),array("2", "class2")); } } ini_set("soap.wsdl_cache_enabled", "0"); $server = new SoapServer("SchoolAPI.wsdl"); $server->setClass("SchoolAPI"); $server->handle(); ?> wsdl file is named SchoolAPI.wsdl and look like that: <wsdl:definitions xmlns="http://schemas.xmlsoap.org/wsdl/" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:tns="http://schema.example.com" targetNamespace="http://schema.example.com" > <wsdl:types> <xsd:schema targetNamespace="http://schema.example.com"> <xsd:complexType name="myarry2"> <xsd:sequence> <xsd:element minOccurs="0" maxOccurs="unbounded" name="row" nillable="true" type="xsd:string" /> </xsd:sequence> </xsd:complexType> </xsd:schema> <xsd:schema targetNamespace="http://schema.example.com"> <xsd:complexType name="myarray"> <xsd:sequence> <xsd:element minOccurs="0" maxOccurs="unbounded" name="table" nillable="true" type="tns:myarry2" /> </xsd:sequence> </xsd:complexType> </xsd:schema> </wsdl:types> <wsdl:message name="getSubjectsRequest"></wsdl:message> <wsdl:message name="getSubjectsResponse"> <part name="getSubjectsReturn" type="tns:myarray"/> </wsdl:message> <wsdl:message name="getClassesRequest"></wsdl:message> <wsdl:message name="getClassesResponse"> <part name="getClassesReturn" type="tns:myarray"/> </wsdl:message> <wsdl:portType name="SchoolAPIPortType"> <wsdl:operation name="getSubjects"> <wsdl:input message="tns:getSubjectsRequest"/> <wsdl:output message="tns:getSubjectsResponse"/> </wsdl:operation> <wsdl:operation name="getClasses"> <wsdl:input message="tns:getClassesRequest"/> <wsdl:output message="tns:getClassesResponse"/> </wsdl:operation> </wsdl:portType> <wsdl:binding name="SchoolAPIBinding" type="tns:SchoolAPIPortType"> <soap:binding transport="http://schemas.xmlsoap.org/soap/http"/> <wsdl:operation name="getSubjects"> <soap:operation soapAction="urn:SchoolAPI/getSubjects" style="document"/> <wsdl:input> <soap:body use="literal"/></wsdl:input> <wsdl:output><soap:body use="literal"/></wsdl:output> </wsdl:operation> <wsdl:operation name="getClasses"> <soap:operation soapAction="urn:SchoolAPI/getClasses" style="document"/> <wsdl:input> <soap:body use="literal"/></wsdl:input> <wsdl:output><soap:body use="literal"/></wsdl:output> </wsdl:operation> </wsdl:binding> <wsdl:service name="SchoolAPI"> <wsdl:port name="SchoolAPIPort" binding="tns:SchoolAPIBinding"> <soap:address location="http://localhost:82/myschool/webservices/SchoolAPI.php" /> </wsdl:port> </wsdl:service> </wsdl:definitions> The problem is that correct data is returned olny by first function declarated in <wsdl:binding> section. In this example correct data will be return by getSubjects function, and function getClassses return null. However, if we change order and put getClasses operation first in binding section like this: <wsdl:binding name="SchoolAPIBinding" type="tns:SchoolAPIPortType"> <soap:binding transport="http://schemas.xmlsoap.org/soap/http"/> <wsdl:operation name="getClasses"> <soap:operation soapAction="urn:SchoolAPI/getClasses" style="document"/> <wsdl:input> <soap:body use="literal"/></wsdl:input> <wsdl:output><soap:body use="literal"/></wsdl:output> </wsdl:operation> <wsdl:operation name="getSubjects"> <soap:operation soapAction="urn:SchoolAPI/getSubjects" style="document"/> <wsdl:input> <soap:body use="literal"/></wsdl:input> <wsdl:output><soap:body use="literal"/></wsdl:output> </wsdl:operation> </wsdl:binding> then correct data will be return by getClasses function, and getSubjects will return null. Do you know what is going on? I do my best to solve this problem and I have no idea what is wrong... Hi, Im in trouble with a script. Mainly the problem is that the declared value is not reachable. lets sai i have main.php file where i declare that $user_id = '22'; and then i include a file that needs to get that value to work include('somescript.php'); now when i go over to the somescript.php i write at the top that print $user_id; and i get nothing. What am i doing wrong? I have the following php code that errors as indicated: $query = $con->query('SELECT FILENAME, country, area, city FROM download WHERE FILENAME is not null'); Fatal error: Uncaught PDOException: SQLSTATE[42S22]: Column not found: 1054 Unknown column 'country' in 'field list' in /home/larry/web/test/public_html/report1.php:47 Stack trace: #0 /home/larry/web/test/public_html/report1.php(47): PDO->query('SELECT FILENAME...') #1 {main} thrown in /home/larry/web/test/public_html/report1.php on line 47 The Select statement doesn't error when run in mysql shell or phpmyadmin. Here's the result of show create table download: localhost/test/download/ http://localhost/phpmyadmin/tbl_sql.php?db=test&table=download&token=5739c407033be3e118287bc7a9041c2c Current selection does not contain a unique column. Grid edit, checkbox, Edit, Copy and Delete features are not available. Your SQL query has been executed successfully. show create table download download CREATE TABLE `download` ( `ID` int(5) NOT NULL AUTO_INCREMENT, `LOG_TIME` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP, `IP_ADDRESS` int(64) unsigned NOT NULL, `FILENAME` varchar(50) COLLATE utf8_general_mysql500_ci DEFAULT NULL, `country` varchar(50) COLLATE utf8_general_mysql500_ci DEFAULT NULL, `area` varchar(50) COLLATE utf8_general_mysql500_ci DEFAULT NULL, `city` varchar(50) COLLATE utf8_general_mysql500_ci DEFAULT NULL, PRIMARY KEY (`ID`), UNIQUE KEY `ID` (`ID`) ) ENGINE=InnoDB AUTO_INCREMENT=1266 DEFAULT CHARSET=utf8 COLLATE=utf8_general_mysql500_ci Does anyone have an idea why this is happening? I have been using this script for years. I realise it is a little old and probably not well written, however it has been functional. I suspect the problem is that maybe they have turned the register_globals off at the server and the script is no longer working. I don't know if that is the problem. The error I get when I attempt to upload an image is this: Error: MySQL error reported! Query: INSERT INTO photos values(NULL,'corrobex', 1, 10, , 'makinti', '', '', 'makinti.jpg', 571, 381, 42520, '0', 0, 0, 0, '1', , '0', 'no', '', '', '', '', '') Result: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ' 'makinti', '', '', 'makinti.jpg', 571, 381, 42520, '0', 0, 0, 0, '1', , '0', 'n' at line 1 Database handle: Resource id #3 Now here is the script: Code: [Select] <?php include("pp-inc.php"); include("login-inc.php"); include("image-inc.php"); if ( is_array($HTTP_POST_FILES) ) { while(list($key,$value) = each($HTTP_POST_FILES)) { ${$key} = $value; } } function handleupload( $location = "data" ) { global $HTTP_POST_FILES, $userid, $Globals, $category; $tmpname = $HTTP_POST_FILES['theimage']['tmp_name']; $realname = $HTTP_POST_FILES['theimage']['name']; $tmpcloseup = $HTTP_POST_FILES['closeup']['tmp_name']; if (is_uploaded_file($tmpname) ) { $realname = fixfilenames( $realname ); $closeup = preg_replace("/(\.[A-Za-z]+)$/", "-closeup\\1", $realname); if ( $location != "data" ) { $dst_file = $location; } else { $dst_file = $Globals{'datafull'}."$category/$userid$realname"; $closeup_file = $Globals{'datafull'}."$category/$userid$closeup"; } copy($tmpname, $dst_file); copy($tmpcloseup, $closeup_file); } else { dieWell("Uploaded file not found: $realname<br>Typical reason is that the file exceeded allowed limits."); exit; } return; } authenticate(); $nolimit = 0; if ( $Globals{'adminnolimit'} == "yes" && $adminedit == 1 ) { $nolimit = 1; } $adminexclude = 0; if ( $Globals{'adminexclude'} == "yes" && $adminedit == 1 ) { $adminexclude = 1; } if ( $adminedit == 0 ) { if ( $Globals{'allowup'} == "no" ) { dieWell( "User uploads not allowed" ); } } $querystring = findenv("QUERY_STRING"); if ( ($useruploads == 0 && $gologin==1) || $querystring == "gologin" ) { $furl=$Globals{'maindir'}; $furl= str_replace( $Globals{'domain'}, "", $furl ); $furl="$furl/uploadphoto.php"; login( $furl ); exit; } if ( $gologin != 0 ) { if ( $useruploads == 0 ) { dieWell("Sorry, you don't have permission to upload photos."); exit; } } topmenu(); if ( !isset($theimage) ) { $catdefault = ""; if ( !empty($cat) ) { $query = "SELECT id,catname,thumbs FROM categories WHERE id=$cat LIMIT 1"; $resultb = ppmysql_query($query,$link); while ( list( $subid, $subcatname, $subthumbs ) = mysql_fetch_row($resultb) ) { if ( $ugcat{$subid} != 1 ) { $catdefault = "<option selected value=\"$subid\">$subcatname</option>"; } } ppmysql_free_result( $resultb ); } $header = str_replace( "titlereplace", "Upload Photo", $header ); $output = "$header<center><p> <table cellpadding=\"0\" cellspacing=\"0\" border=\"0\" height=\"40\" width=\"".$Globals{'tablewidth'}."\"><Tr> <Td valign=\"middle\" width=\"50%\">$menu2</td> <td width=\"50%\" align=\"right\" valign=\"middle\">$menu</td></tr></table> <table cellpadding=\"0\" cellspacing=\"0\" border=\"0\" bgcolor=\"".$Globals{'bordercolor'}."\" width=\"".$Globals{'tablewidth'}."\" align=\"center\"><tr><td> <table cellpadding=\"4\" cellspacing=\"1\" border=\"0\" width=\"100%\"> <tr align=\"center\"> <td colspan=\"1\" align=\"left\" bgcolor=\"".$Globals{'headcolor'}."\"><font face=\"".$Globals{'headfont'}."\" color=\"".$Globals{'headfontcolor'}."\" size=\"".$Globals{'fontmedium'}."\"><B>".$Globals{'galleryname'}." Image Upload</font></td> <td colspan=\"1\" align=\"right\" bgcolor=\"".$Globals{'headcolor'}."\"><font face=\"".$Globals{'mainfonts'}."\" color=\"".$Globals{'headfontcolor'}."\" size=\"".$Globals{'fontmedium'}."\"> <a href=\"javascript:PopUpHelp('uploadphoto.php')\">help</a></font> </td> </tr> <form method=\"post\" action=\"".$Globals{'maindir'}."/uploadphoto.php\" enctype=\"multipart/form-data\"> <tr><Td bgcolor=\"".$Globals{'maincolor'}."\"><font size=\"".$Globals{'fontmedium'}."\" face=\"".$Globals{'mainfonts'}."\" color=\"".$Globals{'maintext'}."\">Username</font></td><td bgcolor=\"".$Globals{'maincolor'}."\"> <font size=\"".$Globals{'fontmedium'}."\" face=\"".$Globals{'mainfonts'}."\" color=\"".$Globals{'maintext'}."\">$username</td></tr> <tr><Td bgcolor=\"".$Globals{'maincolor'}."\" width=\"50%\"><font size=\"".$Globals{'fontmedium'}."\" color=\"".$Globals{'maintext'}."\" face=\"".$Globals{'mainfonts'}."\">Choose a category</font></td><Td bgcolor=\"".$Globals{'maincolor'}."\"><select name=\"category\">$catdefault"; if (empty($subid)) $subid=""; $selected = $subid; catmoveopt(0); $output .= $catoptions; $imgdir = $Globals{'zipuploaddir'}."/$userid"; $skiphtml = "</table><table cellpadding=\"4\" cellspacing=\"0\" border=\"0\" width=\"100%\"> <tr><Td bgcolor=\"".$Globals{'headcolor'}."\" align=\"center\"> <font size=\"".$Globals{'fontmedium'}."\" color=\"".$Globals{'headfontcolor'}."\" face=\"".$Globals{'mainfonts'}."\"> <b>ADMIN OPTIONS FOR BULK OR ZIP UPLOADS</b></font> </td> <td align=\"right\" bgcolor=\"".$Globals{'headcolor'}."\"><font face=\"".$Globals{'mainfonts'}."\" color=\"".$Globals{'headfontcolor'}."\" size=\"".$Globals{'fontmedium'}."\"> <a href=\"javascript:PopUpHelp('adminskip.php')\">help</a></font> </td> </tr></table> <table cellpadding=\"4\" cellspacing=\"1\" border=\"0\" width=\"100%\"> <tr><Td bgcolor=\"".$Globals{'maincolor'}."\"><font size=\"".$Globals{'fontmedium'}."\" color=\"".$Globals{'maintext'}."\" face=\"".$Globals{'mainfonts'}."\">Skip upload and process the files in your upload directory<br><font size=\"".$Globals{'fontsmall'}."\">Files should already be in: <b>$imgdir</b></td> <td bgcolor=\"".$Globals{'maincolor'}."\" align=\"center\"><input type=\"checkbox\" name=\"skipupload\" value=\"skipupload\"></td></tr> <tr><Td bgcolor=\"".$Globals{'maincolor'}."\"><font size=\"".$Globals{'fontmedium'}."\" color=\"".$Globals{'maintext'}."\" face=\"".$Globals{'mainfonts'}."\">Show thumbnails during processing?</td> <td bgcolor=\"".$Globals{'maincolor'}."\" align=\"center\"><font size=\"".$Globals{'fontmedium'}."\" color=\"".$Globals{'maintext'}."\" face=\"".$Globals{'mainfonts'}."\"><select name=\"dthumbs\"><option selected>yes</option><option>no</option></select></font></td></tr> <tr><Td bgcolor=\"".$Globals{'maincolor'}."\"><font size=\"".$Globals{'fontmedium'}."\" color=\"".$Globals{'maintext'}."\" face=\"".$Globals{'mainfonts'}."\">Number of thumbnails to process next?</td> <td bgcolor=\"".$Globals{'maincolor'}."\" align=\"center\"><font size=\"".$Globals{'fontmedium'}."\" color=\"".$Globals{'maintext'}."\" face=\"".$Globals{'mainfonts'}."\"><select name=\"numprocess\"><option selected>10</option><option>25</option><option>50</option><option>100</option></select></td></tr>"; $output .= "</select></td></tr> <tr><Td bgcolor=\"".$Globals{'maincolor'}."\"><font size=\"".$Globals{'fontmedium'}."\" face=\"".$Globals{'mainfonts'}."\" color=\"".$Globals{'maintext'}."\">Photo to upload:</font><br><b><font size=\"".$Globals{'fontsmall'}."\" face=\"".$Globals{'mainfonts'}."\" color=\"red\">$maxfilesize</font></b></td><td bgcolor=\"".$Globals{'maincolor'}."\"><input type=\"file\" name=\"theimage\"></td></tr> <tr><Td bgcolor=\"".$Globals{'maincolor'}."\"><font size=\"".$Globals{'fontmedium'}."\" face=\"".$Globals{'mainfonts'}."\" color=\"".$Globals{'maintext'}."\">Matching closeup to upload:</font><br><b><font size=\"".$Globals{'fontsmall'}."\" face=\"".$Globals{'mainfonts'}."\" color=\"red\">$maxfilesize</font></b></td><td bgcolor=\"".$Globals{'maincolor'}."\"><input type=\"file\" name=\"closeup\"></td></tr> <tr><Td bgcolor=\"".$Globals{'maincolor'}."\"><font size=\"".$Globals{'fontmedium'}."\" color=\"".$Globals{'maintext'}."\" face=\"".$Globals{'mainfonts'}."\">Enter a title for the photo</td><td bgcolor=\"".$Globals{'maincolor'}."\"><input type=\"text\" name=\"title\"></td></tr> <tr><Td bgcolor=\"".$Globals{'maincolor'}."\"><font size=\"".$Globals{'fontmedium'}."\" color=\"".$Globals{'maintext'}."\" face=\"".$Globals{'mainfonts'}."\">To help users find your photo, please enter a few (up to 10) descriptive keywords (separated by spaces):</td><td bgcolor=\"".$Globals{'maincolor'}."\"><input type=\"text\" name=\"keywords\"></td></tr> <tr><Td bgcolor=\"".$Globals{'maincolor'}."\"><font size=\"".$Globals{'fontmedium'}."\" color=\"".$Globals{'maintext'}."\" face=\"".$Globals{'mainfonts'}."\">Photo Description</td><td bgcolor=\"".$Globals{'maincolor'}."\"><textarea name=\"desc\" cols=\"30\" rows=\"5\"></textarea></td></tr> $skiphtml <Center> <Tr><Td colspan=\"2\" bgcolor=\"".$Globals{'maincolor'}."\"><font size=\"".$Globals{'fontmedium'}."\" face=\"".$Globals{'mainfonts'}."\"><center> <input type=\"hidden\" name=\"password\" value=\"$password\"> <input type=\"hidden\" name=\"userid\" value=\"$userid\"> <input type=\"hidden\" name=\"MAX_FILE_SIZE\" value=\"2000000\"> <input type=\"submit\" value=\"Upload/Submit\"> <p><b>When you hit SUBMIT, the file you selected will be uploaded.</b><br></font><font size=\"".$Globals{'fontsmall'}."\" face=\"".$Globals{'mainfonts'}."\"> (Depending on the size of the file and your connection, this may take some time. <b>Please be patient.</b>)</p></font></td></tr></table></td></tr></table><p>".$Globals{'cright'}."$footer"; print $output; } else { if (empty($skipupload)) $skipupload=""; if ( $category == "" ) { dieWell( "You must choose a category before uploading."); exit; } if ( $skipupload == "skipupload" ) { $deftitle = urlencode($title); $defdesc = urlencode($desc); $furl = $Globals{'zipuploadurl'}."/$userid"; forward( $Globals{'maindir'}."/bulkupload.php?ppaction=addphotos&do=preview&photopath=$userid&deftitle=$deftitle&defdesc=$defdesc&defcat=$category&keywords=$keywords&numprocess=$numprocess&dthumbs=$dthumbs&furl=$furl", "Preparing to process image list!" ); exit; } $realname = $HTTP_POST_FILES['theimage']['name']; if ( $realname == "" ) { dieWell( "You need to enter the name of a file to upload! $thevideo / $theimage" ); exit; } $realname = fixfilenames( $realname ); $theext = get_ext( $realname ); $filepath = $Globals{'datafull'}."$category/$userid$realname"; $outfilename = "$userid$realname"; $query = "SELECT userid,bigimage FROM photos where userid=$userid"; $resulta = ppmysql_query($query,$link); while( list( $uid, $bgimage ) = mysql_fetch_row($resulta) ) { if ($uid == $userid && $uid != 0) { if ( $bgimage == $realname ) { dieWell("Sorry, you already uploaded an image called $realname. Try a different name."); exit; } } } ppmysql_free_result($resulta); $title = fixmessage( $title ); $keywords = fixmessage( $keywords ); $desc = fixmessage( $desc ); if ( $category == "notcat" ) { $emessage = "The category you chose is a top level category.<p>Please go back and choose one of its subcategories to upload your image."; dieWell($emessage); } //####// Write the file to a directory ##### //#// Do you wish to allow all file types? yes/no (no capital letters) $allowall = "no"; //#// If the above = "no"; then which is the only extention to allow? //#// Remember to have the LAST 4 characters i.e. .ext if ($realname != "") { $isfilegood = "yes"; if ( $allowall != "yes" ) { if ( !is_image($outfilename) ) { $isfilegood = "no"; } } if ($isfilegood == "yes") { handleupload(); } // // ZIP Uploads for Users // if ( $Globals{'allowzip'} ) { if (strtolower(substr($outfilename,strlen($outfilename) - 4,4)) == ".zip" ) { $filepath = $Globals{'zipuploaddir'}."/$userid"; $filedir = "$filepath/$outfilename"; if ( !file_exists( $filepath ) ) { mkdir( $filepath, 0755 ); chmod( $filepath, 0777 ); } chdir( $filepath ); handleupload( $filedir ); $sys_cmd = $Globals{'zip_command'}." -qq $filedir"; system( $sys_cmd ); unlink( $filedir ); $deftitle = urlencode($title); $defdesc = urlencode($desc); $furl = $Globals{'zipuploadurl'}."/$userid"; if ( empty($numprocess) ) $numprocess = 10; if ( empty($dthumbs) ) $dthumbs = "yes"; forward( $Globals{'maindir'}."/bulkupload.php?ppaction=addphotos&do=preview&photopath=$userid&deftitle=$deftitle&defdesc=$defdesc&defcat=$category&keywords=$keywords&numprocess=$numprocess&dthumbs=$dthumbs&furl=$furl", "Preparing to process image list!" ); exit; } } } if ( file_exists($filepath) ) { $insize = filesize( $filepath ); } else { dieWell("File upload error. Cannot find uploaded file.<br>Path: [$filepath]"); exit; } if ( $isfilegood != "yes" ) { dieWell( "Image must be a .jpg, .gif, .tif or .png file." ); exit; } $thumbsize = create_thumb( $realname, $filepath, $category ); process_image( $realname, $filepath, $category ); $query = "SELECT id FROM photos WHERE userid=$userid AND bigimage='$realname'"; $resulta = ppmysql_query($query,$link); list( $forwardid ) = mysql_fetch_row($resulta); ppmysql_free_result($resulta); if ( empty($forwardid) ) { dieWell( "There was a problem processing your image: $realname.<p>Please notify the System Administrator." ); exit; } forward( $Globals{'maindir'}."/showphoto.php?photo=$forwardid", "Your image was uploaded successfully!" ); } ?> Do Globals need to be on for this to work? Or is there another problem? thanks Paul MOD EDIT: [code] . . . [/code] tags added. 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>"; ?> 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. 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? 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. 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 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(); ?> 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. |