dessolator Posted January 11, 2008 Share Posted January 11, 2008 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>'); } ?> Quote Link to comment Share on other sites More sharing options...
drummer101 Posted January 11, 2008 Share Posted January 11, 2008 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>); Quote Link to comment Share on other sites More sharing options...
dessolator Posted January 11, 2008 Author Share Posted January 11, 2008 Hi, No its just displaying the data passed from the form with no error and isn't inserting to the db. Thanks, Ian Quote Link to comment Share on other sites More sharing options...
drummer101 Posted January 11, 2008 Share Posted January 11, 2008 See above Quote Link to comment Share on other sites More sharing options...
toplay Posted January 11, 2008 Share Posted January 11, 2008 Well, in the code you posted, I don't see where the $event_xxx variables are being set. Quote Link to comment Share on other sites More sharing options...
toplay Posted January 11, 2008 Share Posted January 11, 2008 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. Quote Link to comment Share on other sites More sharing options...
dessolator Posted January 11, 2008 Author Share Posted January 11, 2008 Haha that would be why lol, I feel like such a fool I should have seen that . Thanks a lot for your help, Ian Quote Link to comment Share on other sites More sharing options...
revraz Posted January 12, 2008 Share Posted January 12, 2008 Only optional if you insert the exact number of fields that you have in your DB. Quote Link to comment Share on other sites More sharing options...
toplay Posted January 12, 2008 Share Posted January 12, 2008 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 Quote Link to comment 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.