ball420 Posted January 29, 2007 Share Posted January 29, 2007 here is my script<h1 align="center">SEARCH RESULTS </h1><p align="center"> </p><p align="center"> </p><?php$db = msql_connect("localhost");mysql_select_db("krankdcontacts, $db);$query = "SELECT * FROM krankdcontacts WHERE name LIKE '%".$name."%'"; $result = mysql_query($query); while ($record = mysql_fetch_assoc($result)) { echo $fieldname.": <b>".$fieldvalue."</b><br>"; } echo "<br>"; ?>the error i'm getting is on this line (13)$query = "SELECT * FROM krankdcontacts WHERE name LIKE '%".$name."%'";my table is called krankdcontacts and by saying select * from krankd contacts it should search for all fields with anything in it right??i'm doing a tutorial and i copied exactly what the person explaining the tutorial is doing but it doesnt work on my machine?? any clue why i don't wnat to just give up but it is getting frustrating please help anyone Quote Link to comment Share on other sites More sharing options...
smartguyin Posted January 29, 2007 Share Posted January 29, 2007 i think error is in this [b]mysql_select_db("krankdcontacts, $db);[/b]while selecting db you forgot [b]"[/b]correct it to [b]mysql_select_db("krankdcontacts", $db);[/b] Quote Link to comment Share on other sites More sharing options...
linuxdream Posted January 29, 2007 Share Posted January 29, 2007 Also, where are you setting the $name variable? Shouldn't matter as all results should return if it has no value...just wondering though. Quote Link to comment Share on other sites More sharing options...
ballhogjoni Posted January 29, 2007 Share Posted January 29, 2007 Also you forgot the y in mysql$db = [color=red]msql[/color]_connect("localhost"); Quote Link to comment Share on other sites More sharing options...
dgiberson Posted January 29, 2007 Share Posted January 29, 2007 [quote]my table is called krankdcontacts and by saying select * from krankd contacts it should search for all fields with anything in it right??[/quote]This statement will return all rows where the name field is like the $name variable provided. It will not search all of the columns in the table for this variable. Quote Link to comment Share on other sites More sharing options...
ball420 Posted January 29, 2007 Author Share Posted January 29, 2007 thank you everyone for your input i need to pay a little mor attention to spelling and what not at least now i'm getting it to work semi-??? now here is the error's--Warning: mysql_connect() [function.mysql-connect]: Access denied for user 'ODBC'@'localhost' (using password: NO) in E:\wamp\www\resultsbyname.php on line 11Warning: mysql_select_db() [function.mysql-select-db]: Access denied for user 'ODBC'@'localhost' (using password: NO) in E:\wamp\www\resultsbyname.php on line 12Warning: mysql_select_db() [function.mysql-select-db]: A link to the server could not be established in E:\wamp\www\resultsbyname.php on line 12Warning: mysql_query() [function.mysql-query]: Access denied for user 'ODBC'@'localhost' (using password: NO) in E:\wamp\www\resultsbyname.php on line 15Warning: mysql_query() [function.mysql-query]: A link to the server could not be established in E:\wamp\www\resultsbyname.php on line 15Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in E:\wamp\www\resultsbyname.php on line 16-- is this because of the way that my table database is set up? i'm not asking anyone to do it for me it's just that i'm trying to learn and dont' really have a teacher to ask questions or help me understand. so again thanks for the feedback. Quote Link to comment Share on other sites More sharing options...
chronister Posted January 29, 2007 Share Posted January 29, 2007 Your not calling a mysql_connect() properly with a username and password.[code]$db = mysql_connect("localhost"); // you need a username and password here.[/code][quote]Warning: mysql_connect() [function.mysql-connect]: Access denied for user 'ODBC'@'localhost' (using password: NO) in E:\wamp\www\resultsbyname.php on line 11Warning: mysql_select_db() [function.mysql-select-db]: Access denied for user 'ODBC'@'localhost' (using password: NO) in E:\wamp\www\resultsbyname.php on line 12[/quote]Once you fix the first error, the rest should fix themselves as they are simply failing because there is no connection and no results.I like to use something like this[code]function connectdb(){mysql_connect('HOST', 'USERNAME', 'PASSWORD');mysql_select_db('DATABASE') or die('Unable to select database!');};[/code]then anytime you need to make a db connection, simply call the function[code]connectdb();[/code] Quote Link to comment Share on other sites More sharing options...
ball420 Posted January 29, 2007 Author Share Posted January 29, 2007 i'm not using any username or password?? what is odbc anyway? learning php is killing me!! Quote Link to comment Share on other sites More sharing options...
Jessica Posted January 29, 2007 Share Posted January 29, 2007 then your username is 'root', and your password is '' Quote Link to comment Share on other sites More sharing options...
ball420 Posted January 29, 2007 Author Share Posted January 29, 2007 can anyone recommend somthing that will work, i'm using myphpadmin i have no username set no password it still gives me the same damn error i changed it set username password still nothing restarted it the whole nine. i'm trying to learn simple scripts and nothing can anyone suggest anything besides just throwing in the towel. mabey somthing that could help me i don't know. i'm getting really frustrated.HELP PLEASE!!!! Quote Link to comment Share on other sites More sharing options...
Jessica Posted January 29, 2007 Share Posted January 29, 2007 In phpmyadmin, there is a config file which has your username and password. If you never set those, your username is root, no password. Is this on a hosted server, or your own? If it's hosted, they set the config file with your username and password and can supply you with them. Quote Link to comment Share on other sites More sharing options...
ball420 Posted January 29, 2007 Author Share Posted January 29, 2007 no this is my own own computer "localhost" Quote Link to comment Share on other sites More sharing options...
Jessica Posted January 29, 2007 Share Posted January 29, 2007 So use the function chronister posted and use 'root' as username and '' as password. Quote Link to comment Share on other sites More sharing options...
ball420 Posted January 29, 2007 Author Share Posted January 29, 2007 This is what i'm getting now. what is odbc??Warning: mysql_query() [function.mysql-query]: Access denied for user 'ODBC'@'localhost' (using password: NO) in E:\wamp\www\resultsbyname.php on line 18Warning: mysql_query() [function.mysql-query]: A link to the server could not be established in E:\wamp\www\resultsbyname.php on line 18Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in E:\wamp\www\resultsbyname.php on line 19 Quote Link to comment Share on other sites More sharing options...
Jessica Posted January 29, 2007 Share Posted January 29, 2007 Post the new code, I don't think you changed it correctly to reflect what was posted. Quote Link to comment Share on other sites More sharing options...
ball420 Posted January 29, 2007 Author Share Posted January 29, 2007 <?phpfunction connectdb(){mysql_connect('localhost', 'root', '');mysql_select_db('krankdcontacts') or die('Unable to select database!');$query = "SELECT * FROM krankdcontacts WHERE name LIKE '%".$name."%'"; $result = mysql_query($query); while ($record = mysql_fetch_assoc($result)) { echo $fieldname.": ".$fieldvalue."; } echo "; ?> Quote Link to comment Share on other sites More sharing options...
Jessica Posted January 29, 2007 Share Posted January 29, 2007 You never close the function, or call it. Quote Link to comment Share on other sites More sharing options...
chronister Posted January 29, 2007 Share Posted January 29, 2007 like jesirose said... close the function, then call it when you need to connect.[code]<?phpfunction connectdb(){mysql_connect('localhost', 'root', '');mysql_select_db('krankdcontacts') or die('Unable to select database!');};//end functionconnectdb();$query = "SELECT * FROM krankdcontacts WHERE name LIKE '%".$name."%'"; $result = mysql_query($query); while ($record = mysql_fetch_assoc($result)) { echo $fieldname.": ".$fieldvalue."; } echo "; ?>[/code]You were not calling the function, so it was trying to log in anonymously. The above code should work.Don't give up or get overly frustrated.. we all had these kinds of things when we started learning PHP. I have only been seriously trying to learn php / mysql for less than a year and I still have issues like this and get pretty worked up about something not working like I want it to Quote Link to comment Share on other sites More sharing options...
ball420 Posted January 29, 2007 Author Share Posted January 29, 2007 thanks for the boost! i'm so frustrated!!! i'm using a learning program from vtc.com and it sucks even the code the give me as sample stuff doesnt' even work. how am i supposed to learn from people that can't even get it right ya know. but i paid for it so i have to try to use it now ya know. would you have any suggestions on a good place to learn? or mabey a good book, i seem to learn better from watching someone else do it though mabay another online course??thanks again Quote Link to comment Share on other sites More sharing options...
chronister Posted January 30, 2007 Share Posted January 30, 2007 Thorpe has posted this a couple of times and it looks pretty good. [url=http://hudzilla.org/phpwiki/index.php?title=Main_Page]http://hudzilla.org/phpwiki/index.php?title=Main_Page[/url]Otherwise invest in a good book. I read How To Do Everything with PHP & MySql by Vikram Vaswami and really liked it because it does not fill you up with a bunch of commentary. It is pretty straightforward, and gives good working examples.Good luck Quote Link to comment 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.