yoda69 Posted June 3, 2007 Share Posted June 3, 2007 Hi, Been working on this for a while with very slow progress, would appreciate your help a lot. Here is what i am trying to achieve: 1. a very simple from (1.php) that store some information and send it to the next page for a check 2. a second page (2.php), which present the data to the user and then ask him to confirm. on the same page the user confirm and then the data is inserted into the database. 3. a successful insertion ends with a "tnx" message in a tnx.php page. What happens is that everything works well until the user confirm in the second page the insertion into the database. When the "submit" is pushed, then the database is inserted with a blank line. It must be a problem with the variables, but since I really don't have a lot of experience in programming I don't know where my problem lies. Thanks, Here is 1.php: <html> <body> <form action="2.php" method="post"> <p>Enter your data here:</p> <p>Discipline:</p> <p><input type="text" name="discipline" size="63"></p> <p>Name of teacher:</p> <p><input type="text" name="teacher" size="64"></p> <input type="submit" name="GO" value="SUBMIT" /> </p> </form> <?php $discipline = $_POST['discipline']; $teacher = $_POST['teacher']; ?> </body> </html> Here is 2.php: <html> <body> <?php echo "<br/> Is this data correct? <br/> <br/>Discipline = $discipline<br/> <br/>Teacher = $teacher <br/> "; ?> <form action="tnx.php" method="post"> <input type="submit" name="SendToDatabase" value="Okay" /> </p> </form> <?php // Connect to the database server $dbcnx = @mysql_connect('myWebServer', 'user', 'pass'); if (!$dbcnx) { die( '<p>Unable to connect to the ' . 'database server at this time.</p>' ); } // Select the teaching database if (! @mysql_select_db('myDatabase') ) { die( '<p>Unable to locate the teaching ' . 'database at this time.</p>' ); } // If a teaching has been submitted, // add it to the database if (isset($_POST['SendToDatabase'])) { $sql = "INSERT INTO teachings SET discipline='$discipline', teacher ='$teacher'"; mysql_query($sql) or die('Error, insert query failed'); } ?> </body></html> Quote Link to comment https://forums.phpfreaks.com/topic/54099-from-checking-data-and-into-a-database/ Share on other sites More sharing options...
penguin0 Posted June 3, 2007 Share Posted June 3, 2007 This is how your query should look: if (isset($_POST['SendToDatabase'])) { $sql = "INSERT INTO teachings (discipline, teaching) VALUES ('$_POST[discipline]', '$_POST[teaching]')"; $result = @mysql_query($sql) or die(mysql_error()); } Quote Link to comment https://forums.phpfreaks.com/topic/54099-from-checking-data-and-into-a-database/#findComment-267468 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.