maverick_ph Posted October 21, 2010 Share Posted October 21, 2010 hi to everyone.. i need help with my php scripting..i just can't connect to my mysql database..the message was this.."Warning: mysql_connect() [function.mysql-connect]: Access denied for user 'ODBC'@'localhost' (using password: NO) in C:\xampp\htdocs\HR\checklogin.php on line 10 cannot connect" i got the code from http://www.phpeasystep.com/workshopview.php?id=6 <?php session_start(); $host="localhost"; // Host name $username=""; // Mysql username $password=""; // Mysql password $db_name="test"; // Database name $tbl_name="members"; // Table name // Connect to server and select databse. mysql_connect("$host", "$username", "$password")or die("cannot connect"); mysql_select_db("$db_name")or die("cannot select DB"); // Define $myusername and $mypassword $myusername=$_POST['myusername']; $mypassword=$_POST['mypassword']; // To protect MySQL injection (more detail about MySQL injection) $myusername = stripslashes($myusername); $mypassword = stripslashes($mypassword); $myusername = mysql_real_escape_string($myusername); $mypassword = mysql_real_escape_string($mypassword); $sql="SELECT * FROM $tbl_name WHERE username='$myusername' and password='$mypassword'"; $result=mysql_query($sql); // Mysql_num_row is counting table row $count=mysql_num_rows($result); // If result matched $myusername and $mypassword, table row must be 1 row if($count==1){ $_SESSION['logged'] = true; header("location:login_success.php"); exit;} else { echo "Wrong Username or Password"; } ob_end_flush(); ?> Link to comment https://forums.phpfreaks.com/topic/216436-database-connectin-problem/ Share on other sites More sharing options...
phprocker Posted October 21, 2010 Share Posted October 21, 2010 You have to define the username and password for the database. You have: $host="localhost"; // Host name $username=""; // Mysql username $password=""; // Mysql password $db_name="test"; // Database name $tbl_name="members"; // Table name When it should be: $host="localhost"; // Host name $username="somedatabaseusername"; // Mysql username $password="somedatabasepassword"; // Mysql password $db_name="test"; // Database name $tbl_name="members"; // Table name Link to comment https://forums.phpfreaks.com/topic/216436-database-connectin-problem/#findComment-1124753 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.