8 Replies - 1106 Views - Last Post: 17 January 2011 - 05:18 AM Rate Topic: -----

#1 Sutirth  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 12
  • Joined: 16-January 11

Can't connect to mysql database

Posted 16 January 2011 - 08:58 AM

<?php
  // Insert the page header
  $page_title = 'Registration.php';
  // Connect to the database
 $dbc = mysql_connect("192.168.100.254","ty16","");
 mysql_select_db("tydb16",$dbc);

  if (isset($_POST['submit'])) {
    // Grab the profile data from the POST
    $firstname = mysql_real_escape_string($dbc, trim($_POST['firstname']));
    $lastname = mysql_real_escape_string($dbc, trim($_POST['lastname']));
    $email = mysql_real_escape_string($dbc, trim($_POST['email']));
    $password1 = mysql_real_escape_string($dbc, trim($_POST['pwd']));
    $password2 = mysql_real_escape_string($dbc, trim($_POST['conpwd']));
    $country = mysql_real_escape_string($dbc, trim($_POST['country']));
    $state = mysql_real_escape_string($dbc, trim($_POST['state']));
    $city = mysql_real_escape_string($dbc, trim($_POST['city']));
    $address = mysql_real_escape_string($dbc, trim($_POST['add']));
    $mobile = mysql_real_escape_string($dbc, trim($_POST['mno']));

  if (!empty($firstname) && !empty($lastname) && !empty($email)&& !empty($pwd) && !empty($conpwd) && ($pwd == $conpwd)&& !empty($country) && !empty($state) && !empty($city) && !empty($address) && !empty($mobile) {
      // Make sure someone isn't already registered using this username
      $query = "SELECT * FROM user WHERE firstname = '$username' and lastname='$lastname'";
      $data = mysql_query($dbc, $query);
  $query = "INSERT INTO user (firstname,lastname,email,password,country,state,city,address,mobile) VALUES ('$username',
 '$lastname','$email',SHA('$pwd'),'$country','$state','$city','$address','$mobile' )";

   mysql_query($dbc, $query);

        // Confirm success with the user
        echo '<p>Your new account has been successfully created. You\'re now ready to <a href="login.php">log in</a>.</p>';

        mysqli_close($dbc);
        exit();
      }
      else {
        // An account already exists for this username, so display an error message
        echo '<p class="error">An account already exists for this username. Please use a different address.</p>';
        $username = "";
      }
    }
    else {
      echo '<p class="error">You must enter all of the sign-up data, including the desired password twice.</p>';
    }
  }

  mysql_close($dbc);
?>


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

<head>
<meta http-equiv="Content-Type" content="text/html;charset=iso-8859-1" />
<meta http-equiv="Content-Style-Type" content="text/css" />

<title>Movie Company - Free Website Templates</title>

<link rel="stylesheet" href="style.css" type="text/css" media="screen" />

</head>

<body>

<div id="container">

	<!-- Start of Page Header -->

	<div id="page_header">

		<div id="company_name">
		<h1><span>Film Fanatics</span></h1>
		</div>

	</div>

	<!-- End of Page Header -->


	<!-- Start of Page Menu -->

	<div id="page_menu">

		<ul>
		<li class="home"><a href="http://www.freewebsitetemplates.com/" title="Home"><span>Home</span></a></li>
		
		</ul>

	</div>

	<!-- End of Page Menu -->



	<!-- Start of Main Content -->

	<div id="main_content">

		<div class="content_header">
		<h2><span>Registration Form</span></h2>
		</div>

		<div class="content_box_right">
		<div class="content_box_left">
		<div class="content_box">
		<div id="main_content_border">

	                        <form method="POST" action="register.php">
				<strong>First Name:</strong> <input type="text" name="firstname"/><br/><br/>
				<strong>Last Name: </strong> <input type="text" name="lastname"/><br/><br/>
				<strong>E-mail id:</strong> <input type="text" name="email"/><br/><br/>
				<strong>Password: </strong> <input type="password" name="pwd"/><br/><br/>
				<strong>Confirm Password:</strong> <input type="password" name="conpwd"/><br/><br/>
				<strong>Country:</strong> <input type="text" name="country"/><br/><br/>
				<strong>State:</strong> <input type="text" name="state"/><br/><br/>
				<strong>City:</strong> <input type="text" name="city"/><br/><br/>
				<strong>Address:</strong> <input type="text" name="add"/><br/><br/>
				<strong>Mobile No.:</strong> <input type="text" name="mno"/><br/><br/>
				<strong>Userame:</strong> <input type="text" name="uname"/><br/><br/>
				</form>


			


			

			<div class="clearthis"> </div>

		</div>
		</div>
		</div>
		</div>

	</div>

	<!-- End of Main Content -->


	<div class="clearthis"> </div>


	

</div>

</body>
</html>


MOD EDIT: When posting code...USE CODE TAGS!!!

:code:

This post has been edited by JackOfAllTrades: 16 January 2011 - 10:32 AM


