Jump to content

Recommended Posts

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

Link to comment
https://forums.phpfreaks.com/topic/155963-solved-php-mysql-connection-error/
Share on other sites

document path comes from the factory with a trailing slash
No 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";

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");

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

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
}

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

 

2wgyy38.jpg

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>

 

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']

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>

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.