Re: [PHP-DB] php 5.2.9 and Postgres 8.3.7
Do you have postgres module for PHP installed? This will probably be the cause. Didier Gasser-Morlay napsal(a): Hello, I tried all day yesterday to setup a brand new machine with a fresh Linux install; with apache 2.2.10 (from source) php 5.2.9 (from source) and PostgresQL 8.3.7 (from the very neat one-click installer provided by Enterprisedb) ; everything compiles and installs fine but when trying to run the first query to my database I consistently get a message about pg_escape_string function missing. I am connecting through ADODB which filters any query via '.pg_escape_string($this-_connectionID,$s).'; I had no problem using the same build with php 5.2.8 and Postgres 8.3.4, so I ended up using the mod_php5.so module for apache build with these versions, but would like to get to the bottom of it. Any idea or comment ? Didier -- S pozdravem Daniel Tlach Freelance webdeveloper Email: m...@danaketh.com ICQ: 160914875 MSN: danak...@hotmail.com Jabber: danak...@jabbim.cz -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] oci8 1.3.4 working for months on my simple browser based php
Look what extensions are you loading. You should find that in php.ini file. Maybe something nasty happened and you php.ini has extension=php_oracle.dll instead of extension=php_oracle.so. Also, if you are about to compile a module for PHP, first you have to run phpize, than ./configure and make ;) Fred Silsbee napsal(a): For months I've had a Oracle 11g1 browser based table access site/program working. I do regular Fedora 9 yum updates and have seen some pecl/pear stuff whizzing by. Just tried the Oracle 11g1 browser based table access site/program and NOTHING shows on the Firefox 3.0.10 screen. Not even an error. /etc/httpd/logs/error_log says something about cannot open php_oracle.dll or php_oci8.dll That is good...there isn't any dll on Linux. Proble: downloaded oci8-1.3.5 and the README file says to run ./configure but there are 2 files config.m4 and config.w32 nothing in this README file works...is it up to date? -- S pozdravem Daniel Tlach Freelance webdeveloper Email: m...@danaketh.com ICQ: 160914875 MSN: danak...@hotmail.com Jabber: danak...@jabbim.cz
Re: [PHP-DB] pg_prepare()/pg_execute() and pg_query_params()
Can you provide us with some of the queries you send to database? I'd suggest you test it with some easy and simple one, like this on from PHP documentation: |$result = pg_query_params($dbconn, 'SELECT * FROM shops WHERE name = $1', array(Joe's Widgets)); | Brandon Metcalf napsal(a): I'm fairly new to PHP but have a great deal of Perl experience for what it's worth. I'm having a problem where if I try to use a parameterized query it fails but pg_last_error() returns nothing. For example, $result = pg_query_params($pgconn, $update, array($foo, $bar)); if (! $result) { fwrite($fp, before); fwrite($fp, pg_last_error()); fwrite($fp, after); } The strings before and after are showing up in $fp, but nothing from pg_last_error(). Similarly, if I use pg_prepare() and pg_execute(), pg_prepare() fails but nothing is returned from pg_last_error(). Using pg_query() works, but I need to parameterize the SQL. The versions I'm using are $ php --version PHP 5.2.4-2ubuntu5.5 with Suhosin-Patch 0.9.6.2 (cli) (built: Feb 11 2009 20:09:52) Copyright (c) 1997-2007 The PHP Group Zend Engine v2.2.0, Copyright (c) 1998-2007 Zend Technologies and PostgreSQL 8.3.6. What am I missing? -- S pozdravem Daniel Tlach Freelance webdeveloper Email: m...@danaketh.com ICQ: 160914875 MSN: danak...@hotmail.com Jabber: danak...@jabbim.cz
Re: [PHP-DB] pg_prepare()/pg_execute() and pg_query_params()
Then you should put some debugging around the connection code. |$pgconn = pg_connect(host=localhost port=5432 dbname=test user=test password=test)| or die(Problem with connection to PostgreSQL: .pg_last_error()); So you can be sure that you are really connected. Also you can use pg_result_error()... $result = pg_query_params($pgconn, $update, array($foo, $bar)); echo pg_result_error($result); or even pg_result_error_field(). Brandon Metcalf napsal(a): b == bran...@geronimoalloys.com writes: b I'm fairly new to PHP but have a great deal of Perl experience for b what it's worth. I'm having a problem where if I try to use a b parameterized query it fails but pg_last_error() returns nothing. For b example, b $result = pg_query_params($pgconn, $update, array($foo, $bar)); b if (! $result) { b fwrite($fp, before); b fwrite($fp, pg_last_error()); b fwrite($fp, after); b } I should also mentioned with log_statement = 'all' in postgresql.conf, nothing is dumped to the logs. This tells me pg_query_params() isn't passing anything to the postgres server. -- S pozdravem Daniel Tlach Freelance webdeveloper Email: m...@danaketh.com ICQ: 160914875 MSN: danak...@hotmail.com Jabber: danak...@jabbim.cz
Re: [PHP-DB] multi user php login script with user image upload
I'd suggest using Google, but you can try phpclasses.org instead. There you'll find everything you need. Wilson Osemeilu napsal(a): I need multi user login php script which each user can upload their profile picture.. i mean the index.php register.php login.php changepassword.php etc not a forum but for a restricted site where users have i already know how to create the login scripts but it'll be better if someone has all in one including the user photo upload.which is my greatest problem right now php users are the gr8test, pls help me. Thanks -- S pozdravem Daniel Tlach Freelance webdeveloper Email: m...@danaketh.com ICQ: 160914875 MSN: danak...@hotmail.com Jabber: danak...@jabbim.cz
Re: [PHP-DB] Assigning the current value of a sequence to a variable - Postgres 8.3.6
Hello, you're not fetching the query results. $query = SELECT currval('\tblPeople_peopleId_seq\'); $result = pg_query($query) or die(Can't execute 4th query); if ($result != false) { $row = pg_fetch_row($result); echo person id is . $row[0] . br /; } else { // no curval() found or something bad happened... } This should work for you. If you run SELECT query, you have to fetch the results before you can access the data. If you expect more than one row, you can use while($row = pg_fetch_row($result)) { // code to process data from database } Hope this will help you :) Carol Walter napsal(a): Hello, I have a program that looks for a name in a database. If the name is found the id of the record is assigned to a variable. Later in the program that value is used to insert records associated with the name into the database using a variable called person_id. If the name is not found, then a new record is build from data entered into a form. There is a name record and a contact information record and a bridge table record to create the relationship between them. After that, the program may create additional records related to the new person record in the same way it creates records related to the person records that might already exist in the database. It would make this process lots easier if I can assign currval of the new person record to the same variable that I use when I already have a record in the database. Can I assign currval to a variable? Below is the code that I'm using. The value that displays for person id which I'm trying to capture at the bottom of this code is person id is Resource id #6. if (($submit_db_name == Submit) ($submit_new_name == Submit)) { echop Contact Locator: $cont_loc/p; echop Contact Type Rank: $cont_rank/p; echop Contact Info Type: $contact_type/p; echop New name string: $f_name_new/p; echop New name string: $m_name_new/p; echop New name string: $l_name_new/p; echop New ivl web string: $ivl_web_peop/p; echop New cns_web string: $cns_web_peop/p; echop New contact rank string: $cont_rank/p; echop New contact locator string: $cont_loc/p; echop New contact item string: $contact_info1/p; echop New contact type string: $contact_type/p; begin; $query = INSERT INTO \tblPeople\(\fName\,\mName\,\lName\, ivlweb, cnsweb) VALUES ('$f_name_new', '$m_name_new','$l_name_new', '$ivl_web_peop', '$cns_web_peop'); /* echo First query: . $query . br /; */ $pg_peop_ins = pg_query($query) or die(Can't execute first query); $query = INSERT INTO \tblContactInformation\(\contactItem\,\contactType\) VALUES ('$contact_info1','$contact_type'); /* echo Second query: . $query . br /; */ $pg_contact_ins = pg_query($query) or die(Can't execute 2nd query); $query = INSERT INTO \brdgPeopleContactInformation\ (\peopleId\,\contactInformationId\,rank, type) VALUES (currval('\tblPeople_peopleId_seq\'),currval('\tblContactInformation_contactInformationId_seq\'), '$cont_rank', '$cont_loc'); /* echo Third query: . $query . br /; */ $pg_peop_cont_ins = pg_query($query) or die(Can't execute 3rd query); $query = SELECT currval('\tblPeople_peopleId_seq\'); $person_id = pg_query($query) or die(Can't execute 4th query); echo person id is . $person_id . br /; commit; This is PostgreSQL 8.3.6, PHP 5, on Solaris 10. Thanks for your time. Carol -- S pozdravem Daniel Tlach Freelance webdeveloper Email: m...@danaketh.com ICQ: 160914875 MSN: danak...@hotmail.com Jabber: danak...@jabbim.cz
Re: [PHP-DB] Shopping cart
Hi Vee, You have it all in that error :) You're calling function on non-object. Look into the basket.php. On the lines where you call the MySQL query you have $con-query($sql) but there is no decalaration of $con object anywhere before. I think you have an MySQL layer included (mysql.class.php) but you haven't it declared. You just made a new relation in $con. Instead of calling $con-query() you have to call mysql_query(). You also have some mistakes in query ;) $sql = 'SELECT * FROM spirits ORDER BY id'; $query = mysql_query($sql); ... Look at the PHP documentation how to work with mysql_ functions. Or provide us with link to the MySQL layer you're using - that mysql.class.php - so we can help you with using that. I think there will be something like $con = new MySQL('host', 'user', 'pass', 'db'); Then your syntax will work. However without knowing what layer it is, I can't tell you the right syntax for it ;) Vernon St Croix napsal(a): Hi, I am pretty new to PHP and I am trying to create a shopping cart. I keep on getting the below error when trying to show the shopping list. Any guidance that can be provided will be very much appreciated Fatal error: Call to a member function query() on a non-object in C:\wamp\www\draft\basket.php on line 36 mysql_connect.php ?php $con = mysql_connect(localhost,root,); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db(rum, $con); ? basket.php ?php include(mysql.class.php); include (header.php); include (mysql_connect.php); include (functions.php); ? div id=shopping h2Rum Basket/h2 ?php echo writeCart(); ? /div div id=rumlist h2Rum on Offer/h2 ?php $sql= 'SELECT * FROM spirits BY id'; $result = $con-query($sql); $output[]= 'ul'; while ($row = $result-fetch()) { $output[] = 'li'.$row['name'].': pound;'.$row['price'].'br/a href=cart.php?action=addid= '.$row['id'].'Add to Cart/a/li'; } $output[] = '/ul'; echo join ('', $output); ? /div /div ?php include(footer.html); ? cart.php ?php include (header.php); include (mysql_connect.php); include (functions.php); $cart = $_SESSION['cart']; if(isset($_GET[action])) { $action = $_GET[action]; } else { $action = ; } switch ($action) { case 'add': if ($cart) { $cart .= ','.$_GET['id']; } else { $cart = $_GET['id']; } break; case 'delete': if ($cart) { $items = explode(',',$cart); $newcart = ''; foreach ($items as $item) { if ($_GET['id'] != $item) { if ($newcart != '') { $newcart .= ','.$item; } else { $newcart = $item; } } } $cart = $newcart; } break; case 'update': if ($cart) { $newcart = ''; foreach ($_POST as $key=$value) { if (stristr($key,'qty')) { $id = str_replace('qty','',$key); $items = ($newcart != '') ? explode(',',$newcart) : explode(',',$cart); $newcart = ''; foreach ($items as $item) { if ($id != $item) { if ($newcart != '') { $newcart .= ','.$item; } else { $newcart = $item; } } } for ($i=1;$i=$value;$i++) { if ($newcart != '') { $newcart .= ','.$id; } else { $newcart = $id; } } } } } $cart = $newcart; break; } $_SESSION['cart'] = $cart; ? div id=shopping h2Rum Basket/h2 ?php echo writeCart(); ? /div div id=contents h2Please Check Quantities.../h2 ?php echo showCart(); ? pa href=basket.phpBack to Rum List/a/p /div /div ?php include(footer.html); ? functions.php ?php function writeCart() { $cart = $_SESSION['cart']; if (!$cart) { return 'pThere is no alcohol in your Rum Basket/p'; } else { // Parse the cart session variable $items = explode(',',$cart); $s = (count($items) 1) ? 's':''; return 'pThere area href=cart.php'.count($items).' item'.$s.' in your rum basket/a/p'; } } function showCart() { $cart = $_SESSION['cart']; if ($cart) { $items = explode(',',$cart); $contents = array(); foreach ($items as $item) { $contents[$item] = (isset($contents[$item])) ? $contents[$item] + 1 : 1; } $output[] = 'form action=cart.php?action=update method=post id=cart'; $output[] = 'table'; foreach ($contents as $id=$qty) { $sql = 'SELECT * FROM spirits WHERE id = '.$id; $result = $con-query($sql); $row = $result-fetch(); extract($row); $output[] = 'tr'; $output[] = 'tda href=cart.php?action=deleteid='.$id.' class=rRemove/a/td'; $output[] = 'td'.$name.'/td'; $output[] = 'tdpound;'.$price.'/td'; $output[] = 'tdinput type=text name=qty'.$id.' value='.$qty.' size=3 maxlength=3 /td'; $output[] = 'tdpound;'.($price * $qty).'/td'; $total += $price * $qty; $output[] = '/tr'; } $output[] = '/table'; $output[] = 'pGrand total: pound;'.$total.'/p'; $output[] = 'divbutton type=submitUpdate cart/button/div'; $output[] = '/form'; } else { $output[] = 'pYou shopping cart is empty./p'; } return
Re: [PHP-DB] PHP Postgres - query not writing to database.
Glad that you found the problem :) Carol Walter napsal(a): To all who helped. Thank you very much. I found the problem. There is a leading blank on the last name field that I couldn't see. It was coming from my program code. Thanks for all your help. Carol On May 11, 2009, at 4:23 PM, Carol Walter wrote: I have copied the queries into psql and wrapped them in a BEGIN and COMMIT. Even from psql the queries appear to work but don't store the information. There don't appear to be errors in the log either. Thanks for your help, Carol km_tezt=# begin; BEGIN km_tezt=# INSERT INTO tblPeople(fName,mName,lName, ivlweb, cnsweb) VALU ES ('Frank', 'D',' Oz', 't', 't'); INSERT 0 1 km_tezt=# INSERT INTO tblContactInformation(contactItem,contactType) VALU ES ('f...@indiana.edu','0010'); INSERT 0 1 km_tezt=# INSERT INTO brdgPeopleContactInformation (peopleId,contactInform ationId,rank, type) VALUES (currval('tblPeople_peopleId_seq'),currval('tblC ontactInformation_contactInformationId_seq'), '1', '100'); INSERT 0 1 km_tezt=# commit; COMMIT km_tezt=# select * from tblPeople where lName like 'O%'; peopleId | fName | mName | lName | ivlweb | cnsweb --+-+---+++ 404 | Ilka| | Ott| t | t 410 | Elinor | | Ostrom | t | t 374 | Gregory | | O'Hare | t | t 33 | Terry | J.| Ord| t | t (4 rows) On May 10, 2009, at 4:41 AM, danaketh wrote: I'd suggest you to copy the echoed queries and run them directly in terminal (if you have access). Also if you have remote access to the database and can use tools like pgAdmin or Navicat, that could help you with testing. Or send me the table structure and I'll try them myself ;) Carol Walter napsal(a): Hello, I have a PHP program that contains a number of postgres queries. At the end of the program, it needs to write data to a database. You can see the code that I'm using below. I have die clauses on all the queries and I have the program echoing the queries that it runs to the screen. The die clause does not execute. The queries are echoed to the screen, but nothing is being written to the database. There don't appear to be any errors in the postgres log or the php log. Is there a function that I can use that will tell me exactly what is going on here? If there is, can you give me the syntax? Thanks in advance for your time. Carol P.S. This PHP 5 and PostgreSQL 8.3.6 on Solaris 10. ++ I've written a query that needs to insert data into two base tables and a bridge table. The code looks like... /* Echo data for database to the screen */ echop Contact Locator: $cont_loc/p; echop Contact Type Rank: $cont_rank/p; echop Contact Info Type: $contact_type/p; echop New name string: $f_name_new/p; echop New name string: $m_name_new/p; echop New name string: $l_name_new/p; echop New ivl web string: $ivl_web_peop/p; echop New cns_web string: $cns_web_peop/p; echop New contact rank string: $cont_rank/p; echop New contact locator string: $cont_loc/p; echop New contact item string: $contact_info1/p; echop New contact type string: $contact_type/p; /* Connect to database*/ include connect_km_tezt.php; /* Run queries*/ $query = INSERT INTO \tblPeople\(\fName\,\mName\,\lName\, ivlweb, cnsweb) VALUES ('$f_name_new', '$m_name_new',' $l_name_new', '$ivl_web_peop', '$cns_web_peop'); echo First query: . $query . br /; $pg_peop_ins = pg_query($query) or die(Can't execute first query); // echo pg_last_error(Last Error . $pg_peop_ins); //echo pg_result_error($pg_peop_ins); $query = INSERT INTO \tblContactInformation\(\contactItem\,\contactType\) VALUES ('$contact_info1','$contact_type'); echo Second query: . $query . br /; $pg_contact_ins = pg_query($query) or die(Can't execute 2nd query); $query = INSERT INTO \brdgPeopleContactInformation\ (\peopleId\,\contactInformationId\,rank, type) VALUES (currval('\tblPeople_peopleId_seq\'),currval('\tblContactInformation_contactInformationId_seq\'), '$cont_rank', '$cont_loc'); echo Third query: . $query . br /; $pg_peop_cont_ins = pg_query($query) or die(Can't execute 3rd query); + The postgres log looks like this ... [km_app_admin:km_tezt:2009-05-08 10:34:49 EDT]STATEMENT: INSERT INTO tblPeople(fName,mName,lName
Re: [PHP-DB] PHP Postgres - query not writing to database.
I'd suggest you to copy the echoed queries and run them directly in terminal (if you have access). Also if you have remote access to the database and can use tools like pgAdmin or Navicat, that could help you with testing. Or send me the table structure and I'll try them myself ;) Carol Walter napsal(a): Hello, I have a PHP program that contains a number of postgres queries. At the end of the program, it needs to write data to a database. You can see the code that I'm using below. I have die clauses on all the queries and I have the program echoing the queries that it runs to the screen. The die clause does not execute. The queries are echoed to the screen, but nothing is being written to the database. There don't appear to be any errors in the postgres log or the php log. Is there a function that I can use that will tell me exactly what is going on here? If there is, can you give me the syntax? Thanks in advance for your time. Carol P.S. This PHP 5 and PostgreSQL 8.3.6 on Solaris 10. ++ I've written a query that needs to insert data into two base tables and a bridge table. The code looks like... /* Echo data for database to the screen */ echop Contact Locator: $cont_loc/p; echop Contact Type Rank: $cont_rank/p; echop Contact Info Type: $contact_type/p; echop New name string: $f_name_new/p; echop New name string: $m_name_new/p; echop New name string: $l_name_new/p; echop New ivl web string: $ivl_web_peop/p; echop New cns_web string: $cns_web_peop/p; echop New contact rank string: $cont_rank/p; echop New contact locator string: $cont_loc/p; echop New contact item string: $contact_info1/p; echop New contact type string: $contact_type/p; /* Connect to database*/ include connect_km_tezt.php; /* Run queries */ $query = INSERT INTO \tblPeople\(\fName\,\mName\,\lName\, ivlweb, cnsweb) VALUES ('$f_name_new', '$m_name_new',' $l_name_new', '$ivl_web_peop', '$cns_web_peop'); echo First query: . $query . br /; $pg_peop_ins = pg_query($query) or die(Can't execute first query); // echo pg_last_error(Last Error . $pg_peop_ins); //echo pg_result_error($pg_peop_ins); $query = INSERT INTO \tblContactInformation\(\contactItem\,\contactType\) VALUES ('$contact_info1','$contact_type'); echo Second query: . $query . br /; $pg_contact_ins = pg_query($query) or die(Can't execute 2nd query); $query = INSERT INTO \brdgPeopleContactInformation\ (\peopleId\,\contactInformationId\,rank, type) VALUES (currval('\tblPeople_peopleId_seq\'),currval('\tblContactInformation_contactInformationId_seq\'), '$cont_rank', '$cont_loc'); echo Third query: . $query . br /; $pg_peop_cont_ins = pg_query($query) or die(Can't execute 3rd query); + The postgres log looks like this ... [km_app_admin:km_tezt:2009-05-08 10:34:49 EDT]STATEMENT: INSERT INTO tblPeople(fName,mName,lName, ivlweb, cnsweb) VALUES ('Frank', 'D',' Oz', 't', 't') [km_app_admin:km_tezt:2009-05-08 10:34:49 EDT]LOG: duration: 105.005 ms [km_app_admin:km_tezt:2009-05-08 10:34:49 EDT]LOG: PLANNER STATISTICS [km_app_admin:km_tezt:2009-05-08 10:34:49 EDT]DETAIL: ! system usage stats: ! 0.51 elapsed 0.50 user 0.06 system sec ! [0.064533 user 0.013546 sys total] ! 0/2 [2976/197116] filesystem blocks in/out ! 0/0 [44325584/1] page faults/reclaims, 0 [465469248] swaps ! 0 [0] signals rcvd, 1/3 [2/5] messages rcvd/sent ! 10/0 [-64186124/0] voluntary/involuntary context switches ! buffer usage stats: ! Shared blocks: 0 read, 0 written, buffer hit rate = 0.00% ! Local blocks: 0 read, 0 written, buffer hit rate = 0.00% ! Direct blocks: 0 read, 0 written [km_app_admin:km_tezt:2009-05-08 10:34:49 EDT]STATEMENT: INSERT INTO tblContactInformation(contactItem,contactType) VALUES ('f...@indiana.edu','0010') [km_app_admin:km_tezt:2009-05-08 10:34:49 EDT]LOG: duration: 10.856 ms [km_app_admin:km_tezt:2009-05-08 10:34:49 EDT]LOG: PLANNER STATISTICS [km_app_admin:km_tezt:2009-05-08 10:34:49 EDT]DETAIL: !
Re: [PHP-DB] PostgreSQL query many escape characters?
Hi, you should post the INSERT query too. I'd recommend you to print the query before running it. Just put echo $query; before/after pg_query(). You'll see what are you sending to the database. This may help you find the problem. Also using ` instead of in query may help you to make it easier to read. Carol Walter napsal(a): Hello, I am very new to this process, so please forgive me if this is a silly question. I have a number of PostgreSQL tables that use the naming convention that capitalizes the first character of each word, therefor the data names require quotes. When I put together my queries using parameters for the selected columns and the table names and use pg_query_params instead of pg_query to build the query? Doing it without the parameterization looks like this... $query = SELECT tp.\peopleId\,\fName\,\mName\,\lName\,\contactItem\ FROM \tblPeople\ tp LEFT JOIN \brdgPeopleContactInformation\ bpci ON tp.\peopleId\ = bpci.\peopleId\ LEFT JOIN \tblContactInformation\ tci ON bpci.\contactInformationId\ = tci.\contactInformationId\ WHERE (\lName\ like '$l_name' AND \fName\ IS NULL) OR (\lName\ like '$l_name' AND \fName\ LIKE '$f_name') ORDER BY \lName\,\fName\,\mName\; $SciName = pg_query($query); This actually works, believe it or not, but my next query where I'm doing an insert to the tables does not. Thank you in advance for your time. Carol -- S pozdravem Daniel Tlach Freelance webdeveloper Email: m...@danaketh.com ICQ: 160914875 MSN: danak...@hotmail.com Jabber: danak...@jabbim.cz
Re: [PHP-DB] Not getting option value from my database...
Can't say for sure where the problem is but seems to me that you're using global variables instead of $_GET and $_POST. After sending the form, you should access it's content using $_POST... if (isset($_POST['get_name'])){ echo People Id = .$_POST['GetName'].br/; } This should solve the problem of yours. Carol Walter napsal(a): Hello, I am trying to get an option value from a database. I'm using the following code snippet. This is a postgres 8.3.6 database. I am able to use echo to get a list from the database. The code appears to work, but later when I try to echo the id from the selected record, I get no result. What I'm trying to do, is select the appropriate row from the database using the options menu construct. form method=POST ? echo p Choose your prospect:br /select name='GetName' size='. $rows .'; while (list($peopleId, $fName, $mName, $lName, $contactItem) = pg_fetch_row($SciName)) { echo option value='.$peopleId.' . $fName . . $mName . .$lName . nbsp; . ---. nbsp; . $contactItem . /option; } echo /select; ? br / br / input type=submit name=get_name value=Submit / input type=reset value=Reset //p /form ? } } if ($get_name == Submit) { echo People Id = . $peopleId. br /; } Thank you for your time, Carol Walter -- S pozdravem Daniel Tlach Freelance webdeveloper Email: m...@danaketh.com ICQ: 160914875 MSN: danak...@hotmail.com Jabber: danak...@jabbim.cz
Re: [PHP-DB] Re: session variable in select query showing picture from database
Don't see session_start() in your script. If you work with SESSION, you must have it on the first lines of the file (before any output and work with $_SESSION so it's good to put it on the first lines). And it must be in every file which works with them (except for included files). It should look like this: ?php session_start(); // open session function db_connect($host='', $user='', $password='', $db='') { mysql_connect($host, $user, $password) or die('I cannot connect to db: ' . mysql_error()); mysql_select_db($db); } db_connect(); $band_id = $_SESSION['session_var']; $query=SELECT * FROM pic_upload WHERE band_id=$band_id; $result=mysql_query($query); while($row = mysql_fetch_array($result)) { $bytes = $row['pic_content']; } header(Content-type: image/jpeg); print $bytes; exit (); mysql_close(); ? Mika Jaaksi napsal(a): Still fighting with it... So, these work: $query=SELECT * FROM pic_upload; $query=SELECT * FROM pic_upload WHERE band_id=11; picture is shown on the other page but when adding variable into query it doesn't show the picture on the other page $query=SELECT * FROM pic_upload WHERE band_id='{$band_id}'; I'm out of ideas at the moment... ps. forget what I said about the weird markings... 2009/2/12 Mika Jaaksi mika.jaa...@gmail.com I'm trying to show picture from database. Everything works until I add variable into where part of the query. It works with plain number. example ...WHERE id=11... ...picture is shown on the page. Here's the code that retrieves the picture. show_pic.php ?php function db_connect($host='', $user='', $password='', $db='') { mysql_connect($host, $user, $password) or die('I cannot connect to db: ' . mysql_error()); mysql_select_db($db); } db_connect(); $band_id = $_SESSION['session_var']; $query=SELECT * FROM pic_upload WHERE band_id=$band_id; $result=mysql_query($query); while($row = mysql_fetch_array($result)) { $bytes = $row['pic_content']; } header(Content-type: image/jpeg); print $bytes; exit (); mysql_close(); ? other page that shows the picture ?php echo img width='400px' src='./show_pic.php' /; ? Any help would be appreciated... -- S pozdravem Daniel Tlach Freelance webdeveloper Email: m...@danaketh.com ICQ: 160914875 MSN: danak...@hotmail.com Jabber: danak...@jabbim.cz
Re: [PHP-DB] Problems with INNER JOIN
Maybe LEFT instead of INNER? Terion Miller napsal(a): Hi Everyone! I am having problems getting an INNER JOIN to work and need some tips trouble shooting where the problem may be. What I'm trying to do is match up AdminID's from two tables and display only that users orders, sounds simple enough right...but I can't get it to return the AdminID... My Query: $sql = SELECT admin.AdminID , workorders.AdminID FROM admin INNER JOIN workorders ON (admin.AdminID=workorders.AdminID) WHERE admin.UserName = '.$_SESSION['user'].' ; $result = mysql_query ($sql); $row = mysql_fetch_assoc ($result); $Total = ceil(mysql_num_rows($result)/$PerPage); Thanks for any tips on how else I can accomplish this... Terion -- S pozdravem Daniel Tlach Freelance webdeveloper Email: m...@danaketh.com ICQ: 160914875 MSN: danak...@hotmail.com Jabber: danak...@jabbim.cz
Re: [PHP-DB] Re: Problems with INNER JOIN
Try that query in console or use Navicat/phpMyAdmin to run it. Remove the HAVING part to see if the SELECT returns what you need. Terion Miller napsal(a): Thanks Martin, oddly enough that still doesn't pull any results, it won't even print the variables if I try to list them to see, I know my db connection is good checked that, and can do really simple queries, would something be preventing a JOIN from working? When I Reveal my variables this query snippet: $sql = SELECT admin.AdminID, workorders.WorkOrderID FROM admin INNER JOIN workorders ON admin.AdminID=workorders.AdminID HAVING admin.username='.$_SESSION['user'].' ; $result2 = mysql_query ($sql); $row2 = mysql_fetch_assoc ($result2); $Total = ceil(mysql_num_rows($result2)/$PerPage); Returns this: $sqlSELECT admin.AdminID, workorders.WorkOrderID FROM admin INNER JOIN workorders ON admin.AdminID=workorders.AdminID HAVING admin.username='tmiller' $result2$row2 Terion On Thu, Jan 29, 2009 at 11:56 AM, Martin Zvarík mzva...@gmail.com wrote: This will work: $sql = SELECT admin.AdminID, workorders.WHAT_YOU_WANT FROM admin INNER JOIN workorders ON admin.AdminID=workorders.AdminID HAVING admin.username='.$_SESSION['user'].' ; Terion Miller napsal(a): Hi Everyone! I am having problems getting an INNER JOIN to work and need some tips trouble shooting where the problem may be. What I'm trying to do is match up AdminID's from two tables and display only that users orders, sounds simple enough right...but I can't get it to return the AdminID... My Query: $sql = SELECT admin.AdminID , workorders.AdminID FROM admin INNER JOIN workorders ON (admin.AdminID=workorders.AdminID) WHERE admin.UserName = '.$_SESSION['user'].' ; $result = mysql_query ($sql); $row = mysql_fetch_assoc ($result); $Total = ceil(mysql_num_rows($result)/$PerPage); Thanks for any tips on how else I can accomplish this... Terion -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- S pozdravem Daniel Tlach Freelance webdeveloper Email: m...@danaketh.com ICQ: 160914875 MSN: danak...@hotmail.com Jabber: danak...@jabbim.cz
Re: [PHP-DB] re:database tables relations advice
This is solved by using FOREIGN KEY but I'm not sure if MySQL have them present or just planned for some future release. mrfroasty napsal(a): I am quite new to database designs, I have a problem in my design...I can actually feel it, but I am not quite sure if there is a feature in mysql or I have to solve it with programming. Example: CREATE TABLE A ( user_id int(16) NOT NULL auto_increment, ..other datas PRIMARY KEY (user_id) ); CREATE TABLE B ( user_id int(16) NOT NULL auto_increment, ..other datas PRIMARY KEY (contact_id) ); Question: How can I declare that the user_id in my 1st table is related to user_id in the 2nd table...actually I prefer to have it exactly the same user_id in both tablesI think if those 2 entries are the same it will be great, but I am not sure how to achieve this. P:S -Ofcourse I know that I can extract it from TABLE A and save it in TABLE Bbut is that a way to go???Because this issue arise in couple of tables in my data structure that I am tending to use in my application(web). -I also know that its possible to make just 1 big table with lots of columnsbut I read its not a good database design... -please advice, running out of ideas :-( Thanks.. -- S pozdravem Daniel Tlach Freelance webdeveloper Email: [EMAIL PROTECTED] ICQ: 160914875 MSN: [EMAIL PROTECTED] Jabber: [EMAIL PROTECTED]
Re: [PHP-DB] Universal Update / Delete Script
Well, if you're using some good database layer, you can have for example insert.php file with query template and give it some parameters. $arr = array( 'field1' = 'value1', 'field2' = 'valuer2', ... ); $query = layer::query('INSERT INTO [table]', $arr); Then you will need just to prepare you're posted values for inserting (remove submit button from POST array etc.). If you have you form inputs named after fields in database, you should have no problems. Craig Hoffman napsal(a): Hey There - I could use some suggestions / advice here. I have to create several update and delete scripts for two different areas of a site. For example Update the News, Update an Event, Delete News, Delete Event and so on. Instead of writing 4 separate scripts that updates and / or deletes records in MySQL, what would be the best approach in having an 2 universal scripts that updates and another one that just deletes? Does this make sense? Here's a breakdown: Events - Update / Delete (events table) News - Update / Delete (news table) ___ Craig Hoffman iChat / AIM: mountain.dog ___ -- S pozdravem Daniel Tlach Freelance webdeveloper Email: [EMAIL PROTECTED] ICQ: 160914875 MSN: [EMAIL PROTECTED] Jabber: [EMAIL PROTECTED]
Re: [PHP-DB] Could not run query
Well, seems to me like a problem with quotes you're using in query... The ` quotes you're using doesn't work, when I tried to use them in PHP called query. Maybe you should try use single quotes and if they works. boclair napsal(a): I need help to track down the cause of the error,Could not run query A typical query is $laterrecords = mysql_query(SELECT * FROM messages WHERE `logged` $timebegin ORDER BY `logged` DESC ) or die (Cannot select:br$querybrError: . mysql_error()); Louise
Re: [PHP-DB] Performance (lots of tables / databases...)
Hi, the first choice is probably the best for you. When you think about second solution, it will be a nightmare when you have 1000+ databases and have to administrate them from one central system (if you're about to do it like this). The third solution looks little complicated to me - have one DB for comments, one for items etc. But you can do it also in one database and six tables. Make one table 'blogs' where the blogs names and ids will be stored. Then you can just add one more field 'blog_id' to every table and identify items, categories, whatever on this. However in your situation (1000+ blogs) it may be not the best solution. Martin Zvarík napsal(a): Hi, I am working on a blog system and I am currently thinking of what would be the best DB approach. I have read lots about wordpress and other blog's optimizations and DB structure, but I have not found any mention of having separate database for each blog/user. So, my question is, which one is performance better (talking about 1000 blogs): a) 1000 blogs * 5 (let's say we will have tables like comments, post... for each blog) = 5000 tables in one database ... this is Wordpress default b) 1000 databases (for each blog) each having 5 tables c) 5 databases by 1000 tables - in this case, won't this be an issue when SELECTing like this: [db_comments].testblog, [db_posts].testblog ? Is that a controversial topic? :-/ Thanks for ideas, Martin