m-hrt Posted April 28, 2009 Share Posted April 28, 2009 php mysql connection error? when ever i run my local server i get this error why??? every thing is correct database name congig file then why can some one help me out here is the code: first db_config.php code <?php $host ("localhost"); $user ("root@localhost"); $pass ("autodeskmaya"); $db_name ("online_bus_project"); ?> now my orignal php code which is ticketregistration.php <?php require($_SERVER["DOCUMENT_ROOT"] ."/config/db_config.php"); $connection = mysql_connect("$host","$user","$pass") or die("error connect"); mysql_select_db($db_name, $Connection); $first_name = $_post["txt_fname"]; $last_name = $_post["txt_lname"]; $email_address = $_post["txt_email"]; $address = $_post["txt_address"]; $city = $_post["txt_city"]; $province = $_post["txt_province"]; $contact_no = $_post["txt_contact"]; $query = "INSERT INTO user_information (first_name, last_name, email_address, address, city, province, contact_no) VALUES('$first_name', '$last_name', '$email_address', '$address', '$city', '$province', '$contact_no')"; mysql_query($query, $connection) or die(mysql_error());s ?> i have included only the php connection code not the html code like the forum and so on. here is the error: http://i44.tinypic.com/nv5err.jpg And im using new wamp server on windows xp sp3 Quote Link to comment https://forums.phpfreaks.com/topic/155963-solved-php-mysql-connection-error/ Share on other sites More sharing options...
Prismatic Posted April 28, 2009 Share Posted April 28, 2009 the document path comes from the factory with a trailing slash, change your require line to this require($_SERVER["DOCUMENT_ROOT"] ."config/db_config.php"); Quote Link to comment https://forums.phpfreaks.com/topic/155963-solved-php-mysql-connection-error/#findComment-820978 Share on other sites More sharing options...
PFMaBiSmAd Posted April 28, 2009 Share Posted April 28, 2009 document path comes from the factory with a trailing slashNo it does not. If there require() statement was failing due to an improper path statement, there would be an error message or a blank page. The remaining code would not execute. $host ("localhost"); $user ("root@localhost"); $pass ("autodeskmaya"); $db_name ("online_bus_project"); Those 4 lines of code are incorrect. You assign values to variables using an equal sign =, for example - $host = "localhost"; Quote Link to comment https://forums.phpfreaks.com/topic/155963-solved-php-mysql-connection-error/#findComment-820997 Share on other sites More sharing options...
m-hrt Posted April 28, 2009 Author Share Posted April 28, 2009 $host = ("localhost"); $user = ("root@localhost"); $pass = ("autodeskmaya"); $db_name = ("online_bus_project"); i have did this = to all variables its not working same error on line 2? Quote Link to comment https://forums.phpfreaks.com/topic/155963-solved-php-mysql-connection-error/#findComment-821190 Share on other sites More sharing options...
wildteen88 Posted April 28, 2009 Share Posted April 28, 2009 Where is your config folder located to? As on this line require($_SERVER["DOCUMENT_ROOT"] ."config/db_config.php"); You are telling PHP to include the file db_config.php from C:/wamp/www/config. Is this correct? Quote Link to comment https://forums.phpfreaks.com/topic/155963-solved-php-mysql-connection-error/#findComment-821194 Share on other sites More sharing options...
m-hrt Posted April 28, 2009 Author Share Posted April 28, 2009 solved im not including db_config just doing direct connect now this error comes? Quote Link to comment https://forums.phpfreaks.com/topic/155963-solved-php-mysql-connection-error/#findComment-821201 Share on other sites More sharing options...
m-hrt Posted April 28, 2009 Author Share Posted April 28, 2009 Where is your config folder located to? As on this line require($_SERVER["DOCUMENT_ROOT"] ."config/db_config.php"); You are telling PHP to include the file db_config.php from C:/wamp/www/config. Is this correct? no its c:/wamp/www/site/config Quote Link to comment https://forums.phpfreaks.com/topic/155963-solved-php-mysql-connection-error/#findComment-821203 Share on other sites More sharing options...
mattal999 Posted April 28, 2009 Share Posted April 28, 2009 I think POST needs to be in Capitals. I think so anyways... Quote Link to comment https://forums.phpfreaks.com/topic/155963-solved-php-mysql-connection-error/#findComment-821222 Share on other sites More sharing options...
wildteen88 Posted April 28, 2009 Share Posted April 28, 2009 Yes $_post should be $_POST (php is case-sensitive). Where is your config folder located to? As on this line require($_SERVER["DOCUMENT_ROOT"] ."config/db_config.php"); You are telling PHP to include the file db_config.php from C:/wamp/www/config. Is this correct? no its c:/wamp/www/site/config In that case your path should be require($_SERVER["DOCUMENT_ROOT"] ."site/config/db_config.php"); Quote Link to comment https://forums.phpfreaks.com/topic/155963-solved-php-mysql-connection-error/#findComment-821245 Share on other sites More sharing options...
premiso Posted April 28, 2009 Share Posted April 28, 2009 Also $_post should be $_POST as php is caSe SenSItIve to variable names and array indexes. Quote Link to comment https://forums.phpfreaks.com/topic/155963-solved-php-mysql-connection-error/#findComment-821255 Share on other sites More sharing options...
m-hrt Posted April 28, 2009 Author Share Posted April 28, 2009 Also $_post should be $_POST as php is caSe SenSItIve to variable names and array indexes. thanx man and thanx to all who helped appreciate. now it say:From line 6 to 12 check the picture and tell me? Notice: Undefined index: txt_fname in C:\wamp\www\site\ticketregistration.php on line 6 Quote Link to comment https://forums.phpfreaks.com/topic/155963-solved-php-mysql-connection-error/#findComment-821269 Share on other sites More sharing options...
wildteen88 Posted April 28, 2009 Share Posted April 28, 2009 You will get those notices if the form has not been submitted yet. You should check to see if the form has been submitted before using your $_POST variables. For example if you have named your submit button as submit. Then you should do if(isset($_POST['submit'])) { // code for processing your form here } Quote Link to comment https://forums.phpfreaks.com/topic/155963-solved-php-mysql-connection-error/#findComment-821278 Share on other sites More sharing options...
m-hrt Posted April 28, 2009 Author Share Posted April 28, 2009 You will get those notices if the form has not been submitted yet. You should check to see if the form has been submitted before using your $_POST variables. For example if you have named your submit button as submit. Then you should do if(isset($_POST['submit'])) { // code for processing your form here } thanx solved. now error int the line 19 all the database table contents error: Notice: Undefined variable: first_name in C:\wamp\www\site\ticketregistration.php on line 19 $query = "INSERT INTO user_information (first_name, last_name, email_address, address, city, province, contact_no) VALUES('$first_name', '$last_name', '$email_address', '$address', '$city', '$province', '$contact_no')"; mysql_query($query, $connection) or die(mysql_error()); why error on the user_information my table field contains these all names Quote Link to comment https://forums.phpfreaks.com/topic/155963-solved-php-mysql-connection-error/#findComment-821287 Share on other sites More sharing options...
m-hrt Posted April 29, 2009 Author Share Posted April 29, 2009 cmon guys this one is i think last? plz help and also when ever im refreshing page contact_no add 0 in it why? Quote Link to comment https://forums.phpfreaks.com/topic/155963-solved-php-mysql-connection-error/#findComment-821645 Share on other sites More sharing options...
m-hrt Posted April 29, 2009 Author Share Posted April 29, 2009 every thing solved just the last thing then im goin to close thread: when ever i press submit button nothing is happening why? <?php require($_SERVER["DOCUMENT_ROOT"] ."site/config/db_config.php"); $connection = mysql_connect("$host","$user","$pass") or die("error connect"); mysql_select_db("$db_name"); if(isset($_POST['submit'])) { $first_name = $_POST["fname"]; $len = strlen($first_name); if ($len >0) { $last_name = $_POST["lastname"]; $email_address = $_POST["email"]; $address = $_POST["address"]; $city = $_POST["city"]; $province = $_POST["province"]; $contact_no = $_POST["contactno"]; } $query = "INSERT INTO user_information (first_name, last_name, email_address, address, city, province, contact_no) VALUES('$first_name', '$last_name', '$email_address', '$address', '$city', '$province', '$contact_no')"; mysql_query($query, $connection) or die(mysql_error()); } ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Untitled Document</title> <link href="obrs.css" rel="stylesheet" type="text/css" /> <!--[if IE 5]> <style type="text/css"> /* place css box model fixes for IE 5* in this conditional comment */ .twoColFixRtHdr #sidebar1 { width: 220px; } </style> <![endif]--><!--[if IE]> <style type="text/css"> /* place css fixes for all versions of IE in this conditional comment */ .twoColFixRtHdr #sidebar1 { padding-top: 30px; } .twoColFixRtHdr #mainContent { zoom: 1; } /* the above proprietary zoom property gives IE the hasLayout it needs to avoid several bugs */ </style> <![endif]--> <script src="Scripts/AC_RunActiveContent.js" type="text/javascript"></script> <style type="text/css"> <!-- .style1 { color: #FFFF00; font-weight: bold; } .style2 { color: #FFFF66; font-weight: bold; } .style8 { color: #0066FF; font-weight: bold; } --> </style> </head> <body class="twoColFixRtHdr"> <div id="container"> <div id="header"> <!-- end #header --> <img src="images/header" alt="OBTRS: Header" /></div> <div id="sidebar1"> <!-- end #sidebar1 --> <img src="images/sidebar_slideshow" alt="" /> <div id="blogarea"> <p class="style2">Casual Dining Restaurants</p> <p><br /> Our family-style restaurants are the favorite of thousands of tourists and professional drivers alike. Our clean and friendly surroundings encourage people to stop and enjoy a wholesome meal with us when they travel. Our customers recognize our strong teamwork ethic as we provide them quality service.</p> <p><br /> <span class="style1">Convenience Stores</span></p> <p><br /> Our cashiers take pride in having the items on the shelf ready for our travelers when they stop. We know many are in a hurry and we need to be "fast" to meet their busy schedules. Some of our returning customers enjoy fresh coffee and we have it ready for them. The joint effort of our managers and associates creates a strong "team spirit" that provides the customers what they are looking for as they travel.</p> </div> </div> <div id="mainContent"> <div id="nav"> <script type="text/javascript"> AC_FL_RunContent( 'codebase','http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,28,0','width','760','height','30','src','images/nav_bar2','quality','high','pluginspage','http://www.adobe.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash','movie','images/nav_bar2' ); //end AC code </script> <noscript> <object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,28,0" width="760" height="30"> <param name="movie" value="images/nav_bar2.swf" /> <param name="quality" value="high" /> <embed src="images/nav_bar2.swf" quality="high" pluginspage="http://www.adobe.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash" type="application/x-shockwave-flash" width="760" height="30"></embed> </object> </noscript> </div> <div id="features"></div> <div class="style8" id="writeinfo">Please Fill your Personal Information below</div> <div id="forminfo"><frorm action="<?php echo $_server[php_SELF]; ?>" method="POST"> First Name: <INPUT type="text" name=fname style="HEIGHT: 19px; WIDTH: 174px" size="20" align="center"> <br/> <br/> Last Name: <INPUT type="text" name=lastname style="HEIGHT: 19px; WIDTH: 174px" size="20" align="center"> <br /> <br/> Email Address: <INPUT type="text" name=email style="HEIGHT: 19px; WIDTH: 174px" size="20" align="center"> <br /> <br/> Address: <INPUT type="text" name=address style="HEIGHT: 19px; WIDTH: 174px" size="20" align="center"> <br /> <br/> City: <INPUT type="text" name=city style="HEIGHT: 19px; WIDTH: 174px" size="20" align="center"> <br /> <br/> Province: <INPUT type="text" name=province style="HEIGHT: 19px; WIDTH: 174px" size="20" align="center"> <br /> <br/> Contact No: <INPUT type="text" name=contactno style="HEIGHT: 19px; WIDTH: 174px" size="20" align="center"> <br /> <br /> <br/> <input type="submit" value="submit" /> </form> </div> <!-- end #mainContent --> </div> <!-- This clearing element should immediately follow the #mainContent div in order to force the #container div to contain all child floats --> <br class="clearfloat" /> <div id="footer"> <p><a href="aboutus.html">About us</a> |<a href="feedback.html"> Feedback</a> |<a href="faqs.html"> FAQs</a> | <a href="terms.html">Terms & Conditions</a> | <a href="contactus.html">Contact us</a></p> <p> 2009 Copyright - Shah Abdul Latif University Khairpur</p> <!-- end #footer --> </div> <!-- end #container --> </div> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/155963-solved-php-mysql-connection-error/#findComment-821720 Share on other sites More sharing options...
premiso Posted April 29, 2009 Share Posted April 29, 2009 <input type="submit" name="submit" value="submit" /> Your submit button was missing the name field. Quote Link to comment https://forums.phpfreaks.com/topic/155963-solved-php-mysql-connection-error/#findComment-821775 Share on other sites More sharing options...
mattal999 Posted April 29, 2009 Share Posted April 29, 2009 Also, you have this line: <frorm action="<?php echo $_server[php_SELF]; ?>" method="POST"> which should be form... <form action="<?php echo $_server[php_SELF]; ?>" method="POST"> Quote Link to comment https://forums.phpfreaks.com/topic/155963-solved-php-mysql-connection-error/#findComment-821830 Share on other sites More sharing options...
wildteen88 Posted April 29, 2009 Share Posted April 29, 2009 Also, you have this line: <frorm action="<?php echo $_server[php_SELF]; ?>" method="POST"> which should be form... <form action="<?php echo $_server[php_SELF]; ?>" method="POST"> Not fogetting $_server[php_SELF] should be $_SERVER['PHP_SELF'] Quote Link to comment https://forums.phpfreaks.com/topic/155963-solved-php-mysql-connection-error/#findComment-821966 Share on other sites More sharing options...
m-hrt Posted April 30, 2009 Author Share Posted April 30, 2009 done every thing thanx guys it says: Not Found The requested URL /site/<br /><b>Notice</b>: Undefined variable: _server in <b>C:\wamp\www\site\ticketregistration.php</b> on line <b>103</b><br /> was not found on this server. <?php require($_SERVER["DOCUMENT_ROOT"] ."site/config/db_config.php"); $connection = mysql_connect("$host","$user","$pass") or die("error connect"); mysql_select_db("$db_name"); if(isset($_POST['submit'])) { $first_name = $_POST["fname"]; $len = strlen($first_name); if ($len >0) { $last_name = $_POST["lastname"]; $email_address = $_POST["email"]; $address = $_POST["address"]; $city = $_POST["city"]; $province = $_POST["province"]; $contact_no = $_POST["contactno"]; } $query = "INSERT INTO user_information (first_name, last_name, email_address, address, city, province, contact_no) VALUES('$first_name', '$last_name', '$email_address', '$address', '$city', '$province', '$contact_no')"; mysql_query($query, $connection) or die(mysql_error()); } ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Untitled Document</title> <link href="obrs.css" rel="stylesheet" type="text/css" /> <!--[if IE 5]> <style type="text/css"> /* place css box model fixes for IE 5* in this conditional comment */ .twoColFixRtHdr #sidebar1 { width: 220px; } </style> <![endif]--><!--[if IE]> <style type="text/css"> /* place css fixes for all versions of IE in this conditional comment */ .twoColFixRtHdr #sidebar1 { padding-top: 30px; } .twoColFixRtHdr #mainContent { zoom: 1; } /* the above proprietary zoom property gives IE the hasLayout it needs to avoid several bugs */ </style> <![endif]--> <script src="Scripts/AC_RunActiveContent.js" type="text/javascript"></script> <style type="text/css"> <!-- .style1 { color: #FFFF00; font-weight: bold; } .style2 { color: #FFFF66; font-weight: bold; } .style8 { color: #0066FF; font-weight: bold; } --> </style> </head> <body class="twoColFixRtHdr"> <div id="container"> <div id="header"> <!-- end #header --> <img src="images/header" alt="OBTRS: Header" /></div> <div id="sidebar1"> <!-- end #sidebar1 --> <img src="images/sidebar_slideshow" alt="" /> <div id="blogarea"> <p class="style2">Casual Dining Restaurants</p> <p><br> Our family-style restaurants are the favorite of thousands of tourists and professional drivers alike. Our clean and friendly surroundings encourage people to stop and enjoy a wholesome meal with us when they travel. Our customers recognize our strong teamwork ethic as we provide them quality service.</p> <p><br> <span class="style1">Convenience Stores</span></p> <p><br> Our cashiers take pride in having the items on the shelf ready for our travelers when they stop. We know many are in a hurry and we need to be "fast" to meet their busy schedules. Some of our returning customers enjoy fresh coffee and we have it ready for them. The joint effort of our managers and associates creates a strong "team spirit" that provides the customers what they are looking for as they travel.</p> </div> </div> <div id="mainContent"> <div id="nav"> <script type="text/javascript"> AC_FL_RunContent( 'codebase','http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,28,0','width','760','height','30','src','images/nav_bar2','quality','high','pluginspage','http://www.adobe.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash','movie','images/nav_bar2' ); //end AC code </script> <noscript> <object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,28,0" width="760" height="30"> <param name="movie" value="images/nav_bar2.swf" /> <param name="quality" value="high" /> <embed src="images/nav_bar2.swf" quality="high" pluginspage="http://www.adobe.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash" type="application/x-shockwave-flash" width="760" height="30"></embed> </object> </noscript> </div> <div id="features"></div> <div class="style8" id="writeinfo">Please Fill your Personal Information below</div> <div id="forminfo"><form action="<?php echo $_server['PHP_SELF']; ?>" method="POST"> First Name: <INPUT type="text" name=fname style="HEIGHT: 19px; WIDTH: 174px" size="20" align="center"> <br> <br> Last Name: <INPUT type="text" name=lastname style="HEIGHT: 19px; WIDTH: 174px" size="20" align="center"> <br> <br> Email Address: <INPUT type="text" name=email style="HEIGHT: 19px; WIDTH: 174px" size="20" align="center"> <br> <br> Address: <INPUT type="text" name=address style="HEIGHT: 19px; WIDTH: 174px" size="20" align="center"> <br> <br> City: <INPUT type="text" name=city style="HEIGHT: 19px; WIDTH: 174px" size="20" align="center"> <br> <br> Province: <INPUT type="text" name=province style="HEIGHT: 19px; WIDTH: 174px" size="20" align="center"> <br> <br> Contact No: <INPUT type="text" name=contactno style="HEIGHT: 19px; WIDTH: 174px" size="20" align="center"> <br> <br> <br> <input type="submit" name="submit" value="submit" /> </form> </div> <!-- end #mainContent --> </div> <!-- This clearing element should immediately follow the #mainContent div in order to force the #container div to contain all child floats --> <br class="clearfloat" /> <div id="footer"> <p><a href="aboutus.html">About us</a> |<a href="feedback.html"> Feedback</a> |<a href="faqs.html"> FAQs</a> | <a href="terms.html">Terms & Conditions</a> | <a href="contactus.html">Contact us</a></p> <p> 2009 Copyright - Shah Abdul Latif University Khairpur</p> <!-- end #footer --> </div> <!-- end #container --> </div> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/155963-solved-php-mysql-connection-error/#findComment-822530 Share on other sites More sharing options...
m-hrt Posted April 30, 2009 Author Share Posted April 30, 2009 Topic Solved: every thing done thanx guys thanx for the help all i really appreciate Thanx to wildteen88 , mattal999 , premiso , Prismatic , PFMaBiSmAd Quote Link to comment https://forums.phpfreaks.com/topic/155963-solved-php-mysql-connection-error/#findComment-822534 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.