Jump to content

insert and forward id to 2nd page.


turpentyne

Recommended Posts

I stepped away from teaching myself php for a few months, and I want to work more on the site I'd started. But I found a glitch and have forgotten enough to not know what to do.

 

I have a form, that is filled out. I want it to enter the info into a mysql database and then forward to a new page, using the ID to submit to a second table. If I set the form action to the new page, it goes to the new page, but never submits any info to the database.

 

If I set the form action to itself, it does put the information into the database. I'm not sure what problem this might indicate.

 

Forgive me for dropping in the entire code, but I'm at a loss and learning how important it is to have notes. (and I seem to have forgotten how to put code into a box? is it div class="codeheader"?

 

 

 

<html>

<title>submit a new plant form </title>

<link rel="stylesheet" type="text/css" href="gaiapedia_styles.css">

<body>

 

 

 

 

<?php

 

if (isset($_POST['submitted'])) {

$errors = array();

 

 

if (empty($_POST['scientific_name'])) {

$errors[] = 'you forgot to enter the scientific name';

 

} else {

$sn = trim($_POST['scientific_name']);

}

 

if (empty($_POST['common_name_english'])) {

$errors[] = 'you forgot to enter the common name';

 

} else {

$cne = trim($_POST['common_name_english']);

}

 

$description4 = trim($_POST['common_names_spanish']);

$description5 = trim($_POST['common_names_french']);

$description6 = trim($_POST['common_name_chinese']);

$description7 = trim($_POST['taxonomic_domain']);

$description8 = trim($_POST['taxonomic_subkingdom']);

$description9 = trim($_POST['taxonomic_superdivision']);

$description10 = trim($_POST['taxonomic_phylum_divis']);

$description11 = trim($_POST['taxonomic_class']);

$description12 = trim($_POST['taxonomic_order']);

$description13 = trim($_POST['taxonomic_suborder']);

$description14 = trim($_POST['taxonomic_family']);

$description15 = trim($_POST['taxonomic_tribe']);

$description16 = trim($_POST['taxonomic_genus']);

$description17 = trim($_POST['taxonomic_subgenus']);

$description18 = trim($_POST['taxonomic_section']);

$description19 = trim($_POST['taxonomic_series']);

$description20 = trim($_POST['taxonomic_division']);

$description21 = trim($_POST['taxonomic_species']);

$description22 = trim($_POST['taxonomic_variety']);

$description23 = trim($_POST['taxonomic_form']);

$description24 = trim($_POST['itis_serial_number']);

$description25 = trim($_POST['paraphyletic_grade']);

$description26 = trim($_POST['clade1']);

$description27 = trim($_POST['subclade1']);

$description28 = trim($_POST['subclade2']);

$description29 = trim($_POST['subclade3']);

$description30 = trim($_POST['subclade4']);

$description31 = trim($_POST['subclade_order']);

$description32 = trim($_POST['subclade_family']);

$description33 = trim($_POST['earliest_date_known']);

 

if (empty($errors)) {

 

require_once ('sqlconnectfile.php');

 

$query = "INSERT INTO plantae (scientific_name, common_name_english, common_names_spanish, common_names_french, common_name_chinese, taxonomic_domain, taxonomic_subkingdom,

taxonomic_superdivision, taxonomic_phylum_divis, taxonomic_class, taxonomic_subclass, taxonomic_order, taxonomic_suborder, taxonomic_family, taxonomic_tribe, taxonomic_genus,taxonomic_subgenus, taxonomic_section,

taxonomic_series, taxonomic_division, taxonomic_species, taxonomic_variety, taxonomic_form, itis_serial_number, paraphyletic_grade, clade1, subclade1, subclade2, subclade3, subclade4, subclade_order, subclade_family, latest_date_known, earliest_date_known)

VALUES ('$sn', '$cne', '$description4', '$description5', '$description6', '$description7', '$description8',

'$description9', '$description10', '$description11', '$description12', '$description13', '$description14', '$description15', '$description16', '$description17', '$description18', '$description19',

'$description20', '$description21', '$description22', '$description23', '$description24', '$description25', '$description26', '$description27', '$description28', '$description29', '$description30', '$description31', '$description32', '$description33', '$description34', '$description35')";

 

$result = @mysql_query ($query);

 

 

 

if ($result) {

 

if(isset($_POST['scientific_name']))

{

$plant_id=mysql_insert_id();

}

 

 

exit();

} else {

echo 'system error. No plant added';

 

echo '<p>' . mysql_error() . '<br><br>query:' . $query . '</p>';

 

 

 

 

 

 

 

 

exit();

 

}

mysql_close();

 

} else {

 

echo 'error. the following error occured <br>';

foreach ($errors as $msg) {

 

echo " - $msg<br>\n";

 

}

 

} // end of if

 

} // end of main submit conditional

 

