[PHP-DB] Re: permissions system
I've heard a couple of ideas, but so far nothing very different from what I'm planning. Has anyone done anything really different out there? Kevin, I like your idea for quickly protecting several pages. The difference here is that I need to be able to turn on any combination of access for users. By using Levels, it doesn't give me quite the granularity of permissions for this particular project. Come on, let's see some creative solutions! I know there's some pretty dang smart people out there, and this isn't a new problem. I'm also starting to dissect some existing open source projects that have multiple users and permissions to get (hopefully) some other ideas. Thanks for any thoughts! Jason ATTACHMENT part 9 message/rfc822 From: Kevin Stone [EMAIL PROTECTED] To: [EMAIL PROTECTED] Date: Wed, 5 Jun 2002 14:14:11 -0600 Subject: Re: [PHP-DB] permissions system Very simply I protect whole pages on my member's website by include()'ing a script called auth.php into the top of each page. Rather than using a binary string to turn functions 'on' and 'off', I do things a bit more general than that. I have defined levels of access (ie, L1, L2, L3, etc..) stored in the member's table in the database. At the top of each page I wish to protect I write ($min_access = 'L2') to define a minimum level of access. If the user has L2 access or greater they'll fall right through the auth.php and end up on the page. Otherwise one of the conditionals will catch them like a net and dump them into the logout() function which kills the session and displays the login screen with a lovely ACCESS DENIED (or other appropriate text) message. In this way I can protect any number and type of webpage (so long as I rename it .php) without registering the filename. And all of my staff and admin scripts can remain public instead of behind some .htaccess file. As for the complexity of auth.php. It's hardly complex but I'm fairly thurough in my check. The auth.php script is actually about 150 lines of code and does timeout, tracks the member's movement and more... but it could be as simple as a single db query. This is the best continuous pervasive authentication scheme I have devised. It's probably not as good as other systems out there but it does the job in the limited scope of protecting my member's site. :) -Keivn - Original Message - From: Jason Markantes [EMAIL PROTECTED] To: [EMAIL PROTECTED] Sent: Tuesday, June 04, 2002 10:43 PM Subject: [PHP-DB] permissions system Howdy All- I've poked around the net for some snippets, and have done my own in the past, but wanted to get some more ideas on how you do a permissions system. This means, in your application, how do you control and enforce different permissions for different users? Simple example: An image repository. You have users who can download images and/or upload images. And certain users can only search for images within a certain criteria. What I've done in the past is created a permission_flag column for each user. Zero or One determines whether or not the user can do that function, and the various functions are indicated by position (or index). So if you had upload and download functions, you can have: 01 = can download, but can't upload 11 = can download and upload. If I add a new function, I have to add another digit (and potentially increase the column size if things grow faster than planned). To enforce this, as a user attempts each function, I simply check the function index and see if it's one or zero. With me so far? Now, for restricting database access: What I've done is created a user_where column for each user. In this column I add a where clause that's appended to each and every search the user attempts (with the usual input safety checks for common db exploits). For example, if a user can only see Approved images (in my pretend application example here), the user_where value might be category = 'Approved'. For multiple values, it could be category IN ('Approved', 'Pending'). Does this make sense? How are other people doing things? I've given a little bit of thought to it, but not enough. With all the applications out there everyone at some point has to come up with their own system. Ideas? Thanks, Jason = Just Another Fu@#in' Adventure http://markantes.com/jason __ Do You Yahoo!? Yahoo! - Official partner of 2002 FIFA World Cup http://fifaworldcup.yahoo.com -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-DB] mail() function
Hello I want to test the mail() function locally, i'm using esays php, how can I do that? thanks Walid -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-DB] problem with mysql_query
Hi, I've a problem with the following script. Sometimes it does write the data into the database, sometimes it doesn't. When it doesn't $result is completely blank, otherwise it is 1. $sql always returns the propper values even though $result is blank. Can anybody tell me what I'm doing wrong? TIA, Rene Here's the code: --- ?php if (isset($submit)) { // process form $db = mysql_connect($host, $user, $pass); mysql_select_db(test_db,$db); $sql = INSERT INTO news (newsTitle,newsDate,newsSource,newsTeaser,newsText,newsPhoto,newsUrl) VALUES ('$newsTitle','$newsDate','$newsSource','$newsTeaser','$newsText','$news Photo','$newsUrl'); $result = mysql_query($sql); echo $result.brbr; echo $sql.brbr; echo Het nieuwsbericht is succesvol toegevoegd.p\n; echo a href=\news_input.php\Meer nieuws toevoegen/ap\n; echo a href=\../news.php\Bekijk het resultaat/ap; } else{ // display form ? form method=post action=?php echo $PHP_SELF? table cellspacing=0 cellpadding=0 border=0 cellpadding=0 cellspacing=0 tr td valign=toptitel:/td tdinput type=Text name=newsTitle size=55/td /tr tr td valign=topdatum:/td tdinput type=Text name=newsDate size=55/td /tr tr td valign=topbron:/td tdinput type=Text name=newsSource size=55/td /tr tr td valign=topinleiding:nbsp;/td tdtextarea name=newsTeaser rows=5 cols=58/textarea/td /tr tr td valign=toptekst:/td tdtextarea name=newsText rows=5 cols=58/textarea/td /tr tr tdfoto:/td tdinput type=Text name=newsPhoto size=55nbsp;input type=button value=Selecteer foto onClick=javascript:popUp('upload.php')/td /tr tr td colspan=2brToevoegen zonder http:// Voorbeeld: www.indyschoenmakers.com /td /tr tr td valign=toplink:/td tdinput type=Text name=newsUrl size=55/td /tr tr td/td tdinput type=Submit name=submit value=voeg nieuws toe/td /tr /table /form ?php } // end if ? -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] problem with mysql_query
On Monday 10 Jun 2002 12:14 pm, Rene Schoenmakers wrote: Hi, I've a problem with the following script. Sometimes it does write the data into the database, sometimes it doesn't. When it doesn't $result is completely blank, otherwise it is 1. $sql always returns the propper values even though $result is blank. Can anybody tell me what I'm doing wrong? $result = mysql_query($sql); Try changing this to (for example) if(!$result = mysql_query($sql)) { echo MySQL error . mysql_errno() . - . mysql_error(); die(); } and see what you get. There's probably some problem with the database connection. Cheers, Markus -- Markus Lervik Linux-administrator Vaasa City Library - Regional Library, Finland [EMAIL PROTECTED] +358-6-325 3589/+358-40-832 6709 -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP-DB] problem with mysql_query
Hi, I know what's causing the problem. In $newsText sometimes single quotes are entered. There the error occurs. How can I escape these singel quotes? Regards, Rene -Original Message- From: Markus Lervik [mailto:[EMAIL PROTECTED]] Sent: maandag 10 juni 2002 12:45 To: Rene Schoenmakers Cc: [EMAIL PROTECTED] Subject: Re: [PHP-DB] problem with mysql_query On Monday 10 Jun 2002 12:14 pm, Rene Schoenmakers wrote: Hi, I've a problem with the following script. Sometimes it does write the data into the database, sometimes it doesn't. When it doesn't $result is completely blank, otherwise it is 1. $sql always returns the propper values even though $result is blank. Can anybody tell me what I'm doing wrong? $result = mysql_query($sql); Try changing this to (for example) if(!$result = mysql_query($sql)) { echo MySQL error . mysql_errno() . - . mysql_error(); die(); } and see what you get. There's probably some problem with the database connection. Cheers, Markus -- Markus Lervik Linux-administrator Vaasa City Library - Regional Library, Finland [EMAIL PROTECTED] +358-6-325 3589/+358-40-832 6709 -- 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] problem with mysql_query
On Monday 10 Jun 2002 2:15 pm, Rene Schoenmakers wrote: Hi, I know what's causing the problem. In $newsText sometimes single quotes are entered. There the error occurs. How can I escape these singel quotes? with $newsText = addslashes($newsText); http://www.php.net/manual/en/function.addslashes.php Cheers, Markus -- Markus Lervik Linux-administrator Vaasa City Library - Regional Library, Finland [EMAIL PROTECTED] +358-6-325 3589/+358-40-832 6709 -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] problem with mysql_query
On Monday 10 Jun 2002 2:37 pm, Markus Lervik wrote: On Monday 10 Jun 2002 2:15 pm, Rene Schoenmakers wrote: Hi, I know what's causing the problem. In $newsText sometimes single quotes are entered. There the error occurs. How can I escape these singel quotes? with $newsText = addslashes($newsText); http://www.php.net/manual/en/function.addslashes.php Oh yea, forgot to mention, when pulling the field back from the database, use the stripslashes -function in the same manner. Cheers, Markus -- Markus Lervik Linux-administrator Vaasa City Library - Regional Library, Finland [EMAIL PROTECTED] +358-6-325 3589/+358-40-832 6709 -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP-DB] problem with mysql_query
It works! Thanks! -Original Message- From: Markus Lervik [mailto:[EMAIL PROTECTED]] Sent: maandag 10 juni 2002 13:37 To: Rene Schoenmakers; [EMAIL PROTECTED] Subject: Re: [PHP-DB] problem with mysql_query On Monday 10 Jun 2002 2:15 pm, Rene Schoenmakers wrote: Hi, I know what's causing the problem. In $newsText sometimes single quotes are entered. There the error occurs. How can I escape these singel quotes? with $newsText = addslashes($newsText); http://www.php.net/manual/en/function.addslashes.php Cheers, Markus -- Markus Lervik Linux-administrator Vaasa City Library - Regional Library, Finland [EMAIL PROTECTED] +358-6-325 3589/+358-40-832 6709 -- 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] date format display
Hello dear all, in my mysql-db I have a date_tbl with this format: (20020531). how is possible in PHP do display date_tbl's values in a more human-readable format like 05-31-2002 or 31/05/2002 ? thaks in advance, regards fabrizio -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] date format display
Monday, June 10, 2002, 2:00:59 PM, you wrote: in my mysql-db I have a date_tbl with this format: (20020531). how is possible in PHP do display date_tbl's values in a more human-readable format like 05-31-2002 or 31/05/2002 ? Look at date and strtotime... http://www.php.net/date http://www.php.net/strtotime Also take a look at DATE_FORMAT in the MySQL manual... http://www.mysql.com/doc/D/a/Date_and_time_functions.html -- Stuart -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] date format display
This function will fix your date display. $sqldate=20020531; $sqldate= fixdate($sqldate); function fixdate($data){ $aux=; $z=0; for($i=0; $istrlen($data); $i++) { if($i=3) { $aux[0].=$data[$i]; } if($i==4 or $i==5) { $aux[1].=$data[$i]; } if($i==6 or $i==7) { $aux[2].=$data[$i]; } } $mdate= $aux[1]./.$aux[2]./.$aux[0]; if(checkdate($aux[1], $aux[2], $aux[0])) { Return $mdate; } else { Return ERROR; } } fabrizio [EMAIL PROTECTED] wrote: Hello dear all, in my mysql-db I have a date_tbl with this format: (20020531). how is possible in PHP do display date_tbl's values in a more human-readable format like 05-31-2002 or 31/05/2002 ? thaks in advance, regards fabrizio -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php ~ Manuel Ochoa ~ Seven days is too long to wait for a gun! - Do You Yahoo!? Sign-up for Video Highlights of 2002 FIFA World Cup
Re: [PHP-DB] mail() function
On 6/10/02 5:02 AM, Dib, Walid (MED, Stagiaire GEMS) [EMAIL PROTECTED] pressed the keys forming the message: Hello I want to test the mail() function locally, i'm using esays php, how can I do that? Not sure what esays php is, but you don't say what platform you're on. Basically, you need some kind of mail server. If you're on Linux or MacOS X, great: you've got sendmail built in. If you're on Windows, you either need an SMTP product running locally, or you need one you can connect to. -- Ed Marczak [EMAIL PROTECTED] -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP-DB] date format display
This is how I'd do it: $strtime = 20020531; // Example date string // STEP 1: Turn the MMDD string into a UNIX date $unixtime = mktime(substr($strtime, 8, 2),substr($strtime, 10, 2),0,substr($strtime, 4, 2),substr($strtime, 6, 2),substr($strtime, 0, 4)); // STEP 2: Use the date() function to format the date however you'd like echo date(m-d-Y, $unixtime); // Outputs 05-31-2002 echo date(d/m/Y, $unixtime); // Outputs 31/05/2002 Things I highly recommend reading: http://www.php.net/manual/en/function.substr.php http://www.php.net/manual/en/function.mktime.php http://www.php.net/manual/en/function.date.php You'll really want to read the page about the date function. The options for formatting your date output are just about limitless. Gary Pullis Office Management Technologies http://www.omt.cc -Original Message- From: fabrizio [mailto:[EMAIL PROTECTED]] Sent: Monday, June 10, 2002 9:01 AM To: [EMAIL PROTECTED] Subject: [PHP-DB] date format display Hello dear all, in my mysql-db I have a date_tbl with this format: (20020531). how is possible in PHP do display date_tbl's values in a more human-readable format like 05-31-2002 or 31/05/2002 ? thaks in advance, regards fabrizio -- 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] CSV/TXT file imported via PHP into MySQL
I have a form on a PHP page with which I wish to load a tab delimited text file into a UNIX based MySQL database By using PHPMyAdmin I have tested whether I can upload the file, using MyAdmin to help me construct the Query and to date in MyAdmin it works fine. Taking the query and splitting it across two pages (one for receiving the file, and to action the query) seems to stop it from working. I have detailed the pertinent aspects below. My question is really to do with whether there is a file permissions setting or requirement that I have to be aware of, or if there is merely something else I can do. Form code: echo form method=\post\ action=\$PHP_SELF?command=create\ enctype=\multipart/form-data\; echo \ntable width=\300\trtdinput type=\file\ name=\textfile\/td; echo \n\ntd width=\50\input type=\submit\ name=\submit\ value=\Load File\/td/tr/table/form; Query section: switch ($command) { case 'create': echo br$textfile; \\merely existing to run checks $query = LOAD DATA LOCAL INFILE ' . $textfile . ' INTO TABLE pebble_email_addresses FIELDS TERMINATED BY '\t' LINES TERMINATED BY '\r\n' (firstname, surname, email) ; echo br$query; \\merely existing to run checks $sql_query_result = mysql_query($query, $sql_userdb); if ($sql_query_result and mysql_affected_rows() 0) { //Worked OK echo brit worked; } else { echo brit didn't; break; I have yet to get the damn query to import anything at all! HELP Thanks in Advance! Keiran -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-DB] How do I get a ' in my sql statement?
I have noticed that when I try to assign the value of a input field that has a ' in it for example : can't It will goof up my attempt to load the information to the database. Anyone know a way around this? Do I have to send each string through a parsing routine before assigning my string to a variable that will be used in a SQL statement? Thanks, Blaine -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] How do I get a ' in my sql statement?
Hello!! Spit some code out...I put a lot of ' in my inserts... Is it from a form?!?!!? Is it from a Insert, or Select or Update?!? That's why we need some code... Dan On Monday, June 10, 2002, at 12:01 PM, [EMAIL PROTECTED] wrote: I have noticed that when I try to assign the value of a input field that has a ' in it for example : can't It will goof up my attempt to load the information to the database. Anyone know a way around this? Do I have to send each string through a parsing routine before assigning my string to a variable that will be used in a SQL statement? Thanks, Blaine -- 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] How do I get a ' in my sql statement?
Any text field that has the possibility of getting quotes should be handled by $textfield = addslashes($textfield); prior to insert. Then on displaying, use $textfield = stripslashes($textfield); If it is a big text (including paragraphs) I use $textfield = nl2br(stripslashes($textfield)); On Monday, June 10, 2002, at 12:40 PM, Daniel Brunner wrote: Hello!! Spit some code out...I put a lot of ' in my inserts... Is it from a form?!?!!? Is it from a Insert, or Select or Update?!? That's why we need some code... Dan On Monday, June 10, 2002, at 12:01 PM, [EMAIL PROTECTED] wrote: I have noticed that when I try to assign the value of a input field that has a ' in it for example : can't It will goof up my attempt to load the information to the database. Anyone know a way around this? Do I have to send each string through a parsing routine before assigning my string to a variable that will be used in a SQL statement? Thanks, Blaine -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php Terry Romine Web Developer JumpInteractive.com -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] How do I get a ' in my sql statement?
Terry, Thanks for the tip on the nl2br function. That function proved to be very helpful when displaying data in a HTML table. I noticed the \n is ok when sending text to a form with multiline input boxes. Thanks, Blaine Terry Romine [EMAIL PROTECTED] 06/10/02 02:35PM Any text field that has the possibility of getting quotes should be handled by $textfield = addslashes($textfield); prior to insert. Then on displaying, use $textfield = stripslashes($textfield); If it is a big text (including paragraphs) I use $textfield = nl2br(stripslashes($textfield)); On Monday, June 10, 2002, at 12:40 PM, Daniel Brunner wrote: Hello!! Spit some code out...I put a lot of ' in my inserts... Is it from a form?!?!!? Is it from a Insert, or Select or Update?!? That's why we need some code... Dan On Monday, June 10, 2002, at 12:01 PM, [EMAIL PROTECTED] wrote: I have noticed that when I try to assign the value of a input field that has a ' in it for example : can't It will goof up my attempt to load the information to the database. Anyone know a way around this? Do I have to send each string through a parsing routine before assigning my string to a variable that will be used in a SQL statement? Thanks, Blaine -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php Terry Romine Web Developer JumpInteractive.com -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP-DB] CSV/TXT file imported via PHP into MySQL
Keiran, in your second page, you refer to $textfile as the thing that you want to load into the database; this file doesn't exist on the server, so it is inserting nothing I would imagine. You need to use something like $_FILES['tmp_name'] to refer to the actual file, once it has been successfully uploaded to your server (http://www.php.net/manual/en/features.file-upload.php#features.file-upload. post-method) HTH Beau // -Original Message- // From: Keiran Wynyard [mailto:[EMAIL PROTECTED]] // Sent: Tuesday, 11 June 2002 12:38 AM // To: [EMAIL PROTECTED] // Subject: [PHP-DB] CSV/TXT file imported via PHP into MySQL // // // I have a form on a PHP page with which I wish to load a tab // delimited text file into a // UNIX based MySQL database // // By using PHPMyAdmin I have tested whether I can upload the // file, using MyAdmin to help me // construct the Query and to date in MyAdmin it works fine. // Taking the query and splitting // it across two pages (one for receiving the file, and to // action the query) seems to stop it // from working. // // I have detailed the pertinent aspects below. // My question is really to do with whether there is a file // permissions setting or // requirement that I have to be aware of, or if there is // merely something else I can do. // // Form code: // echo form method=\post\ action=\$PHP_SELF?command=create\ // enctype=\multipart/form-data\; // echo \ntable width=\300\trtdinput type=\file\ // name=\textfile\/td; // echo \n\ntd width=\50\input type=\submit\ // name=\submit\ value=\Load // File\/td/tr/table/form; // // Query section: // switch ($command) // { // case 'create': // echo br$textfile; \\merely existing to run checks // $query = LOAD DATA LOCAL INFILE ' . $textfile // . ' INTO TABLE // pebble_email_addresses FIELDS TERMINATED BY '\t' LINES // TERMINATED BY '\r\n' (firstname, // surname, email) ; // echo br$query; \\merely existing to run checks // $sql_query_result = @mysql_query($query, $sql_userdb); // if ($sql_query_result and @mysql_affected_rows() 0) // { // //Worked OK // echo brit worked; // } // else //{ //echo brit didn't; // break; // // I have yet to get the damn query to import anything at all! HELP // // Thanks in Advance! // // Keiran // // // // -- // 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] Having trouble understanding how to manage arrays
Hi all. I am very new to this, and have been reading my way through php, but have come accross a stumbling block that I just don't seem able to get past, although I'm sure it's something simple. I have a very basic mysql database set up, that contains a table with 4 fields- type, manname, manlink, and recordno What I need to do is pull all records from the database, and provide a list on a page with links to the url's stored in manlink with the lable manname. So far, I've come up with the script at the end of this message. This script works beautifully for me- for the first record. Could anyone point out why it won't go on to any other records? Thanks, Newbie Bill ?php /* Connecting, selecting database */ $link = mysql_connect(192.168.0.112, root, ) or die(Could not connect); print Connected successfully; mysql_select_db(dgdrivers) or die(Could not select database); /* Performing SQL query */ $getlength = select * from man_links; $length = mysql_query($getlength); $idl = count($length); for ($id = 1 ;; $id++ ) { if ($id $idl) { break; } $query = SELECT type, manname, manlink FROM man_links WHERE recordno=$id; $result = mysql_query($query) or die(Query failed); extract(mysql_fetch_array($result)); /* Printing results in HTML */ print table\n; print pa href=$manlink$manname/a; print /table\n; } /* Free resultset */ mysql_free_result($result); /* Closing connection */ mysql_close($link); ?
[PHP-DB] problem with a small script
hi i can't understand whats missing here.thou i knew this ques is asked many times i couldn't find an ans for it. - form method=get action=stuinfo.php firstname: input type=text name=fname size=15 this is te html scrript and the php code is ? $fname=$_GET['fname']; echo $fname; ? --- but on executing this i get a blank page what might be the error suman -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-DB] Re: Having trouble understanding how to manage arrays
Hi Bill, Looks like you're making it hard for yourself, by querying the database for each record found. Here is some code which should make your life easier. Of course, I have developed functions which would turn the following code into 10 or so lines, but this should work for your situation. Adam ?php /* Connecting, selecting database */ $link = mysql_connect(192.168.0.112, root, ) or die(Could not connect); print Connected successfully; mysql_select_db(dgdrivers) or die(Could not select database); /* Performing SQL query */ $query = SELECT type, manname, manlink FROM man_links; $result = mysql_query($query) or die(Query failed); ? table border=0 cellspacing=0 cellpadding=5 ?php while ($row = mysql_fetch_array($result)){ ? tr td?= $row[type] ?/td tda href=?= $row[manlink] ??= $row[manname] ?/a/td /tr ?php } ? /table ?php /* Free resultset */ mysql_free_result($result); /* Closing connection */ mysql_close($link); ?
Re: [PHP-DB] Having trouble understanding how to manage arrays
On Tuesday 11 June 2002 13:20, Bill Fleury wrote: Hi all. I am very new to this, and have been reading my way through php, but have come accross a stumbling block that I just don't seem able to get past, although I'm sure it's something simple. I have a very basic mysql database set up, that contains a table with 4 fields- type, manname, manlink, and recordno What I need to do is pull all records from the database, and provide a list on a page with links to the url's stored in manlink with the lable manname. So far, I've come up with the script at the end of this message. This script works beautifully for me- for the first record. The fact that it works 'beautifully' is just luck! Could anyone point out why it won't go on to any other records? Your logic is completely messed up :) ?php /* Connecting, selecting database */ $link = mysql_connect(192.168.0.112, root, ) or die(Could not connect); print Connected successfully; mysql_select_db(dgdrivers) or die(Could not select database); The above is OK. But for better error reporting you should replace the die() statements with something like: die('Could not connect. The error was: ' . mysql_error()) This will display your message along with the actual error returned by mysql. /* Performing SQL query */ $getlength = select * from man_links; $length = mysql_query($getlength); $idl = count($length); for ($id = 1 ;; $id++ ) { if ($id $idl) { break; } $query = SELECT type, manname, manlink FROM man_links WHERE recordno=$id; $result = mysql_query($query) or die(Query failed); extract(mysql_fetch_array($result)); /* Printing results in HTML */ print table\n; print pa href=$manlink$manname/a; print /table\n; } /* Free resultset */ mysql_free_result($result); /* Closing connection */ mysql_close($link); Here's the standard way to retrieve a set of results from a query: $query = SELECT manname, manlink FROM man_links; $resultID = mysql_query($query) OR die(Error in query $query : . mysql_error()); while ($row = mysql_fetch_array($resultID)) { print Man Name : . $row['manname']; print Man Link : . $row['manlink'] . 'br'; } mysql_free_result($result); # optional, as php cleans up automatically mysql_close($link); # at the end of the script -- Jason Wong - Gremlins Associates - www.gremlins.com.hk Open Source Software Systems Integrators * Web Design Hosting * Internet Intranet Applications Development * /* QOTD: I looked out my window, and saw Kyle Pettys' car upside down, then I thought 'One of us is in real trouble'. -- Davey Allison, on a 150 m.p.h. crash */ -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] problem with a small script
Suman, Firstly, it's a bit longer than necessary. Make your form a 'POST' rather than 'GET' and you'll hide your query and ?php echo $fname; ? will then be the equivalent. I presume that you have been able to display other PHP stuff? Check your php.ini file and make sure that the part that allows you to use the short ? rather than having to always use ?php is enabled. George - Original Message - From: suman [EMAIL PROTECTED] To: [EMAIL PROTECTED] Sent: Monday, June 10, 2002 10:43 PM Subject: [PHP-DB] problem with a small script hi i can't understand whats missing here.thou i knew this ques is asked many times i couldn't find an ans for it. - form method=get action=stuinfo.php firstname: input type=text name=fname size=15 this is te html scrript and the php code is ? $fname=$_GET['fname']; echo $fname; ? --- but on executing this i get a blank page what might be the error suman -- 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