Jump to content

Recommended Posts

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>

Link to comment
https://forums.phpfreaks.com/topic/54099-from-checking-data-and-into-a-database/
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.