Combine 2 .php web forms into 1 .php web form.
Thank any one for viewing! Up front, Im 6 weeks into .php, therefore please be easy one me. I have 2 php forms. Form#1 collects user data / saves to sql db. Form#2 edits db records / saves to db. I also us a Form#3 that selects db records by keyfield and repopulates both Form#1 and Form#2.
How is it possible to combine Form#1 and Form#2 into a single form. Where this single form handles both the user data collection / save and edit / save.
Any direction, sample code, instruction or thoughts would be so helpful. I have read and tested for a solution with all failures. Please help for a solution. Thank You!
Code:
<body>
<!-- // dB Connection - php save form input data to Database // -->
<?php
require('db.php');
if (isset($_GET['name'])){
$tapcon_title = $_GET['tapcon_title'];
$name = $_GET['name'];
$age = $_GET['age'];
$hobby = $_GET['hobby'];
$background_image = $_GET['background_image'];
$trn_date = date("Y-m-d H:i:s");
$query = "INSERT into `search` (tapcon_title, name, age, hobby, background_image, trn_date) VALUES ('$tapcon_title', '$name', '$age', '$hobby', '$background_image', '$trn_date')";
$result = mysql_query($query);
if($result){
echo "<div class='form'><h1>Save to db was successfull.</h1><p> I need a button here to close this page, revieling the TapCon Builder page with form input attrubutes in place.</p>
<br/><h3>Click here to return <a href='https://jakursmu.com/tapcon_builder_development/tb_form_insert_to_db.php'>Db Search</a></h3>
</div>";
}
}else{
// Search db for record - display result in form inputs
// Form1.php
$search=$_GET['search'];
$data = 'SELECT * FROM `search` WHERE `name` = "'.$search.'"';
$query = mysql_query($data) or die("Couldn't execute query. ". mysql_error());
$data2 = mysql_fetch_array($query);
?>
<!-- // Form.html - get key detail of record from database // -->
<div class="form">
<h2> Search db for earlier TapCon by Name</h2>
<form target="_self" name="form" method="GET" action="">
Enter TapCon Name <input type="text" name="search" /> <br /><br />
<input type="submit" value="Search db for TapCon" />
</form>
</div>
<br/>
<!-- // TapCon Builder Form #1 Inputs // -->
<div class="form">
<h2> TapCon Builder</h2>
<form target="_blank" method="GET" action="">
<p> TapCon Title:<input name="tapcon_title" type="text" value="<?php echo $data2[tapcon_title]?>" /> </p>
<p> Name:<input name="name" type="text" placeholder="Name" value="<?php echo $data2[name]?>"/> </p>
<p> Age:<input name="age" type="text" placeholder="Age" value="<?php echo $data2[age]?>"/> </p>
<p> Hobby:<input name="hobby" type="text" placeholder="Hobby" value="<?php echo $data2[hobby]?>" /> </p>
<p> TapCon Background Image / Color:<input name="background_image" type="file" value="<?php echo $data2[background_image]?>"/></p>
<input type="submit" value="Preview TapCon" formaction="tapcon_builder_template.php" >
<input type="submit" value="Save TapCon to DB" formaction="" >
</form>
</div>
<br/>
<!-- // Form1.php - Display / Edit record from database Form #2 Inputs // -->
<div class="form">
<h2> TapCon Editor</h2>
<form target="_self" name="form" method="GET" action="">
<p>TapCon Title:<input type="text" name="tapcon_titlefield" value="<?php echo $data2[tapcon_title]?>" /></p>
<p>Name:<input type="text" name="namefield" value="<?php echo $data2[name]?>"/></p>
<p>age:<input type="text" name="agefield" value="<?php echo $data2[age]?>"/></p>
<p>hobby:<input type="text" name="hobbyfield" value="<?php echo $data2[hobby]?>"/></p>
<p> TapCon / <input name="background_image" type="file" value="<?php echo $data2[background_image]?>"/></p>
<p><input type="hidden" name="keyfield" value="<?php echo $search?>"></p>
<p><input type="submit" value="submit to Edit TapCon">
</form>
</div>
<h2> TapCon Edit Results</h2>
<!-- // Form2.php Db Edit Results // -->
<?php
$Key=$_GET['keyfield'];
$Tapcon_Title=$_GET['tapcon_titlefield'];
$Name=$_GET['namefield'];
$Age=$_GET['agefield'];
$Hobby=$_GET['hobbyfield'];
$Background_Image=$_GET['background_imagefield'];
$data = "UPDATE `search` SET tapcon_title='$Tapcon_Title', name='$Name', age='$Age', hobby='$Hobby', background_image='$Background_Image' WHERE name=".'"'.$Key.'"';
$query = mysql_query($data) or die("Couldn't execute query. ". mysql_error());
?>
<!-- display the changed record from database -->
TapCon Title: <?php echo $Tapcon_Title?><br>
Name: <?php echo $Name?><br>
Age: <?php echo $Age?> <br>
Hobby: <?php echo $Hobby?><br>
Background Image: <?php echo $Background_Image?><br>
<br>
<br />
<?php } ?>
</body>