Jump to content

what is wrong???


ball420

Recommended Posts

here is my script

<h1 align="center">SEARCH RESULTS
</h1>
<p align="center">&nbsp;</p>
<p align="center">&nbsp;</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
Link to comment
Share on other sites

[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.
Link to comment
Share on other sites

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 11

Warning: 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

Warning: mysql_select_db() [function.mysql-select-db]: A link to the server could not be established in E:\wamp\www\resultsbyname.php on line 12

Warning: mysql_query() [function.mysql-query]: Access denied for user 'ODBC'@'localhost' (using password: NO) in E:\wamp\www\resultsbyname.php on line 15

Warning: mysql_query() [function.mysql-query]: A link to the server could not be established in E:\wamp\www\resultsbyname.php on line 15

Warning: 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.

Link to comment
Share on other sites

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 11

Warning: 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]
Link to comment
Share on other sites

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!!!!
Link to comment
Share on other sites

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.
Link to comment
Share on other sites

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 18

Warning: mysql_query() [function.mysql-query]: A link to the server could not be established in E:\wamp\www\resultsbyname.php on line 18

Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in E:\wamp\www\resultsbyname.php on line 19




Link to comment
Share on other sites

<?php

function 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 ";
     
?>
Link to comment
Share on other sites

like jesirose said... close the function, then call it when you need to connect.


[code]<?php

function connectdb(){
mysql_connect('localhost', 'root', '');
mysql_select_db('krankdcontacts') or die('Unable to select database!');
};//end function


connectdb();

$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
Link to comment
Share on other sites

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
Link to comment
Share on other sites

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
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.