Jump to content

Mysql gets unable to register!


erikn68

Recommended Posts

While doing a website in php using mysql db I get the unable to register error:  Below is my code, if anyone can help.

 

ajaxinsert.php file

 

<?php
$username=$_POST['username'];
$password=$_POST['password'];
$mobile=$_POST['mobile'];
$email=$_POST['email'];
$Fname=$_POST['Fname'];
$Lname=$_POST['Lname'];
$street=$_POST['street'];
$city=$_POST['city'];
$state=$_POST['state'];
$zip=$_POST['zip'];

mysql_connect("localhost","webspace_er5","c6b7s9t1") or die(mysql_error());
$query=mysql_query("INSERT INTO Registration (`username`, `date`, `email`, `password`, `mobile`, `Fname`, `Lname`, `street`, `state`, `zip`, `ip`) VALUES ('', '$username', '$date('d-m-Y')', '$email', '$password', '$mobile', '$Fname', '$Lname','$street', '$city', '$state', '$zip', '".$_SERVER['REMOTE_ADDR']."')");
mysql_select_db("webspace_eriknel1") or die(mysql_error());
if($query)
{
?>
    <div style="color:#008000; font-weight:bold;">Registered successfully..!!</div>
<?php
}else
{
?>
    <div style="color:#c24f00; font-weight:bold;">unable to register !!</div>
<?php
}
?>

Registration.html file code


