Re: [PHP-DB] marking DB entries...
Thanks Frank! Just to be certain, cant I If two users enter the same address you will have two different records in the address table - identical except for the authority field. store the information and just update the authority field? i.e If the are two fields that look the same (made by user1 and user2) I want them to become one and just update the authority field so that it would look like authority=user1,user2. Is that possible or is that to much trouble? I dont have ANY experience about databases so I dont really know what is most common to do. But for sure, the sollution you gave me seems very easy, almost to easy =). I kept thinking about storing in the same field, hehe! thanks again! /Ljungan Frank Flynn [EMAIL PROTECTED] skrev i meddelandet [EMAIL PROTECTED]">news:[EMAIL PROTECTED]... OK so you have 2 tables one for users login and one for the addresses a user may store and retrieve. Your users will login, you will validate their name and password combination and have either a userID or the name is fine too (an integer ID is smaller to store and possibly more efficient). Now your PHP script will know the users name and userID (you will be looking this up each time they view a page or somehow storing it -- I assume you know how to do this since this isn't what your were asking about) So now you can search on your address table however you like but always be sure to include: and authority = $userID In your where clause. Obviously you include other conditions or your users will get every single entry they ever made. Just be sure that the insert and update functions will always set the authority field to the proper userID. If two users enter the same address you will have two different records in the address table - identical except for the authority field. Easy as pie... Good Luck, Frank On 3/22/02 8:25 PM, [EMAIL PROTECTED] [EMAIL PROTECTED] wrote: From: Ljungan [EMAIL PROTECTED] Date: Fri, 22 Mar 2002 18:07:06 +0100 To: [EMAIL PROTECTED] Subject: marking DB entries... Im making an adressbook using PHP and mySQL. I want each user to have access only to his/hers adressinputs. Now Im wondering how I gonna solve this, ofcourse its very easy just to create a table for each user but then the hole idea of database loose its purpose =). How can I mark each input so that only the specific user who entered the information can access it? If two users enters the exact same information I want them both to have access to it... I was thinking about a table looking like this: name CHAR(30), adress CHAR(30), email CHAR(30), phonenumber INT(20), authority ENUM()//here is my thought-- I was thinking I could save the users name in authority and thereby marking that this entry was made bye the specific person. Is it possible to use this? Please give me a few pointers or better, give me a website where I can read about it... thanks! /Ljungan -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] marking DB entries...
thanks for your answer! I already made the login page =). /Ljungan Adam Royle [EMAIL PROTECTED] skrev i meddelandet [EMAIL PROTECTED]">news:[EMAIL PROTECTED]... I have done an address book in php, although I kept the username/password in with the rest of their details. If you wanted to keep it all in two tables, then go ahead. You really should have an ID field in every table, whether you use it or not, and most of the times, you'll find you will use it. So if you're using two tables, you'll have a column in each of them 'linking' up the columns (ie, the same number). If you don't know how to do this, there are tons of tutorials on the net which gloss over this... (have a look at the mysql documentation/examples). Then on your actual page, what you should do is have a login page, which checks a username/password from a form against the database. At the same time, retrieve the ID number where it matches the user/name password and put the username and id number in separate session variables. Once you have the ID number of the person logged in, you can allow/disallow what they can edit depending on the ID. If you need further help, contact me directly. Adam. Im making an address book using PHP and mySQL. I want each user to have access only to his/hers adressinputs. Now Im wondering how I gonna solve this, ofcourse its very easy just to create a table for each user but then the hole idea of database loose its purpose =). How can I mark each input so that only the specific user who entered the information can access it? If two users enters the exact same information I want them both to have access to it... I was thinking about a table looking like this: name CHAR(30), adress CHAR(30), email CHAR(30), phonenumber INT(20), authority ENUM()//here is my thought-- I was thinking I could save the users name in authority and thereby marking that this entry was made bye the specific person. Is it possible to use this? Please give me a few pointers or better, give me a website where I can read about it... thanks! /Ljungan -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP-DB] Remote Connection to Mysql
Also make sure you don't have anything blocking port 3306 like a FW or some IP Filter between the computers. Sincerely berber Visit http://www.weberdev.com Today!!! To see where PHP might take you tomorrow. -Original Message- From: Jason Wong [mailto:[EMAIL PROTECTED]] Sent: Saturday, March 23, 2002 10:26 AM To: [EMAIL PROTECTED] Subject: Re: [PHP-DB] Remote Connection to Mysql On Friday 22 March 2002 07:42, Marcus Rigby wrote: Hi all, I know there are plenty of remote connection posts herebut none have helped me solve my problem. I have 2 win98 machines on a novell network, both have static IP addresses, and both machines can ping each other. One machine is running a webserver and the other the Mysql server, and I cannot get scripts on the webserver to connect to MySql. Using : $dbcnx = mysql_connect(xxx.xxx.xxx.xxx, user, pword); if (!$dbcnx) { echo( PUnable to connect to the . database server at this time.Try again later/P ); exit(); } RESULTS in the error message Unable to connect to the database server. When I do a netstat -a on the PC with MySQL I dont see any listening ports, should there be. Well there should be. You can try telnet xxx.xxx.xxx.xxx 3306 If that fails then you most likely don't have mysql running on xxx.xxx.xxx.xxx -- Jason Wong - Gremlins Associates - www.gremlins.com.hk /* Hearts will never be practical until they can be made unbreakable. -- The Wizard of Oz */ -- 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: calculations based on checkbox value
Here is some code, which I modestly suggest is superior for the following reasons: 1. Includes simply scaffolding (ie a sample form). 2. Code is separated into functions, rather than one monolithic block. 3. Somewhat improved word-counting. == html head style body { font-family: Verdana,Arial,sans-serif; } /style /head body h2Price-An-Ad/h2 form New ad text:br / textarea name='ad' style='width:400px; height:300px;'/textareabr / input type='checkbox' name='deduct' value='true'Make deductionbr / Run length select name='weeks' option value='1' selectedOne week option value='2'Two weeks option value='4'One month /selectbr / input type='submit' value='Calculate' /form ?php if (isset($ad)) { $ad = stripslashes($ad); $words = count_words($ad); $price = calc_price($words, $deduct, $weeks); echo Priced text: .div style='width:400px;'pre$ad/pre/div .$words words, .(isset($deduct) ? with : no). deduction, for $weeks weeks comes to .sprintf(\$%01.2f,$price); } function count_words($text) { $count = 0; $tok = strtok($text, ); while (is_string($tok)) { if (strlen($tok) 0) $count++; $tok = strtok( ); } return $count; } function calc_price($words, $deduct, $weeks) { // base price $price = 5.00; // additional cost for more than ten words if ($words 10) $price += ($word - 10) * 0.20; // favored-customer deduction if ($deduct) $price -= 1.50; // by number of weeks to appear $price *= $weeks; return $price; } ? /body/html -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-DB] Re: php-db Digest 23 Mar 2002 22:20:08 -0000 Issue 1113
See below... On 3/23/02 2:20 PM, [EMAIL PROTECTED] [EMAIL PROTECTED] wrote: From: Ljungan [EMAIL PROTECTED] Date: Sat, 23 Mar 2002 11:17:15 +0100 To: [EMAIL PROTECTED] Subject: Re: [PHP-DB] marking DB entries... Thanks Frank! Just to be certain, cant I If two users enter the same address you will have two different records in the address table - identical except for the authority field. store the information and just update the authority field? i.e If the are two fields that look the same (made by user1 and user2) I want them to become one and just update the authority field so that it would look like authority=user1,user2. Is that possible or is that to much trouble? I dont have ANY experience about databases so I dont really know what is most common to do. But for sure, the sollution you gave me seems very easy, almost to easy =). I kept thinking about storing in the same field, hehe! thanks again! /Ljungan The short answer is you can't. The longer answer is you can but don't, you're asking for trouble... It violates one of the rules of data normalization. I forget which one - if you have no experience with DB's and want to learn something do a web search on data normalization maybe include rules (** Yes DBA types are a pretty anal bunch and they did number their rules **). But basically you would have one of these problems: -when user 2 updates that record the authority field gets set to him and user 1 can't see the record anymore. -if you put each user in the authority field (as you suggest) it won't scale; you have authority=user1,user2 which might work although now the SQL cannot use '=' (which is fast and can use indexes) and it has to use: authority like %user2% // %'s are wild cards and cannot use indexes -what happens if you have 50 or 200 users who all reference one address? Can the field authority hole that much text? How many would be the limit? You'd have to write some complex code to handle when the number of users goes over that limit. You have a 'one to many' scheme here; many addresses are owned by one user; that's simple and works well. If you did want to do groups where several people have authority to view the several of the same records you'd call that a 'many to many' relationship and it's traditionally solved with three tables. AdressUsersAuthority ---- -- addIDuserID userID name name addID address password Where if Address #1 (addID = 1) could be edited by Users 3, 5 and 7 there would be three records in the Authority table 3,1 5,1 and 7,1. Now you'd join all three, get the userID from your users login, joined to the Authority table will get the addID's they can edit and now joined to the Address table will only get the records they can edit. If you want to do groups that's how to do it. Good Luck, Frank -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-DB] Again Select then update
Hi all! $query = SELECT name FROM users WHERE uid={$session[uid]}; $ret = mysql_query($query); while(list($name) = mysql_fetch_row($ret)) print (your name is $name); $update = $name; $query_update[name] = UPDATE my_items SET name = $update; $result = mysql_query($query_update[name])or die(Error: .mysql_error()); When the script is run I receive this error and I am not understanding why, can some point out why? your name is Test Error: Unknown column 'Test' in 'field list' TIA Jen -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-DB] Please help me! :(
I have a site where things in the database have ids. When something new is added, it gets an id one higher than the highest existing id. I use code something like this: $gethighestid = mysql_fetch_array(mysql_query(select id from table order by id desc limit 1)); $tobeid = $gethighestid[id]+1; mysql_query(insert into table(id,othercolumn,othercolumn2) values('$tobeid','something','something')); The thing is, I just got two rows with duplicate ids. Aparantley, two people must of added two things at just the right times to make the same id. Is there any way that will reduce, or eliminate, the time gap between getting id and inserting? -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP-DB] Please help me! :(
Can I ask why you're not using autoincrement for your id field? If you used this you would never have the problem your having. Everytime a record is added it will increment the id field by one, so you don't have to use all the code your using. Howard -Original Message- From: Leif K-Brooks [mailto:[EMAIL PROTECTED]] Sent: Sunday, 24 March 2002 3:42 PM To: [EMAIL PROTECTED] Subject: [PHP-DB] Please help me! :( I have a site where things in the database have ids. When something new is added, it gets an id one higher than the highest existing id. I use code something like this: $gethighestid = mysql_fetch_array(mysql_query(select id from table order by id desc limit 1)); $tobeid = $gethighestid[id]+1; mysql_query(insert into table(id,othercolumn,othercolumn2) values('$tobeid','something','something')); The thing is, I just got two rows with duplicate ids. Aparantley, two people must of added two things at just the right times to make the same id. Is there any way that will reduce, or eliminate, the time gap between getting id and inserting? -- 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