Jump to content

Creating A Record Into Database


Broth3R

Recommended Posts

Thanks guys! I managed to fix the blank page now. But the real problem is, when I entered the details and hit the submit button, the record won't appear in the database. 'INSERT INTO User values' should work >:) frustrating.http://carus.aces.shu.ac.uk/students/a8028...er/viewpage.phpThis is my form: (viewpage.php)

<form method="post" action="viewpage1.php">User Number must be between 1 and 999.<BR>UserNumber: <input type="text" name="UserNumber" size="40" length="40" value=""><BR>Initial: <input type="text" name="Initial" size="40" length="40" value=""><BR>FirstName: <input type="text" name="FirstName" size="40" length="40" value=""><BR>LastName: <input type="text" name="LastName" size="40" length="40" value=""><BR>Address1: <input type="text" name="Address1" size="40" length="40" value=""><BR>PostCode: <input type="text" name="PostCode" size="40" length="40" value=""><BR>Email: <input type="text" name="Email" size="40" length="40" value=""><BR>PhoneNo: <input type="text" name="PhoneNo" size="40" length="40" value=""><BR>Gender: <input type="text" name="Gender" size="40" length="40" value=""><BR><BR><INPUT TYPE="Reset" ><INPUT TYPE="submit" VALUE="Submit"></form>

This is the code I use to insert a data: (viewpage1.php)

<?php$UserNumber=$_POST["UserNumber"];$Initial=$_POST["Initial"];$FirstName=$_POST["FirstName"];$LastName=$_POST["LastName"];$Address1=$_POST["Address1"];$PostCode=$_POST["PostCode"];$Email=$_POST["Email"];$PhoneNo=$_POST["PhoneNo"];$Gender=$_POST["Gender"];Print "You entered '$UserNumber' '$Initial' '$FirstName' '$LastName' '$Address1' '$PostCode' '$Email' '$PhoneNo' '$Gender'";$sql = "INSERT INTO User values ('$UserNumber', '$FirstName','$LastName','$Address1','$PostCode','$Email','$PhoneNo','$Gender')"; print "<br>";$connstr = "DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=". realpath("ImageAsset.mdb").";";$conn=odbc_connect($connstr,'','');$stmt = odbc_exec($conn,$sql);odbc_close($conn);?>

Link to comment
Share on other sites

Thanks for replying, but I still get the blank page. I added the code at the top of my php code right after <?php. Still get a black white page. Is it someting to do with my css code?Input page - viewpage.phphttp://carus.aces.shu.ac.uk/students/a8028...er/viewpage.phpThis is everything in my viewpage1.php

