zodiac Posted October 2, 2007 Share Posted October 2, 2007 I am having real trouble with my php code, it all looks correct and i have had several people look at it and not see anything wrong with it. I have got a register page where people fill out their details, but when i click submit it seems like it has worked as there was no error messages, but no data actually appears in the database. Can anyone help me, as i have been getting really annoyed at it as i cant think why it isn't working. Please help Zodiac Quote Link to comment https://forums.phpfreaks.com/topic/71531-solved-php-trouble-with-access-database/ Share on other sites More sharing options...
MadTechie Posted October 2, 2007 Share Posted October 2, 2007 Can you post the code (in code tags) so we can see, Form and Code please Quote Link to comment https://forums.phpfreaks.com/topic/71531-solved-php-trouble-with-access-database/#findComment-360129 Share on other sites More sharing options...
zodiac Posted October 2, 2007 Author Share Posted October 2, 2007 lol, yea sorry, <?php if(isset($_POST['submit'])) { $Title = $_POST['title']; $Forename = $_POST['forename']; $Surname = $_POST['surname']; $JobTitle = $_POST['jobtitle']; $AreaCoverage = $_POST['areacoverage']; $Email = $_POST['email']; $UserType = $_POST['usertype']; $MobileNumber = $_POST['mobilenumber']; $Username = $_POST['username']; $txtPassword = $_POST['txtpassword']; // creates a new Common-Object-Model (COM) connection object $adoCon = new COM("ADODB.Connection"); $thisfolder = dirname(__FILE__); // opens the connection using a standard Access connection string try {$adoCon->Open( "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=$thisfolder/scheduler.mdb"); } catch(Exception $e) { die('Sorry - There was a problem with opening the database.<br />'); } try { $adoCon->Execute //query to put data from textboxes to the database table ( "INSERT INTO User ([Employee title], [Employee surname], [Employee forename], [Job title], [Area coverage], ) VALUES ('$Title', '$Forename', '$Surname', '$JobTitle', '$AreaCoverage', '$Email'); INSERT INTO [user type] ([user type]) VALUES ('$UserType'); INSERT INTO Login ([Employee forename], [Employee surname], Username, Password) VALUES ('$Forename', '$Surname', '$Username', '$txtPassword');" ); } catch(Exception $e) { echo 'Sorry - There was a problem with adding the data to the database.<br />'; } $adoCon->Close(); //close connections $adoCon = null; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/71531-solved-php-trouble-with-access-database/#findComment-360134 Share on other sites More sharing options...
zodiac Posted October 2, 2007 Author Share Posted October 2, 2007 And here is the form: it goes just before the php code <form name="form1" method="post" action="Loginpage.php"> <!-- setting page to post form to self --> <table width="50%" border="1"> <tr> <td width="38%"><div align="right" class="style2"><strong>Title:</strong></div></td> <td width="62%"> <select name="select"> <option>Mr</option> <option>Mrs</option> <option>Miss</option> </select> </td> </tr> <tr> <td><div align="right" class="style2"><strong><strong>Forename</strong>:</strong></div></td> <td> <input name="forename" type="text" id="forename"> </td> </tr> <tr> <td><div align="right" class="style2"><strong><strong>Surname</strong>:</strong></div></td> <td><input name="surname" type="text" id="surname"></td> </tr> <tr> <td><span class="style2"></span></td> <td> </td> </tr> <tr> <td><div align="right" class="style2"><strong>Job title : </strong></div></td> <td> <input name="jobtitle" type="text" id="jobtitle"> </td> </tr> <tr> <td><div align="right" class="style2"><strong>Area coverage :</strong></div></td> <td> <input name="areacoverage" type="text" id="areacoverage"> </td> </tr> <tr> <td><div align="right" class="style2"><strong>Email address :</strong></div></td> <td> <input name="email" type="text" id="email"> </td> </tr> <tr> <td><div align="right" class="style2"><strong>User type :</strong></div></td> <td> <select name="usertype" id="usertype"> <option>Admin</option> <option>Employee</option> </select> </td> </tr> <tr> <td><div align="right" class="style2"><strong>Mobile number:</strong></div></td> <td> <input name="mobilenumber" type="text" id="mobilenumber"> </td> </tr> <tr> <td> </td> <td> </td> </tr> <tr> <td><div align="right" class="style2"><strong>Username:</strong></div></td> <td> <input name="username" type="text" id="username"> </td> </tr> <tr> <td><div align="right" class="style2"><strong>Password:</strong></div></td> <td> <input name="txtpassword" type="password" id="txtpassword"> </td> </tr> <tr> <td> </td> <td> <input name="submit" type="submit" id="submit" value="Submit"> </td> </tr> </table> </form> Quote Link to comment https://forums.phpfreaks.com/topic/71531-solved-php-trouble-with-access-database/#findComment-360160 Share on other sites More sharing options...
MadTechie Posted October 2, 2007 Share Posted October 2, 2007 humm, do you have other code that connect to the MDB (that works)? i am not sure if you can send multiple statments to ADODB Connection... i would normally write the code like so.. $conn = new COM("ADODB.Connection") or die("Cannot start ADO"); // Microsoft Access connection string. $conn->Open("DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=$thisfolder/scheduler.mdb"); // SQL statement to build recordset. $rs = $conn->Execute("INSERT INTO User (`Employee title`, `Employee surname`, `Employee forename`, `Job title`, `Area coverage`, `Email address`) VALUES ('$Title', '$Forename', '$Surname', '$JobTitle', '$AreaCoverage', '$Email');"); But i don't use PHP with MS access, so i am probably wrong! Quote Link to comment https://forums.phpfreaks.com/topic/71531-solved-php-trouble-with-access-database/#findComment-360170 Share on other sites More sharing options...
zodiac Posted October 2, 2007 Author Share Posted October 2, 2007 Yea, someone who has done some access said that i can insert into 3 tables, but to just use 3 insert into statements. My friend is having the same problem as me and she only has 1 insert into statement. Just wondering if it is something in the access database stopping the data from going in. The thing which is confusing me the most is the fact that no error messages are coming up, even though i have put some catch error code in there. Quote Link to comment https://forums.phpfreaks.com/topic/71531-solved-php-trouble-with-access-database/#findComment-360186 Share on other sites More sharing options...
MadTechie Posted October 2, 2007 Share Posted October 2, 2007 just an idea try adding this at the start error_reporting(E_ALL); Quote Link to comment https://forums.phpfreaks.com/topic/71531-solved-php-trouble-with-access-database/#findComment-360188 Share on other sites More sharing options...
zodiac Posted October 2, 2007 Author Share Posted October 2, 2007 hmmm...... still not putting the data into the database, or catching any error messages. are you any good with logging in, as i have some php which is falling on the username and password part. I did have the code on the welcome page at the top and it did work, but since i have moved the code the bottom of the login page, it doesnt seem to work or even check the username or password before logging people in. This is the php and form on the login page: <form action="scheduler.php" method="post" name="form1"> <p align="center"><em><strong></strong></em></p> <p align="center" class="style12 style1"><u>Login Details</u><br><br></p> <p align="center"><strong>Username: <input name="Username" type="text" id="Username" size="16" maxlength="16"> <br> Password: <input name="txtPassword" type="password" id="txtPassword" size="16" maxlength="16"> </strong></p> <div align="center"><strong> <input name="btnLogin" type="submit" class="style9" value="Log In"> </strong></div> </form> <form action="register.php" method="post" name="form2" class="style9"> <div align="center"> <input name="btnRegister" type="submit" class="style9" value="Register"> </div> </form> <p class="style9"> </p></td> </tr> </table> <p> </p> <p> </p> <p> </p> <p> </p> </TR> </table> </body> </html> <?php { $Username = $_POST['Username']; $Password = $_POST['txtPassword']; if( ( !$Username ) or ( !$Password ) ) { header( "Location:register.php" ); exit(); } // creates a new Common-Object-Model (COM) connection object $adoCon = new COM("ADODB.Connection"); $thisfolder = dirname(__FILE__); // opens the connection using a standard Access connection string $adoCon->Open( "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=$thisfolder/scheduler.mdb"); //Create sql query $SQL="SELECT tblPassword FROM Login WHERE Username = '$Username'"; // execute query try { $rs = $adoCon->Execute($SQL); } catch(Exception $e) { die( "Could not execute query" ); } //if there isa match the log-in is authenticated if(!$rs->EOF ) { if($Password == $rs->Fields('tblPassword')->Value) { $msg = "Welcome $Username."; //set cookie setcookie('login',$Username,Time()+5*60); } else { header( "Location:Loginpage.php" ); exit(); } } else { header( "Location:Loginpage.php" ); exit(); } } ?> Quote Link to comment https://forums.phpfreaks.com/topic/71531-solved-php-trouble-with-access-database/#findComment-360195 Share on other sites More sharing options...
MadTechie Posted October 2, 2007 Share Posted October 2, 2007 the problem is Header() and setcookie() MUST be used before ANYTHING is outputted to the screen.. Quote Link to comment https://forums.phpfreaks.com/topic/71531-solved-php-trouble-with-access-database/#findComment-360200 Share on other sites More sharing options...
zodiac Posted October 2, 2007 Author Share Posted October 2, 2007 So where abouts does it need to be? at the start of the php, or at the top of the page out side the html? Quote Link to comment https://forums.phpfreaks.com/topic/71531-solved-php-trouble-with-access-database/#findComment-360219 Share on other sites More sharing options...
MadTechie Posted October 2, 2007 Share Posted October 2, 2007 this should work ok <?php if( isset($_POST['submit']) ) //added { $Username = $_POST['Username']; $Password = $_POST['txtPassword']; if( ( !$Username ) or ( !$Password ) ) { header( "Location:register.php" ); exit(); } // creates a new Common-Object-Model (COM) connection object $adoCon = new COM("ADODB.Connection"); $thisfolder = dirname(__FILE__); // opens the connection using a standard Access connection string $adoCon->Open( "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=$thisfolder/scheduler.mdb"); //Create sql query $SQL="SELECT tblPassword FROM Login WHERE Username = '$Username'"; // execute query try { $rs = $adoCon->Execute($SQL); } catch(Exception $e) { die( "Could not execute query" ); } //if there isa match the log-in is authenticated if(!$rs->EOF ) { if($Password == $rs->Fields('tblPassword')->Value) { $msg = "Welcome $Username."; //set cookie setcookie('login',$Username,Time()+5*60); } else { header( "Location:Loginpage.php" ); exit(); } } else { header( "Location:Loginpage.php" ); exit(); } } } ?> <?php //put their where you like echo $msg; ?> <form action="scheduler.php" method="post" name="form1"> <p align="center"><em><strong></strong></em></p> <p align="center" class="style12 style1"><u>Login Details</u><br><br></p> <p align="center"><strong>Username: <input name="Username" type="text" id="Username" size="16" maxlength="16"> <br> Password: <input name="txtPassword" type="password" id="txtPassword" size="16" maxlength="16"> </strong></p> <div align="center"><strong> <input name="btnLogin" type="submit" class="style9" value="Log In"> </strong></div> </form> <form action="register.php" method="post" name="form2" class="style9"> <div align="center"> <input name="btnRegister" type="submit" class="style9" value="Register"> </div> </form> <p class="style9"> </p></td> </tr> </table> <p> </p> <p> </p> <p> </p> <p> </p> </TR> </table> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/71531-solved-php-trouble-with-access-database/#findComment-360222 Share on other sites More sharing options...
zodiac Posted October 2, 2007 Author Share Posted October 2, 2007 Thanks, for helping, there is an error somewhere on that page but computer refusing to show it, so will have to wait till i get to use another computer which works. But i do appreciate your help on this matter. Quote Link to comment https://forums.phpfreaks.com/topic/71531-solved-php-trouble-with-access-database/#findComment-360226 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.