?>

 

<form action="insertaplant1.php" method="post"><fieldset><legend><b>Enter your new plant here</b></legend>

 

blahblah

 

<br><br>

Plant name<br>

<table bgcolor=#FFEC8B width=590>

<tr><td>

Scientific Name:<br> <input type="text" name="scientific_name"  value="<?php if(isset($_POST['scientific_name'])) echo $_POST['scientific_name']; ?>" /><br>

<font color=red>*Required field</font><br>

</td>

<td>Common Names:<br> <input type="text" name="common_name_english" value="<?php if(isset($_POST['common_name_english'])) echo $_POST['common_name_english']; ?>" /><br><br>

</td>

<td>Common Name, Spanish:<br> <input type="text" name="common_names_spanish" value="<?php if(isset($_POST['common_names_spanish'])) echo $_POST['common_names_spanish']; ?>" /><br><br>

</td><tr>

 

<td>Common Names, French:<br> <input type="text" name="common_names_french" value="<?php if(isset($_POST['common_names_french'])) echo $_POST['common_names_french']; ?>" /><br><br>

</td>

<td>Common names, Chinese:<br> <input type="text" name="common_name_chinese" value="<?php if(isset($_POST['common_name_chinese'])) echo $_POST['common_name_chinese']; ?>" /><br><br>

</td>

<td>Taxonomic domain:<br> <input type="text" name="taxonomic_domain" value="<?php if(isset($_POST['taxonomic_domain'])) echo $_POST['taxonomic_domain']; ?>" /><br><br>

</td></tr><table>

<br>

 

<b>Taxonomy, traditional</b><br>

<table bgcolor=#EEDD82 width=590>

<tr><td>Kingdom:<br><b>Plantae</b><br>

</td>

<td>Subkingdom:<br> <SELECT NAME="taxonomic_subkingdom" value="<?php if(isset($_POST['taxonomic_subkingdom'])) echo $_POST['taxonomic_subkingdom']; ?>" >

<OPTION VALUE="unknown">unknown

<OPTION VALUE="Tracheobionta - vascular plants">Tracheobionta - vascular plants

<OPTION VALUE="Embryobionta - embryophytes">Embryobionta - embryophytes

</SELECT><br><br>

</td>

<td>Superdivision:<br> <input type="text" name="taxonomic_superdivision" value="<?php if(isset($_POST['taxonomic_superdivision'])) echo $_POST['taxonomic_superdivision']; ?>" /><br><br>

</td></tr>

 

<tr><td>Division/phylum:<br> <input type="text" name="taxonomic_phylum_divis" value="<?php if(isset($_POST['taxonomic_phylum_divis'])) echo $_POST['taxonomic_phylum_divis']; ?>" /><br><br>

</td>

<td>Class:<br> <input type="text" name="taxonomic_class" value="<?php if(isset($_POST['taxonomic_class'])) echo $_POST['taxonomic_class']; ?>" /><br><br>

</td>

<td>Subclass:<br> <input type="text" name="taxonomic_subclass" value="<?php if(isset($_POST['taxonomic_subclass'])) echo $_POST['taxonomic_subclass']; ?>" /><br><br>

</td></tr>

 

<tr><td>Order:<br> <input type="text" name="taxonomic_order" value="<?php if(isset($_POST['taxonomic_order'])) echo $_POST['taxonomic_order']; ?>" /><br><br>

</td>

<td>Suborder:<br> <input type="text" name="taxonomic_suborder" value="<?php if(isset($_POST['taxonomic_suborder'])) echo $_POST['taxonomic_suborder']; ?>" /><br><br>

</td>

<td>Subfamily:<br> <input type="text" name="taxonomic_family" value="<?php if(isset($_POST['taxonomic_family'])) echo $_POST['taxonomic_family']; ?>" /><br><br>

</td></tr>

 

<tr><td>Tribe:<br> <input type="text" name="taxonomic_tribe" value="<?php if(isset($_POST['taxonomic_tribe'])) echo $_POST['taxonomic_tribe']; ?>" /><br><br>

