PHP - Mysql Query Works In Phpmyadmin But Not In Php Script
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. Similar TutorialsGood 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`])) {
Hi, this query runs fine when I run it from PHPMyAdmin: UPDATE `tran_term_taxonomy` SET `description` = (SELECT keyword from `good_keywords` ORDER BY RAND() LIMIT 1,1) WHERE `tran_term_taxonomy`.`taxonomy` = 'post_tag' AND `tran_term_taxonomy`.`description` = "" LIMIT 1 However, when I run the same query in a PHP file on my server, the page doesn't load at all. The message I get is: www.somesite.com is currently unable to handle this request. HTTP ERROR 500. This is my PHP code: <?php include("/database/connection/path/db_connect.php"); $result4 = mysqli_query($GLOBALS["___mysqli_ston"], "UPDATE `tran_term_taxonomy` SET `description` = (SELECT keyword from `good_keywords` ORDER BY RAND() LIMIT 1,1) WHERE `tran_term_taxonomy`.`taxonomy` = 'post_tag' AND `tran_term_taxonomy`.`description` = "" LIMIT 1"); echo $result4; ?> So how do I make this query work please? Thanks for your guidance. Hi, I have a sql query that executes perfectly in phpMyAdmin but when applied to a PHP script returns nothing. It won't even start a "while" loop. Please review code snippits below. Submission Script calls function in Database Class: $result = $database->testReturnId($_POST['years'], $_POST['model']); while($row = mysql_fetch_array($result)) { $i = $i + 1; echo "ROW " . $i . " " . $row['auto_id'] . " " . $row['auto_year'] . " " . $row['auto_year_high'] . " " . $row['auto_make'] . " " . $row['auto_model'] . "<br />"; } Database Class Function: function testReturnId($year, $model){ global $form; $q = 'SELECT * FROM tbl_svc_auto WHERE auto_model = "$model" AND "$year" BETWEEN auto_year AND auto_year_high'; if(!mysql_query($q, $this->connection)){ return false; }else{ return $result = mysql_query($q, $this->connection); } } I have moved the query to the submission script and replaced the variables with actual data and it still will not work. I can take the same query with out the variables and input it into phpMyAdmin and it works great. On the submission script, I added a row number to the echo thinking that it would a least return the word "ROW" and it does not. I have tested each step of the execution of the query and have not returned any errors. I do not receive any errors at all even during execution. It just seems to refuse to run the "while" statement. I do not know where my problem is......Please help. Thank you in advance for any assitance you can offer. Joshua I'm trying to update every record where one field in a row is less than the other. The code gets each row i'm looking for and sets up the query right, I hope I combined the entire query into one string each query seperated by a ; so it's like UPDATE `table` SET field2= '1' WHERE field1= '1';UPDATE `table` SET field2= '1' WHERE field1= '2';UPDATE `table` SET field2= '1' WHERE field1= '3';UPDATE `table` SET field2= '1' WHERE field1= '4';UPDATE `table` SET field2= '1' WHERE field1= '5'; this executes properly if i run the query in phpMyAdmin, however when I run the query in PHP, it does nothing... Any advice? Server version: 5.1.53-log I have the following queries Code: [Select] SELECT user_id FROM phpbb_profile_fields_data WHERE pf_rsname = "Atroxide" LIMIT 1 SELECT user_id FROM phpbb_profile_fields_data WHERE pf_rsname = "Delia Smith" LIMIT 1 SELECT user_id FROM phpbb_profile_fields_data WHERE pf_rsname = "espinozagabe" LIMIT 1 SELECT user_id FROM phpbb_profile_fields_data WHERE pf_rsname = "Jaunty1" LIMIT 1 SELECT user_id FROM phpbb_profile_fields_data WHERE pf_rsname = "lvoos" LIMIT 1 All 5 of these queries are executed at a different time (in a foreach loop). All 5 except for the one below returned a result. Code: [Select] SELECT user_id FROM phpbb_profile_fields_data WHERE pf_rsname = "Delia Smith" LIMIT 1 I couldn't figure out why it wasn't working so I copy pasted it into PHPMyAdmin and it returned the result I was looking for. What could cause for PHPMyAdmin to work but not the exact same query in a php script to not? It didn't return an error using mysql_error() either. Pretty sure its irreverent but here is the php script. Code: [Select] foreach ($online as $username => $activity) { $query = " SELECT user_id FROM phpbb_profile_fields_data WHERE pf_rsname = \"" . $username . "\" LIMIT 1 "; $result = $db->query($query); } The table is Code: [Select] user_id mediumint(8) UNSIGNED No 0 pf_rsname varchar(255) utf8_bin Yes NULL Here is my code: // Start MySQL Query for Records $query = "SELECT codes_update_no_join_1b" . "SET orig_code_1 = new_code_1, orig_code_2 = new_code_2" . "WHERE concat(orig_code_1, orig_code_2) = concat(old_code_1, old_code_2)"; $results = mysql_query($query) or die(mysql_error()); // End MySQL Query for Records This query runs perfectly fine when run direct as SQL in phpMyAdmin, but throws this error when running in my script??? Why is this??? Code: [Select] 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 '= new_code_1, orig_code_2 = new_code_2WHERE concat(orig_code_1, orig_c' at line 1 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? Hi all,
I'v table called vehicles with id (int auto_increment) and plate_number (varchar 150). the plate_number have records like (a a a 1 1 1 1) (b b b 2 2 2 2), three chars and four numbers spliced by spaces. I'v php search page with url like this: http://localhost/vehicles/show.php?plate_number=f%20f%20f%205%205%205%205 search about plate_numbet = f f f 5 5 5 5my php code: // pdo connection. // first sql test $sql = "SELECT * FROM vehicles WHERE plate_number LIKE '%".$_GET['plate_number']."%'"; // second sql test // $sql = "SELECT * FROM vehicles WHERE plate_number = '".$_GET['plate_number']."'"; $db->query($sql); if($db->rowcount() > 0){ // print all results... }else{ echo "There are no results."; }The query result is: There are no results.. But, when I copy the sql statements into phpmyadmin it is works fine. (there is a result). like this: SELECT * FROM vehicles WHERE plate_number LIKE '%f f f 5 5 5 5%'; OR SELECT * FROM vehicles WHERE plate_number = 'f f f 5 5 5 5';Also i used string functions (htmlspecialchars, rawurldecode, ... ), still not work. any suggestion to solve this issue? Thanks to all 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 TRUNCATE TABLE CubeCart_cats_idx; INSERT INTO CubeCart_cats_idx (productid, cat_id) SELECT productid, cat_id FROM CubeCart_inventory; I an running the following in MyPHPAdmin, but need this to be automated in a PHP script, how would I do it ? all help is appreciated, still new to PHP & MySQL many thanks D Hey guys, so I have this script:
<?php $databasehost = "localhost"; $databasename = "import"; $databasetable = "import"; $databaseusername="import"; $databasepassword = "password"; $fieldseparator = ","; $lineseparator = "\n"; $csvfile = "test.csv"; if(!file_exists($csvfile)) { die("File not found. Make sure you specified the correct path."); } try { $pdo = new PDO("mysql:host=$databasehost;dbname=$databasename", $databaseusername, $databasepassword, array( PDO::MYSQL_ATTR_LOCAL_INFILE => true, PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION ) ); } catch (PDOException $e) { die("database connection failed: ".$e->getMessage()); } $affectedRows = $pdo->exec(" LOAD DATA LOCAL INFILE ".$pdo->quote($csvfile)." REPLACE INTO TABLE `$databasetable` FIELDS TERMINATED BY ".$pdo->quote($fieldseparator)." LINES TERMINATED BY ".$pdo->quote($lineseparator)); echo "Loaded a total of $affectedRows records from this csv file.\n"; ?> Hello, I am trying to pick up php again and just exercising my skills. So I have it so that it fills my form with the values of what I want to edit, and when I click the edit button, it doesn't edit any of the information. When I echo out $result, I get a MYSQL query string that has the same values as the table, so its not getting the new values that are edited. <?php @mysql_connect('localhost', 'root', '') or die("Could not connect to Mysql Server. " . mysql_error()); @mysql_select_db('tutorials') or die("Could not connect to Database. " . mysql_error()); if(isset($_GET['edit'])) { $id = $_GET['edit']; $query = "SELECT `username`, `password` FROM `users` WHERE `id` = '$id'"; $result = mysql_query($query); $row = mysql_fetch_array($result); $name = $row['username']; $password = $row['password']; } if(isset($_POST['edit'])) { $id = $_GET['edit']; $query = "UPDATE `users` SET `username` = '$name', `password` = '$password' WHERE `id` = '$id'"; $result = mysql_query($query); echo $query; if(!$result) { echo mysql_error(); }else{ echo 'updated post'; } } ?> <form method="POST" action="" > <input type="text" name="name" value="<?php echo $name; ?>" /> First name <br /> <input type="text" name="password" value="<?php echo $password; ?>" /> Last name <br /> <input type="submit" name="edit" value="edit" /> </form> I believe it has something to do with the values of $name and $password in the form conflicting with the first if isset and the second if isset. Thanks for any help possible I have a db.php and inside it I filled out all the info needed:
<?php define('DB_HOST', 'example.com'); define('DB_NAME', 'database_name'); define('DB_USERNAME', 'user_name'); define('DB_PASSWORD', '*******'); $odb = new PDO('mysql:host=' . DB_HOST . ';dbname=' . DB_NAME, DB_USERNAME, DB_PASSWORD); ?>My problem is with the DB_HOST, is that my direct URL to the site? for example, google.com or is it like an IP? I am trying to simplify my coding work for my website and wanting to make it operate more professionally (as part of my training to better my programming skills, which I know will take a lot of time to do). One of the things I`d like to improve on it is to create tables and fields in my mysql database, but not have to go into phpmyadmin to do it. I know open source programs like Drupal can do this easily so that when you add modules, the user does not have to access the database to set it up. But looking at the codes, I`m unable to figure out how it works. How will I be able to program my code to do something like, I`ll have a form where I enter in what I want the new table to be called, what fields to add in and their specifications, where I could do this by just going into my website as the admin? 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 a template page that opens with a GO click from a drop-down in a different page. The variable is being passed through to the URL and in the GET statement. However, my PHP code is producing the following error: Quote Warning: mysqli_num_rows() expects parameter 1 to be mysqli_result, boolean given in /data/23/2/100/53/2263053/user/2487001/htdocs/myalaskacenter/events/venues/test_venues-results.php on line 52 . Here is my code: Code: [Select] <?php //Assigns the venueCode tothe variable with a more convenient name $venueURL = $_GET['VenueCode']; @$DB = mysqli_connect('server','username','password','database'); if (mysqli_connect_errno()){ echo '</blockquote><br/><br /> Sorry, this webpage is temporarily unavailable.<br /> <a href="http://alaskapac.centertix.net/">Click here to search for events.</a>'; } else { ?> <?php $Query = "SELECT Events.EventTitle, DATE_FORMAT(Performance.startDateTime, '%W, %M %e, %Y') AS startDate, DATE_FORMAT(Performance.startDateTime, '%h:%i %p') AS startTime, Events.EventID, Events.thumb, Events.ShoWareEventLink, Events.tagline, Performance.category_id, Promoters.Presenter, Promoters.website, Events.startDATE, Events.endDATE, Events.EventOnSaleDate, venues.VenueName FROM ((Events LEFT JOIN Performance ON Events.EventID = Performance.EventID) LEFT JOIN Promoters ON Events.PromoterCode = Promoters.PromoterCode) LEFT JOIN venues ON Performance.VenueCode = venues.VenueCode WHERE venues.VenueCode=".$venueURL." AND Events.group_id=1 AND Performance.category_id!=2 AND Performance.category_id!=5 AND Performance.category_id!=7 AND Performance.category_id!=8 AND Events.EventOnSaleDate IS NOT NULL AND (Performance.PerfType='Public Event' OR Events.EventID='79') AND Performance.endDateTime >= now()-INTERVAL 1 DAY AND Events.PublishDate <= now() AND Events.startDATE IS NOT NULL ORDER BY Performance.startDateTime"; $Result = mysqli_query($DB,$Query); $NumResults = mysqli_num_rows($Result); ?> <?php if($NumResults=0){ echo "<p class='submenu'>$NumResults Performances</p>"; } while ($Row = mysqli_fetch_assoc($Result)){ $eventtitle = $Row['EventTitle']; $eventDate = $Row['startDate']; echo '<p><a href="' . $Row['ShoWareEventLink'] . '"><img src="https://alaskapac.centertix.net/UPLImage/' . $Row['thumb'] . '" alt="' . $Row['EventTitle'] . '" title="' . $Row['EventTitle'] . '" align="left" border="0"><span class="Heading3_blue">' . $Row['EventTitle'] . '</span>'; if($Row['FreeEvents']==TRUE){ echo '<img src="/images/free.gif" alt="Free Event" title="Free Event" width="80" height="80" align="right" border="0"></a><br />'; } elseif ($Row['EventOnSaleDate'] <= date("Y-m-d g:i a")){ /** IF ONSALEDATE<=NOW**/ echo '<img src="/images/logos/ctx/BUY_Tickets_gold.gif" alt="Buy Tickets" title="Buy Tickets" width="85" height="32" align="right" border="0"></a><br />'; } else {/** IF ONSALEDATE!<NOW**/ echo '<img src="/images/logos/ctx/AvailableSoon.png" alt="Available Soon" title="Available Soon" align="right" border="0"></a><br /><i>Tickets available ' . date("l, F j, Y", strtotime($Row['EventOnSaleDate'])) . ' at ' . date("g:i a", strtotime($Row['EventOnSaleDate'])) . '.</i>'; /** +ONSALEDATE **/ } echo '<br />Presented by <a href="' . $Row['website'] .'" target="_blank">' . $Row['Presenter'] . '</a>'; echo '<br />'.$Row['startDate']. ' at ' . $Row['startTime'].' - '.$Row['VenueName']; if ($Row['FreeEvents']==TRUE){ echo '<br /><br />'.$Row['BriefDescription']; } echo '<br /><br /></p><hr>'; } ?> <?php mysqli_free_result($Result); mysqli_close($DB); } ?> Here is my sample Results page: http://www.myalaskacenter.com/events/venues/test_venues-results.php?VenueCode=ACH If you also have any feedback on my code, please do tell me. I wish to improve my coding base. Basically when you fill out the register form, it will check for data, then execute the insert query. But for some reason, the query will NOT insert into the database. In the following code below, I left out the field ID. Doesn't work with it anyways, and I'm not sure it makes a difference. Code: Code: [Select] mysql_query("INSERT INTO servers (username, password, name, type, description, ip, votes, beta) VALUES ($username, $password, $name, $server_type, $description, $ip, 0, 1)"); Full code: Code: [Select] <?php include_once("includes/config.php"); ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title><? $title; ?></title> <meta http-equiv="Content-Language" content="English" /> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <link rel="stylesheet" type="text/css" href="style.css" media="screen" /> </head> <body> <div id="wrap"> <div id="header"> <h1><? $title; ?></h1> <h2><? $description; ?></h2> </div> <? include_once("includes/navigation.php"); ?> <div id="content"> <div id="right"> <h2>Create</h2> <div id="artlicles"> <?php if(!$_SESSION['user']) { $username = mysql_real_escape_string($_POST['username']); $password = mysql_real_escape_string($_POST['password']); $name = mysql_real_escape_string($_POST['name']); $server_type = mysql_real_escape_string($_POST['type']); $description = mysql_real_escape_string($_POST['description']); if(!$username || !$password || !$server_type || !$description || !$name) { echo "Note: Descriptions allow HTML. Any abuse of this will result in an IP and account ban. No warnings!<br/>All forms are required to be filled out.<br><form action='create.php' method='POST'><table><tr><td>Username</td><td><input type='text' name='username'></td></tr><tr><td>Password</td><td><input type='password' name='password'></td></tr>"; echo "<tr><td>Sever Name</td><td><input type='text' name='name' maxlength='35'></td></tr><tr><td>Type of Server</td><td><select name='type'> <option value='Any'>Any</option> <option value='PvP'>PvP</option> <option value='Creative'>Creative</option> <option value='Survival'>Survival</option> <option value='Roleplay'>RolePlay</option> </select></td></tr> <tr><td>Description</td><td><textarea maxlength='1500' rows='18' cols='40' name='description'></textarea></td></tr>"; echo "<tr><td>Submit</td><td><input type='submit'></td></tr></table></form>"; } elseif(strlen($password) < 8) { echo "Password needs to be higher than 8 characters!"; } elseif(strlen($username) > 13) { echo "Username can't be greater than 13 characters!"; } else { $check1 = mysql_query("SELECT username,name FROM servers WHERE username = '$username' OR name = '$name' LIMIT 1"); if(mysql_num_rows($check1) < 0) { echo "Sorry, there is already an account with this username and/or server name!"; } else { $ip = $_SERVER['REMOTE_ADDR']; mysql_query("INSERT INTO servers (username, password, name, type, description, ip, votes, beta) VALUES ($username, $password, $name, $server_type, $description, $ip, 0, 1)"); echo "Server has been succesfully created!"; } } } else { echo "You are currently logged in!"; } ?> </div> </div> <div style="clear: both;"> </div> </div> <div id="footer"> <a href="http://www.templatesold.com/" target="_blank">Website Templates</a> by <a href="http://www.free-css-templates.com/" target="_blank">Free CSS Templates</a> - Site Copyright MCTop </div> </div> </body> </html> I have a need to do a special sorting for a bunch of leads. The person who sees the leads (l.user) is looking at leads that are for a few different people (l.team_id). When I run my query in sqlyog, it gives me the results I am looking for, where the rank is used to sort. When I run my query through phpMyAdmin, php, or the MySQL command line, all of the ranks are NULL, so nothing gets sorted. All of these attempts are on the same database, on the same computer (Windows 7). Any ideas or help is appreciated.
SELECT x.lead_id, x.rank, x.team_id, x.status FROM (SELECT l.lead_id, l.team_id, l.status, CASE WHEN @ps != l.team_id THEN @rownum := 0 WHEN @ps = l.team_id THEN @rownum := @rownum + 1 ELSE @rownum END AS rank, @ps := l.team_id FROM `system-leads` l WHERE (l.user = 189905706) AND l.status != "closed" LIMIT 100000000 OFFSET 0) `x` ORDER BY x.status ASC, x.rank ASC, x.lead_id ASCI wonder why it works in sqlyog and not the others, but I need it to work regardless of what client I am using. so my situation is something like this , i'm trying to fetch user details based on `id` that isset is getting, but some how the `variable that contains the $_GET value doesn't work` in query but when i put an static value to pdo query then it works and show the result. i have checked by doing `var_dump` of variable `$user` before query and it shows the correct value but not working in query. Below is the code i'm working with: I'm having trouble with a simple SELECT query. I just cannot figure out what the problem is... <?php //Include database connection details include 'login/config.php'; //Connect to mysql server $link = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD); if(!$link) { die('Failed to connect to server: ' . mysql_error()); } //Select database $db = mysql_select_db(DB_DATABASE); if(!$db) { die("Unable to select database"); } $qry="SELECT * FROM members"; $result = mysqli_query($link, $qry); echo "<table>"; while($row = mysqli_fetch_array($result, MYSQL_ASSOC)) { $getid = ($row['member_ID']); $firstname = ($row['firstname']); $lastname = ($row['lastname']); $email = ($row['email']); echo "<tr><td>$firstname</td><td>$email</td></tr>"; } echo "</table>"; ?> I know I have a connection to the DB, and I know that the query will return values as I have tested in in phpmyadmin. Can anyone see anything obvious I am missing? Thanks |