[PHP-DB] Retrieve data from a table, edit/add it and enter it in a new table
Hi, I am trying to do the following: Retrieve some information from a table, edit it by appending some further information to it (a few more fields) and then enter the new data record into a new table, and delete the old data in the original table. Sounds confusing I know. The code is below (I apologise for its poor style etc as I am very new to php), but when I click on the 'Enter Information' button, nothing happens. The existing data is retrieved without any problems and I can select it using the radio button. But when I try and add data to the new fields ('option_close_price' and 'notes'), nothing happens. Any help appreciated. form action=? echo $PHP_SELF ? method=post ? mysql_pconnect(localhost,root,password); mysql_select_db(options); if(!$cmd) { $result = mysql_query(select * from open_trades); while($r=mysql_fetch_array($result)) { $open_date=$r[open_date]; $share=$r[share]; $code=$r[code]; $short_long_trade=$r[short_long_trade]; $id=$r[id]; $expiry=$r[expiry]; $exercise=$r[excercise]; $option_price=$r[option_price]; $no_purchased=$r[no_purchased]; $no_sold=$r[no_sold]; $income_in=$r[income_in]; $income_out=$r[income_out]; print table border=\1\ cellpadding=\3\ cellspacing=\0\\n; print td/tdtdOpen Date/tdtdShare/tdtdCode/tdtdShort orbr Long Trade/tdtdExpiry/tdtdExcercise/tdtdOption Price/tdtdNumberbr Purchased/tdtdNumber Sold/tdtdIncome In/tdtdIncome Out/tdtd /tr; while ($row = mysql_fetch_array($result)) { print trtd; print INPUT TYPE='RADIO' NAME='id' VALUE='echo $id'; print /tdtd; print $row[open_date]; print /tdtd; print $row[share]; print /tdtd; print $row[code]; print /tdtd; print $row[short_long_trade]; print /tdtd; print $row[expiry]; print /tdtd; print $row[excercise]; print /tdtd; print $row[option_price]; print /tdtd; print $row[no_purchased]; print /tdtd; print $row[no_sold]; print /tdtd; print $row[income_in]; print /tdtd; print $row[income_out]; print /td/tr\n; } print /table\n; ? ? }? input type=submit name=cmd value=Close/form ? } ? ? if($cmd==Close) { if (!$submit) { $result = mysql_query(select * from open_trades); while($myrow=mysql_fetch_array($result)) ? input type=hidden name=id value=?php echo $myrow[id] ? Option Close PriceINPUT TYPE=TEXT NAME=option_close_price VALUE=?PHP echo $myrow[option_close_price]? SIZE=7 br Notes:INPUT TYPE=TEXT NAME=notes VALUE=?php echo $myrow[notes] ? SIZE=60br input type=hidden name=cmd value=edit input type=Submit name=submit value=Enter information /form ? } ? ? if($submit) { $query = INSERT INTO closed_trades SET code='$code', option_price='$option_price', option_close_price='$option_close_price', no_sold='$no_sold', open_date='$open_date', short_long_trade='$short_long_trade, share='$share', expiry='$expiry', excercise='$excercise', no_purchased='$no_purchased', income_in='$income_in', income_out='$income_out', notes='$notes', id=$id'; $result = mysql_query($ql); $query = DELETE FROM open_trades WHERE id=$id; $result = mysql_query($sql); echo Thank you! Information updated.; } } ? /td /table
[PHP-DB] Re: PHP/MySQL learning project
Hi. In trying to learn PHP and MySQL, I'm trying to create a web-based database application that will keep track of my movies. I have five tables (shown in the graphic). I'm trying to be able to display the results of the tables with one movie title, all of the actors associated with it, and all of the genre's associated with it. You are thinking not in the terms of relational db. It's impossible on the mysql db level. WBR, Wicked -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-DB] PHP and DBA (db3)
Hello! Trying to bring that code to work on win32. --- h1dba_perf_test.php/h1 ?php $handlers = dba_handlers(true); print pre; print_r($handlers); print /pre; $dbtype = db3; $dbfile = C:/dbfile; $nrecs = 100; echo using datafile: $dbfile.$dbtypebr\n; $id = dba_open($dbfile...$dbtype, c, $dbtype); if (!$id) { die(\nbrdhi: could not open dbfile); } for ($i=0; $i$nrecs; $i++) { $key = rand(1, $nrecs); $value = date(D M j G:i:s T Y); if(!dba_exists($key, $id)) { $ins = dba_insert($key, $value, $id); echo inserted $key:$value in $dbfile.$dbtypebr\n; } } dba_close($id); /// Finds in db $success = 0; $id = dba_open($dbfile...$dbtype, r, $dbtype); if (!$id) { die(could not open dbfile); } $success = 0; for ($i=0; $i$nrecs; $i++) { $key = rand(1, $nrecs); if(dba_exists($key, $id)) { $success++; } } dba_close($id); ? --- Result: Warning: dba_open(C:/dbfile.db3,c): Driver initialization failed for handler: db3: Permission denied in e:\data\dhidata\meddictool2\dba_news.php on line 18 Any Ideas? Thanks! dhi -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-DB] GROUP_CONCAT query
Hi all, I sometimes find the MYSQL manual very difficult to understand- perhaps I am alone in this. I am wanting to do the following, and I think I need to use GROUP_CONCAT in my query. I have a table of webstats for my site with columns for IP, Hostname, referer website etc and I want to show the occurences of the the same IP, hostname and referer website and how many times. How do I do this? My normal query would look like this? $query = SELECT `id` , `clicks` , `os` , `browser` , `ip` , `port` , `host` , `country_code` , `country_name` , `cookies` , `crawler` , `referer_website` , `qs` , `datestart` , `dateend` , `timestart` , `timeend` , `history` , `fulltimestart` , `daystart` , `fulltimeend` , `dayend` , `timelength` FROM `webstatstable` I have tried doing SELECT referer_website, GROUP_CONCAT(referer_website) FROM 'webstatstable' but that doesn't seem to work. Any ideas?
[PHP-DB] diplicate entries
Hi! What is the best way to check if a record allready exists in a msql-db from php in the case of when the same form is submited twice beacuse of the refresh-button? Should I allways check the db for the same entry, or is there some esier way to prevent the user from submiting a form more then once? Btw, is it possible for an sql-query to stop halfway through (if the server goes down or something)? Thanks! .bobo -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-DB] Re: diplicate entries
Bobo Wieland [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] Hi! What is the best way to check if a record allready exists in a msql-db from php in the case of when the same form is submited twice beacuse of the refresh-button? Should I allways check the db for the same entry, or is there some esier way to prevent the user from submiting a form more then once? Btw, is it possible for an sql-query to stop halfway through (if the server goes down or something)? Please don't hijack threads! As to your duplicate form submits: This is usually prevented by using a hidden form element with a randomly generated token (string). When the form is submitted check if the token already exists in a session array - if not this is the first submit so store the token in the array and process the form. If the same form is re-submitted the token will be found in the session array and therefore the form should not be processed. IMPORTANT: When creating the random token check if a token with this value already exists in the session array. Hope this helps. Regards, Torsten Roehr -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-DB] mysql results, arrays, and for loops
Hi all! I am using a select statement to obtain all the dates whenever someone submitted a problem in a database. Well, I want to get the result (which could be multiple dates) and then print that in a table format with some other information on a webpage. So I want to use a FOR loops and go through each of the dates and dynamically create a table. My question is: how do I store the results of the select query? Would I want to store them in an array, and then just parse through each element of the array, and what is the syntax for that? Or is there a better way? Thanks, ~Philip -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-DB] Re: mysql results, arrays, and for loops
Philip Thompson [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] Hi all! I am using a select statement to obtain all the dates whenever someone submitted a problem in a database. Well, I want to get the result (which could be multiple dates) and then print that in a table format with some other information on a webpage. So I want to use a FOR loops and go through each of the dates and dynamically create a table. My question is: how do I store the results of the select query? Would I want to store them in an array, and then just parse through each element of the array, and what is the syntax for that? Or is there a better way? You can loop through your query results in this way: $result = mysql_query('SELECT * FROM table'); while ($row = mysql_fetch_assoc($result)) { // row is now the current record set as an associative array, keys represent the field names // do what you want with row, e.g. print a field value from column date echo $row['date']; } Is this what you are looking for? Regards, Torsten Roehr -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-DB] Re: PHP/MySQL learning project
Alexey Kupershtokh wrote: Hi. In trying to learn PHP and MySQL, I'm trying to create a web-based database application that will keep track of my movies. I have five tables (shown in the graphic). I'm trying to be able to display the results of the tables with one movie title, all of the actors associated with it, and all of the genre's associated with it. You are thinking not in the terms of relational db. It's impossible on the mysql db level. WBR, Wicked I don't know what you're trying to say here. You can do relational databases with mysql without any trouble whatsoever. Just because it doesn't support foreign keys (constraints) doesn't mean you can't have foreign keys. In fact, foreign keys mostly just slow down the run-time of your system, but I don't want to start a holy war here. -- paperCrane Justin Patrin -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] Re: mysql results, arrays, and for loops
Yes, thanks to all that assisted. I got it working like a charm! ~Philip On Jun 11, 2004, at 9:30 AM, Torsten Roehr wrote: Philip Thompson [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] Hi all! I am using a select statement to obtain all the dates whenever someone submitted a problem in a database. Well, I want to get the result (which could be multiple dates) and then print that in a table format with some other information on a webpage. So I want to use a FOR loops and go through each of the dates and dynamically create a table. My question is: how do I store the results of the select query? Would I want to store them in an array, and then just parse through each element of the array, and what is the syntax for that? Or is there a better way? You can loop through your query results in this way: $result = mysql_query('SELECT * FROM table'); while ($row = mysql_fetch_assoc($result)) { // row is now the current record set as an associative array, keys represent the field names // do what you want with row, e.g. print a field value from column date echo $row['date']; } Is this what you are looking for? Regards, Torsten Roehr -- 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] MySQL persistent connections
Hey there PHP fiends, I have a bit of cookie here. We're designing a PHP based app that uses MySQL as the data storage. Scalability is an issue, we want to be able to handle up to 1 people utilizing the system (not at once of course). Question is, should I be connecting and disconnecting from the DB on each operation or increase the maximum number of allowed connections with MySQL and connect just once. TIA R - -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-DB] Re: PHP/MySQL learning project
So given the same database diagram (MovieMain, Actors, Genre, then a table named MovieActor to allow multiple actors to be associated with a movie, and MovieGenre to allow multiple genre's to be associated with a movie), can you steer me in the right direction on writnig the PHP to display all movies (one by one) with all of the actors and genre's associated with each movie (yet only display the movie title once)? thanks a million! News.Php.Net Hi everyone! In trying to learn PHP and MySQL, I'm trying to create a web-based database application that will keep track of my movies. I have five tables (shown in the graphic). I'm trying to be able to display the results of the tables with one movie title, all of the actors associated with it, and all of the genre's associated with it. Of course I can do the query: Select * From MovieMain, MovieActor, MovieGenre, Genre, Actors Where MovieMain.MovieID=MovieGenre.MovieID And MovieMain.MovieID=MovieActor.MovieID And MovieActor.ActorID=Actors.ActorID And MovieGenre.GenreID=Genre.GenreID But that displays the movie title for every genre and actor there is. Is there another way to perform the query that will display the title once, and all of the associated genres and all of the associated actors for that movie? Or should I try to code it using PHP to find the movie title first? Thanks in advance, everyone! -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-DB] Re: GROUP_CONCAT query
i presume you want something like: select ip,hostname,referer,count(*) from table group by ip,hostname,referer; note: all fields in the select clause that are not affected by any aggregate function must appear in the group by clause; I.A. Gray writes: Hi all, I sometimes find the MYSQL manual very difficult to understand- perhaps I am alone in this. I am wanting to do the following, and I think I need to use GROUP_CONCAT in my query. I have a table of webstats for my site with columns for IP, Hostname, referer website etc and I want to show the occurences of the the same IP, hostname and referer website and how many times. How do I do this? My normal query would look like this? $query = SELECT `id` , `clicks` , `os` , `browser` , `ip` , `port` , `host` , `country_code` , `country_name` , `cookies` , `crawler` , `referer_website` , `qs` , `datestart` , `dateend` , `timestart` , `timeend` , `history` , `fulltimestart` , `daystart` , `fulltimeend` , `dayend` , `timelength` FROM `webstatstable` I have tried doing SELECT referer_website, GROUP_CONCAT(referer_website) FROM 'webstatstable' but that doesn't seem to work. Any ideas? * * Rui Pedro Cunha * * Dpto. de Ciências e Tecnologias * * Universidade Autónoma de Lisboa * * Rua de Santa Marta, 56, * * 1169-023 Lisboa * * Telefone (+351) 21 317 76 35/49 * * Fax (+351) 21 353 37 02 * * Url : http://www.ual.pt/dct/ * * E-mail: [EMAIL PROTECTED] * * -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-DB] Re: mysql results, arrays, and for loops
hope this code will help you TABLE WIDTH=100% HEIGHT=100% ?php $db = mysql_connect ('localhost') or die ($MYSQL_NO_CON); mysql_select_db ('database_name',$db) or die ($MYSQL_NO_BD); $query = SELECT * FROM table or die ($MYSQL_NO_QUERY); $result = mysql_query($query); if (mysql_num_rows($result) 0 ) { $num_rows = mysql_num_rows($result); for ($i=0; $i $num_rows; $i++) { $row = mysql_fetch_row($result); echo TRTD$row[0]/TD/TR; } }else echo no records found!; ? /TABLE Rui Cunha Philip Thompson writes: Hi all! I am using a select statement to obtain all the dates whenever someone submitted a problem in a database. Well, I want to get the result (which could be multiple dates) and then print that in a table format with some other information on a webpage. So I want to use a FOR loops and go through each of the dates and dynamically create a table. My question is: how do I store the results of the select query? Would I want to store them in an array, and then just parse through each element of the array, and what is the syntax for that? Or is there a better way? Thanks, ~Philip -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP-DB] Re: Anyone using MSQL Server with PHP?
Thanks a lot Hans for your great explanation about this type of passwords, salted passwords. I will google for that term, time-memory Tradeoff. Thanks one more time!! Miguel Guirao Servicios Datacard www.SIASA.com.mx -Mensaje original- De: Hans Lellelid [mailto:[EMAIL PROTECTED] Enviado el: Viernes, 11 de Junio de 2004 12:15 a.m. Para: Miguel Guirao CC: 'Justin Patrin'; [EMAIL PROTECTED] Asunto: Re: [PHP-DB] Re: Anyone using MSQL Server with PHP? Hi Miguel, I would also strongly suggest that you use a salted hash if you are concerned with security -- especially if that md5 could ever be compromised or pass in clear text over an internet connection. The md5() function in PHP produces unsalted hashes, which are fairly easy to crack. Unlike md5(), the PHP crypt() function will generate salted hashes. On my windows system it creates salted MD5 hashes (other operating systems may have other options like SHA1). A salt is essentially an additional random element that gets added into the password hash. This means that unlike md5() you will get a different hash each time you run crypt() on an identical string: crypt(hello) = $1$bJoW4DmS$GDNwsRSjd5rwkfra6KOh10 crypt(hello) = $1$DnL7LQXm$eioj87M92X3IQvoTEquY21 crypt(hello) = $1$h488/RAa$e8tA4K1hEuBBRnagJbBnV1 instead of: md5(hello) = 5d41402abc4b2a76b9719d911017c592 md5(hello) = 5d41402abc4b2a76b9719d911017c592 md5(hello) = 5d41402abc4b2a76b9719d911017c592 Why does this matter? Well, because of something called the time-memory tradeoff (try a google search to see the math behind this). The basic principle of the time-memory tradeoff is that you could either spend a long time trying to brute force each password hash or you could just spend time once creating really big (memory) tables that contain all the possibilities and then crack a hashed password in seconds. Of course the more complex the passwords you want to crack the longer it takes to build these tables (could be days, weeks, months, etc.), but the idea is that once you've built these tables it only takes a few seconds to crack any supported password. Time-memory tradeoff only works with unsalted passwords because these are 100% predicatble (hash of unsalted MD5 is always the same, as seen above). To check an entered password against the original when using salted hashes, you need to do something a little different: you have to pass the original encrypted password as the salt to the crypt() function (the crypt() function extracts the salt from the passed password and uses that same salt to encrypt the entered password). For example in PHP, check entered password against real password like this: if (crypt($entered_pw, $real_pw) == $real_pw) { // login success } Hope that helps. (Anyone, please correct any errors or misinformation above!) Hans Miguel Guirao wrote: Thanks!! It Works out pretty nice!! Miguel Guirao Servicios Datacard www.SIASA.com.mx -Mensaje original- De: Justin Patrin [mailto:[EMAIL PROTECTED] Enviado el: Jueves, 10 de Junio de 2004 05:51 p.m. Para: [EMAIL PROTECTED] Asunto: [PHP-DB] Re: Anyone using MSQL Server with PHP? Miguel Guirao wrote: Hi!! Anybody here using PHP with SQL Server? I would like to use a similar function to password () from MySQL under SQL Server. Anybody knows of a similar function under SQL Server? Kind Regards, Miguel Guirao Servicios Datacard www.SIASA.com.mx If it's for your app only, you could use md5() in PHP. -- 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
Re: [PHP-DB] PHP and DBA (db3)
I assume you're using windows XP or 2000 or server 2003 and are using NTFS. When you get a Permission dinied in e:\data\dhidata\meddictool2 it means the server doesn't have permission to access the folder. You need to go into the folder's properties to change that. I'm not sure how your specific situation, but if you're using IIS I can help you. Email me back if you still have trouble. - Original message - From: Dietmar Hilke [EMAIL PROTECTED] To: [EMAIL PROTECTED] Date: Fri, 11 Jun 2004 12:52:23 +0200 Subject: [PHP-DB] PHP and DBA (db3) Hello! Trying to bring that code to work on win32. --- h1dba_perf_test.php/h1 ?php $handlers = dba_handlers(true); print pre; print_r($handlers); print /pre; $dbtype = db3; $dbfile = C:/dbfile; $nrecs = 100; echo using datafile: $dbfile.$dbtypebr\n; $id = dba_open($dbfile...$dbtype, c, $dbtype); if (!$id) { die(\nbrdhi: could not open dbfile); } for ($i=0; $i$nrecs; $i++) { $key = rand(1, $nrecs); $value = date(D M j G:i:s T Y); if(!dba_exists($key, $id)) { $ins = dba_insert($key, $value, $id); echo inserted $key:$value in $dbfile.$dbtypebr\n; } } dba_close($id); /// Finds in db $success = 0; $id = dba_open($dbfile...$dbtype, r, $dbtype); if (!$id) { die(could not open dbfile); } $success = 0; for ($i=0; $i$nrecs; $i++) { $key = rand(1, $nrecs); if(dba_exists($key, $id)) { $success++; } } dba_close($id); ? --- Result: Warning: dba_open(C:/dbfile.db3,c): Driver initialization failed for handler: db3: Permission denied in e:\data\dhidata\meddictool2\dba_news.php on line 18 Any Ideas? Thanks! dhi -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- Marcjon -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-DB] multidim help for a newbie
Hi :) I am creating an XML file out of a mysql query with nested arrays. Currently I can get 1 element and 1 child with a properly formatted XML file with the below script . My question: is, How do I add 3 to 4 more child elements to the below 'playlist' array ? Currently ,I have one parent 'Artist' and one child 'english' ... I need to add more child elements like urlPath, spanish, biography, etc Do I have to add another dimension to the 'playlist' array? I am a bit new to this so any help would be greatly appretiated ?php @ $db = mysql_connect('127.0.0.1','name','pass'); if (!$db) { echo 'Error:Could Not Connect'; exit; } mysql_select_db('univision'); $sql = 'SELECT artist.artist_name, media.english, media.path '; $sql .= 'FROM media, artist '; $sql .= 'WHERE artist.artist_id = media.artist_id LIMIT 0, 30 '; $result = mysql_query($sql); while ($row = mysql_fetch_array($result)) { $playlist[$row['artist_name']] [] = $row['english']; //would like to add more children here... } $xml = sirenreels\n; foreach ($playlist as $artist = $media) { $num_media = count($media); $xml .= artist\n; $xml .= \tmeta\n; $xml .= \t\ttitle.$artist./title\n; $xml .= \t/meta\n; $xml .= \tcontent\n; foreach ($media as $mediaVal) { $xml .= \t\tmedia\n; $xml .= \t\t\tenglish_name.$mediaVal./english_name\n; $xml .= \t\t\tpath.$mediaVal./path\n; ///add more children here $xml .= \t\t/media\n; } $xml .= \t/content\n; $xml .= /artist\n; } $xml .= /sirenreels\n; print $xml -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php