</td>

<td>Genus:<br> <input type="text" name="taxonomic_genus" value="<?php if(isset($_POST['taxonomic_genus'])) echo $_POST['taxonomic_genus']; ?>" /><br><br>

</td>

<td>Subgenus:<br> <input type="text" name="taxonomic_subgenus" value="<?php if(isset($_POST['taxonomic_subgenus'])) echo $_POST['taxonomic_subgenus']; ?>" /><br><br>

</td></tr>

 

<tr><td>Section:<br> <input type="text" name="taxonomic_section" value="<?php if(isset($_POST['taxonomic_section'])) echo $_POST['taxonomic_section']; ?>" /><br><br>

</td>

<td>Series:<br> <input type="text" name="taxonomic_series" value="<?php if(isset($_POST['taxonomic_series'])) echo $_POST['taxonomic_series']; ?>" /><br><br>

</td>

<td>Variety:<br> <input type="text" name="taxonomic_variety" value="<?php if(isset($_POST['taxonomic_variety'])) echo $_POST['taxonomic_variety']; ?>" /><br><br>

</td></tr>

 

<tr><td>Form:<br> <input type="text" name="taxonomic_form" value="<?php if(isset($_POST['taxonomic_form'])) echo $_POST['taxonomic_form']; ?>" /><br><br>

</td>

<td>Itis Serial Number:<br> <input type="text" name="itis_serial_number" value="<?php if(isset($_POST['itis_serial_number'])) echo $_POST['itis_serial_number']; ?>" /><br><br>

</td>

<td>Paraphyletic grade:<br> <input type="text" name="paraphyletic_grade" value="<?php if(isset($_POST['paraphyletic_grade'])) echo $_POST['paraphyletic_grade']; ?>" /><br><br>

</td></tr>

</table>

 

<br>

<b>APG Plant Taxonomy (based on evolutionary tree)</b><br>

<table bgcolor=#E3CF57 width=590>

<tr><td>Clade1:<br> <input type="text" name="clade1" value="<?php if(isset($_POST['clade1'])) echo $_POST['clade1']; ?>" /><br><br>

</td>

<td>subclade1:<br> <input type="text" name="subclade1" value="<?php if(isset($_POST['subclade1'])) echo $_POST['subclade1']; ?>" /><br><br>

</td>

<td>subclade2:<br> <input type="text" name="subclade2" value="<?php if(isset($_POST['subclade2'])) echo $_POST['subclade2']; ?>" /><br><br>

</td></tr>

 

<tr><td>subclade3:<br> <input type="text" name="subclade3" value="<?php if(isset($_POST['subclade3'])) echo $_POST['subclade3']; ?>" /><br><br>

</td>

<td>subclade4:<br> <input type="text" name="subclade4" value="<?php if(isset($_POST['subclade4'])) echo $_POST['subclade4']; ?>" /><br><br>

</td>

<td>subclade_order:<br> <input type="text" name="subclade_order" value="<?php if(isset($_POST['subclade_order'])) echo $_POST['subclade_order']; ?>" /><br><br>

</td>

</tr>

<tr><td colspan=3>subclade_family:<br> <input type="text" name="subclade_family" value="<?php if(isset($_POST['subclade_family'])) echo $_POST['subclade_family']; ?>" /><br>

</td><tr>

</table>

<br>

 

<b>Plant Timeline</b><br>

<table bgcolor=#CDAD00 width=590>

<tr><td>earliest_date_known:<br> <input type="text" name="earliest_date_known" value="<?php if(isset($_POST['earliest_date_known'])) echo $_POST['earliest_date_known']; ?>" /><br><br>

</td>

<td colspan=2>latest_date_known:<br> <input type="text" name="latest_date_known" value="<?php if(isset($_POST['latest_date_known'])) echo $_POST['latest_date_known']; ?>" /><br><br>

</td>

</tr>

</table>

 

</fieldset><br><br>

<input type="hidden" name="submitted" value="TRUE">

<input type="hidden" name="submitted_forward" value='$sn'>

<input type="submit" />

 

 

</form>

 

Link to comment
Share on other sites

You would make the action of your form point to your form processing script (which could be at the top of the form's page, or it could be a new php file), then once the data has been entered into the database (which you said you have already got working), you want to use 'header' to forward onto a new page, instead of loading the form again.

 

header('Location: http://www.example.com/'); //Pulled from php.net

 

Hope that helps.

Denno

Link to comment
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.