Re: [PHP-DB] mysql table join
You may try to create a VIEW. In this case the tables will be dynamically linked, that is when some values change in both tales the views automatically update itself each time you call it. CPT John W. Holmes [EMAIL PROTECTED] ha scritto nel messaggio news:[EMAIL PROTECTED] From: Roger Miranda (Sumac) [EMAIL PROTECTED] Is there a way to permanently join/link two mysql tables? Not without creating another table. CREATE TABLE MyTable SELECT ... FROM Table1 JOIN Table2 ON ... WHERE ... Although I have to wonder about your schema if you need to do this. ---John Holmes... -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] LEFT joins
Jochem Maas ha scritto: Han wrote: Hmm, still no luck. Thanks for the help. I think I'll have to break the you mean that it still times out? crashes mysql? maybe the table (tc_countries) is corrupt? try doing a repair. select up into 2 selects and throw the results of the first into arrays. Didn't want to do it like that, but it's gonna be quicker now. if at first you don't succeed... hack ;-) snip try removing the ORDER BY Clause: SELECT b.fldName, b.fldEmail, b.fldCountryCode, d.fldCode as FCode, b.fldMobile, a.fldTime as Time, c.fldUsername FROM tblSubscribersChoices a LEFT JOIN tblUser c ON c.fldClientID = a.fldChoice LEFT JOIN tblSubscribers b ON b.fldID = a.fldClientID LEFT JOIN tc_countries d ON d.fldCode = b.fldCountryCode ORDER BY c.fldUsername ASC OR SELECT b.fldName, b.fldEmail, b.fldCountryCode, d.fldCode as FCode, b.fldMobile, a.fldTime as Time, c.fldUsername as Username FROM tblSubscribersChoices a LEFT JOIN tblUser c ON c.fldClientID = a.fldChoice LEFT JOIN tblSubscribers b ON b.fldID = a.fldClientID LEFT JOIN tc_countries d ON d.fldCode = b.fldCountryCode ORDER BY Username ASC and if that works but doesn't give you repeat records try adding the DISTINCT keyword after SELECT. snip Why are you so intrested in LEFT JOIN? I cn't help much since i don't know the schema of the db and i can't see clear the meaning of the tables in the query. Anyway try this: SQL SELECT b.fldName, b.fldEmail, b.fldCountryCode, d.fldCode as FCode, b.fldMobile, a.fldTime as Time, c.fldUsername as Username FROM tblSubscribersChoices a, tblUser c, tblSubscribers b, tc_countries d WHERE c.fldClientID = a.fldChoice AND b.fldID = a.fldClientID AND d.fldCode = b.fldCountryCode ORDER BY Username ASC /SQL Bye -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-DB] Re: Cannot load MySQL extension (mysql.so issues)
Eve Atley ha scritto: Platform: Redhat Linux Enterprise WS 3 PHP installed: 4.3.2 MySQL installed: 4.0.21 Apache installed: 2.0.46 When setting up PhpMyAdmin today, I got the error: Cannot load mysql extension, Please check PHP configuration My phpinfo() shows: 'with-mysql=shared,/usr' (yes, the comma is not a mistake) - This looks like a glitch; should I fix, and if so where? Mysql.so was found in: /usr/lib/php4/ My php.ini has been editted to read: extension=mysql.so ...and I also tried: extension=/usr/lib/php4/mysql.so Any clues on remedying this problem, without upgrading MySQL? I have read the problem is solved by installing a PHP-MySQL package, but when I attempted to do so via up2date, I was notified that a dependency was required for a MySQL-client. But Mysql is already installed and running. Any clues out there? Thanks, Eve Wrong thread and group. Bye -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] Returns Blank
Squeakypants ha scritto: From a forum that recommended this to me, I changed the query execution to this: $query = SELECT credits FROM krypto WHERE user=$user AND pass=$pass; echo query = . $query .\n; $result = mysql_query($query); echo result = . $result .\n; So now it outputs this: query = SELECT credits FROM krypto WHERE user=admin AND pass= result = Could not run query: Unknown column 'admin' in 'where clause' Your query is missing quotes near the values for the attributes user ad pass, so mysql try to compare the value user to some value inside an ipotetic admin field Try this: $query = SELECT credits FROM krypto WHERE user=\$user\ AND pass=\$pass\; Bye -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-DB] Re: MySQL: Random select with specific count of a column
I suggest to first analize the problem and then go through the query, php coding ...etc etc In the table u have only one superkey which is also a key and it is made of the three fields (attributes) 'category', 'language' and ' name'. You should consider to look for a prymary key randomly, toghether with some restriction in the search. Something like select the pryimary key from the table where 'category' equals a number(1, 2,3,n) and 'name' equals some random criterium generated number. A random criteria could be generating a random variables between the ascii code representing the alphabet letters (from 97 to 122 to cover a,b,c,...z). You need to do some work before u can get an executable code here. Hope can open a road Bye Torsten Roehr [EMAIL PROTECTED] ha scritto nel messaggio news:[EMAIL PROTECTED] Hi, I've got the following table: categorylanguagename 1 de a 1 de b 1 de c 2 de a 2 de b 2 de c 3 de a 3 de b 3 de c ... 1 en a 1 en b 1 en c I would like to select 6 random rows where the language is 'de' AND make sure that I will always have 2 rows of EACH category in my result set: 1 de b 1 de c 2 de a 2 de c 3 de a 3 de b Any help greatly appreciated. Thanks and best regards, Torsten Roehr -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-DB] Re: Erroneous date and time
Have you tried with a insted of A for am/pm indication? Hope can help Bye Franciccio Philip Thompson [EMAIL PROTECTED] ha scritto nel messaggio news:[EMAIL PROTECTED] Hi all. Maybe there's something I'm doing incorrectly, but I cannot get the date() function to return the appropriate time. It's always 12 hours off. I've tried using 24-hour time and 12-hour time (with AM/PM), but they both give the wrong time. I even emailed the server admin to make sure that the server clock was set correctly, and he said that it was. I don't know... Here's my PHP: $problemDateTime = date(Y-m-d g:i:s A); which returns: 2004-06-13 11:24:21 PM To the untrained eye ;), that might appear correct. But that was actually submitted at 11:24 AM, not PM. So, that's my code. Any suggestions?? Thanks a bunch, ~Philip -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-DB] Re: [PHP] update count
I don't think you can have a relation (table) without a unique key. Either a single field or a unique relation between 2 or more fields is necessary for the table. Franciccio Bob Lockie [EMAIL PROTECTED] ha scritto nel messaggio news:[EMAIL PROTECTED] On 06/16/04 09:53 John Nichel spoke: Bob Lockie wrote: What is the best way to only do an update if it going to update only one row? I want to protect my code so that it won't accidentally update more than one row. I can do a select first but there must be an easier way. :-) UPDATE thisDB.thisTable SET thisTable.thisColumn = 'thisValue' WHERE thisTable.uniqueColumn = 'someUniqueValue' Ok, a primary key is unique, right? -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-DB] Re: anonymous select error
Here is the lean, corrected code: ?php $link = mysql_connect( $site, $id, $pass ) or die (error connecting); echo 'connection okbr'; mysql_select_db( $dbname, $link) or die (eror selecting db); echo 'selected db ok'br; $result = mysql_query( 'Select * From newsletter_subscribers',$link) or die (error query); // some here code to disply result ? It is easier to evaluate each time the return of the functions using the expression or die Also some sintax error: resource mysql_query(string query [, connection id], int result mode]) you used the mysql_select_db() return instead of mysql_connect() return value (altough it is optional), also it is not necessary to write ; at the end of the query string inside the function. Bye Joshuah Goldstein [EMAIL PROTECTED] ha scritto nel messaggio news:[EMAIL PROTECTED] To: [EMAIL PROTECTED] MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii I'm trying this query: $link = mysql_connect( $site, $id, $pass ); if (!$link) { die('Could not connect: ' . mysql_error()); } echo 'Connected successfullybr'; $db = mysql_select_db( $dbname, $link); if( !$db ) { echo DB falsebr; exit; } $result = mysql_query( 'Select * From newsletter_subscribers;', $db ); if (!$result) { echo DB Error, could not list tablesbr; echo 'MySQL Error: ' . mysql_error(); exit; } with this output: Connected successfully DB Error, could not list tables MySQL Error: I dont understand why there is an error, but it prints nothing for the error. Any ideas? Thanks, Josh __ Do you Yahoo!? Friends. Fun. Try the all-new Yahoo! Messenger. http://messenger.yahoo.com/ -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-DB] Re: Pass into the title meta-tag a variable from an URL Directory Manager
Wathever you are ging to do with meta tag they still are html tag, so as long as you embend the tag in php code it shuold just work fine. ?php echo any_html_tag attribute01=\$myattribute01\ attribute02=\$myzttribute02\ /any_html_tag; ? Any text editor should help you modifying the code by find replace tools. Hope can help ps. FORZA ITALIA AGLI EUROPEI Franciccio Alessandro Folghera [EMAIL PROTECTED] ha scritto nel messaggio news:[EMAIL PROTECTED] I hope that phpers will be not angry if I'm posting that maybe stupid question. I have the following script, an URL Directory Manager (PHP4 from Wrox Press). I'd like to pass the variable category into the TITLE META TAG from php_category when I select the corrispondent category_id into the URL Directory Manager, i.e. to display the right category everytime I call it from the script. As I'm an absolute beginner, I'd like someone could suggestme the most rapid way to do it whitout rewriting all the code. Thanks for all, Alessandro Tables of MySQL sample_db # Table structure for table 'php_category' CREATE TABLE php_category ( category varchar(30) NOT NULL, category_id varchar(15) NOT NULL, num_item int(5) NOT NULL, PRIMARY KEY (category_id) ); # Table structure for table 'php_directory' CREATE TABLE php_directory ( url_id int(10) NOT NULL auto_increment, category_id varchar(15) NOT NULL, title varchar(150) NOT NULL, url varchar(150) NOT NULL, description text NOT NULL, registerdate date, hit int(5) NOT NULL, lastaccesstime timestamp(14), password varchar(20) binary, email varchar(100) NOT NULL, approved char(1) NOT NULL, PRIMARY KEY (url_id), UNIQUE url (url, category_id) ); xxx php_directory.inc xx xx php_directory.php x ; $MYSQL_ERRNO = ''; $MYSQL_ERROR = ''; function directory_header() { global $new_window_width, $new_window_height; ? alert(\Error: $msg\);history.go(-1); directory_footer(); exit; } function user_message($msg, $url='') { directory_header(); if(empty($url)) echo alert(\$msg\);history.go(-1); else echo alert(\$msg\);self.location.href='$url'; directory_footer(); exit; } function get_category_info($category_id) { global $default_dbname, $category_tablename, $root_category_id, $category_id_length, $welcome_message, $PHP_SELF; global $link_id; if(!$link_id) $link_id = db_connect($default_dbname); if($category_id == $root_category_id) { $category_info_array[category] = Top; $category_info_array[num_item] = 0; $query = SELECT max(category_id), count(*) FROM $category_tablename WHERE length(category_id) = $category_id_length; $result = mysql_query($query); if(!$result) echo sql_error(); $query_data = mysql_fetch_row($result); $sibling_id = $query_data[0]; $num_child = $query_data[1]; $category_info_array[num_child] = $num_child; if(!$sibling_id) $next_category_id = '001'; else { $sibling_length = strlen($sibling_id); $next_category_id = $sibling_id + 1; for($i = strlen($next_category_id); $i . $query_data[0] .; $parent_array[$j] = $query_data[0]; $j++; } $category_info_array[href_fullname] = implode(-, $parent_href_array); $category_info_array[fullname] = implode(-, $parent_array); } return $category_info_array; } function get_url_info($url_id) { global $link_id, $default_dbname, $directory_tablename; if(!$link_id) $link_id = db_connect($default_dbname); $query = SELECT url_id, category_id, title, url, description,registerdate, date_format(registerdate, '%M, %e, %Y') as formatted_registerdate, hit, lastaccesstime, date_format(lastaccesstime, '%M, %e, %Y %r') as formatted_lastaccesstime, password, email, approved FROM $directory_tablename WHERE url_id = '$url_id'; $result = mysql_query($query); if(!$result) echo sql_error(); return mysql_fetch_array($result); } function search_form($category_id) { global $root_category_id, $PHP_SELF; if(!isset($category_id)) $category_id = $root_category_id; ? Search: Current Category All Categories OR AND $category_href_fullname ($num_child_str, $num_item_str) \n; else echo $category_href_fullname ($num_child_str) \n; search_form($category_id); $query = SELECT category, category_id FROM $category_tablename WHERE (length(category_id) = $category_depth * $category_id_length) AND category_id LIKE '$category_id%' ORDER BY category; $result = mysql_query($query); if(!$result) echo sql_error(); if(mysql_num_rows($result) 0) { ? \n; echo \n; echo \$PHP_SELF?action=show_list category_id=$my_category_id\ $my_category ($num_child_str, $num_item_str)\n; echo \n; if(!($i % 2)) echo \n; $i++; } if(!($i % 2)) { echo \n ; echo ; } ? $found_str - Keyword(s): $keywords \n; if($total_num 0) echo Displaying page $page_num out of $last_page_num \n; $query = SELECT url_id, category_id, title, url, description, date_format(registerdate, '%M, %e, %Y') as formatted_registerdate, hit, date_format(lastaccesstime, '%M, %e
[PHP-DB] Re: mysql results, arrays, and for loops
Hi, here is my solution (one of the possible) it is tested so it should work fine: ?php $recordset=mysql_query($query); $num_righe=mysql_num_rows($recordset); // here starts the dinamyc table echo TABLE align=\left\ border=\1\ cellspacing=\2\ cellpadding=\2\ width=\80%\\ntr; $record= mysql_fetch_array($recordset, MYSQL_ASSOC); foreach ($record as $k =$val) { echo tdb$k/b/td\n; // print the field name in the first row of the table for ($i=0;$i$num_righe;$i++) { echo /tr; mysql_data_seek($recordset,$i); $record = mysql_fetch_array($recordset, MYSQL_ASSOC); foreach ($record as $val){ echo td$val/td\n; // print the result of query, starting under 1st row } } mysql_free_result($recordset); mysql_close(); echo /tr/tablebr; ? Let me know if it fits your problem. Best regards Francesco Basile Philip Thompson [EMAIL PROTECTED] ha scritto nel messaggio 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? Thanks, ~Philip -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-DB] Re: how to reuse DB results
Sorry for mystakes, (shame on me, i said i was new) using Object array, here is a working version (tested) with use of array. Bye $recordset=mysql_query('SELECT * FROM my_tabella'); // or whatever query is /* define an array with fields to be shown on top of page. Attention ...values name must be the same of table field names you want to show on top of the page*/ $my_key = array('key01','key02','key03'); /* u can use $_REQUEST variables instead of fixed values*/ $i=0; while($record=mysql_fetch_array($recordset, MYSQL_ASSOC)) { foreach ($record as $k=$val) if ($k==$my_key[$i]) { // echo the top of the page echo p$k :$val/p; /* if u need a top_array to store result shown on top of the page, comment this line only $top_array[$i]=$val; // loose the matching key-field!! */ $i++; } } //reset the resource mysql_data_seek($recordset,0); // some middle-page code here echo 'pthis is the bottom page and displays the whole result/p'; while ($record=mysql_fetch_array($recordset, MYSQL_ASSOC)) foreach ($record as $k=$val) echo p$k : $val/p; // make your choice for html code mysql_free_result($recordset); // Bye Aaron Wolski [EMAIL PROTECTED] ha scritto nel messaggio news:[EMAIL PROTECTED] Hi All, Got this logic problem I don't know how to solve. Is there any way I can make a call to the DB for some records. Display some info from a column or two say at the top of the page and then display the full result set in a while() loop? Right now, I am making two calls to the Db to get the data I need to display at the top of the page and then a second query to retrieve the full result set. I'm confused! Thanks for any help! Aaron -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-DB] Re: Retrieve data from a table, edit/add it and enter it in a new table
I see one bug in your code , that is you never rewind the pointer of mysql_fetch_array($result), so at the end of the first cycle ...while ($r=mysq...)... the pointer is at the end of the query resource. You should use mysql_data_seek($result,0) to rewind before doing another while cycle. Hope it can help Bye Francesco Basile (PHP_newbee) Justin [EMAIL PROTECTED] ha scritto nel messaggio news:[EMAIL PROTECTED] 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 Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] Re: HTTP header information
You may try with this: ?php ob_start();/* buffer the output so no header is sent until the script is complete*/ session_start(); if (!session_is_registered('_isLoggedIn')) { header (Location:viewer.php?type=login); } else { // do the stuff to submit a problem if they have // logged in and have pressed the submit button // in the html } ? // then here is all the html for that page ?php ob_end_flush();// send the output now ? Bye Basile Francesco Philip Thompson [EMAIL PROTECTED] ha scritto nel messaggio news:[EMAIL PROTECTED] On Jun 10, 2004, at 9:44 AM, Torsten Roehr wrote: Philip Thompson [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] Hi all. I am running a website to where a user needs to login to authenticate themselves to perform certain tasks. So a user logs in, and I start a session (in PHP, of course). Well, the catch is, I am doing this all from one page, 'viewer.php', and I just tack on the specific view/page that I want them to see, depending on the link selected on that page. Meaning, they click on the 'submit problem' link and it goes to 'viewer.php?type=submitproblem'. The problem comes whenever I load the view 'submitproblem' and I start a session with session_start(), which carries over the variable to tell whether or not the user is logged in. If they have not logged in whenever they click on 'submitproblem' then it will redirect them to 'viewer.php?type=login'. So I log in, and then go to 'submitproblem'. This is where I get the error: Warning: session_start(): Cannot send session cookie - headers already sent. Essentially, I understand why this is occurring, but is there an easy way to get around it without creating a new page, such as 'submitproblem.php' instead of 'viewer.php?type=submitproblem'??? Make sure that NO output is done before session_start() is called. Can you post some of your code? Regards, Torsten Roehr See, that's the case. Because I'm essentially just changing the content within the page, it never leaves the page 'viewer.php' - it just changes the content by tacking on '?type=login, submitproblem, etc'. But my code in the beginning of the file 'submitproblem.view' is: ?php session_start(); if (!session_is_registered('_isLoggedIn')) { header (Location:viewer.php?type=login); } else { // do the stuff to submit a problem if they have // logged in and have pressed the submit button // in the html } ? // then here is all the html for that page So, does that help any? ~Philip -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-DB] Re: how to reuse DB results
Hi here is my logic, i haven't tested but it should work (i hope)!!! i'm not sure if it works only on php5...!?! Let me know if it is a complete crap i've just started learning php. Bye $recordset=mysql_query($query); // whatever query is $obj_array=new ArrayObject($recordset); // get the iterator now $interator=$obj_array-getIterator(); // you can now easly navigate in the recordset by the iterator /* define an array with n fields to be shown on top of page. Attention ...values name must be the same of table field names you want to show on top of the page*/ $my_key = array(0='key1',1= 'key2',,n-1='keyn'); // echo the top of the page $i=0; while($iterator-valid()) { if ($iterator-key()==$my_key[$i] ) { echo p.$iterator-key(). : .$iterator-current()./p; /* if u need a top_array to store result shown on top of the page, uncomment this line only $top_array[$i]=$iterator-current(); // loose the matching key-field!! */ $i++; $iterator-next(); } else $iterator-next(); } /* to display the whole recordset resulting from the query don't forget you still have $recordset free to use with mysql_fetch_array() or other way to display */ echo 'pthis is the bottom page and displays the whole result/p'; while ($res=mysql_fetch_array($recordset)) for each ($res as $k=$val) echo p$k : $val/p; // make your choice for html code Aaron Wolski [EMAIL PROTECTED] ha scritto nel messaggio news:[EMAIL PROTECTED] Hi All, Got this logic problem I don't know how to solve. Is there any way I can make a call to the DB for some records. Display some info from a column or two say at the top of the page and then display the full result set in a while() loop? Right now, I am making two calls to the Db to get the data I need to display at the top of the page and then a second query to retrieve the full result set. I'm confused! Thanks for any help! Aaron -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] Mysql not receiving the data
I agree, the slashes are killing the query. I would suggets doing this: $add = INSERT INTO movies SET movie_name=\$movie_name\, genre=\$genre\, director=\$director\, star1=\$star1\, star2=\$star2\, star3=\$star3\, brief_synopsis=\$brief_synopsis\, imdb_link=\$imdb_link\; Rich Hutchins [EMAIL PROTECTED] ha scritto nel messaggio news:[EMAIL PROTECTED] The apostrophe (') in your data is, most likely, killing the SQL statement when it is sent to the server. Use addslashes() around all of your form data to prevent this and also to help guard against SQL injection attacks. Ex: $add = INSERT INTO movies SET movie_name='.addslashes($movie_name).', genre='.addslashes($genre).', director='.addslashes($director).', star1='.addslashes($star1).', star2='.addslashes($star2).', star3='.addslashes($star3).', brief_synopsis='.addslashes($brief_synopsis).', imdb_link='$imdb_link'; Hope this helped. Rich -Original Message- From: Andrew Rothwell [mailto:[EMAIL PROTECTED] Sent: Sunday, June 13, 2004 1:48 PM To: [EMAIL PROTECTED] Subject: RE: [PHP-DB] Mysql not receiving the data Hi Larry, Thank you very much for the very quick response, I set my php.ini file (located /etc/php.ini ) for the register_globals = On (it was off by default) Now however I get an error Error adding entry: You have an error in your SQL syntax near 's spanish driver is found shot dead, Inspector Jacques Clouseau is the first off' at line 8 My Database is a movie database of my dvd's that I own (for insurance reasons) My addmovie.php is this ? mysql_connect(localhost,username,password); mysql_select_db(movies); $add = INSERT INTO movies SET movie_name='$movie_name', genre='$genre', director='$director', star1='$star1', star2='$star2', star3='$star3', brief_synopsis='$brief_synopsis', imdb_link='$imdb_link'; if (@mysql_query($add)) { echo(pYour entry has been added. br $movie_name/p); } else { echo(pError adding entry: . mysql_error() . /p); } ? And the addmovie.htm page (atleast the form action is this) body bgcolor=#FF form method=post action=addmovie.php name=addmovies table width=300 border=0 cellspacing=2 cellpadding=2 bordercolordark=#FF0033 bordercolorlight=#66 tr td width=41% bgcolor=#99Movie Name /td td width=59% bgcolor=#99FFCC input type=text name=movie_name /td /tr Andrew -Original Message- From: Larry E. Ullman [mailto:[EMAIL PROTECTED] Sent: Sunday, June 13, 2004 11:22 AM To: Andrew Rothwell Cc: [EMAIL PROTECTED] Subject: Re: [PHP-DB] Mysql not receiving the data Online I could see everything, and the pages gave the appearance of working, however when I went into the DB using PHPMYADMIN to check the status of the new data entered, all I found was blank rows ( for the new data since the rebuild, all the old data was there) There were the correct number of new rows for the amount of records that I had entered, which tells me (unless I am nistaken) that the PHP is talking to the DB, and is atleast sending a insert command, but the rest of the data is not getting in. - Without seeing any code whatsoever and since this worked before but no longer works on a new install, I can only assume that your code was written with the assumption that register_globals was turned on and it's not on in your current configuration. If that is the case, see the PHP manual or search the Web for the solution ($_POST, $_GET, etc.). Larry -- 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] Re: Problem in passing the necessary variable.
Ciao..hi, i would suggest to embed the html code in php like this: ?php $_your_variable=$row[imgid]; echo a href=\../images/image.php?img=$_your_variable\ target=\_blank\ onClick=\window.open(this.href, this.target, \'width=200,height=250\'); return false;\img SRC=\../preview.jpg\ ALT=\Click to look at the picture you are charging\ border=\0\/a; ? If it works let me know , bye Francesco Basile __ Alessandro Folghera [EMAIL PROTECTED] ha scritto nel messaggio news:[EMAIL PROTECTED] Hi, I have developed a news system .. I can select to insert an image into the articles. The function to extract the image calling them by the imgid of images table is the following: function getImm() { ? select name=image ? connect(); $sql = select * from images; $result = mysql_query($sql); while($row = mysql_fetch_array($result)) { printf(option value=\%s\%s/option, $row[id_img], $row[imgid]); } ? /select ? I'd like to be able to see the image before to publish the piece of news. I think about a window pop up with java in order to create a preview of the image. The code follows: a href=../images/image.php?img=XX target=_blank onClick=window.open(this.href, this.target, 'width=200,height=250'); return false;img SRC=../preview.jpg ALT=Click to look at the picture you are charging border=0/a The problem is that I can't pass the imgid to the href inspite of the May someone tell me how to pass the id number in order to show me the image or how may I solve the trouble? I hope someone will help me ... Sincerely, Alexander -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] Mysql not receiving the data
Some of the reason to have register_global on is to easly use variables sent by post, get, cookie method of a form. Ex. form name=form1 method=post action=anypage.php?get_var=1 input type=text name=text_post value=Hello World input type=submit name=Submit value=Submit /form in your code at the page anypage.php you will have available the variables: $get_var==1 and $text_post==Hello World if register_global=TRUE in php.ini file - in this case u still have available $_POST;GET ecc... $_GET['get_var']==1 and $_POST['text_post']==Hello World if register_global=FALSE in php.ini file - in this case you don't have the $get_var e $text_post available, so code is safer I would suggest to leave register global=FALSE as to have safer code unless u have to rewrite the whole code. Think about having hacked variables value send by GET, COOKIE method. Bye Hans Lellelid [EMAIL PROTECTED] ha scritto nel messaggio news:[EMAIL PROTECTED] Hi Andrew, Andrew Rothwell wrote: Thank you everybody that responded so quickly - I used the suggestion of Franciccio - and the data is now gow into the db Thank you very much - I really appreciate the help. Another question - with this fix in place - do I still need the register_globals = On ? Or can I now turn it off? It seems like you should have kept your old php.ini file, as this other error you encountered was probably due to your old php.ini file having this setting: magic_quotes_gpc = 1 That INI var instructs PHP to automatically addslashes() to any GET/POST/COOKIE data. I would suggest turning this back on, unless you've thoroughly redesigned your code to not need it. This is unrelated to register_globals, which you will need to leave on unless you redesign your application. Hans -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php