Jump to content

[SOLVED] MySQL query not entering data into database?


dessolator

Recommended Posts

Hi, I have created a register form and a register process form, when I enter data into it and hit submit it echos all the variables like I asked it to but my query isn't inserting the data into the database and is displaying no errors, I would appreciate it if you could take a look at my  code and point me in the right direction.

 

Thanks,

 

Ian

 

 

Register/Login Form:

<!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=iso-8859-1" />
<title>Colab Admin - Login</title>

<link href="images/stylesheet1.css" rel="stylesheet" type="text/css" />
<style type="text/css">
<!--
#Layer1 {
position:absolute;
left:13px;
top:21px;
width:158px;
height:78px;
z-index:1;
}
#Layer2 {
position:absolute;
left:350px;
top:290px;
width:400px;
height:180px;
z-index:2;
}
.style1 {
font-size: 16px;
font-weight: bold;
color: #FF0000;
}
-->
</style>
</head>

<body>
<table width="773" border="0" cellpadding="0" cellspacing="0">
  <!--DWLayoutDefaultTable-->
  <tr>
    <td width="435" height="166"> </td>
    <td width="255"> </td>
  </tr>
  <tr>
    <td height="221"> </td>
    <td valign="top"><table width="100%" border="0" cellpadding="0" cellspacing="0">
      <!--DWLayoutTable-->
      <tr>
        <td height="91" valign="top"><div align="center">
          <p align="center"><img src="images/logo.gif" alt="Colab Logo" width="91" height="77" /><br />
              <span class="style1">Admin</span><br />
              <br />
          </p>
          </div></td>
  </tr>
      <tr>
        <td height="56" valign="top">          <div align="center"><form id="form1" name="form1" method="post" action="check_login.php">
          <p>Username:
            <input name="adminusername" type="text" id="adminusername" size="25" maxlength="25" />
            <br />
              <br />
              <br />
            Password:
            <input name="adminpassword" type="password" id="adminpassword" size="25" maxlength="25" />
          </p>
          <p align="center">
            <input type="submit" name="Submit" value="Submit" />
            <input name="Reset" type="reset" id="Reset" value="Reset" />
          </p>
        </form>
        </div>
          
          </td>
        </tr>
      <tr>
        <td height="56" valign="top"><!--DWLayoutEmptyCell--> </td>
      </tr>
      
    </table>
    </td>
  </tr>
</table>
</body>

</html>

 

 

 

Register Process Form:

<?php
//Database Connection Details
$host="localhost"; // Host name
$dbusername="root"; // Mysql username
$dbpassword="abc123"; // Mysql password
$db_name="colab_booking"; // Database name

//Gets the data submitted from the form
$forename = substr($_POST['forename2'], 0, 65);
$surname = substr($_POST['surname2'], 0, 65);
$course = substr($_POST['course'], 0, 65);
$email = substr($_POST['email2'], 0, 65);
$vemail = substr($_POST['verifyemail2'], 0, 65);
$username = substr($_POST['username2'], 0, 65);
$password = substr($_POST['password2'], 0, 65);
$vpassword = substr($_POST['confirmpassword2'], 0, 65);

if ($email != $vemail) {
echo "The email addresses don't match!";
exit();
}

else{
mysql_connect("$host", "$dbusername", "$dbpassword")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");

$sql="SELECT * FROM members WHERE email = '$email'";
$result=mysql_query($sql);
$count=mysql_num_rows($result);
if($count==1){
echo "The email address that you requested already exists, please go back and choose a new one!";
exit();
}

//Checks to see that the username doesn't already exist
mysql_connect("$host", "$dbusername", "$dbpassword")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");

$sqlselect="SELECT * FROM members WHERE username = '$username'";
$result1=mysql_query($sqlselect);
$count1=mysql_num_rows($result1);
if($count1==1){
echo "The username that you requested already exists, please go back and choose a new one!";
exit();
}
//Ensuring that the passwords submitted are the same
else if ($password != $vpassword) {
echo "The passwords don't match!";
exit();
}

echo $forename; 
echo $surname; 
echo $course; 
echo $email; 
echo $vemail;
echo $username;
echo $password;
echo $vpassword;



//Converts from human readable time to unix timestamp
$unixTimestamp = mktime($hour, $minute, 00, $month, $day, $year);

//Database Connection Details
$host="localhost"; // Host name
$dbusername="root"; // Mysql username
$password="abc123"; // Mysql password
$db_name="colab_booking"; // Database name

//Connect to database or display error message
mysql_connect("$host", "$dbusername", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");

//Insert the values from the form and the converted time>timestamp into the database
$query = "INSERT INTO events 
          VALUES ('','$event_name','$event_description', '$unixTimestamp', '$event_location', '$event_limit')";
mysql_query($query) or die('<BR />Insert query 1 failed: ' . mysql_error() . '</BODY></HTML>');
}
?>

Link to comment
Share on other sites

Are you getting an error?

 

Also

INSERT INTO events 
          VALUES ('','$event_name','$event_description', '$unixTimestamp', '$event_location', '$event_limit')";

 

you need to have the table col headers directly following INSERT INTO events (<col headers>) VALUES (<values>);

Link to comment
Share on other sites

Are you getting an error?

 

Also

INSERT INTO events 
          VALUES ('','$event_name','$event_description', '$unixTimestamp', '$event_location', '$event_limit')";

 

you need to have the table col headers directly following INSERT INTO events (<col headers>) VALUES (<values>);

 

FYI - Actually that's optional drummer101, but I highly recommend that everyone specifies the column names.

Link to comment
Share on other sites

Only optional if you insert the exact number of fields that you have in your DB.

Yes, very good clarification. Thank you.

 

I believe that you always specify the column names. Also, that way when you need to add new columns you can do it without breaking existing code

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.