<!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>Registration Form</title>
<style type="text/css">
<!--
body,td,th {
font-family: Trebuchet MS, Arial, Helvetica, sans-serif;
font-size: 12px;
color: #333;
}
body {
margin-left: 0px;
margin-top: 30px;
margin-right: 0px;
margin-bottom: 0px;
}
.maindiv{ width:600px; margin:0 auto;}
.textbox{ padding:2px 4px; width:200px;}
.submit{ border:solid 1px #008000; background:#008000; color:#FFF; font-weight:bold;}
-->
</style>
<script type="text/javascript" src="ajaxjquery.js"></script>
<script type="text/javascript">
                $(document).ready(function()
                {
                $("#register").click(function(){
                var element = $(this);
                var Id = element.attr("id");
                var loadplacecomment = $("#message");
                
                var username = $("#username").val();
                var password = $("#password").val();
                var email = $("#email").val();
	var Fname = $("#Fname").val();
	var Lname = $("#Lname").val();
                var mobile = $("#mobile").val();
	var street = $("#street").val();
	var city = $("#city").val();
	var state = $("#state").val();
	var zip = $("#zip").val();
                var dataString = 'username='+ username + '&password='+ password + '&email='+ email + '&Fname='+ Fname + '&Lname=' + Lname +'&mobile='+ mobile + '&street='+ street + '&city='+ city + '&state='+ state + '&zip='+ zip;
                //alert(dataString); 
                if(username==''|| password=='' || email=='' || mobile=='')
                {
                alert("Please Enter all the Fields");
                }
                else
                {
                $("#flash").show();
                $("#flash").fadeIn(400).html('<img src="ajax-loader.gif" align="absmiddle"> loading.....');
                
                $.ajax({
                type: "POST",
                url: "ajaxinsert.php",
                data: dataString,
                cache: false,
                success: function(html){
			loadplacecomment.html('');
                $("#message").append(html);
                $("#flash").hide();
                }
                });
                }
                return false;});});
                </script>
</head>
<body>
<div style="display:none;"><img src="ajax-loader.gif" /></div>
<div style="text-align:center;">
  <h1 style="color:#CCC;">Registration Form</h1></div>
<div class="maindiv">
<form method="post">
<table width="100%" border="0" cellpadding="2" cellspacing="2">
  <tr>
    <td colspan="3" align="left" valign="middle" bgcolor="#008000"><div style="margin:0px 10px; font-weight:bold; color:#FFF; font-size:16px;">Registration Form</div></td>
    </tr>
  <tr>
    <td colspan="3" align="left" valign="middle">
    <div id="flash"></div>
    <div id="message"></div>
    </td>
    </tr>
  <tr>
    <td width="13%" align="left" valign="middle"><strong>Userame</strong></td>
    <td width="2%" align="left" valign="middle">:</td>
    <td width="85%" align="left" valign="middle"><label>
      <input name="username" type="text" class="textbox" id="username" />
    </label></td>
  </tr>
  <tr>
    <td width="13%" align="left" valign="middle"><strong>Password</strong></td>
    <td width="2%" align="left" valign="middle">:</td>
    <td width="85%" align="left" valign="middle"><label>
      <input name="password" type="password" class="textbox" id="password" />
    </label></td>
  </tr>
  <tr>
    <td align="left" valign="middle"><strong>Email</strong></td>
    <td align="left" valign="middle">:</td>
    <td align="left" valign="middle"><label>
      <input name="email" type="text" class="textbox" id="email" />
    </label></td>
  </tr>
<tr>
    <td align="left" valign="middle"><strong>First Name</strong></td>
    <td align="left" valign="middle">:</td>
    <td align="left" valign="middle"><label>
      <input name="Fname" type="text" class="texbox" id="Fname" />
    </label></td>
  </tr>
<tr>
    <td align="left" valign="middle"><strong>Last Name</strong></td>
    <td align="left" valign="middle">:</td>
    <td align="left" valign="middle"><label>
      <input name="Lname" type="text" class="texbox" id="Lname" />
    </label></td>
  </tr>
<tr>
    <td align="left" valign="middle"><strong>Street</strong></td>
    <td align="left" valign="middle">:</td>
    <td align="left" valign="middle"><label>
      <input name="street" type="text" class="texbox" id="street" />
    </label></td>
  </tr>
<tr>
    <td align="left" valign="middle"><strong>City</strong></td>
    <td align="left" valign="middle">:</td>
    <td align="left" valign="middle"><label>
      <input name="city" type="text" class="texbox" id="city" />
    </label></td>
  </tr>
<tr>
    <td align="left" valign="middle"><strong>State</strong></td>
    <td align="left" valign="middle">:</td>
    <td align="left" valign="middle"><label>
      <input name="state" type="text" class="texbox" id="state" />
    </label></td>
  </tr>
<tr>
    <td align="left" valign="middle"><strong>Zipcode</strong></td>
    <td align="left" valign="middle">:</td>
    <td align="left" valign="middle"><label>
      <input name="zip" type="text" class="texbox" id="zip" />
    </label></td>
  </tr>
  <tr>
    <td align="left" valign="middle"><strong>Cellphone</strong></td>
    <td align="left" valign="middle">:</td>
    <td align="left" valign="middle"><label>
      <input name="mobile" type="text" class="textbox" id="mobile" />
    </label></td>
  </tr>
  <tr>
    <td align="left" valign="middle"> </td>
    <td align="left" valign="middle"> </td>
    <td align="left" valign="middle"><label>
      <input name="register" type="button" class="submit" id="register" value="Register" />
    </label></td>
  </tr>
</table>
</form>
</div>
</body>
</html>

 

Any suggestions would be nice.

 

Erik

Link to comment
Share on other sites

I switched the code and I am now getting this error:

 

Warning: mysql_select_db() [function.mysql-select-db]: Access denied for user 'webspace'@'localhost' (using password: NO) in /home/webspace/public_html/Erik.Nelson/ajaxinsert.php on line 13

 

Warning: mysql_select_db() [function.mysql-select-db]: A link to the server could not be established in /home/webspace/public_html/Erik.Nelson/ajaxinsert.php on line 13

Access denied for user 'webspace'@'localhost' (using password: NO)

 

here is the php file code

 

<?php
$username=$_POST['username'];
$password=$_POST['password'];
$mobile=$_POST['mobile'];
$email=$_POST['email'];
$Fname=$_POST['Fname'];
$Lname=$_POST['Lname'];
$street=$_POST['street'];
$city=$_POST['city'];
$state=$_POST['state'];
$zip=$_POST['zip'];

mysql_select_db("webspace_eriknel1") or die(mysql_error());
mysql_connect("localhost","webspace_er5","c6b7s9t1") or die(mysql_error());
$query=mysql_query("INSERT INTO Registration (`username`, `date`, `email`, `password`, `mobile`, `Fname`, `Lname`, `street`, `state`, `zip`, `ip`) VALUES ('', '$username', '$date('d-m-Y')', '$email', '$password', '$mobile', '$Fname', '$Lname','$street', '$city', '$state', '$zip', '".$_SERVER['REMOTE_ADDR']."')");

if($query)
{
?>
    <div style="color:#008000; font-weight:bold;">Registered successfully..!!</div>
<?php
}else
{
?>
    <div style="color:#c24f00; font-weight:bold;">unable to register !!</div>
<?php
}
?>

Link to comment
Share on other sites

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.