JackCode Posted January 7, 2014 Share Posted January 7, 2014 Whats wrong with this? Basically I'm trying to create a universal link for people logged into go to their profile named profile.php. I want the code to grab their id and then take them to their specific profile page like <a href="profile.php?id=idhere">My profiel</a>. So here is the code I have but it doesnt work: <?php mysql_connect('localhost', '732936', 'jackfinley3000') or die ($error); mysql_select_db('732936') or die ('$error'); $query = "SELECT * FROM `732963`'" or die('mysql_error()'); $info = mysql_fetch_array($query); ?> <div id="secmenu"> <ul id="nav"> <li><a href="profile.php?id=<?php echo $info; ?>">My profile</a></li> <li><a href="#">Packs</a></li> <li><a href="#">Freinds</a></li> <li><a href="#">Cirlce</a></li> <li><a href="#">Private Messages</a></li> </ul> </div> </div> Quote Link to comment https://forums.phpfreaks.com/topic/285174-universal-link/ Share on other sites More sharing options...
ginerjm Posted January 7, 2014 Share Posted January 7, 2014 Where do you execute your query? Not that the query makes sense. Quote Link to comment https://forums.phpfreaks.com/topic/285174-universal-link/#findComment-1464279 Share on other sites More sharing options...
JackCode Posted January 7, 2014 Author Share Posted January 7, 2014 Sorry I don't know PHP very well, just started it and I'm 13. I call the $info variable inside the first link. Quote Link to comment https://forums.phpfreaks.com/topic/285174-universal-link/#findComment-1464284 Share on other sites More sharing options...
ginerjm Posted January 7, 2014 Share Posted January 7, 2014 It is obvious you have ABSOLUTELY NO KNOWLEDGE of anything you are doing here. Try a book. Quote Link to comment https://forums.phpfreaks.com/topic/285174-universal-link/#findComment-1464286 Share on other sites More sharing options...
JackCode Posted January 7, 2014 Author Share Posted January 7, 2014 (edited) It is obvious you have ABSOLUTELY NO KNOWLEDGE of anything you are doing here. Try a book. First: Why is it obvious? I'm learning, don't you have to start from somewhere? Second: I have been reading a book, 'PHP and MYSQL for dynamic websites' by Larry Ulman. Thirdly: I was only asking for a little bit of help, now please could you spare a minute to give some instead of telling me how useless I am? Edited January 7, 2014 by JackCode Quote Link to comment https://forums.phpfreaks.com/topic/285174-universal-link/#findComment-1464288 Share on other sites More sharing options...
ginerjm Posted January 7, 2014 Share Posted January 7, 2014 Why is it so obvious? 1 - you select a db with a numeric name - very unusual IMHO. 2 - then you query a table that is named the same as the db - also very unusual. 3 - you write a query that has no criteria in it to get the specific record you need 4 - then you attempt to access the results of a query but you're feeding it a query string 5 - then you attempt to echo the resource supposedly returned from your (non-executed) query, but again you are providing the query string So - I'd say it's pretty obvious. Read your book; learn how to use the mysqli functions in php; then attempt this code again. With so much wrong with your code it is meaningless for us to offer you assistance. And - learn how to spell too! You'll make a better impression. Quote Link to comment https://forums.phpfreaks.com/topic/285174-universal-link/#findComment-1464294 Share on other sites More sharing options...
JackCode Posted January 7, 2014 Author Share Posted January 7, 2014 (edited) Why is it so obvious? 1 - you select a db with a numeric name - very unusual IMHO. 2 - then you query a table that is named the same as the db - also very unusual. 3 - you write a query that has no criteria in it to get the specific record you need 4 - then you attempt to access the results of a query but you're feeding it a query string 5 - then you attempt to echo the resource supposedly returned from your (non-executed) query, but again you are providing the query string So - I'd say it's pretty obvious. Read your book; learn how to use the mysqli functions in php; then attempt this code again. With so much wrong with your code it is meaningless for us to offer you assistance. And - learn how to spell too! You'll make a better impression. Thanks, that was a little more helpful. Here's my answer to your questions: 1. I was given these database info by my PHPmyadmin host. 2. Same as above. 3. OK, thanks but I thought by default it chooses the top row which for me is default, so I don't need to have a criteria. 4. OK, thank you, but I got this from: http://php.about.com/od/phpwithmysql/ss/mysql_php_2.htm 5. OK, then could you tell me an alternative? Thanks, I am in the process of learning. Spell? I can spell perfectly fine thanks, at least I know how to use grammar properly as-well. Anyway, I'm not trying to gain a better impression, I'm trying to learn how to programme in PHP. Edited January 7, 2014 by JackCode Quote Link to comment https://forums.phpfreaks.com/topic/285174-universal-link/#findComment-1464296 Share on other sites More sharing options...
ginerjm Posted January 7, 2014 Share Posted January 7, 2014 Sorry - but you're digging yourself in deeper. 1 - your grammer is not good. Check your uses of tense in your last post... tsk, tsk. 2 - examples of your perfect spelling: <li><a href="#">Freinds</a></li> <li><a href="#">Cirlce</a></li> 3 - if your isp is providing you such great help, ask them for more. Sorry - I've done enough here. Quote Link to comment https://forums.phpfreaks.com/topic/285174-universal-link/#findComment-1464298 Share on other sites More sharing options...
JackCode Posted January 7, 2014 Author Share Posted January 7, 2014 *Freinds *Circle Happy now? Why so picky about such little things, its not a formal forum is it? I just asked for some simple help... Quote Link to comment https://forums.phpfreaks.com/topic/285174-universal-link/#findComment-1464300 Share on other sites More sharing options...
ginerjm Posted January 7, 2014 Share Posted January 7, 2014 That's just it though - you need much more than "simple help". As I said before - read a book - learn the old fashioned way. When you get something developed that resembles good code and need some help, then we'll be more than willing to help. BTW - nice try on your spelling corrections but you still have it wrong. tsk, tsk. At 13, perhaps you should be concentrating more on school - reading, writing, arithmetic, and such instead of trying to learn programming. Those things will get you much farther in this world than learning how to program. Spelling too! Quote Link to comment https://forums.phpfreaks.com/topic/285174-universal-link/#findComment-1464303 Share on other sites More sharing options...
GetFreaky Posted January 7, 2014 Share Posted January 7, 2014 (edited) *Freinds *Circle Happy now? Why so picky about such little things, its not a formal forum is it? I just asked for some simple help... Hi JackCode, some little help here I will try to provide. 1. When creating a database table make sure the name is meaningful and analogous with the tables it contains. The table structure should be human readable, I think you'll find it that the entire purpose of high-level languages and relational database management systems was to make things easier for the programmer, and less tedious. If your database contains records for a Blog, then make sure you use the right prefixes, table names, and fields. 2. You seem have to grasped the right idea here but you need a little push further with the way you are handling your access to database records. Firstly I would create a config.php file and place my database connection/site wide configuration inside it, then include the file in a bootstrap file which loads the views of my site, this way the connection is always available through out my site, albeit though there are better ways to do this. Or simple include the config.php on the pages where you require database connectivity. 3. Your $query is fine but it can be fixed to grab only the records which will lighten the burden on server/compiler/interpreters which lies behind the abstraction. for example: SELECT `id`,`name`,`email` FROM `table_name` 4. I suggest you look into what type of value the mysql_query function returns, because it seems as your just calling an Array object without a specific index. in your case, if you have a field named 'id' in your table then you would invoke the index on the array to $info['id'] Edited January 7, 2014 by GetFreaky Quote Link to comment https://forums.phpfreaks.com/topic/285174-universal-link/#findComment-1464304 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.