Is This A Good Question/Topic? 0
  • +

Replies To: Can't connect to mysql database

#2 atik97  Icon User is offline

  • ???
  • member icon

Reputation: 144
  • View blog
  • Posts: 715
  • Joined: 16-September 08

Re: Can't connect to mysql database

Posted 16 January 2011 - 09:21 AM

There is a function called mysql_error(), which will help you to have an idea about the reason why error is occuring. Use this function in all possible cases-

$dbc = mysql_connect("192.168.100.254","ty16","") or die(mysql_error());
mysql_select_db("tydb16",$dbc) or die(mysql_error());
$data = mysql_query($dbc, $query) or die(mysql_error());



And do this in other cases. Hope it will help you to figure out the problem.
Was This Post Helpful? 0
  • +
  • -

#3 Sutirth  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 12
  • Joined: 16-January 11

Re: Can't connect to mysql database

Posted 16 January 2011 - 09:43 AM

View Postatik97, on 16 January 2011 - 09:21 AM, said:

There is a function called mysql_error(), which will help you to have an idea about the reason why error is occuring. Use this function in all possible cases-

$dbc = mysql_connect("192.168.100.254","ty16","") or die(mysql_error());
mysql_select_db("tydb16",$dbc) or die(mysql_error());
$data = mysql_query($dbc, $query) or die(mysql_error());



And do this in other cases. Hope it will help you to figure out the problem.


hey atik i will try to that but thr is one more question i would like to ask i m using "POST" method in the form as wella s in the script but still the values are get shown in url browser how do i figure out whst wrong??

This post has been edited by Sutirth: 16 January 2011 - 09:44 AM

Was This Post Helpful? 0
  • +
  • -

#4 atik97  Icon User is offline

  • ???
  • member icon

Reputation: 144
  • View blog
  • Posts: 715
  • Joined: 16-September 08

Re: Can't connect to mysql database

Posted 16 January 2011 - 10:11 AM

There is no reason to show post data in url, either get variables or query strings are shown in url. However, i haven't found any submit button in your code.
Was This Post Helpful? 0
  • +
  • -

#5 JackOfAllTrades  Icon User is offline

  • Saucy!
  • member icon

Reputation: 6063
  • View blog
  • Posts: 23,518
  • Joined: 23-August 08

Re: Can't connect to mysql database

Posted 16 January 2011 - 10:35 AM

Way to completely ignore the code tags directions all over the site!

:code:

If that's too complicated for you, please read the first link in my signature.

How about making an effort to learn how to use PHP, rather than just copying and pasting stuff?
Was This Post Helpful? 2
  • +
  • -

#6 LoDx  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 16
  • Joined: 16-January 11

Re: Can't connect to mysql database

Posted 16 January 2011 - 01:49 PM

Also double check that the IP is correct

$dbc = mysql_connect("192.168.100.254","ty16","");

Was This Post Helpful? 0
  • +
  • -

#7 Sutirth  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 12
  • Joined: 16-January 11

Re: Can't connect to mysql database

Posted 17 January 2011 - 04:06 AM

View PostLoDx, on 16 January 2011 - 01:49 PM, said:

Also double check that the IP is correct

$dbc = mysql_connect("192.168.100.254","ty16","");



@lodx ya the IP is correct its like i m working on a proj submission in the coll so the IP address of the coll is the above itself.

@jack of all trades : we have to write our comments compulsory to explain the internal guide its a copy and paste stuff for god sake !!!

This post has been edited by Sutirth: 17 January 2011 - 04:07 AM

Was This Post Helpful? 0
  • +
  • -

#8 LoDx  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 16
  • Joined: 16-January 11

Re: Can't connect to mysql database

Posted 17 January 2011 - 04:56 AM

View PostSutirth, on 17 January 2011 - 12:06 PM, said:

View PostLoDx, on 16 January 2011 - 01:49 PM, said:

Also double check that the IP is correct

$dbc = mysql_connect("192.168.100.254","ty16","");



@lodx ya the IP is correct its like i m working on a proj submission in the coll so the IP address of the coll is the above itself.

@jack of all trades : we have to write our comments compulsory to explain the internal guide its a copy and paste stuff for god sake !!!


Please post the output from atik97's response

Regarding the POST information getting shown in the url, do you have method="post" in your form? Do you get redirected to this page from a form on another page?

This post has been edited by LoDx: 17 January 2011 - 04:58 AM

Was This Post Helpful? 0
  • +
  • -

#9 aaron1178  Icon User is offline

  • Dovakiin, Dragonborn
  • member icon

Reputation: 169
  • View blog
  • Posts: 1,298
  • Joined: 22-October 08

Re: Can't connect to mysql database

Posted 17 January 2011 - 05:18 AM

Hello,
I've noticed that on line 33, you have mysqli_close($dbc); Whats the go? your using mysql to try and connect but you try closing using mysqli? Maybe your server cannot accept those type of connections. Try using "localhost" instead of the IP.

Hope it helps,

Thanks,
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1