<title>Tana Photography</title><link rel="shortcut icon" href="http://carus.aces.shu.ac.uk/students/a8028496/wfolder/picture/icon.jpg" /><head><style type="text/css">body {	background-color: #000000;	margin: 0 20px 0 20px;}.align-center {	text-align: center;}#container {	width: 650px;	margin-left: auto;	margin-right: auto;}#logo {	margin: 0px 0 0px 0;}#intro {	font-size: 197%;	color: #606060;}#choices {	margin: 0px 0 0 0;	word-spacing: 1.0em;	color: #606060;}</style></script></head><html><body><div id="container"><div id="logo" class="align-center"><a href="http://carus.aces.shu.ac.uk/students/a8028496/wfolder/homepage.php">		<img border= "0" src ="http://carus.aces.shu.ac.uk/students/a8028496/wfolder/picture/logo.jpg" width="650" height="190" alt="logo" />		</a></div></div><div id="intro" class="align-center">	Record Inserted</div><div id="choices" class="align-center">	<FORM><INPUT TYPE="BUTTON" VALUE="OK" ONCLICK="window.location.href='http://carus.aces.shu.ac.uk/students/a8028496/wfolder/view.php'"></FORM>	<head><title> Inserting a record </title></head><?php$Initial=$_POST["Initial"];$FirstName=$_POST["FirstName"];$LastName=$_POST["LastName"];$Address1=$_POST["Address1"];$PostCode=$_POST["PostCode"];$E-mail=$_POST["E-mail"];$PhoneNo=$_POST["PhoneNo"];$Gender=$_POST["Gender"];Print "You entered '$Initial' '$FirstName' '$LastName' '$Address1' '$PostCode' '$E-mail' '$PhoneNo' '$Gender'";$sql = "INSERT INTO CreateUser values ($FirstName,'$LastName','$Address1','$PostCode','$E-mail','$PhoneNo','$Gender')"; print "<br>";$connstr = "DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=". realpath("ImageAsset.mdb").";";$conn=odbc_connect($connstr,'','');$stmt = odbc_exec($conn,$sql);print "Record Inserted OK";odbc_close($conn);?><BR><BR></body></html>

Link to comment
Share on other sites

IT DOESN'T HAV E ANY THING TO DO WITH UR CSS WHAT U HAVE TO DO IS THAT U INSERT THE ERROR REPORT THEN WRITE UR ERROR MESSAGE AFTER ANY EXECUTION SO THAT IF A PARTICULAR LINE DIDN'T EXECUTE THEN IT WILL SHOW THE ERROR U ASSIGNED TO THAT LINE, BY DOING SO U WILL BE ABLE TO KNOW WHERE THE ERROR IS COMING FROM....IF U STILL EXPERIENCE THE SAME PROBLEM THEN STILL LET US KNOW

Link to comment
Share on other sites

A blank page usually means a syntax error. This means your page won't parse. This means that your error reporting statement never gets executed, because the script is terminated before it ever runs.Try commenting out all your PHP statements. See if the page loads. Then un-comment half of your statements at a time until you find the error.That is, un-comment half. If it runs, un-comment half of the remaining statements. When it stops running, you know which section contains the error. Comment and un-comment until you find the statement.It takes much less time than it seems.ORCreate a file called test.php . Switch on error reporting in that file. Make sure it runs. Than use an include statement to include the file that's giving you problems. That should also locate the syntax error.

Link to comment
Share on other sites

Thanks guys! I managed to fix the blank page now. But the real problem is, when I entered the details and hit the submit button, the record won't appear in the database. 'INSERT INTO User values' should work >:) frustrating.http://carus.aces.shu.ac.uk/students/a8028...er/viewpage.phpThis is my form: (viewpage.php)

<form method="post" action="viewpage1.php">User Number must be between 1 and 999.<BR>UserNumber: <input type="text" name="UserNumber" size="40" length="40" value=""><BR>Initial: <input type="text" name="Initial" size="40" length="40" value=""><BR>FirstName: <input type="text" name="FirstName" size="40" length="40" value=""><BR>LastName: <input type="text" name="LastName" size="40" length="40" value=""><BR>Address1: <input type="text" name="Address1" size="40" length="40" value=""><BR>PostCode: <input type="text" name="PostCode" size="40" length="40" value=""><BR>Email: <input type="text" name="Email" size="40" length="40" value=""><BR>PhoneNo: <input type="text" name="PhoneNo" size="40" length="40" value=""><BR>Gender: <input type="text" name="Gender" size="40" length="40" value=""><BR><BR><INPUT TYPE="Reset" ><INPUT TYPE="submit" VALUE="Submit"></form>

This is the code I use to insert a data: (viewpage1.php)

<?php$UserNumber=$_POST["UserNumber"];$Initial=$_POST["Initial"];$FirstName=$_POST["FirstName"];$LastName=$_POST["LastName"];$Address1=$_POST["Address1"];$PostCode=$_POST["PostCode"];$Email=$_POST["Email"];$PhoneNo=$_POST["PhoneNo"];$Gender=$_POST["Gender"];Print "You entered '$UserNumber' '$Initial' '$FirstName' '$LastName' '$Address1' '$PostCode' '$Email' '$PhoneNo' '$Gender'";$sql = "INSERT INTO User values ('$UserNumber', '$FirstName','$LastName','$Address1','$PostCode','$Email','$PhoneNo','$Gender')"; print "<br>";$connstr = "DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=". realpath("ImageAsset.mdb").";";$conn=odbc_connect($connstr,'','');$stmt = odbc_exec($conn,$sql);odbc_close($conn);?>

Link to comment
Share on other sites

Try executing your SQL with plain text instead of variables. Make sure that your connection and query syntax are 100% correct before you try it with variable data. You could even try this with a small, separate test script.You should also be testing the return values of your odbc function calls. The way your script is written now, you don't even know if you have a connection. Then you don't know what happens with your query. So in your test script, echo ($conn) and echo ($stmt) . (You should not even call odbc_exec() if odbc_connect() returns false. Add some if blocks.)

Link to comment
Share on other sites

Try executing your SQL with plain text instead of variables. Make sure that your connection and query syntax are 100% correct before you try it with variable data. You could even try this with a small, separate test script.You should also be testing the return values of your odbc function calls. The way your script is written now, you don't even know if you have a connection. Then you don't know what happens with your query. So in your test script, echo ($conn) and echo ($stmt) . (You should not even call odbc_exec() if odbc_connect() returns false. Add some if blocks.)
I'm not sure what you mean, I am very new to PHP. Only started a few weeks ago doing web design.
Link to comment
Share on other sites

Before you go testing your form submission mechanism, you need to test your DB mechanism. Otherwise you won't know where to look for your problem. So write a small test script. The following should cover it.querytest.php

<?php   $sql = "INSERT INTO User values ('123', 'Bob','Smith','100 High St','ABC','bob@smith.com','9876','male')";   $connstr = "DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=" . realpath("ImageAsset.mdb") . ";";   $conn = odbc_connect($connstr, '', '');   if (!$conn) {	  die ('No connection');   }   $stmt = odbc_exec($conn, $sql);   if (!$stmt) {	  die ('Query failed');   }   odbc_close($conn);?>

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...