homer.favenir Posted September 7, 2007 Share Posted September 7, 2007 im a beginner and student. i want to learn how to connect php to mysql? just a basic tutorial. pls kindly teach me how. thanks ??? Quote Link to comment https://forums.phpfreaks.com/topic/68353-pls-help-how-can-i-connect-php-to-mysql/ Share on other sites More sharing options...
AdRock Posted September 7, 2007 Share Posted September 7, 2007 Try these for starters http://www.tizag.com/ www.w3schools.com Quote Link to comment https://forums.phpfreaks.com/topic/68353-pls-help-how-can-i-connect-php-to-mysql/#findComment-343684 Share on other sites More sharing options...
$username Posted September 7, 2007 Share Posted September 7, 2007 You can google search it and you will find lots of help on this. Brett Quote Link to comment https://forums.phpfreaks.com/topic/68353-pls-help-how-can-i-connect-php-to-mysql/#findComment-343686 Share on other sites More sharing options...
homer.favenir Posted September 7, 2007 Author Share Posted September 7, 2007 thanks. but can you just tell me the basic. thanks Quote Link to comment https://forums.phpfreaks.com/topic/68353-pls-help-how-can-i-connect-php-to-mysql/#findComment-343690 Share on other sites More sharing options...
Mr P!nk Posted September 7, 2007 Share Posted September 7, 2007 simplest form <?php $db = mysql_connect("url", "username", "password"); mysql_select_db("database your connecting to", $db); ?> eg <?php $db = mysql_connect("www.yoursite.com", "admin", "123" mysql_select_db("admindb", $db) ?> and save that as something along the lines of db_inc.php and what page you need the database inserted put <?php include('includes/db_inc.php'); ?> at the top below <body> tag. hope this helps P.S this is tried and tested with my connection to mysql ** EDIT ** this is a basic log in using a database to store usernames and passwords that i use for low end tasks <?php include('includes/db_inc.php'); if(isset($submit)) // name of submit button { $sql = "SELECT * FROM dst_users WHERE username='$username' AND password='$password'"; $result = mysql_query($sql); $isAuth = false; //set to false originally while($row = mysql_fetch_array($result)){ if($row['username'] == $username) // above row checks to see if username/password combination exists { $isAuth = true; @session_start(); session_register('username'); } } } ?> <form method="post" action="index.php"> <?php // if login/pass exists if($isAuth && isset($submit)){ printf("<div id=\"system\">You have logged in successfully. <a href=\"admin.php\">Go to Admin System</a></div>"); } // if login/pass does not exist else if(!$isAuth && isset($submit)){ printf("<div id=\"system\">Login unsuccessful. Check your details and <a href=\"index.php\">try again</a></div>"); } // if not logged in if(!isset($submit)){ printf("<div id=\"formLabel\">username</div> <div id=\"formField\"> <label> <input name=\"username\" type=\"text\" class=\"loginText\" id=\"username\" size=\"15\" maxlength=\"15\" /> </label> </div> <div id=\"formLabel\">password</div> <div id=\"formField\"> <label> <input name=\"password\" type=\"password\" class=\"loginText\" id=\"password\" size=\"15\" maxlength=\"15\" /> </label> </div> <div id=\"formLabel\"> </div> <div id=\"formField\"> <label> <input name=\"submit\" type=\"submit\" id=\"submit\" value=\"login\" /> </label> </div> </div> <div id=\"loginButton\"></div>"); } ?> </form> Quote Link to comment https://forums.phpfreaks.com/topic/68353-pls-help-how-can-i-connect-php-to-mysql/#findComment-343693 Share on other sites More sharing options...
homer.favenir Posted September 7, 2007 Author Share Posted September 7, 2007 well thank you very much for the help i will try that. thanks Quote Link to comment https://forums.phpfreaks.com/topic/68353-pls-help-how-can-i-connect-php-to-mysql/#findComment-343697 Share on other sites More sharing options...
homer.favenir Posted September 7, 2007 Author Share Posted September 7, 2007 can i connect also php to msaccess? thanks Quote Link to comment https://forums.phpfreaks.com/topic/68353-pls-help-how-can-i-connect-php-to-mysql/#findComment-343698 Share on other sites More sharing options...
Styles2304 Posted September 7, 2007 Share Posted September 7, 2007 . . . you should be willing to search first before you ask. The best way to learn is to find out which direction you should head, then walk down that road yourself. Quote Link to comment https://forums.phpfreaks.com/topic/68353-pls-help-how-can-i-connect-php-to-mysql/#findComment-343703 Share on other sites More sharing options...
Mr P!nk Posted September 7, 2007 Share Posted September 7, 2007 have you tried the tutorials on the home page? http://www.phpfreaks.com/tutorials/61/0.php or google it also w3schools is very helpful http://www.w3schools.com/php/php_db_odbc.asp Quote Link to comment https://forums.phpfreaks.com/topic/68353-pls-help-how-can-i-connect-php-to-mysql/#findComment-343704 Share on other sites More sharing options...
$username Posted September 7, 2007 Share Posted September 7, 2007 Post some of the code you are using so we can take a look at so we can point you in the right direction. Brett Quote Link to comment https://forums.phpfreaks.com/topic/68353-pls-help-how-can-i-connect-php-to-mysql/#findComment-343718 Share on other sites More sharing options...
homer.favenir Posted September 7, 2007 Author Share Posted September 7, 2007 thanks!!! i will try these website first. Quote Link to comment https://forums.phpfreaks.com/topic/68353-pls-help-how-can-i-connect-php-to-mysql/#findComment-343735 Share on other sites More sharing options...
homer.favenir Posted September 7, 2007 Author Share Posted September 7, 2007 there is an error when i try to connecto to mysql error: Warning: mysql_connect() [function.mysql-connect]: Host 'AAI-AGS-139DW.AAIGLOBAL.local' is not allowed to connect to this MySQL server in C:\wamp\www\first project\connect_mysql.php on line 10 Could not connect: Host 'AAI-AGS-139DW.AAIGLOBAL.local' is not allowed to connect to this MySQL server what does it mean? how can i solved it? thanks Quote Link to comment https://forums.phpfreaks.com/topic/68353-pls-help-how-can-i-connect-php-to-mysql/#findComment-344053 Share on other sites More sharing options...
corbin Posted September 7, 2007 Share Posted September 7, 2007 That means that the MySQL host is denying access based on the host of the webserver.... MySQL needs to accept remote connections for the username you're using, or you need to run the PHP script on a host the MySQL server will accept. Quote Link to comment https://forums.phpfreaks.com/topic/68353-pls-help-how-can-i-connect-php-to-mysql/#findComment-344062 Share on other sites More sharing options...
homer.favenir Posted September 8, 2007 Author Share Posted September 8, 2007 thanks for the reply but how can i do that? thanks Quote Link to comment https://forums.phpfreaks.com/topic/68353-pls-help-how-can-i-connect-php-to-mysql/#findComment-344071 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.