Re: [PHP-DB] Compatibility with PHP and MySQL
On Mon, Sep 5, 2011 at 3:49 PM, Gabriel Solberg solbergdes...@gmail.com wrote: Will installing the most recent XMAPP to install PHP MySQL and Apache to create a development environment on my local computer affect how everything runs when I upload it to the server (My web host 1and1.com runs php 5.0 and MySQL 5.0) thanks You may notice differences if your php.ini and http.conf files are not the same in both development and production environments. I would compare them first. -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-DB] foreign key
Okay. I am pretty new to mysql so this may seem like a ridiculous question to some people. I am trying to use a LEFT JOIN query, but the results I am finding unusual. For every record occurrence there is for the query, the results are duplicated by that amount. So if there are 3 records from the query results, then the output is 3 times what I expect.. if that makes sense. From what I have researched so far. I believe I may need to add a foreign key to build the relations between the two tables. Based on the query can any tell me the correct way of adding the foreign key if ,in fact, that is what I need? I can provide table structures and information if necessary. The query is: $posts_sql = SELECT store_subject, store_comments, store_date, store_tptest, store_by, users.user_id, users.user_name, users.first_name, users.last_name FROM stores LEFT JOIN users ON stores.store_by = users.user_id WHERE stores.store_subject = ' . mysql_real_escape_string($_GET['id']).' ORDER BY stores.store_date DESC ; The query dump is: SELECT store_subject, store_comments, store_date, store_tptest, store_by, users.user_id, users.user_name, users.first_name, users.last_name FROM stores LEFT JOIN users ON stores.store_by = users.user_id WHERE stores.store_subject = 'Noland Park Plaza 3509 S. Noland Rd' ORDER BY stores.store_date DESC -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] foreign key
Is users.user_id unique? yes it is. -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] foreign key
What does your result look like? Hard to say what the problem is without seeing the result. I am echoing the query and printing the get array just for debugging purposes, but below you can see how it is repeating its' self. Thank you Array ( [id] = Bella Roe 4980 Roe Blvd ) Bella Roe 4980 Roe BlvdSELECT stores.store_subject, stores.store_comments, stores.store_date, stores.store_tptest, stores.store_by, users.user_id, users.user_name, users.first_name, users.last_name FROM stores LEFT JOIN users ON stores.store_by = users.user_id WHERE stores.store_subject = 'Bella Roe 4980 Roe Blvd' ORDER BY stores.store_date DESC Chris Stinemetz 08-09-2011 02:08PM600kbps-3.8mbps testChris Stinemetz 08-09-2011 02:07PM0-250kbps test1Reply: Bella Roe 4980 Roe BlvdSELECT stores.store_subject, stores.store_comments, stores.store_date, stores.store_tptest, stores.store_by, users.user_id, users.user_name, users.first_name, users.last_name FROM stores LEFT JOIN users ON stores.store_by = users.user_id WHERE stores.store_subject = 'Bella Roe 4980 Roe Blvd' ORDER BY stores.store_date DESC Chris Stinemetz 08-09-2011 02:08PM600kbps-3.8mbps testChris Stinemetz 08-09-2011 02:07PM0-250kbps test1Reply:
Re: [PHP-DB] foreign key
Okay. I just validated it is not in the left join query, but in my php. I was able to build the correct relations. Does anyone see any think in the php code below that may cause duplicate table rows? Thank you all. ?php //store.php include_once 'includes/connect.php'; include_once 'includes/header.php'; print(pre.print_r($_GET,true)./pre); $sql = SELECT store_id, store_subject, store_comments, store_date, store_tptest, store_by FROM stores WHERE store_subject = ' . mysql_real_escape_string($_GET['id']).'; $result = mysql_query($sql); if(!$result) { echo 'The latest post could not be displayed, please try again later.'; //echo mysql_error(); //debugging purposes, uncomment when needed } else { if(mysql_num_rows($result) == 0) { echo 'This store visit doesnprime;t exist.'; } else { while($row = mysql_fetch_assoc($result)) { //display post data echo 'table class=table1 border=1 tr th colspan=2' . $row['store_subject'] . '/th /tr'; //fetch the posts from the database $posts_sql = SELECT stores.store_subject, stores.store_comments, stores.store_date, stores.store_tptest, stores.store_by, users.user_id, users.user_name, users.first_name, users.last_name FROM stores LEFT JOIN users ON stores.store_by = users.user_id WHERE stores.store_subject = ' . mysql_real_escape_string($_GET['id']).' ORDER BY stores.store_date DESC ; //echo $posts_sql; $posts_result = mysql_query($posts_sql); if(!$posts_result) { echo 'trtdThe posts could not be displayed, please try again later./tr/td/table'; //echo mysql_error(); //debugging purposes, uncomment when needed } else { while($posts_row = mysql_fetch_assoc($posts_result)) { echo 'tr class=topic-post td class=user-post' . $posts_row['first_name'] . ' ' . $posts_row['last_name'] . 'br/' . date('m-d-Y h:iA', strtotime($posts_row['store_date'])) . '/td td class=post-content' . $posts_row['store_tptest'] . 'br/' . htmlentities(stripslashes($posts_row['store_comments'])) . '/td /tr'; } } if(!$_SESSION['signed_in']) { echo 'trtd colspan=2You must be a href=signin.phpsigned in/a to reply. You can also a href=signup.phpsign up/a for an account.'; } else { //show reply box echo 'trtd colspan=2h2Reply:/h2br / form method=post action=reply.php?id=' . $row['store_id'] . ' textarea name=reply-content/textareabr /br / input type=submit value=Submit reply / /form/td/tr'; } //finish the table echo '/table'; } } } include_once 'includes/footer.php'; ?
[PHP-DB] Re: php-db foreign key
On Tue, Aug 9, 2011 at 2:55 PM, Frank Flynn fr...@declan.com wrote: You already have a foreign key, that is stores.store_by references users.user_id. You might not have declared it (which is OK) but if that is the key you want that is fine. I suspect you are seeing an inadvertent Cartesian product. The way you have written this query you will get one row from the stores table for each row in the users table where a store_by = user_id - and because you said LEFT JOIN you will get one row from the stores table even if there are no matching rows in the users table. So you say you get 3 x the rows you're expecting; are there 3 users that match that store_by? No there is only 1 user that match the sotre_by. If the query is not written correctly do you mind trying to show me how to correctly right it? When I dump the query and run it in console I get the results I want. Not sure what I am doing wrong. mysql SELECT stores.store_subject, stores.store_comments, stores.store_date, stores.store_tptest, stores.store_by, user s.user_id, users.user_name, users.first_name, users.last_name FROM stores LEFT JOIN users ON stores.store_by = users.use r_id WHERE stores.store_subject = 'Bella Roe 4980 Roe Blvd' ORDER BY stores.store_date DESC ; +-++-+-+--+-+--- -++---+ | store_subject | store_comments | store_date | store_tptest| store_by | user_id | user_name | first_name | last_name | +-++-+-+--+-+--- -++---+ | Bella Roe 4980 Roe Blvd | test | 2011-08-09 14:08:05 | 600kbps-3.8mbps |1 | 1 | chrisstinemetz | Chris | Stinemetz | | Bella Roe 4980 Roe Blvd | test1 | 2011-08-09 14:07:49 | 0-250kbps |1 | 1 | chrisstinemetz | Chris | Stinemetz | +-++-+-+--+-+--- -++---+ 2 rows in set (0.00 sec)
Re: [PHP-DB] Re: php-db foreign key
Your php code had more than one query running (one inside the other). It's the outer query that runs twice, not the inner one returning double the results Thanks Peter, Do you have any suggestions on how to fix this? Thank you, Chris -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] Re: php-db foreign key
Yes, debug your code and figure out why it's looping twice instead. For instance, try the other query in the mysql console. Thank you! It was the first query. I put a LIMIT 1 on it and now it is working correctly. I appreciate your help! Thank you, Chris -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-DB] Left Join
I am tyring to build a query that will take the most recent stores.store_date column then join it with store_list.store_name where store_list.store_name and stores.store_subject match then return the most recent stores.store_date. I am guessing this will require some sort of join. I have been tyring to figure it out but have had no luck. Any help is greatly apprciated. Thank you. mysql select * from stores; +--+-++-+---+--+-+-- ---+ | store_id | store_subject | store_type | store_date | store_mar | store_by | store_tptest| store_comment s | +--+-++-+---+--+-+-- ---+ | 78 | Bella Roe | corporate | 2011-06-28 15:01:02 | 0 |1 | | | | 79 | Bella | corporate | 2011-08-06 08:48:26 | 0 |1 | 600kbps-3.8mbps | test | | 80 | Brittney~2120 | corporate | 2011-08-06 08:48:50 | 1 |1 | 600kbps-3.8mbps | should post t o Wichita! | | 81 | Motor | premier| 2011-08-06 14:52:55 | 1 |1 | 600kbps-3.8mbps | test | | 82 | Liberty | corporate | 2011-08-06 14:54:41 | 0 |1 | 0-250kbps | test | | 83 | Seneca~3165 | corporate | 2011-08-06 14:58:47 | 0 |1 | 600kbps-3.8mbps | test | | 84 | Liberty | corporate | 2011-08-06 14:59:32 | 0 |1 | 400-600kbps | test | | 85 | Brittney~2120 | corporate | 2011-08-06 15:00:43 | 0 |1 | 600kbps-3.8mbps | test | | 86 | Liberty | corporate | 2011-08-06 15:01:11 | 0 |1 | 300-400kbps | test | | 87 | Brittney~2120 | corporate | 2011-08-06 15:11:06 | 0 |1 | 250-300kbps | test | | 88 | Brittney~2120 | corporate | 2011-08-06 15:23:53 | 1 |1 | 600kbps-3.8mbps | test | | 89 | Bella | corporate | 2011-08-06 15:31:49 | 0 |1 | 600kbps-3.8mbps | test | | 90 | Cleartalk~10221 | premier| 2011-08-06 15:32:54 | 0 |1 | 250-300kbps | test | | 91 | Chit| premier| 2011-08-06 15:33:50 | 1 |1 | 250-300kbps | test | | 92 | || 2011-08-06 15:34:21 | 2 |1 | 300-400kbps | test | | 93 | Bella | corporate | 2011-08-07 11:26:13 | 0 |1 | 600kbps-3.8mbps | test | +--+-++-+---+--+-+-- ---+ 16 rows in set (0.00 sec) mysql mysql select * from store_list LIMIT 15;' ++---+++-+---+ | id | market_prefix | store_name | store_type | market_name | id_market | ++---+++-+---+ | 1 | MCI | Bella Roe~4980 Roe Blvd| Corporate | Kansas City | 0 | | 2 | MCI | Cleartalk~4635 Shawnee Dr | Premier| Kansas City | 0 | | 3 | MCI | Cleartalk~3612 State Avenue| Premier| Kansas City | 0 | | 4 | MCI | Endless Wireless~1620 Central Avenue | Premier| Kansas City | 0 | | 5 | MCI | Get Wireless~840 Minnesota | Premier| Kansas City | 0 | | 6 | MCI | Ring Ring Wireless~7559 State Avenue | Premier| Kansas City | 0 | | 7 | MCI | Cleartalk~1212 Sante Fe| Premier| Kansas City | 0 | | 8 | MCI | Cleartalk~10221 W 75th Street | Premier| Kansas City | 0 | | 9 | MCI | Free Talk~10830 Shawnee Mission Pkwy | Premier| Kansas City | 0 | | 10 | MCI | Loma Vista~8712 Blue Ridge Blvd| Corporate | Kansas City | 0 | | 11 | MCI | Ring Ring Wireless~25 W. 39th Street | Premier| Kansas City | 0 | | 12 | MCI | Ring Ring Wireless~3039 Prospect Ave | Premier| Kansas City | 0 | | 13 | MCI | Ring Ring Wireless~1201 E Linwood Blvd | Premier| Kansas City | 0 | | 14 | MCI | Ring Ring Wireless~4314 Rainbow Blvd | Premier| Kansas City | 0 | | 15 | MCI | Ring Ring Wireless~7445 Prospect Ave. | Premier| Kansas City | 0 | ++---+++-+---+ 15 rows in set (0.00 sec)
Re: [PHP-DB] Left Join
On Sun, Aug 7, 2011 at 3:00 PM, Peter Lind peter.e.l...@gmail.com wrote: Maybe it's just me, but I can't see anything that would work as foreign key for you to join on - neither table seems to have a foreign key Sorry for my ignorance. How do I create the foreign key? The two columns from each table that have a similar relationship are stores.store_mar and store_list.id_market. Once the foreign key is build what would be the correct syntax to achieve my query? Thank you very much, Chris
[PHP-DB] Insert query error
I am getting the following error trying to run the below query. Any suggestions on what I am doing wrong? Thank you, Something went wrong while inserting your store visitCannot add or update a child row: a foreign key constraint fails (`store`.`posts`, CONSTRAINT `posts_ibfk_1` FOREIGN KEY (`post_store`) REFERENCES `stores` (`store_id`) ON DELETE CASCADE ON UPDATE CASCADE) $sql = INSERT INTO posts(market, type, post_store, post_tptest, post_content, post_by, post_date) VALUES(' . mysql_real_escape_string($_POST['market']) . ', ' . mysql_real_escape_string($_POST['type']) . ', ' . mysql_real_escape_string($_POST['post_store']) . ', ' . sha1($_POST['post_tptest']) . ', ' . mysql_real_escape_string($_POST['post_content']) . ', . $_SESSION['user_id'] . , NOW()); -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-DB] cascading select
I am trying to create a cascading seletct with 3 menu choices. For some reason my third select menu is not populating. It does not seem like my ajax is correctly sending $_post values to the final query in my PHP class I built. By the time I make it to the final (third) select menu there are no choices. Hopefully someone can find something I missed in the following code snippits. Any help is greatly appreciated. Please excuse the incorrect indentions. For some reason gmail changes it. Thanks, Chris ajax code... script $(document).ready(function(){ $(select#type).attr(disabled,disabled); $(select#store).attr(disabled,disabled); $(select#market).change(function(){ $(select#type).attr(disabled,disabled); $(select#type).html(optionplease wait.../option); var id = $(select#market option:selected).attr('value'); $.post(select_type.php, {id:id}, function(data){ $(select#type).removeAttr(disabled); $(select#type).html(data); }); }); $(select#type).change(function(){ $(select#store).attr(disabled,disabled); $(select#store).html(optionplease wait.../option); var id = $(select#type option:selected).attr('value'); $.post(select_store.php, {id:id}, function(data){ $(select#store).removeAttr(disabled); $(select#store).html(data); }); }); $(form#select_form).submit(function(){ var market = $(select#market option:selected).attr('value'); var type = $(select#type option:selected).attr('value'); var store = $(select#store option:selected).attr('value'); if(market0 type0 store0) { var market = $(select#market option:selected).html(); var type = $(select#type option:selected).html(); var store = $(select#store option:selected).html(); $(#result).html('your choices were: '+market +' , '+type +' and '+store); } else { $(#result).html(you must choose three options!); } return false; }); }); /script php class for populating select menus ?php class SelectList { protected $conn; public function __construct() { $this-DbConnect(); } protected function DbConnect() { include db_config.php; $this-conn = mysql_connect($host,$user,$password) OR die(Unable to connect to the database); mysql_select_db($db,$this-conn) OR die(can not select the database $db); return TRUE; } public function ShowMarket() { $sql = SELECT DISTINCT id_markets FROM store_list; $res = mysql_query($sql,$this-conn); $market = 'option value=0market.../option'; while($row = mysql_fetch_array($res)) { $market .= 'option value=' . $row['id'] . '' . $row['id_markets'] . '/option'; } return $market; } public function ShowType() { $sql = SELECT DISTINCT store_type FROM store_list; $res = mysql_query($sql,$this-conn); $type = 'option value=0store type.../option'; while($row = mysql_fetch_array($res)) { $type .= 'option value=' . $row['id'] . '' . $row['store_type'] . '/option'; } return $type; } public function ShowStore() { $sql = SELECT store_name FROM store_list WHERE id_markets=$_POST[id] AND store_type=$_POST[id]; $res = mysql_query($sql,$this-conn); $Store = 'option value=0stores.../option'; while($row = mysql_fetch_array($res)) { $Store .= 'option value=' . $row['id'] . '' . $row['store_name'] . '/option'; } return $Store; } } $opt = new SelectList(); ? -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] Re: radio form submission
Thanks everyone. If there is no purpose, I would make the values of the inputs the values you want to store in your database. Muuch easier.. So I am trying to keep this simple and just assign the value with the radio button and then insert it into mysql database, but with the following code I am getting the mysql error: Unknown column '250kbps' in 'field list' when I choose the first radio button. I think it has to do with the value being a string, but I haven't been able to figure out the fix. Thanks everyone for your help in accomplishing one thing with many differnt techniques. It is greatly appreciated. Chris Form echo 'form method=post action= Store name: input type=text name=store_subject /br /br / Market:'; echo 'select name=store_mar'; while($row = mysql_fetch_assoc($result)) { echo 'option value=' . $row['mar_id'] . '' . $row['mar_name'] . '/option'; } echo '/selectbr /br /'; echo 'Broadband speed test results: br /br / 0-250kbpsinput type=radio name=post_tptest value=0-250kbps /| 250-300kbpsinput type=radio name=post_tptest value=250-300kbps /| 300-400kbpsinput type=radio name=post_tptest value=300-400kbps /| 400-600kbpsinput type=radio name=post_tptest value=400-600kbps /| 600kbps-3.8mbpsinput type=radio name=post_tptest value=600kbps-3.8mbps /br /br / Store visit details: br /br / textarea name=post_content //textareabr /br / input type=submit value=Add a store visit / /form'; } } } Insert Code $sql = INSERT INTO posts(post_content, post_date, post_tptest, post_store, post_by) VALUES (' . mysql_real_escape_string($_POST['post_content']) . ', NOW(), . $_POST['post_tptest'] . , . $storeid . , . $_SESSION['user_id'] . ); $result = mysql_query($sql); if(!$result) { //something went wrong, display the error echo 'An error occured while inserting your post. Please try again later.br /br /' . mysql_error(); $sql = ROLLBACK;; $result = mysql_query($sql); } else { $sql = COMMIT;; $result = mysql_query($sql); //after a lot of work, the query succeeded! echo 'You have succesfully created a href=store.php?id='. $storeid . 'your new store visit/a.'; } } } } } -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-DB] radio form submission
So far I am good on creating the form and submitting it to mysql database and calling the submitting value from a different script. My question is: How can I make it so when a user selects radio option value 1 it will then be displayed as 0-250kbps when I call it the value in the bottom script? forgive my indention. Gmail messes it up. My Form echo 'form method=post action= Store name: input type=text name=store_subject /br /br / Market:'; echo 'select name=store_mar'; while($row = mysql_fetch_assoc($result)) { echo 'option value=' . $row['mar_id'] . '' . $row['mar_name'] . '/option'; } echo '/selectbr /br /'; echo 'Broadband speed test results: br /br / 0-250kbpsinput type=radio name=post_tptest value=1 /| 250-300kbpsinput type=radio name=post_tptest value=2 /| 300-400kbpsinput type=radio name=post_tptest value=3 /| 400-600kbpsinput type=radio name=post_tptest value=4 /| 600kbps-3.8mbpsinput type=radio name=post_tptest value=5 /br /br / Store visit details: br /br / textarea name=post_content //textareabr /br / input type=submit value=Add a store visit / /form'; My display script $posts_sql = SELECT posts.post_store, posts.post_content, posts.post_tptest, posts.post_date, posts.post_by, users.user_id, users.user_name, users.first_name, users.last_name FROM posts LEFT JOIN users ON posts.post_by = users.user_id WHERE posts.post_store = . mysql_real_escape_string($_GET['id']) . ORDER BY posts.post_date DESC ; $posts_result = mysql_query($posts_sql); if(!$posts_result) { echo 'trtdThe posts could not be displayed, please try again later./tr/td/table'; } else { while($posts_row = mysql_fetch_assoc($posts_result)) { echo 'tr class=topic-post td class=user-post' . $posts_row['first_name'] . ' ' . $posts_row['last_name'] . 'br/' . date('m-d-Y h:iA', strtotime($posts_row['post_date'])) . '/td td class=post-content' . $posts_row['post_tptest'] . 'br/' . htmlentities(stripslashes($posts_row['post_content'])) . '/td /tr'; } } -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] radio form submission
On Thu, Jun 23, 2011 at 2:49 PM, Daniel P. Brown daniel.br...@parasane.net wrote: On Thu, Jun 23, 2011 at 15:46, Chris Stinemetz chrisstinem...@gmail.com wrote: Use an if or a switch. For example: I think your suggestions are exactly what I am looking for. I am not sure exactly where to place it. Do I insert it after the query statment? During your while() loop. This line here: td class=post-content' . $posts_row['post_tptest'] . If you convert it to a function as Karl suggested, you could do something like this: td class=post-content' . getSpeed($posts_row['post_tptest']) . I must be missing something. I am just getting a blank page. Your help is greatly apprecieated. The function and query statement is: function getSpeed($val) { if($val != 'undefined') { switch ($val){ case 1: $post_tptest = 0-250kbps; break; case 2: $post_tptest = 250-300kbps; break; case 3: $post_tptest = 300-400kbps; break; case 4: $post_tptest = 400-600kbps; break; case 5: $post_tptest = 600kbps-3.8mbps; break; default: $post_tptest = Speed Undetected; // or 0-250kbps break; } } else { return(Error, no speed value set); } } } $post_speed = getSpeed($post_tptest); //fetch the posts from the database $posts_sql = SELECT posts.post_store, posts.post_content, posts.post_speed, posts.post_date, posts.post_by, users.user_id, users.user_name, users.first_name, users.last_name FROM posts LEFT JOIN users ON posts.post_by = users.user_id WHERE posts.post_store = . mysql_real_escape_string($_GET['id']) . ORDER BY posts.post_date DESC ; The call: while($posts_row = mysql_fetch_assoc($posts_result)) { echo 'tr class=topic-post td class=user-post' . $posts_row['first_name'] . ' ' . $posts_row['last_name'] . 'br/' . date('m-d-Y h:iA', strtotime($posts_row['post_date'])) . '/td td class=post-content' . getSpeed($posts_row['post_tptest']) . 'br/' . htmlentities(stripslashes($posts_row['post_content'])) . '/td /tr'; } } Thank you! -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] radio form submission
Use an if or a switch. For example: I think your suggestions are exactly what I am looking for. I am not sure exactly where to place it. Do I insert it after the query statment? Thank you, Chris -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-DB] ORDER BY DESC
I have the bellow sql query. What is the correct way to add ORDER BY posts.post_date DESC I would like to add it to the end of my query, but I am just getting a blank page or my added query doesn't work echo: The posts could not be displayed, please try again later. The query is: //fetch the posts from the database $posts_sql = SELECT posts.post_store, posts.post_content, posts.post_date, posts.post_by, users.user_id, users.user_name FROM posts LEFT JOIN users ON posts.post_by = users.user_id WHERE posts.post_store = . mysql_real_escape_string($_GET['id']); Thank you in advance for your help. Chris -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] ORDER BY DESC
On Mon, Jun 20, 2011 at 3:49 PM, Karl DeSaulniers k...@designdrumm.com wrote: Try.. $posts_sql = SELECT posts.post_store, posts.post_content, posts.post_date, posts.post_by, users.user_id, users.user_name FROM posts LEFT JOIN users ON osts.post_by = users.user_id WHERE posts.post_store = .mysql_real_escape_string($_GET['id']). ORDER BY posts.post_date DESC; Got it working thanks everyone who responded. Working query: $posts_sql = SELECT posts.post_store, posts.post_content, posts.post_date, posts.post_by, users.user_id, users.user_name FROM posts LEFT JOIN users ON posts.post_by = users.user_id WHERE posts.post_store = . mysql_real_escape_string($_GET['id']) . ORDER BY posts.post_date DESC ; -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-DB] delete message function
I created the below delete function, but it doesn't seem to be working correctly. When I enter the correct password it get my echo Incorrect Password Did not Delete! When I leave the password blank the message will delete from mysql table. Am I missing something?? Thanks in advance, Chris function delete_message($msg) { extract($msg, EXTR_PREFIX_ALL, 'row'); $result = mysql_query(SELECT ID FROM mbmsgs WHERE Parent = $row_ID;); while ($row = mysql_fetch_array($result)) { delete_message($row); } mysql_query(DELETE FROM mbmsgs WHERE ID = $row_ID;); } $result = mysql_query(SELECT Title, Password FROM mbmsgs WHERE ID = {$_REQUEST['Msg']};); if (!$result) exit; if (!mysql_num_rows($result)) exit; extract(mysql_fetch_array($result), EXTR_PREFIX_ALL, 'msg'); if (isset($_POST['Password'])) { if (sha1($_POST['Password']) != $msg_Password) { echo Incorrect password did not delete!; exit; -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-DB] Re: delete message function
On Tue, Jun 14, 2011 at 12:31 AM, Chris Stinemetz chrisstinem...@gmail.com wrote: I created the below delete function, but it doesn't seem to be working correctly. When I enter the correct password it get my echo Incorrect Password Did not Delete! When I leave the password blank the message will delete from mysql table. Am I missing something?? Thanks in advance, Chris Sorry. I left out the call to the function. Below is the whole snippit for the function and call. function delete_message($msg) { extract($msg, EXTR_PREFIX_ALL, 'row'); $result = mysql_query(SELECT ID FROM mbmsgs WHERE Parent = $row_ID;); while ($row = mysql_fetch_array($result)) { delete_message($row); } mysql_query(DELETE FROM mbmsgs WHERE ID = $row_ID;); } $result = mysql_query(SELECT Title, Password FROM mbmsgs WHERE ID = {$_REQUEST['Msg']};); if (!$result) exit; if (!mysql_num_rows($result)) exit; extract(mysql_fetch_array($result), EXTR_PREFIX_ALL, 'msg'); if (isset($_POST['Password'])) { if (sha1($_POST['Password']) != $msg_Password) { echo Incorrect password did not delete!; exit; } $result = mysql_query(SELECT ID FROM mbmsgs WHERE Parent = {$_POST['Msg']};); while ($row = mysql_fetch_array($result)) { delete_message($row); } -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-DB] mysql_query
Hello all, Not sure what I am doing wrong. I have a simple form that populate the variables in a mysql query. I know the selected values are making it to the form porcessing script because I can echo them on the processing script as indicated below. You Selected Cell_Sect = 1_1 You Selected Date = 03/10/11 18:15 You Selected Market = MCI For some reason the above is all I am getting when I submit my form. I beleive it has somthing to do with my results query below. $result = mysql_query(select * FROM evdo WHERE Market like '%$term' and Cell_Sect = '$cat' and Date = '$subcat' LIMIT 10); Beow is my whole script for processing the form in case it maybe something else. Thanks, Chris !doctype html public -//w3c//dtd html 3.2//en html ?php // database access parameters $dbservertype='mysql'; $servername= left out for privacy; // username and password to log onto db server $dbusername=''; $dbpassword=''; // name of database $dbname='pcmd'; connecttodb($servername,$dbname,$dbusername,$dbpassword); function connecttodb($servername,$dbname,$dbuser,$dbpassword) { global $link; $link=mysql_connect ($servername,$dbuser,$dbpassword); if(!$link){ die('Could not conect: ' . mysql_error()); } echo 'YOU ARE CONNECTED TO PCMD DATABASE'; mysql_select_db($dbname,$link) or die (could not open db.mysql_error()); } End of connecting to database ? !!DOCTYPE HTML PUBLIC '-//W3C//DTD XHTML 1.0 Transitional//EN' 'http://www.w3.org/TR/xhtml1-transitional.dtd' head titleDemo Multiple drop down list box for PCMD data/title style type=text/css TABLE { border: 1px solid #98bf21; border-collapse:collapse; } TH { border: 1px solid #98bf21; padding-bottom: 4px; padding-left: 7px: padding-right: 7px; padding-top: 5px; font-size: 1.2em; background-color:limegreen; color: white; text-align: left; } TD { border: 1px solid #98bf21; padding-bottom: 2px; padding-left: 7px: padding-right: 7px; padding-top: 3px; font-size: 1.0em; } TR.alt TD { background-color: #eaf2d3; } /style meta name=GENERATOR content=Arachnophilia 4.0 meta name=FORMATTER content=Arachnophilia 4.0 /head body ?php $cat=$_POST['cat']; $subcat=$_POST['subcat']; $term=$_POST['term']; $result = mysql_query(select * FROM evdo WHERE Market like '%$term' and Cell_Sect = '$cat' and Date = '$subcat' LIMIT 10); $firstRow=1; $rowNum = 0; echo table; while($row = mysql_fetch_assoc($result)) { if($firstRow == 1) { echo tr; foreach($row as $key = $value) { echo th . $key . /th; } echo /trtr; $firstRow=0; $rowNum++; } else { if( ($rowNum++ % 2) == 1) { echo tr class=\alt\; } else { echo tr; } } foreach($row as $key = $value ) { echo td . $value . /td ; } echo /tr; } echo /table; echo You Selected Cell_Sect = $cat brYou Selected Date = $subcatbrYou Selected Market = $term; ? /body /html -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-DB] Event Calendar tutorial
Hello all, I am curious if anyone knows of a good tutorial to build an event calendar? Thank you, Chris -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-DB] PHP Delete confirmation
I have been trying to figure out how to add delete confirmation for the bellow snippet of code. I would prefer not to use javascript. Can anyone offer any advise on how to right the delete confirmation in PHP? Thank you in advance. P.S. I apologize for the indention. For some reason gmail messes it up. ?php // loop through results of database query, displaying them in the table while($row = mysql_fetch_array( $result )) { // echo out the contents of each row into a table echo tr; echo 'td' . $row['Name'] . '/td'; echo 'td' . $row['Date'] . '/td'; echo 'td' . $row['StoreInfo'] . '/td'; echo 'td' . $row['Address'] . '/td'; echo 'td' . $row['Type'] . '/td'; echo 'td' . $row['EngTech'] . '/td'; echo 'td' . $row['StoreManager'] . '/td'; echo 'td' . $row['BBtime'] . '/td'; echo 'td' . $row['BBup'] . '/td'; echo 'td' . $row['BBdown'] . '/td'; echo 'td' . $row['SiteSect'] . '/td'; echo 'td' . $row['VoiceCall'] . '/td'; echo 'td' . $row['Comments'] . '/td'; echo 'tda href=edit.php?id=' . $row['id'] .'Edit/a/td'; echo 'tda href=delete.php?id=' . $row['id'] .'Delete/a/td'; echo /tr; } // close table echo /table; ? -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-DB] automactic email notification
I have an all-in-one form which allows record edits, adds and deletes in a mysql table. I would like to add the ability to automatically send email update to a distribution list whenever a record is edited, deleted, or added. I won't be hosting my own mail server so instead I will be using remote SMTP. The mail script I created works just fine I am just not sure how to put this all together for the notifications when the table is altered. Thank you in advance! Mail Script: ?php require_once Mail.php; $from = Someone email@.com; $to = Someone Recipient email@.com; $subject = Hi!; $body = Hi,\n\nHow are you?; $host = example.com; $port = 587; $username = example; $password = example; $headers = array ('From' = $from, 'To' = $to, 'Subject' = $subject); $smtp = Mail::factory('smtp', array ('host' = $host, 'port' = $port, 'auth' = true, 'username' = $username, 'password' = $password)); $mail = $smtp-send($to, $headers, $body); if (PEAR::isError($mail)) { echo(p . $mail-getMessage() . /p); } else { echo(pMessage successfully sent!/p); } ? Form Script: !DOCTYPE HTML PUBLIC -//W3C//DTD HTML 4.01//EN http://www.w3.org/TR/html4/strict.dtd; html head titleATC West Swap/title script type='text/javascript' src='../js/jquery-1.2.3.js'/script script type='text/javascript' src='../js/menu.js'/script link rel=stylesheet href=../css/style.css type=text/css media=screen / /style /head body div id=boundary h1West RF Engineering Dashboard/h1 ul id=nav lia href=../index.phpHome/a/li lia href=#ATC West Swap/a ul lia href=atcswap.phpExpiring Leases/a/li lia href=lowmou.phpLow MOU/a/li /ul /li /ul div id=content /div p id=footerLow MOU WEST/p HR ? $objConnect = mysql_connect(localhost,cstine,cstine) or die(mysql_error()); $objDB = mysql_select_db(atc); //*** Add Condition ***// if($_POST[hdnCmd] == Add) { $strSQL = INSERT INTO lowmou ; $strSQL .=(SiteID,NewSiterraSiteID,ATCSiteID,CricketRegion,Comments, Progress,willsitebedecom,relocationTowerVendor) ; $strSQL .=VALUES ; $strSQL .=('.$_POST[txtAddSiteID].','.$_POST[txtAddNewSiterraSiteID].' ; $strSQL .=,'.$_POST[txtAddATCSiteID].' ; $strSQL .=,'.$_POST[txtAddCricketRegion].','.$_POST[txtAddComments].' ; $strSQL .=,'.$_POST[txtAddProgress].' ; $strSQL .=,'.$_POST[txtAddwillsitebedecom].','.$_POST[txtAddrelocationTowerVendor].') ; $objQuery = mysql_query($strSQL); if(!$objQuery) { echo Error Save [.mysql_error().]; } //header(location:$_SERVER[PHP_SELF]); //exit(); } //*** Update Condition ***// if($_POST[hdnCmd] == Update) { $strSQL = UPDATE lowmou SET ; $strSQL .=SiteID = '.$_POST[txtEditSiteID].' ; $strSQL .=,NewSiterraSiteID = '.$_POST[txtEditNewSiterraSiteID].' ; $strSQL .=,ATCSiteID = '.$_POST[txtEditATCSiteID].' ; $strSQL .=,CricketRegion = '.$_POST[txtEditCricketRegion].' ; $strSQL .=,Comments = '.$_POST[txtEditComments].' ; $strSQL .=,Progress = '.$_POST[txtEditProgress].' ; $strSQL .=,willsitebedecom = '.$_POST[txtEditwillsitebedecom].' ; $strSQL .=,relocationTowerVendor = '.$_POST[txtEditrelocationTowerVendor].' ; $strSQL .=WHERE SiteID = '.$_POST[hdnEditSiteID].' ; $objQuery = mysql_query($strSQL); if(!$objQuery) { echo Error Update [.mysql_error().]; } //header(location:$_SERVER[PHP_SELF]); //exit(); } //*** Delete Condition ***// if($_GET[Action] == Del) { $strSQL = DELETE FROM lowmou ; $strSQL .=WHERE SiteID = '.$_GET[srID].' ; $objQuery = mysql_query($strSQL); if(!$objQuery) { echo Error Delete [.mysql_error().]; } //header(location:$_SERVER[PHP_SELF]); //exit(); } $strSQL = SELECT * FROM lowmou; $objQuery = mysql_query($strSQL) or die (Error Query [.$strSQL.]); ? form name=frmMain method=post action=?=$_SERVER[PHP_SELF];? input type=hidden name=hdnCmd value= table tr thSiteID /th thNewSiterraSiteID /th thATCSiteID /th thCricketRegion /th thComments /th thProgress/th thWill site be decom?/th thRelocation Tower Vendor/th thEdit /th thDelete /th /tr ? while($objResult = mysql_fetch_array($objQuery)) { ? ? if($objResult[SiteID] == $_GET[srID] and $_GET[Action] == Edit) { ? tr tddiv align=center input type=text name=txtEditSiteID size=5 value=?=$objResult[SiteID];? input type=hidden name=hdnEditSiteID size=5 value=?=$objResult[SiteID];? /div/td tdinput type=text name=txtEditNewSiterraSiteID size=10 value=?=$objResult[NewSiterraSiteID];?/td tdinput type=text name=txtEditATCSiteID size=10
Re: [PHP-DB] Re: automactic email notification
On Wed, Apr 13, 2011 at 11:08 AM, Jim Giner jim.gi...@albanyhandball.com wrote: Without looking at your HUGE code stream, I'm curious what your question really is. If you know how to send an email, and you know how to update your table, then isn't your task simply to send an email after updating the table? Yes. I would make the email a function to get it out of the way and then add a call to it right after I did an update. The user probably gets a message of the successful update, so when you do that, that's when you call your email function. Maybe have a couple of arguments in the function to pass some specifics and that's that. Could you possbily show me an example? I am a newby when it comes to PHP. Thank you! -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-DB] error
I am getting the following error when I try to use my edit.php script: 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 '' at line 1 I can't seem to find anything wrong with my syntax below. Has anyone ever had this issue? I have been googling it for a couple hours now. Thank you in advance! Chris ?php error_reporting(E_ALL); ini_set('display_errors', '1'); /* EDIT.PHP Allows user to edit specific entry in database */ // creates the edit record form // since this form is used multiple times in this file, I have made it a function that is easily reusable function renderForm($id, $Cricket_Region, $Market, $error) { ? !DOCTYPE HTML PUBLIC -//W3C//DTD HTML 4.01//EN http://www.w3.org/TR/html4/strict.dtd; html head titleEdit Record/title /head body ?php // if there are any errors, display them if ($error != '') { echo 'div style=padding:4px; border:1px solid red; color:red;'.$error.'/div'; } ? form action= method=post input type=hidden name=id value=?php echo $id; ?/ div pstrongID:/strong ?php echo $id; ?/p strongCricket Region: */strong input type=text name=Cricket Region value=?php echo $Cricket_Region; ?/br/ strongMarket: */strong input type=text name=Market value=?php echo $Market; ?/br/ p* Required/p input type=submit name=submit value=Submit /div /form /body /html ?php } // connect to the database include('../PHP_Scripts/connect-db.php'); // check if the form has been submitted. If it has, process the form and save it to the database if (isset($_POST['submit'])) { // confirm that the 'id' value is a valid integer before getting the form data if (is_numeric($_POST['id'])) { // get form data, making sure it is valid $id = $_POST['id']; $Cricket_Region = mysql_real_escape_string(htmlspecialchars($_POST['Cricket_Region'])); $Market = mysql_real_escape_string(htmlspecialchars($_POST['Market'])); // check that firstname/lastname fields are both filled in if ($Cricket_Region == '' || $Market == '') { // generate error message $error = 'ERROR: Please fill in all required fields!'; //error, display form renderForm($id, $Cricket_Region, $Market, $error); } else { // save the data to the database mysql_query(UPDATE expiringleases SET Cricket_Region='$Cricket_Region', Market='$Market' WHERE id='$id') or die(mysql_error()); // once saved, redirect back to the view page header(Location: view.php); } } else { // if the 'id' isn't valid, display an error echo 'Error!'; } } else // if the form hasn't been submitted, get the data from the db and display the form { // get the 'id' value from the URL (if it exists), making sure that it is valid (checking that it is numeric/larger than 0) if (isset($_GET['id'])) { // query db $id = $_GET['id']; $result = mysql_query(SELECT * FROM expiringleases WHERE id=$id) or die(mysql_error()); $row = mysql_fetch_array($result); // check that the 'id' matches up with a row in the databse if($row) { // get data from db $Cricket_Region = $row['Cricket_Region']; $Market = $row['Market']; // show form renderForm($id, $Cricket_Region, $Market, ''); } else // if no match, display result { echo No results!; } } else // if the 'id' in the URL isn't valid, or if there is no 'id' value, display an error { echo 'Error!'; } } ? -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] error
I am pretty sure it is in my code. I am just getting an error form one of my echoes. Still can't get it to work correctly though. Any help is greatly appreciated. Thank you, Chris ?php /* EDIT.PHP Allows user to edit specific entry in database */ // creates the edit record form // since this form is used multiple times in this file, I have made it a function that is easily reusable function renderForm($id, $Cricket_Region, $Market, $error) { ? !DOCTYPE HTML PUBLIC -//W3C//DTD HTML 4.01//EN http://www.w3.org/TR/html4/strict.dtd; html head titleEdit Record/title /head body ?php // if there are any errors, display them if ($error != '') { echo 'div style=padding:4px; border:1px solid red; color:red;'.$error.'/div'; } ? form action= method=post input type=hidden name=id value=?php echo $id; ?/ div pstrongID:/strong ?php echo $id; ?/p strongFirst Name: */strong input type=text name=Cricket_Region value=?php echo $Cricket_Region; ?/br/ strongLast Name: */strong input type=text name=Market value=?php echo $Market; ?/br/ p* Required/p input type=submit name=submit value=Submit /div /form /body /html ?php } // connect to the database include('../PHP_Scripts/connect-db.php'); // check if the form has been submitted. If it has, process the form and save it to the database if (isset($_POST['submit'])) { // confirm that the 'id' value is a valid integer before getting the form data if (is_string($_POST['Search_Ring'])) { // get form data, making sure it is valid $id = $_POST['Search_Ring']; $Cricket_Region = mysql_real_escape_string(htmlspecialchars($_POST['Cricket_Region'])); $Market = mysql_real_escape_string(htmlspecialchars($_POST['Market'])); // check that Cricket_Region/Market fields are both filled in if ($Cricket_Region == '' || $Market == '') { // generate error message $error = 'ERROR: Please fill in all required fields!'; //error, display form renderForm($id, $Cricket_Region, $Market, $error); } else { // save the data to the database mysql_query(UPDATE expiringleases SET Cricket_Region='$Cricket_Region', Market='$Market' WHERE Search_Ring='$id') or die(mysql_error()); // once saved, redirect back to the view page header(Location: ATC.php); } } else { // if the 'id' isn't valid, display an error echo 'Error!'; } } else // if the form hasn't been submitted, get the data from the db and display the form { // get the 'id' value from the URL (if it exists), making sure that it is valid (checing that it is numeric/larger than 0) if (isset($_GET['Search_Ring'])) { // query db $id = $_GET['Search_Ring']; $result = mysql_query(SELECT * FROM expiringleases WHERE Search_Ring=$id) or die(mysql_error()); $row = mysql_fetch_array($result); // check that the 'id' matches up with a row in the databse if($row) { // get data from db $Cricket_Region = $row['Cricket_Region']; $Market = $row['Market']; // show form renderForm($id, $Cricket_Region, $Market, ''); } else // if no match, display result { echo No results!; } } else // if the 'id' in the URL isn't valid, or if there is no 'id' value, display an error { echo 'Error!'; } } -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] Re: jpgraph and mysql passing array
On Sat, Mar 26, 2011 at 9:44 PM, Brian Smither bhsmit...@gmail.com wrote: Would you try an experiment? Thanks for for the suggestion but this didn't seem to work. I beleive it is a header conflict based on what I have researched. I just can't seem to find a solution. In this line: $sql = (SELECT * FROM evdobanding WHERE Market like '%$term' and Cell_Sect = '$term2' and Date = '$term3' ORDER BY distance asc); Change to: $sql = SELECT * FROM evdobanding WHERE Market like '%.$term.' and Cell_Sect = '.$term2.' and Date = '.$term3.' ORDER BY distance asc; That is, remove the parenthesis and concatenate the variables into the string. The code in the PHP block: echo TEST DATA PRINT; print_r($datay,false); is passing all the values from the sql query because I can see them on the page with the jpgraph error. For example: TEST DATA PRINTArray ( [0] = 665 [1] = 7093 [2] = 3 [3] = 45816 [4] = 70848 [5] = 41365 [6] = 35676 [7] = 22434 [8] = 5450 [9] = 29131 [10] = 35244 [11] = 48614 [12] = 51748 [13] = 55497 [14] = 79042 [15] = 732 [16] = 1375 [17] = 1094 [18] = 897 [19] = 1122 [20] = 3059 [21] = 5350 [22] = 5080 [23] = 3082 [24] = 2737 [25] = 326 [26] = 1334 [27] = 736 [28] = 469 [29] = 127 [30] = 105 [31] = 111 [32] = 197 [33] = 208 [34] = 950 [35] = 9 [36] = 9 [37] = 19 [38] = 8 [39] = 17 [40] = 90 [41] = 1917 [42] = 1289 [43] = 2051 [44] = 1534 [45] = 1 [46] = 2 [47] = 4 [48] = 4 [49] = 7 [50] = 8 [51] = 9 [52] = 18 [53] = 22 [54] = 5 [55] = 3 [56] = 1 [57] = 1 [58] = 2 ) JpGraph ERROR 25121 From the research I have done so far using Jpgraph I have found this link to a similar issue: http://ubuntuincident.wordpress.com/tag/jpgraph/ but I am unable to get my arrays from the sql query to populate the graph. Thank you in advance, Chris -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-DB] jpgraph and mysql passing array
Hello, I hope you can help me. The Jpgraph forum seems to be pretty uneventful with participation. I am trying to pass arrays through the image tag to populate my variables for my graph. I keep getting an error that there is no input. Do you have any suggestions? I would greatly appreciate it! I have been trying to figure this out for several hours. Below is my code: I need some help with finding a solution. For some reason my graph is not showing up when it evident that my arrays are being passed. When I use: echo TEST DATA PRINT; print_r($datay,false); --- I keep getting the error: Empty input data array specified for plot. --- My php script is as follows: --- !DOCTYPE html PUBLIC -//W3C//DTD XHTML 1.0 Transitional//EN http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd; html xmlns=http://www.w3.org/1999/xhtml; head titleKCRF Dashboard/title ?php ini_set('display_errors', 1); error_reporting(E_ALL); $term=$_POST['term']; $term2=$_POST['term2']; $term3=$_POST['term3']; //include ('err_reporting.php'); require ('PHP_Scripts/config.php'); require_once ('jpgraph/jpgraph.php'); require_once ('jpgraph/jpgraph_line.php'); $sql = (SELECT * FROM evdobanding WHERE Market like '%$term' and Cell_Sect = '$term2' and Date = '$term3' ORDER BY distance asc); $result = mysql_query($sql); while($row = mysql_fetch_array($result)) { $datay[] = $row[MBusage]; $datax[] = $row[Distance]; } echo TEST DATA PRINT; print_r($datay,false); ? style type=text/css !-- #navbar ul { margin: 0; padding: 5px; list-style-type: none; text-align: center; background-color: #000; } #navbar ul li { display: inline; } #navbar ul li a { text-decoration: none; padding: .2em 1em; color: #fff; background-color: #000; } #navbar ul li a:hover { color: #000; background-color: #fff; } -- /style /head fieldset style=border: 1px ridge limegreen; color: limegreen; legend style=color: #000; font-family: verdana; font-size: 14pt;EVDO PCMD BANDING/legend body div id=navbar ul lia href=index.phpHome/a/li lia href=dd3.phpEVDO PCMD KPI/a/li lia href=banding.phpEVDO Distance Banding/a/li lia href=test.phpTEST_BANDING/a/li lia href=LinkHere/a/li /ul /div /fieldset ?php echo You Selected the following:brMarket = $term brCell_Sector = $term2brTimestamp = $term3br; ? img src=bandingGraph.php?$datax=$row[Distance]$datay=$row[MBusage]; // I think this is where I am having issues. /body /html --- My graph script is: ?php // content=text/plain; charset=utf-8 require_once ('jpgraph/jpgraph.php'); require_once ('jpgraph/jpgraph_line.php'); // Create the graph. $graph = new Graph(1024,450,auto); $graph-SetScale(textlin); $graph-SetShadow(); // Slightly adjust the legend from it's default position $graph-legend-Pos(0.03,0.5,right,center); $graph-legend-SetFont(FF_FONT1,FS_BOLD); //Setup X-scale $graph-xaxis-SetTextTickInterval(10); $graph-xaxis-SetTickLabels($datax); //$graph-xtick_factor = 1; $graph-xaxis-SetLabelAngle(30); // Create the linear plot $lineplot= new LinePlot($datay); $p1 = new LinePlot($datay); $p1-mark-SetType(MARK_DIAMOND); $p1-mark-SetFillColor(blue); $p1-mark-SetWidth(; $p1-SetColor(blue); $p1-SetCenter(); $p1-SetLegend(EVDO F1 Carrier); $graph-Add($p1); // Add the plot to the graph $graph-Add($lineplot); // Setup margin and titles $graph-img-SetMargin(40,40,50,60); $graph-title-SetMargin(10); $graph-title-Set(Distance in MIles); $graph-title-SetFont(FF_VERDANA,FS_BOLD,12); // set margin color $graph-SetMarginColor('#dcfade'); // Use built in font $graph-title-SetFont(FF_ARIAL,FS_NORMAL,14); $graph-ygrid-SetFill(true,'#EFEFEF@0.6','#e5e5e5@0.6'); $graph-xgrid-Show(); $graph-SetBackgroundImageMix(15); $graph-legend-Pos(0.02,0.03,right,top); $graph-legend-SetFont(FF_FONT1,FS_BOLD); $graph-xaxis-title-Set(Miles); $graph-yaxis-title-Set(MBusage); $graph-SetAlphaBlending(); // Display the graph $graph-Stroke(); ? Thank you, Chris -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] SUM() Math in mySQL
On 20/12/10 15:38, Ron Piggott wrote: I am working on the query below. It’s purpose is to manage the RSS Feed for the site. The part of the query I am struggling with is: SUM(`include_in_rss_feed`) AS current_rss_feed What I need is the total value of *ALL* the `include_in_rss_feed` , not the specific row. `include_in_rss_feed` is an integer. It only ever has a value of 1 Well you're going to get an error with your current attempt - but you know that already I assume. You have an aggregate function (sum) but no group by clause for the outer query. I think you're better off just having 2 queries - one with the sum() and the group by include_in_rss_feed, and one with all of your other data. I don't think combining them will be very easy. -- Postgresql php tutorials http://www.designmagick.com/ -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] NULL to 0 result
On 15/12/10 21:42, Richard Quadling wrote: On 14 December 2010 21:53, Ron Piggottron.pigg...@actsministries.org wrote: What change is needed to this query so if “currently_in_rss” is NULL it will be assigned a value of 0 SELECT `reference`, COUNT(`reference`) AS currently_in_rss FROM `ministry_profiles` WHERE `rss_feed_include` = 1 GROUP BY `rss_feed_include` Ron Doesn't that query give you an error saying that `reference` isn't in the GROUP BY clause? Nah mysql lets you do it. Other db's enforce it as you pointed out. -- Postgresql php tutorials http://www.designmagick.com/ -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] Reading from file
On 02/11/10 14:34, Ethan Rosenberg wrote: Dear List - Thank you for all your help. Here is another one. I have a file [/home/ethan/PHP/RecNum] which consists of the number 1005. It also has been 1005. No matter how I do it, it is only recognized as 1. Here is the code. In this case, the file is 1005. $fptr1 = fopen(/home/ethan/PHP/RecNum, r+); $recNum = (int)fscanf($fptr1,%s); echo $recNum; //which always is 1 If I do not typecast $recNum to int, the value is Array. Right, which is what the manual says as well: http://www.php.net/fscanf If only two parameters were passed to this function, the values parsed will be returned as an array. So you can either do: $line = fscanf($fptr1, %s); $recNum = $line[0]; // get the first element in the array as $recNum or while ($line = fscanf($fptr1, %s\n)) { $recNum = $line[0]; } -- Postgresql php tutorials http://www.designmagick.com/ -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] Variable Assignment
However, I am totally confused. All the texts state that to set a variable, the code is: $st=100; That's how you do it in php. Doing it in the db is different and depends on the db you are using. -- Postgresql php tutorials http://www.designmagick.com/ -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] Creating an INDEX on multiple tables?
On 22/10/10 21:00, Ron Piggott wrote: I have moved the GROUP BY outside now Chris. In the queries that make up the UNION ALL (such as below) is there a way to only SELECT matches that are 70% or greater based on the users input? Right now each and every listing is a search result. http://dev.mysql.com/doc/refman/5.0/en/fulltext-natural-language.html has info about doing that sort of thing. -- Postgresql php tutorials http://www.designmagick.com/ -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] Creating an INDEX on multiple tables?
On 22/10/10 13:31, Ron Piggott wrote: Bastien (and others) I am still having one problem with this query I don't know how to resolve: When I add the category column: `ministry_categories`.`category` as part of the MATCH () I receive the error: Incorrect arguments to MATCH I create the LEFT OUTER JOINs to allow additional columns to be part of the MATCH. I have made this category column a FULLTEXT index in the ministry_categories table. The query that produces the error is below. You can't do a full text match across tables. One of the previous suggestions was to union the results, you end up with something like select field from t1 where match(field1, field2) against ('search term') union all select field from t2 where match(field3, field4) against ('search term') etc though I don't know if that would work (I've never tried it). -- Postgresql php tutorials http://www.designmagick.com/ -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] Creating an INDEX on multiple tables?
On 22/10/10 15:24, Ron Piggott wrote: The query works using UNION ALL and MATCH ( ) AGAINST --- one table at a time for the MATCH. The down side is that each SELECT is giving it's own search results. The directory listings are being displayed multiple times when one of the SELECTS produces it as a result. How do I limit the results? Can I do this some how with results.reference and results.organization (I made the UNION ALLs sub queries) Get rid of the group by references inside each bit and move it to the outer: SELECT reference, organization FROM ( SELECT `ministry_profiles`.`reference`, `ministry_profiles`.`organization` FROM ... UNION ALL SELECT `ministry_profiles`.`reference`, ... ) GROUP BY reference, organization; You'll get one reference per organization. -- Postgresql php tutorials http://www.designmagick.com/ -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] RE: php-db Digest 19 Oct 2010 22:24:15 -0000 Issue 4629
On 20/10/10 09:55, Jimmy Sole wrote: Hello everyone, I'm having trouble executing a insert select query in PHP Here is the code: $exec = self::init()-prepare(INSERT INTO owners (f_name, l_name, username, password, email, company, str_address, city, state, zip, phone, website, desc, categories) SELECT f_name, l_name, username, password, email, company, street_address, city, state, zip, phone_number, website, description, categories FROM pending WHERE pid '0'); if ($exec-execute() !== false) { return true; } else { throw new Exception(Error processing the query.); } Any help would be appreciated, as PDO is not returning an error or anything. Doesn't look like it should - it looks like a valid query. Check your database logs or even run the query inside a transaction (and rollback) to see if it errors. -- Postgresql php tutorials http://www.designmagick.com/ -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] Query for duplicate records
On 18/10/10 06:55, Ron Piggott wrote: Is there a query you could help me write a SELECT query that would search table `ministry_profiles` for where column `organization` has the same organization more than once? I am trying to delete the duplicate organization records, but I am working with 1,000+ businesses and I can't go through each record looking for duplicates. select organization, count(*) from ministry_profiles group by organization having count(*) 1; gives you which organization has more than 1 account (and how many duplicates you are dealing with). -- Postgresql php tutorials http://www.designmagick.com/ -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] Re: SOUNDS_LIKE, SOUNDEX
On 12/10/10 08:45, Ron Piggott wrote: After looking at the response I tried to make 2 mySQL queries that I need help with. (I didn't use the PHP functions because I am trying to query the database for results: #1: SELECT `word` FROM `bible_concordance_words` WHERE SOUNDEX('command') ORDER BY `word` ASC - There are no results, I don't understand because Commanded, Commander, Commanding, Commandment, Commandments are all in the datase #2: SELECT `word` FROM `bible_concordance_words` WHERE command SOUNDS_LIKE `word` ORDER BY `word` ASC - I receive the error: 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 'SOUNDS_LIKE `word` ORDER BY `word` ASC RTFM? http://dev.mysql.com/doc/refman/5.0/en/string-functions.html#operator_sounds-like This stuff isn't that difficult to find. -- Postgresql php tutorials http://www.designmagick.com/ -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] Slashes or no slashes
In the case that your comparing a field to a field in the database (the field name) do you escape that or because it is hardcoded you dont need to? My thoughts are that you need to escape all data going in. Correct. A field name is not data though. You've already validated it (somehow, either by hardcoding it, or checking it against field names to make sure it's a proper field and doesn't contain weird chars). But I do not know if it will match. EG: /** * updateProduct */ function updateProduct($ProductName, $field, $value){ $q = UPDATE .TBL_PRODUCTS. SET .$field. = '.mysql_real_escape_string($value).' WHERE ProductName = '.mysql_real_escape_string($ProductName).'; return $this-query($q); } Do I escape $field? mysql_real_escape_string($field)? You can only escape data, not field or table (or database) names. -- Postgresql php tutorials http://www.designmagick.com/ -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] Slashes or no slashes
You use mysql_real_escape_string for queries on the way in. $query = select * from table where name='.mysql_real_escape_string($_POST['name']).'; You use htmlspecialchars on the way out: $value = htmlspecialchars($row['name']); -- Postgresql php tutorials http://www.designmagick.com/ -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php Ah.. thanks Chris. If I want to compare that value I get from the database to what a user entered, do I escape the value they entered or add htmlspecialchars to it before comparing it to what comes out of the database. Sorry this is such a PHP 101 question. If you have time to respond, please do, otherwise no worries, I am sure I will figure it out. If you want to compare, you're doing a query - so use mysql_real_escape_string: $query = select blah from table where name=' . mysql_real_escape_string($_POST['name']) . '; When you print results, you use htmlspecialchars: echo Your search for . htmlspecialchars($_POST['name']) . returned X resultsbr/; -- Postgresql php tutorials http://www.designmagick.com/ -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] Slashes or no slashes
To be more specific. Is this correct? function confirmUP($username, $password){ $username = mysql_real_escape_string($username); /* Verify that user is in database */ $q = SELECT password FROM TBL-U WHERE username = '$username'; I normally do it in the query in case you use the variable somewhere else but here it's ok because you don't use $username elsewhere. Be careful though, it may bite you and it will be difficult to track down. eg $q = select password from table where username=' . mysql_real_escape_string($username) . '; echo You entered . htmlspecialchars($username) . , either it was wrong or the password was wrong. Try again.; Doing the escape_string before the query means you end up with (basically) htmlspecialchars(mysql_real_escape_string($username)); which will cause weird characters to show up in certain cases. $result = $this-query($q); if(!$result || (mysql_numrows($result) 1)){ return 1; //Indicates username failure } /* Retrieve password from result */ $dbarray = mysql_fetch_array($result); $dbarray['password'] = htmlspecialchars($dbarray['password']); $password = mysql_real_escape_string(md5($password)); $password = htmlspecialchars($password); You're not displaying the password so don't htmlspecialchars it. Just: if ($dbarray['password'] == md5($password)) { return 0; // success! } Only specialchars it when you display it (like the echo above). -- Postgresql php tutorials http://www.designmagick.com/ -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] Slashes or no slashes
Just to make sure, cause I am ready to get past this. Is this correct? function confirmUP($username, $password){ /* Verify that user is in database */ $q = SELECT password FROM .TBL_USERS. WHERE username = '.mysql_real_escape_string($username).'; Perfect. /* Retrieve password from result */ $dbarray = mysql_fetch_array($result); $dbarray['password'] = htmlspecialchars($dbarray['password']); //Or is this where I need to leave htmlspecialchars off too? Leave it off. You're not displaying $dbarray['password'] here - so you don't need to use htmlspecialchars. -- Postgresql php tutorials http://www.designmagick.com/ -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] Slashes or no slashes
Got it. So only when I am going to diplay the result from the database. I see. Or email (or otherwise present it to the user), yes. But for comparing $dbarray['password'] to $password, don't I have to escape $password and then md5 it? Right. -- Postgresql php tutorials http://www.designmagick.com/ -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] Slashes or no slashes
On 20/08/10 08:05, Karl DeSaulniers wrote: On Aug 19, 2010, at 4:44 PM, Karl DeSaulniers wrote: On Aug 19, 2010, at 4:36 PM, Daevid Vincent wrote: You should be using http://us2.php.net/manual/en/function.mysql-escape-string.php You don't need to search with extra slashes for retrieval. -Original Message- From: Karl DeSaulniers [mailto:k...@designdrumm.com] Sent: Thursday, August 19, 2010 2:29 PM To: php-db@lists.php.net Subject: [PHP-DB] Slashes or no slashes Hello, When I add an item to my database and I use addslashes(), do I have to use addslashes() to a query that looks for that item? Or would I be adding double slashes and canceling my own result? TIA Karl DeSaulniers Design Drumm http://designdrumm.com -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php Ah, but lets say I am using a character set utf-8, I should use mysql_real_escape_string() instead? Best, Karl DeSaulniers Design Drumm http://designdrumm.com -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php For a line like this.. return htmlspecialchars(stripslashes($this-values[$field])); would I change this to? return mysql_real_escape_string($this-values[$field]); Or do I still need the htmlspecialchars? In that case would I change it to? return htmlspecialchars(mysql_real_escape_string($this-values[$field])); You use mysql_real_escape_string for queries on the way in. $query = select * from table where name='.mysql_real_escape_string($_POST['name']).'; You use htmlspecialchars on the way out: $value = htmlspecialchars($row['name']); -- Postgresql php tutorials http://www.designmagick.com/ -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] SELECT with ' in search term
On 13/08/10 13:26, Ron Piggott wrote: If the variable $segment has an ' in it the $query won't work because of having 3 ' 's. Should I be using: $segment = mysql_real_escape_string($segment); before querying the database? Use it in your query. Don't use it anywhere else. Your code may use it after the query and cause weird stuff, ala: $segment = 'this is my segment'; $segment = mysql_real_escape_string($segment); $query = ; echo 'My segment name is ' . htmlspecialchars($segment); So it'll become: $query=SELECT `reference` FROM `bible_concordance_words` WHERE `word` = ' . mysql_real_escape_string($segment) . ' LIMIT 1; Please note: $segment wasn't submitted through a form. Doesn't matter. -- Postgresql php tutorials http://www.designmagick.com/ -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] Re: Stuck in apostrophe hell
On 03/08/10 23:04, paul_s_john...@mnb.uscourts.gov wrote: Yes, I may have mixed up the input and output from different iterations of running it. Let me try posting this again although it may not be an issue. Once again if I enter two sequential apostrophes in the name (O''Brien) the INSERT passes right through to MySQL without an error. THE INPUT: $sql_insert_registration = sprintf(INSERT INTO Registrations ( Class_ID, prid, Registrant, Company, Phone, Email ) VALUES ( $_POST[Class_ID], ^^ needs a mysql_real_escape_string or validation to make sure it's an integer $_POST[prid], ^^ needs a mysql_real_escape_string or validation to make sure it's an integer '%s',. ^^ has a mysql_real_escape_string, but it's the only one. parseNull($_POST['Company'])., Without knowing what this function does, it's hard to say what this needs. '$_POST[Phone]', ^^ needs a mysql_real_escape_string '$_POST[Email]' ^^ needs a mysql_real_escape_string ), mysql_real_escape_string($_POST['Registrant'])); This has already all been pointed out previously. -- Postgresql php tutorials http://www.designmagick.com/ -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] calling a page for each row
On 16/07/10 09:38, listread wrote: We need to load a page which performs some tasks specific to each record, including writing some results to another table. I have tried to place a page loading script within the while loop that creates the table, but it seems to only load the page on the last record in the table. Is there a better way to do this? Why does it need to call a page to do all the work? If it was just a function call you'd be off and racing already. -- Postgresql php tutorials http://www.designmagick.com/ -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] calling a page for each row
On 16/07/10 09:51, listread wrote: On 7/15/2010 6:42 PM, Chris wrote: On 16/07/10 09:38, listread wrote: We need to load a page which performs some tasks specific to each record, including writing some results to another table. I have tried to place a page loading script within the while loop that creates the table, but it seems to only load the page on the last record in the table. Is there a better way to do this? Why does it need to call a page to do all the work? If it was just a function call you'd be off and racing already. The page I want to call is a little involved. It makes a geocode request from Google Maps and then parses the resulting json code and then writes the parsed data to another table. I guess it could be done with functions, but the other page was already written... :-) I guess you could do a file_get_contents on the url of the page. If I call a function, will the while loop wait for the function to complete before going to the next row? Yes. -- Postgresql php tutorials http://www.designmagick.com/ -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] anyone has experience with pgslq Cybercluster 2 ?
On 02/06/10 04:34, Artur Ejsmont wrote: Hi there i just noticed announcement of cybercluster 2 release for postgres. http://www.cybertec.at/en/postgresql_news they say its open source but did not find downloads on their site ; ) Anyone has experinece with it? i loved postgres and used to work with it for a long time but lack of easy and reliable replication forced me to move back to mysql. To be honest did not look at postgres for a few years now : / Anyone could share some tips on php-pgsql-replication experiences? There are some comparisons here between the different postgres replication options: http://wiki.postgresql.org/wiki/Replication%2C_Clustering%2C_and_Connection_Pooling -- Postgresql php tutorials http://www.designmagick.com/ -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] Need Simple PHP mysql search engine script
On 24/05/10 16:01, nagendra prasad wrote: Hi Chaitanya, I have used the below script but its not meeting my requirements. What I need is that I have a database in which their are names which I wanted to use as keywords. I want to search with only one variable called Names. the other stuff will come along with it. Please help me if anyone knows a good script for it. Requirements that specific won't have a generic script. Start coding.. -- Postgresql php tutorials http://www.designmagick.com/ -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] PHP / iODBC / PostGreSQL: running into a deadlock
To try to solve this issue, I grabed the sources for PHP (5.3.2) and libiodbc (3.52.7). When ran under GDB, I can observe the following: odbc_exec() [PHP code] calls SQLAllocStmt() [libiodbc code], which calls some internal function that tries to call SQLAllocStmt(), in some indirect recursive way. As SQLAllocStmt() is protected by a mutex, there's a deadlock. The BT is as follows: Probably best to ask on the php-internals list, they write the C code behind php so will be best able to help you. -- Postgresql php tutorials http://www.designmagick.com/ -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] Call two class object failed
On 24/05/10 11:55, win.a wrote: Hi my friend,i wrote two classed on is user,the other is db .The user have a property which from the db class object . When i writing my application have both class object invoked at the same time ,just like $user_a = new user($para); $db_a = new db() Then the problem occurs only one of the class object could work, or $user_a or $db_a not both,What 's problem of my code The two class works well in the single application when only of them are invoked ,i cost me much time to deal it Any advice and suggestions are thankful ! You'll need to include the 'db' class first if that's in a separate file before you include the 'user' class. Apart from that, what's the error you're getting? -- Postgresql php tutorials http://www.designmagick.com/ -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] how to upgrade php in linux
On 05/05/10 15:02, Chaitanya Yanamadala wrote: hai dan thank you for your suggestion regarding the google thing.. thank god u said me that or else i could have never known that google will get me all the results. dude i just asked this question thinking that some one would help me find the solution not for fun. regarding the thing of compiling i require it to be done, hai kesavan thank you for the help i have done that search and i found the things but the thing is that it is an old version of the gcc that is still exisiting in the yum repository. i require one dependancy apr-1.3.3 for the compiling of httpd 2.3.5 which i have found out, but the thing is that it requires two more dependancies uname=2.6 and rpmlib=4.4.6 which are not available in the yum repo.. Do you need to use centos? Maybe it'll be easier for you to use a more up to date operating system. Ubuntu 10 just came out and it has php 5.3 available. We can't teach you how to compile stuff, that's way outside what we're here to help you with. Don't forget everyone here is helping you in their own free time, so you may not get perfect answers but you will get pointers in the right direction (even if it is to google or tutorials on other websites). -- Postgresql php tutorials http://www.designmagick.com/ -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB]how to handle exception in php
On 02/05/10 15:26, Bavithra R wrote: hi friends I am doing a simple student mark details project. for calculating rank I need to compare the total marks one by one. To do so i use *for loop.* so atlast while reaching the end of the table it shows the following warning. * Warning*: mysql_result() [function.mysql-resulthttp://127.0.0.1/pro/function.mysql-result]: Unable to jump to row 18 on MySQL result index on line *50* It is because it has no next value to compare.How to use try..catch exception handling in this.?Or any other suggestion. Can anybody help me This isn't an exception, so a try catch won't work. (Exceptions are fatal and would say something like uncaught exception ...). This is a warning about trying to read something that doesn't exist from mysql. I'd do something like $query = select blah; $result = mysql_query($query); while ($row = mysql_fetch_assoc($result)) { echo do stuff here; } -- Postgresql php tutorials http://www.designmagick.com/ -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] Problem with pg_prepare - PostgresSQL
Giancarlo Boaron wrote: Hi all. I'm receiving the following message when I try to use pg_prepare() function: Call to undefined function pg_prepare(). My application works very well with others pg_* commands... What version of php do you have? This came in with 5.1.0 according to the manual. -- Postgresql php tutorials http://www.designmagick.com/ -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] Sharing happiness!!
Chaitanya Yanamadala wrote: Are promotional messages a part of the PHP-DB No, it's spam that got through the filters. Thankfully we don't get many of them. -- Postgresql php tutorials http://www.designmagick.com/ -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] Sharing happiness!!
Karl DeSaulniers wrote: Well what's weird is that the person who it says sent it is someone who helped me with a PHP problem. So that means the spammers are spoofing our email addresses to send their spam. That's nothing new. Not to mention this spam email had all our email addresses in the to field. Anyone who got this email now has all the emails of the list or as many were in the To field. I removed them all before replying - check again. -- Postgresql php tutorials http://www.designmagick.com/ -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] Sharing happiness!!
That's quick thinking, but they were still in the message they sent. I know I have them all right here. My point being that anyone that got that message, now has all our emails. Your email is already available anyway. Everything posted here is archived at http://lists.php.net/ (http://news.php.net/php.db/47072) and theaimsgroup.com (http://marc.info/?l=php-dbr=1b=201004w=2 - not as up to date but it'll find this convo eventually) and phpbuilder and other places too. You're getting two emails because I habitually hit reply-all which will send you an email personally and one to the list. -- Postgresql php tutorials http://www.designmagick.com/ -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] Session Timeout question
Karl DeSaulniers wrote: What is the best way to set a user timeout on a session? Say if the user steps away from their computer for say 5 min, and they come back to the page they were on, I want when the user clicks something for the session to kick them off and redirect to login saying their session has timed out. I have this code currently: /*Users timout*/ function getIdle(){ global $database; if($this-isGuest()) { if (!isset($_SESSION['timeout_idle'])) { $_SESSION['timeout_idle'] = time() + GUEST_TIMEOUT; } else { if ($_SESSION['timeout_idle'] time()) { //destroy session return(true); } else { $_SESSION['timeout_idle'] = time() + GUEST_TIMEOUT; return(false); } } } else { if (!isset($_SESSION['timeout_idle'])) { $_SESSION['timeout_idle'] = time() + USER_TIMEOUT; } else { if ($_SESSION['timeout_idle'] time()) { //destroy session return(true); } else { $_SESSION['timeout_idle'] = time() + USER_TIMEOUT; return(false); } } } } But it doesn't time anything out.. I could walk away for an hour and come back and go to a link. TIA, Firstly - is it getting into this function (yep I ask stupid questions)? Which branch is it taking (guest or user)? What values are USER_TIMEOUT and GUEST_TIMEOUT? -- Postgresql php tutorials http://www.designmagick.com/ -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] mySQL date query
Ron Piggott wrote: I am trying to write a mySQL query on my stats table. I am trying to determine the number of records (users) during a 7 day period ending yesterday. I always to keep it current ... Yesterday will keep changing. In other words I want to know the number of users who accessed the web site during seven full days. This is the beginning of the query. The date column is date. SELECT count(`visits`) as users FROM `stats` WHERE `date` The mysql manual is a good place to start. http://dev.mysql.com/doc/refman/5.0/en/date-and-time-functions.html#function_date-sub -- Postgresql php tutorials http://www.designmagick.com/ -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] Postgres - how to skip 'sequence' columns
Gary . wrote: Is it possible to skip column(s) in the target table when using pg_copy_from? When I tried to bulk insert some data from a csv file by way of pg_copy_from I received the error Warning: pg_copy_from() [function.pg-copy-from]: Copy command failed: ERROR: permission denied for relation xyz, pretty much as I expected since things look like: CREATE SEQUENCE xyz; CREATE TABLE some_table ( id int NOT NULL PRIMARY KEY DEFAULT nextval('xyz') ... (i.e. the first column is automatically populated by the db itself). It seems not from looking at the php manual. You could use http://www.php.net/manual/en/function.pg-put-line.php instead. -- Postgresql php tutorials http://www.designmagick.com/ -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] phpmailer/mysql/ timout issues
ad wrote: I'm running php 5.1.6 with mysql 5.0.45 on CentOS 5.3 box trying to loop through a while statement to send about 3000 email using phpmailer. It's worked well in the past but after an upgrade it seems to be timing out now After an upgrade of what? php? mysql? phpmailer? the whole o/s? -- Postgresql php tutorials http://www.designmagick.com/ -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] Mysql completing Query fast but mysql-query() takes long time to return even single selects/updates
David Murphy wrote: As you can see PHP claims it took 20 seconds for mysql-query() to return but mysql think is took around 1.0s This is from our application I enabled profile in mysql to determine why an update took 20seconds. As you can see MySQL reported no where near that amount of duration took place. Is there any way I can dig into php and determine why mysql client libs are so slow (this is not using mysqlnd but mysql-client-libs on CentOS using 5.3.2) Is this a one-off thing or is it happening all the time? If it's a one-off thing it could be a spurious result (maybe someone else was doing a mysqldump when your query ran, the dump blocks your query).. What sort of mysql table is it? if it's innodb you can try it in a transaction and roll it back: begin; update blah; rollback; see how long it takes. if it takes a short time in the mysql client, then try it in a php script from your other server. -- Postgresql php tutorials http://www.designmagick.com/ -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] reading PDF file into a DB
Vinay Kannan wrote: Hello Guys, I am working on a project, which requires a PDF file to be read page wise into the DB, once it has been uploaded, the contents from the PDF would then appear on a Flash screen. I need help reading the contents of the PDF file into DB retaining the page numbers, does anyone have an idea how this can be accomplished, i hope someone here has done this before :) http://www.php.net/manual/en/book.pdf.php If there are no functions for reading a pdf, there are some links at the bottom of that page that might help. -- Postgresql php tutorials http://www.designmagick.com/ -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] Shopping cart application question
The } else { confuses PHP. I am not sure what I should be doing. You're missing at least one brace. If the code you supplied is a copy of what you have, you're missing a } for the end of the while loop and one for the end of the else condition. So it's treating } else { as part of the while construct (and while() doesn't have anything like an else condition). if ( $_SESSION['user_reference'] 0 ) { snip $i=0; while ( $i $cart_records_found ) { } // end while } else { foreach ($_SESSION['order'] AS $key = $value ) { } } // end else condition -- Postgresql php tutorials http://www.designmagick.com/ -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] Ldap sasl bind(gssapi problem)
??? wrote: Hallo there everyone, after finishing my server side configuration so as to have the maximum security i tried this morning to do a sasl bind with my ldap server , my file looks like that: *$ldapbind=ldap_sasl_bind($ldapconn,NULL,NULL,GSSAPI,TEIPIR.GR ,ldapmaster,dn:cn=ldapmas...@teipir.gr,ou=kerberos,dc=teipir,dc=gr);* *// verify binding* * * * ** ** if ($ldapbind) {* *echo LDAP bind successful... . br /;* * * every other mech i use seems to work fine but only the gssapi is not workign from what i can see on the log i have tried most of the additional commands i found on the net like: putenv(KRB5CCNAME={$_SERVER['KRB5CCNAME']}); *but still nothing * *any idea to make the bind over gssapi so as to have the kerveros ticket exchange actually working* You may have better luck asking on the php-general mailing list, there are a lot more people subscribed to that. I've never tried anything relating to kerberos so unfortunately I don't have any particular suggestions. -- Postgresql php tutorials http://www.designmagick.com/ -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] Building indexes
listread wrote: Chris, I just assumed that everyone on this list was using MySQL... That's what we're using (v. 5.1.45 GA) with InnoDB as the engine. Most people are but there are lots of types of databases out there :) (I just read your tutorial at http://www.designmagick.com/article/16/ It was very helpful - I look forward to checking out more of your articles.) If it is just as efficient to use multiple separate indexes, that would make index building less complicated on our large db. It is, though wildcard searches can't always use indexes. If you do field like 'abcdef%'; then an index can potentially be used because the db (mysql or otherwise) can look at the start of the string to see if it matches. The longer the string the more likely an index can be used (eg doing field like 'a%' probably won't use an index, it'll end up being quicker to scan the actual data). If you do field like '%abcdef%'; then an index can't be used since abcdef could appear anywhere in the string. Without a large dataset, it hard to truly test a system and if you have a large dataset, like we do, it takes quite a while to build indexes. Definitely, it's the best way to test and also the hardest since rebuilding the db takes so long. Our project is a petition signature validation suite. Since many of the handwritten names and addresses on petition sheets are difficult to read, the user needs to be able to do some fuzzy searching. Sometimes it's easier to read the address than it is the name. The zip code is usually easy to read. We almost always need to use LIKE queries, since some part of the name or address is typically hard to read. (We try to use as many of the leading characters as we can and wildcard the remaining.) I'd suggest fulltext but that won't work with innodb, only myisam. You could do something like keep the addresses and names in a separate myisam table just for searching, though that means a whole new import process and also means you'd end up having to do two queries (maybe a subquery or join, you'd have to test) - one do to full text search and one to get the rest of the data based on the result of the first. What do your queries end up looking like? -- Postgresql php tutorials http://www.designmagick.com/ -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] Building indexes
listread wrote: Greetings! We are working on a 4 million record db with about 55 fields. We need to build indexes to speed queries, but it seems to take way too long. I'm assuming your using mysql but that's just a guess. What database? (mysql, oracle, postgres, firebird, sqlite, other) If it's mysql, what db engine? Here are some questions: 1) If a query uses two or three fields is it best to prepare an index with those two or three fields, or will the query be just as efficient if we build three separate index, one for each field? Relates to above, but assuming mysql then it depends on what version. multicolumn indexes work well in all mysql versions. separate indexes can be used and combined in newer versions (v5 I think it came in). 2) Is the index building process any slower, per index, if you are building more than one index at a time? Most indexing I think takes an exclusive lock on the table, so index 1 gets created, index 2 has to wait it's turn until index 1 finishes. I wrote an article on this a while ago, might give you some more insights: http://www.designmagick.com/article/16/ -- Postgresql php tutorials http://www.designmagick.com/ -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] oci_commit always returns true even when the transaction fails.
ZeYuan Zhang wrote: Hi there. Why oci_commit function always returns true even when the transaction fails. I just copied the code in the php manual [Example 1636. oci_commit() example], and runned it, the situation is as follows: * The statements do commit at the moment when oci_commit executes. * But some statements are committed to oracle successfully, when some fails. I think it cannot be called a transaction, and I did used OCI_DEFAULT in the oci_execute function. Code: ?php $conn = oci_connect('scott', 'tiger'); $stmt = oci_parse($conn, INSERT INTO employees (name, surname) VALUES ('Maxim', 'Maletsky')); oci_execute($stmt, OCI_DEFAULT); Reading the docs (straight from http://www.php.net/manual/en/function.oci-commit.php). A transaction begins when the first SQL statement that changes data is executed with oci_execute() using the OCI_NO_AUTO_COMMIT flag. You need to oci_execute($stmt, OCI_NO_AUTO_COMMIT); -- Postgresql php tutorials http://www.designmagick.com/ -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] oci_commit always returns true even when the transaction fails.
Christopher Jones wrote: Chris wrote: ZeYuan Zhang wrote: Hi there. Why oci_commit function always returns true even when the transaction fails. I just copied the code in the php manual [Example 1636. oci_commit() example], and runned it, the situation is as follows: * The statements do commit at the moment when oci_commit executes. * But some statements are committed to oracle successfully, when some fails. I think it cannot be called a transaction, and I did used OCI_DEFAULT in the oci_execute function. Code: ?php $conn = oci_connect('scott', 'tiger'); $stmt = oci_parse($conn, INSERT INTO employees (name, surname) VALUES ('Maxim', 'Maletsky')); oci_execute($stmt, OCI_DEFAULT); Reading the docs (straight from http://www.php.net/manual/en/function.oci-commit.php). A transaction begins when the first SQL statement that changes data is executed with oci_execute() using the OCI_NO_AUTO_COMMIT flag. You need to oci_execute($stmt, OCI_NO_AUTO_COMMIT); OCI_NO_AUTO_COMMIT is a recently introduced alias for OCI_DEFAULT, so the original code is equivalent. This could be made clearer in the oci_commit documentation, but is explained on http://www.php.net/manual/en/function.oci-execute.php, which is where the flag is actually used. Fair enough, thanks for the clarification :) -- Postgresql php tutorials http://www.designmagick.com/ -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] Calculator
Karl DeSaulniers wrote: Hello, I have been asked to see if I can set up an online calculator. I was wondering if anyone had some pointers on where I can lear/find a script that calculates percentages. The regular math part I think I can figure out. Its not a complicated calc, just basic math and percentages calc, a payment calc if you will. loan payments? a bank website should have something like that. search for loan payment calculator and you'll get tons of hits. As for the maths behind it, I'm not sure. -- Postgresql php tutorials http://www.designmagick.com/ -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] 64-bit Linux -- Fatal ... undefined function mysql_connect()
andrew jarcho wrote: Hello all, I'm running Fedora 12 (64-bit), Apache 2.2.14, PHP 5.3.1, MySQL 5.1.42, on a Dell laptop. snip I get the message: Fatal error: Call to undefined function mysql_connect() snip The output of my phpinfo() includes: Is that from command line or webpage? They may read different php.ini files. # php -i | grep mysql return anything from the command line? which config is it reading? # php -i | grep php.ini Is it the one you were editing previously? -- Postgresql php tutorials http://www.designmagick.com/ -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] Are join queries in phpMyAdmin a security hazard?
Ben Hubbell wrote: Hello, My web host does not have join queries in phpMyAdmin enabled. My web host is inexpensive, but their commitment to costumer service is inconsistent. They often dismiss bug reports as feature requests. When pressed to enable join queries in phpMyAdmin several years ago, my web host stated that join queries in phpMyAdmin were a security hazard. Do you know if such a security hazard exists? I've never used phpmyadmin as a query builder - can you really disable joins in there? Wow. No way they are a security hazard. -- Postgresql php tutorials http://www.designmagick.com/ -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] Injection Attack?
Gary wrote: I have a DB on a site that is not really up anymore (a redirect because of a merger), and it seems to have been attacked. I always use REMOTE_IP so that I have a record and able to ban IP's of the endless form spammers, however on this attack, the IP listed is my local IP (actually my old one since I changed ISP's). I was wondering how they did this and how do I protect on other DB's. Some of the other injected text inot almost every field is. 1 AND USER_NAME() = \'; DESC users; -- 1\' OR \'1\'=\'1 There is plenty more, however they submitted the form about 12 times per second. Any thoughts? I guess you didn't use mysql_real_escape_string (or mysql_escape_string) in your queries. -- Postgresql php tutorials http://www.designmagick.com/ -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] Re: Need a tool for mysql file
Ferdi wrote: -- Forwarded message -- From: nagendra prasad nagendra802...@gmail.com To: PHP DB php-db@lists.php.net, phpexpe...@yahoogroups.com, php mysql php_mysql_usergr...@yahoogroups.com Date: Thu, 25 Feb 2010 16:52:40 +0200 Subject: Need a tool for mysql file Hi All, I have a mysql database file of around 1 GB in size. Is their any tool which which I can see all the database without uploading it on phpmyadmin on localhost. I have tried to upload it on localhost but it said the file size is too large (I have changed the ini file as well but no luck ). I need a tool with which I can see all the tables and the data in the file. Best, -- Guru Prasad Ubuntu Voice GTK+ Forum Hi Hove you made all the changes to the php.ini file? That's pretty impractical for a 1g db. Use rsync, scp or ftp which can handle large files. -- Postgresql php tutorials http://www.designmagick.com/ -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] Login query
Bastien Koert wrote: On Thu, Feb 18, 2010 at 4:40 PM, Ron Piggott ron@actsministries.org wrote: I am wondering what others do for a login query. I think there could be two results: correct e-mail password; correct e-mail wrong password So far my login query is: SELECT * FROM `member` WHERE `email` = '$my_email' AND `pass` LIKE BINARY '$my_password' LIMIT 1 This wouldn't tell me if the user has the wrong password. Is there a better way to do this? Ron bad bad bad! never do a like on a password. If there are two passwords that are close, the unauthorized user might get in when they shouldn't. There are two usual approaches: 1. Select the user (providing that the user is distinct) and compare the password in PHP. On a match, allow access. 2. Select the user and password and see if the results return a row. If no row is returned, then access is not granted. If there is a row, then access is granted. I'd also suggest that you don't distinguish between a correct username but wrong password and a correct username and right password. If you say You got the right username but wrong password, a bad guy now has a point of attack .. If you say your username or password are incorrect you don't get that. Check gmail or yahoo or even sourceforge for how they word such attempts. -- Postgresql php tutorials http://www.designmagick.com/ -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] php_warn
madunix wrote: solved by setting error reporting to 0 in “configuration.php” file $mosConfig_error_reporting = '0; That hides the problem, it doesn't solve it. -- Postgresql php tutorials http://www.designmagick.com/ -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] IFNULL
Ron Piggott wrote: How do I add IFNULL to the LEFT JOIN query? I either want the result from the database or a 0 instead of the word NULL Ron SELECT `store_product_profile`.`reference` , inventory.inventory, sold_1.quantity, sold_2.quantity, sold_3.quantity FROM `store_product_profile` LEFT JOIN ( SELECT `store_product_inventory_control`.`store_product_profile_reference` , SUM( `store_product_inventory_control`.`quantity` ) AS inventory FROM `store_product_inventory_control` GROUP BY `store_product_inventory_control`.`store_product_profile_reference` ) AS inventory ON `store_product_profile`.`reference` = `inventory`.`store_product_profile_reference` You don't add it to the join, it goes on a field you're selecting. select IFNULL(inventory.inventory, 0) AS blah, -- Postgresql php tutorials http://www.designmagick.com/ -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] Getting total quantities
Karl DeSaulniers wrote: Would it be? $q = SUM(ProductStock) FROM products; or $q = SELECT SUM(ProductStock) AS ProductStock FROM products; if I want to return $ProductStock as the value? This one. The AS gives it an alias (or shortcut) to make it easier to find in mysql_fetch_array etc. -- Postgresql php tutorials http://www.designmagick.com/ -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] Getting total quantities
Chaitanya Yanamadala wrote: Have you tried using it like this *select count(*) from products;* This will give you the number of rows in the table, not what Karl wants. -- Postgresql php tutorials http://www.designmagick.com/ -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] Getting total quantities
Karl DeSaulniers wrote: Ok, sweet, then I am on the right track. Now I did notice that I forgot the SELECT in the first query, does that matter? Can I just start out with SUM? No - that's invalid sql. -- Postgresql php tutorials http://www.designmagick.com/ -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] upload multiple files and rename wih time()
Emiliano Boragina wrote: Hello php fellows, I have two codes to upload multiple files, works very well, but I cant rename the files... really i dont know... The code looks ok. Do you get an error message? If not, turn up error_reporting and enable display_errors: error_reporting(E_ALL); ini_set('display_errors', true); -- Postgresql php tutorials http://www.designmagick.com/ -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] Cross reference query help
Ron Piggott wrote: The following is a query I am working on today. I need help tweaking on it. What I am trying to get for results from the query are where there are rows in either table, not all 3 tables linked together. In other words I am trying to INNER JOIN these two pairs of tables for possible results: `store_product_profile` and `paypal_cart_info` OR `store_product_profile` and `mail_order_cart` SELECT `store_product_profile`.`product_name` FROM ( `store_product_profile` INNER JOIN `paypal_cart_info` ON `store_product_profile`.`reference` = `paypal_cart_info`.`itemnumber` ) INNER JOIN `mail_order_cart` ON `store_product_profile`.`reference` = `mail_order_cart`.`store_product_profile_reference` WHERE `store_product_profile`.`discontinued` =0 AND `store_product_profile`.`reference` =7 Finally I need help with the GROUP BY syntax also. I only want the name of the product once, not if it was in several previous purchases. Any help is appreciated. So a product is either in the paypal_cart_info table or it's in the mail_order_cart table ? Though maybe this is a bad example - it's looking for reference=7 - you can check for that in your other tables since it seems to be a foreign key of some sort I'm guessing. You could use a union (or union all is probably better in this case) to bring them together. select itemnumber from paypal_cart_info where itemnumber=7 union all select store_product_profile_reference from mail_order_cart where store_product_profile_reference=7 put that into your other query and add your group by: select product_name from store_product_profile where reference in ( select itemnumber from paypal_cart_info where itemnumber=7 union all select store_product_profile_reference from mail_order_cart where store_product_profile_reference=7 ) and discontinued=0 group by product_name; If you put the check for '7' in the paypal and mail_order_cart tables it'll be faster than putting it in the bigger query. The smaller subquery will return less results (I'm guessing 0,1, or 2 results) and therefore the discontinued check will be quicker and so will the group by. If you don't put the check for '7' in the subquery, then mysql will have to go through *all* entries in paypal_cart_info and mail_order_cart (which may or may not be big tables), then make sure there is a reference entry in product_profile (which could be a pretty big table) and finally at the end of all that, check if reference '7' is in that list and it's not discontinued (then the group by etc). So in general, the further down the query chain you can put your where clauses to reduce the number of rows returned, the better. -- Postgresql php tutorials http://www.designmagick.com/ -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] Storing Images #2
elk dolk wrote: On 3 February 2010 16:07, wrote: I currently have all my images referenced by url in my database and stored in a folder/s and I think I will keep it that way... .. If you put the images OUTSIDE of the webroot/docroot/public_html folder (whatever you have), then a user cannot directly navigate to the file. e.g. /home/sites/your_site/public_html/images/image1.jpg http://www.yoursite.com/images/image1.jpg would probably work. But ... /home/sites/your_site/public_html/getImage.php /home/sites/your_site/hidden_images/image1.jpg Now, there is no way I can load image1.jpg from my browser. I have to use getImage.php, which I assume would require me to login or authenticate myself in some way. -- I have my photos in /public_html/img/gid directory and with this path: img src='http://www.mydomain.com/img/{$gid}/{$photoFileName}' in getImage.php the server displays the photos. Now if I put my photos outside of the public_html like this: /hidden_images/img/gid what would be the correct path to the photos in the getImage.php script? Do you mean what url? You'll need a script to pull them from outside the document root. The advantage of this is you can do authentication checks before displaying the image. The disadvantage is the web-server isn't serving the images directly so there will be a slow down. So you point your images to getimage.php?image=123456 and getimage.php does your authentication checks if necessary then pulls the image back using something like http://www.php.net/fpassthru -- Postgresql php tutorials http://www.designmagick.com/ -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] PHP and MYSQL Update problem
Manu Gupta wrote: try .. $q = addslashes(UPDATE episodes SET episode_title = '$_POST[episode_title]' , episode_scheduleddate = .strtotime($_POST['episode_scheduleddate']). , episode_description = '$_POST[episode_description]' WHERE episode_id = $_POST[episode_id]); or try $q = UPDATE episodes SET episode_title = '{$_POST[episode_title]}' , episode_scheduleddate = {.strtotime($_POST['episode_scheduleddate'])}. , episode_description = '{$_POST[episode_description]}' WHERE episode_id = {$_POST[episode_id]}; Good idea but you don't addslashes the whole query (and addslashes is the wrong thing to use). Use mysql_real_escape_string around bits and pieces you want to escape: $q = update episodes set episode_title=' . mysql_real_escape_string($_POST['episode_title']) . ', .. -- Postgresql php tutorials http://www.designmagick.com/ -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] Automatic logoff
listread wrote: Bruno, Thanks for the heads up on the php configuration. I'll check that out. We also need to write some data to a database, things like logout time. That means running a script for some other php code. There are probably a number of situations where the onUnload thing won't work including browser crashes, some browsers may not support it, will it work if you have multiple browser tabs open and close one (something you'll have to research) etc, so be aware that you're not going to get this 100% right. If you just want the timing, I'd do it the other way. Each time their session is checked (on page load), update the end time. In db terms: update session set logout_time=NOW() where session_id='X'; That way you're always going to get at least an idea of how long their session lasts but you won't get reading time on the page (ie it takes me 2 mins to read something on the page, the logout_time will be 2 minutes before I actually close it). -- Postgresql php tutorials http://www.designmagick.com/ -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] Procedure Parameter OUT values
WebPat wrote: Chris wrote: WebPat wrote: I am surprised by the order of the data returned from my stored procedure, and that it appears associated with the incorrect variables. Apparently the data is returned entirely positionally, without consideration for the variable names. So, the names of the OUT parameters in the procedure appear to be invisible outside of the procedure. Although I pass in variables with the same names as the Parameters, they are filled positionally - in the wrong variables - because in this case I had two variables reversed positionally. When I retrieve them using fetch_assoc, the wrong data appears in the result. I'd probably find a more targeted mailing list (a specialized one for your database - whatever it is) and see if they can offer any suggestions. My database is Mysql. The data seems to display properly there. I'm accessing the database with procedures that are part of PHP and that is where I believe the problem is. That's why I asked it on this Newsgroup. I got it to work by putting my parameters in the proper order. I know this is how function and procedure calls normally work, but the documentation of fetch_assoc() leads in another direction. It looks like the Associations are created within my php and not carried from the database for stored procedures. I wonder if PHP does this for all databases? I think this differs from Select * From Table. Certainly could use another sentence in the documentation. You can submit documentation patches and/or submit a note for that situation on that page in the manual. -- Postgresql php tutorials http://www.designmagick.com/ -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] Procedure Parameter OUT values
WebPat wrote: I am surprised by the order of the data returned from my stored procedure, and that it appears associated with the incorrect variables. Apparently the data is returned entirely positionally, without consideration for the variable names. So, the names of the OUT parameters in the procedure appear to be invisible outside of the procedure. Although I pass in variables with the same names as the Parameters, they are filled positionally - in the wrong variables - because in this case I had two variables reversed positionally. When I retrieve them using fetch_assoc, the wrong data appears in the result. I'd probably find a more targeted mailing list (a specialized one for your database - whatever it is) and see if they can offer any suggestions. -- Postgresql php tutorials http://www.designmagick.com/ -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] result set in php pagination
Joe Keenan wrote: Thanks very much Bastien. I haven't the faintest idea why but that simple change in the code sorted all of this. The pagination links now follow through with the complete result set of my query. I will now have to read around this to discover why the change works. By putting it in the url means it's not a POST variable any more, it is now a GET variable. REQUEST covers both (and more) - so if it appears in GET, it will be set to that. If it appears in POST, it'll use that instead. Also nobody's mentioned you should use mysql_real_escape_string when you do your query otherwise your site will (eventually) have problems with sql injection. $query = SELECT article_id, author_name, category_name, title, article_caption, date_format(magazine_date, '%M, %Y') as newdate FROM articles WHERE author_name = '$author_name' ORDER BY magazine_date ASC LIMIT $offset, $rowsperpage; becomes: $query = SELECT article_id, author_name, category_name, title, article_caption, date_format(magazine_date, '%M, %Y') as newdate FROM articles WHERE author_name = ' . mysql_real_escape_string($author_name) . ' ORDER BY magazine_date ASC LIMIT $offset, $rowsperpage; You won't see much difference if you print it out but if you put things like a single quote in your name search, it will be handled now and not cause a mysql error. -- Postgresql php tutorials http://www.designmagick.com/ -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] Transferring rows between 2 databases on 2 web servers
Ferdi wrote: Hi Everybody, There are n number of web servers all having the same Linux-Apache-MySQL-Php setup, with identical databases. Each of these servers functions as a billing server at a store of my company. Now I am required to set up a master server that will copy all data from each of the store servers. All I wish to know is: How can a page on the master server obtain data from a store database by calling a page located on the store server? I do not wish to access a store database directly, but through a page on the store server. Specifically, how can a web page get data from another web page on another server. wget (from linux command line) curl (from linux command line or using the php curl functions) file_get_contents (php function) fopen (php function) There are a number of ways but you'll most likely run into timeout issues. I think you are much better off writing a script that does it command-line and connects to the remote database and pulls the data back. Then if the script takes an hour to run you won't have any problems - you definitely will if you do it through a web page. I'd also say security would be easier to implement via direct database access (firewalls, mysql user limits, ssl-only connections). -- Postgresql php tutorials http://www.designmagick.com/ -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] printf and unsecable char
Jean-Philippe Battu wrote: Hello I would like to print a string formatted on the right side and fill in the left side with the unsecable character [nbsp;] I read in the printf command I could use : printf( %#30s , $mystring ) ; to display $mystring string with the character # before (on the left) and I try to replace # by nbsp; but I can't find a solution Do you know the solution to write the command: printf( %nbsp;30s , $mystring ) ; or something like that ! echo str_repeat('nbsp;', 30); (if I understand what you're trying to do correctly). -- Postgresql php tutorials http://www.designmagick.com/ -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] auto creation of email IDs
Vinay Kannan wrote: Hey Guys, I've been at this for couple of days now, and have no clue where to start, and was almost thinking about scrapping the project, It would be great help if anyone can give me some advice, or guide me in the right direction. I have a portal, where users would come in and register and create an account, as soon as an account is created, I want to be able to auto create an email ID for them, the server would be Linux, any ideas on how this can be done. And also an option of creating a temporary email ID, upon creating a topic or some kind of a post. Could anyone guide me in the right direction or help me on this one, please ? I assume email id means email address or email account. Yes, you can do it - postfix supports talking to a database. Exim and sendmail might also support this, I don't have any experience with them though. -- Postgresql php tutorials http://www.designmagick.com/ -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] Hello
Karl DeSaulniers wrote: What does this do exactly? Documentation was a bit fuzzy for me. Is it needed at all times to protect with? Per the docs: prepends backslashes to the following characters: \x00, \n, \r, \, ', and \x1a. So anything that has a null character, a newline (windows/linux/mac), single and double quotes and \x1a (not sure what that is) is escaped and ready to be put in a query. If you don't quote those characters someone could put one of those characters in a query and cause problems - starting off with an invalid query but possibly ending up worse. -- Postgresql php tutorials http://www.designmagick.com/ -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] Hello
addslashes doesn't take encoding's into account. http://shiflett.org/blog/2006/jan/addslashes-versus-mysql-real-escape-string goes into some details. Karl DeSaulniers wrote: So what's the difference with that and addslashes() ? Karl Sent from losPhone On Dec 15, 2009, at 3:50 PM, Chris dmag...@gmail.com wrote: Karl DeSaulniers wrote: What does this do exactly? Documentation was a bit fuzzy for me. Is it needed at all times to protect with? Per the docs: prepends backslashes to the following characters: \x00, \n, \r, \, ', and \x1a. So anything that has a null character, a newline (windows/linux/mac), single and double quotes and \x1a (not sure what that is) is escaped and ready to be put in a query. If you don't quote those characters someone could put one of those characters in a query and cause problems - starting off with an invalid query but possibly ending up worse. -- Postgresql php tutorials http://www.designmagick.com/ -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- Postgresql php tutorials http://www.designmagick.com/ -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] Random pick
David McGlone wrote: Hi everyone, I've been lurking in the shadows on the list for quite some time and now I'm in need of a little info or advise. I'm looking for a way to grab a record out of a database on a certain day each month and I'm wondering if this can be accomplished with just a mysql query or would I need to use PHP also? A mysql query would do it but you'd use something to talk to mysql and process the results (whether it's php, perl, python, ruby etc depends on your other requirements). -- Postgresql php tutorials http://www.designmagick.com/ -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] Hello
Karl DeSaulniers wrote: HI, Thanks for your response. Here is my query. UserID is auto incrament and UserLastLogin is a current_timestamp. $query_users = INSERT INTO users(UserID, Username, UserEmail, UserPassword, UserFirstName, UserLastName, UserCompany, UserAddress, UserAddress2, UserCity, UserState, UserCountry, UserZip, UserPhone, UserFax, UserEmailVerified, UserRegistrationDate, UserVerificationCode, UserIP, UserLastLogin) VALUES('NULL','.$Username.','.$UserEmail.','.$UserPassword.','.$UserFirstName.','.$UserLastName.','.$UserCompany.','.$UserAddress.','.$UserAddress2.','.$UserCity.','.$UserState.','.$UserCountry.','.$UserZip.','.$UserPhone.','.$UserFax.','.$UserEmailVerified.','.$UserRegistrationDate.','.$UserVerificationCode.','.$UserIP.', now()); This works as far as populating the database, but my results page does not return anything. Only if the VALUES is set like this: VALUES('NULL','.$Username=$_POST['Username'].','.$UserEmail=$_POST['UserEmail'].','.$UserPassword=$_POST['UserPassword'].','.$UserFirstName=$_POST['UserFirstName'].','.$UserLastName=$_POST['UserLastName'].','.$UserCompany=$_POST[$UserCompany].','.$UserAddress=$_POST['UserAddress'].','.$UserAddress2=$_POST['UserAddress2'].','.$UserCity=$_POST['UserCity'].','.$UserState=$_POST['UserState'].','.$UserCountry=$_POST[$UserCountry].','.$UserZip=$_POST['UserZip'].','.$UserPhone=$_POST['UserPhone'].','.$UserFax=$_POST[$UserFax].','.$UserEmailVerified=$_POST[$UserEmailVerified].','.$UserRegistrationDate=$_POST[$UserRegistrationDate].','.$UserVerificationCode=$_POST['UserVerificationCode'].','.$UserIP=$_POST[$UserIP].', now()); but some do not work with this setup. variables like $UserEmailVerified, $UserRegistrationDate and $UserIP are not created from the form that was submitted. for example, User IP date is created like this. $UserIP = md5($_SERVER[REMOTE_ADDR]); Problem 1 is sql injection. Wrap each variable in a mysql_real_escape_string call: insert into table (...) values (' . mysql_real_escape_string($username) . ' also quoting 'NULL' means it will add 'NULL' as the id - not what you want. You can leave out the column to use the default from the database. Any errors from mysql? Add: echo mysql_error(); after your insert call. - Below is a snip of how I retrieve the info on the result page (dont want to clutter with whole code. also $fieldOne etc are MySql wildcards '%' from some dropdown lists that show before this code is executed. The results from adding show up fine there.) $query_users = SELECT * FROM users WHERE UserID LIKE '$fieldOne' AND Username LIKE '$fieldTwo' AND UserEmail LIKE '$fieldThree' AND UserPassword LIKE '$fieldFour' AND UserFirstName LIKE '$fieldFive' AND UserLastName LIKE '$fieldSix' AND UserCompany LIKE '$fieldSeven' AND UserAddress LIKE '$fieldEight' AND UserAddress2 LIKE '$fieldNine' AND UserCity LIKE '$fieldTen' AND UserState LIKE '$fieldEleven' AND UserCountry LIKE '$fieldTwelve' AND UserZip LIKE '$fieldThirteen' AND UserPhone LIKE '$fieldFourteen' AND UserFax LIKE '$fieldFifteen' AND UserEmailVerified LIKE '$fieldSixteen' AND UserRegistrationDate LIKE '$fieldSeventeen' AND UserVerificationCode LIKE '$fieldEighteen' AND UserIP LIKE '$fieldNineteen' AND UserLastLogin LIKE '$fieldTwenty' LIMIT $min, $max_results; Again you need to escape all your data (except $min, $max_results - just make sure they are always integers). I'm assuming there are no errors reported by mysql. To debug this, I'd simplify the query and work out which bit isn't matching what you want (it could be $fieldOne isn't quite what you expect, or it could be $fieldEleven or $fieldEighteen or ..). Start off with one field, then add another and go from there. -- Postgresql php tutorials http://www.designmagick.com/ -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] Mysql query
ron.pigg...@actsministries.org wrote: The query from my previous post was only part of a larger query. This is the entire query: SELECT GREATEST( IF( CURDATE( ) = DATE_SUB( DATE( FROM_UNIXTIME( 1239508800 ) ) , INTERVAL LEAST( 14, ( SELECT COUNT( * ) FROM `verse_of_the_day_Bible_verses` WHERE seasonal_use =1 ) ) DAY ) AND CURDATE( ) = DATE( FROM_UNIXTIME( 1239508800 ) ) , 1, 0 ) , IF( CURDATE( ) = DATE_SUB( DATE( 2009 -12 -25 ) , INTERVAL LEAST( 14, ( SELECT COUNT( * ) FROM `verse_of_the_day_Bible_verses` WHERE seasonal_use =2 ) ) DAY ) AND CURDATE( ) = DATE( 2009 -12 -25 ) , 2, 0 ) ) AS verse_application It took me a while to work out what this was trying to do, that's complicated. Reformatted a little: SELECT GREATEST( IF ( CURDATE() = DATE_SUB( DATE(FROM_UNIXTIME(1239508800)), INTERVAL LEAST(14, (SELECT 1)) DAY) AND CURDATE() = DATE(FROM_UNIXTIME(1239508800)), 1, 0 ), IF ( CURDATE() = DATE_SUB( DATE('2009-12-25'), INTERVAL LEAST(14, (SELECT 2)) DAY) AND CURDATE() = DATE('2009-12-25'), 2, 0 ) ) AS verse_application; (which isn't much better in email). You're not getting '2' because the second part is returning 0. I substituted dummy variables for your subqueries (select 1 and select 2). SELECT COUNT( * ) FROM `verse_of_the_day_Bible_verses` WHERE seasonal_use =2; What does that return by itself? that is what your query will run instead of my 'select 2'. That in turn goes into the select least(14, result_from_above_query); and takes that away from date('2009-12-25'); If the current date is not in that range, it will return 0. Here's the second part of your query isolated for you to test: SELECT IF ( CURDATE() = DATE_SUB( DATE('2009-12-25'), INTERVAL LEAST(14, (SELECT COUNT(*) FROM verse_of_the_day_Bible_verses WHERE seasonal_use=2)) DAY) AND CURDATE() = DATE('2009-12-25'), 2, 0 ) ; -- Postgresql php tutorials http://www.designmagick.com/ -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] Hello
Karl DeSaulniers wrote: Hi Chris, On Dec 14, 2009, at 8:09 PM, Chris wrote: Problem 1 is sql injection. Wrap each variable in a mysql_real_escape_string call: insert into table (...) values (' . mysql_real_escape_string($username) . ' At one point I did have the mysql_real_escape_string() and it worked the same as without as far as populating the database. Did you try names with single quotes? (Tim O'Reilly is a common example to try). But when I would view results, it didnt read anything from the database. Sure it went in? Did you see the data when you viewed the table in phpmyadmin or some other tool? Again you need to escape all your data (except $min, $max_results - just make sure they are always integers). Those are so I can control the number of items shown per page. I realise that. mysql_real_escape_string is used for data in your query, and may cause problems if used in limit clauses. If you end up with this for example: select * from table limit mysql_real_escape_string('blah'); of course it's not going work. Hence the check to make sure $min and $max_results are int's before passing them to the query so if anyone messes with them it won't break your queries. if (!is_int($min)) { $min = 0; } if (!is_int($max_results)) { $max_results = 5; } Basically the result page would not show anything in the database unless it was inserted in the database using the $_POST method. That still suggests an error with the insert. -- Postgresql php tutorials http://www.designmagick.com/ -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] Random pick
David McGlone wrote: On Monday 14 December 2009 21:02:37 Chris wrote: David McGlone wrote: Hi everyone, I've been lurking in the shadows on the list for quite some time and now I'm in need of a little info or advise. I'm looking for a way to grab a record out of a database on a certain day each month and I'm wondering if this can be accomplished with just a mysql query or would I need to use PHP also? A mysql query would do it but you'd use something to talk to mysql and process the results (whether it's php, perl, python, ruby etc depends on your other requirements). What I'm trying to do is to have a record picked from the database at random on the 1st of every month and display it on the page. Here is some code I have been working with: $query = SELECT DATEADD(mm, DATEDIFF(mm,0,getdate()), 0); $result = @mysql_query($query); if (!$result){ $query = SELECT * FROM monthlyPooch ORDER BY RAND() LIMIT 1; $result = @mysql_query($query); while ($row = mysql_fetch_array($result)){ echo $row[poochName] ; echo $row[Birthdate]; } } You can check the day of the month in php then do your other query: $today = date('j'); if ($today !== 1) { echo Today isn't the first. No need to continue.\n; exit; } .. random query etc here. -- Postgresql php tutorials http://www.designmagick.com/ -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php