Part of code:
echo "<form method ='post' action='NextFile.cgi'>";
echo "<table>";
echo "<tr><td>Date: </td></td> <input type='date' name='Date' value =".$record['Date']." autofocus required='required'
/></td></tr>";
echo "<tr><td>Time: </td></td> <input type='time' name='Time' value=".$record['Time']." autofocus required='required'
/></td></tr>";
echo "</table>";
echo "<input type='submit' name='submitname' value='Save' />";
echo "</form>";
$record is related to the mysql query.
When running the code in a web browser, the two input boxes are displayed side by side.
Below are the characters />
Below is 'Date:'
Below is 'Time:'
I am trying to alter the code so that Date: is beside the Date input box, and the same for Time below.
How can I do it?
The main problem is your </td></td> which should be </td><td>
$date = $record["Date"];
$time = $record["Time"];
<form method ="post" action="NextFile.cgi">
<table>
<tr><td>Date: </td><td><input type="date" name="Date"$date" autofocus required="required"/></td></tr>
<tr><td>Time: </td><td><input type="time" name="Time"$time" autofocus required="required"/></td></tr>
</table>"
<input type="submit" name="submitname" value="Save" />
</form>
Here's a cleaned up version of your code:
echo '<table>';
echo '<tr><td>Date: </td> <input type="date" name="Date" "value="'.$record['Date'].'" autofocus required="required" /></td></tr>';
echo '<tr><td>Time: </td> <input type="time" name="Time" value="'.$record['Time'].'" autofocus required="required"/></td></tr>';
echo '</table>';
As an explanation, I added the quotes around your values (not sure if that was causing your issue, but it's good form; and your results might have erred without it) and removed the second close row </td> as was mentioned above.
Edit: try it now
Related
Good day experts!!!
In the code below, the copy.php file will create another php base on input values and will send input values on the newly created php file. On the same page, at first the codes works well but if I open the newly created php file directly, it will give an error PHP Warning: Undefined array key "subject/etc.......). How do I put the values permanently on the post section of the newly created file replacing the post code?
Here's my code below:
copy.php
<?php
$file = 'data.php';
$newfile = $_POST["newFileName"].'.php';
if (!copy($file, $newfile)) {
echo "failed to copy";
}else {
echo "<center><form action='$newfile' method='post'>
Name of the exam: <br><input type='text' name='subject' required><br><br>
Instruction: <br><input type='text' name='instruction' required><br><br>
Questions:<br>
<input type='text' name='new_1'><br>
<input type='text' name='new_2'><br>
<input type='text' name='new_3'><br>
<input type='text' name='new_4'><br>
<input type='text' name='new_5'><br><br>
<input type='submit' value='Create Quiz'>
</form></center>";
}
?>
newfile.php
<?php
$subject=$_POST['subject'];
$instruction=$_POST['instruction'];
$q1=$_POST['new_1'];
$q2=$_POST['new_2'];
$q3=$_POST['new_3'];
$q4=$_POST['new_4'];
$q5=$_POST['new_5'];
echo
"<form action='' method='post' onsubmit='alert('SUBMITTED SUCCESFULLY!')'>
Name: <input type='text' name='NAME' required><br><br>
$subject <br><br>
$instruction <br><br>
<input type='text' name='1' required> $q1 <br>
<input type='text' name='2' required> $q2 <br>
<input type='text' name='3' required> $q3 <br>
<input type='text' name='4' required> $q4 <br>
<input type='text' name='5' required> $q5 <br><br>
<input type='submit' value='submit' onclick='return Confirm();'>
</form>";
?>
You can't open newfile.php directely and have the answers.
The copy file call newfile with the form. newfile expect to receive POST datas. If you open directly newfile, you don't have POST data because no datas where sent.
What you can do :
In copy PHP start a session (session_start()) and give a name to the submit button : <input type='submit' value='Create Quiz' name='subForm'>
In newfile.php you can have something like that :
<?php
session_start();
if(isset($_POST['subForm'])){
$_SESSION['copyForm'] = serialize($_POST);
}
$myForm = unserialize($_SESSION['copyForm']);
$subject=$myForm['subject'];
$instruction=$myForm['instruction'];
$q1=$myForm['new_1'];
$q2=$myForm['new_2'];
$q3=$myForm['new_3'];
$q4=$myForm['new_4'];
$q5=$myForm['new_5'];
echo
"<form action='' method='post' onsubmit='alert('SUBMITTED SUCCESFULLY!')'>
Name: <input type='text' name='NAME' required><br><br>
$subject <br><br>
$instruction <br><br>
<input type='text' name='1' required> $q1 <br>
<input type='text' name='2' required> $q2 <br>
<input type='text' name='3' required> $q3 <br>
<input type='text' name='4' required> $q4 <br>
<input type='text' name='5' required> $q5 <br><br>
<input type='submit' value='submit' onclick='return Confirm();'>
</form>";
?>
Basically this is what I have:
<form method="POST" action="model.php">
<input type="hidden" name="from" value="edit">
<?php
include 'model.php';
$contactID = $_POST['editConRad'];
selectSingle($contactID);
echo "<input type='hidden' name='contactID' value='$contactID'>";
echo "<label>First Name:</label>";
echo "<input type="text" name="fname">";
echo "<label>Last Name:</label>";
echo "<input type="text" name="lname">";
echo "<label>Email:</label>";
echo "<input type="email" name="email">";
echo "<label>Street Address:</label>";
echo "<input type="text" name="streetaddress">";
echo "<label>City:</label>";
echo "<input type="text" name="city">";
echo "<label>Province:</label>";
echo "<input type="text" name="province">";
echo "<label>Postal Code:</label>";
echo "<input type="text" name="postalcode">";
echo "<label>Phone:</label>";
echo "<input type="number" name="phone">";
echo "<label>Date of Birth:</label>";
echo "<input type="date" name="yob">";
echo "<input type="submit" value="Submit Edit">";
?>
</form>
And I think there must be a better way to output html instead of having to output each line with echo, I thought there was a print function to do this but I couldnt find one.
Anyone have a better way of doing this? I know I could do one massive echo but there must still be something better.
I guess this way is better than what I have above but still not looking for a better way.
echo '<label>First Name:</label>.
<input type="text" name="fname">.
<label>Last Name:</label>.
<input type="text" name="lname">.
<label>Email:</label>.
<input type="email" name="email">.
<label>Street Address:</label>.
<input type="text" name="streetaddress">.
<label>City:</label>.
<input type="text" name="city">.
<label>Province:</label>.
<input type="text" name="province">.
<label>Postal Code:</label>.
<input type="text" name="postalcode">.
<label>Phone:</label>.
<input type="number" name="phone">.
<label>Date of Birth:</label>.
<input type="date" name="yob">.
<input type="submit" value="Submit Edit">';
You can switch between PHP and HTML whenever you wish just by adding the appropriate tags.
For example:
<?php
echo "This is output from an echo statement<br>"
?>
This is plain old HTML<br>
<?php
echo "And now we're back to PHP<br>"
Your form becomes:
<form method="POST" action="model.php">
<input type="hidden" name="from" value="edit">
<?php
// Do this bit in PHP
include 'model.php';
$contactID = $_POST['editConRad'];
selectSingle($contactID);
?>
<!-- Now switch back to HTML -->
<!-- PHP variable embedded here-------------|................| -->
<input type='hidden' name='contactID' value='<?= $contactID?>'>";
<label>First Name:</label>
<input type="text" name="fname">
<label>Last Name:</label>";
<input type="text" name="lname">
<label>Email:</label>
<input type="email" name="email">
<!-- and so on -->
</form>
<?php
// You can store long text strings in HEREDOC or NOWDOC syntax
$longString = <<<'EOT'
This is an arbitrarily long string, but this one is only short<br>
EOT
echo $longString;
See the PHP manual for all the details on how PHP handles strings, HEREDOC, NOWDOC, and the significance of single and double quotes.
I have one table , in that i have 4 text fields. So when i enter the values in all text field box. And when i press Update button. The entered values are not showing in my database. Here is my code :
This below code is for textfield box:
<td class="answer">
<input type="text" name="Answer1" value='<?php echo $obj["Answer1"]; ?>' /></td>
<td class="answer">
<input type="text" name="Answer2" value='<?php echo $obj["Answer2"]; ?>' /></td>
<td class="answer">
<input type="text" name="Answer3" value='<?php echo $obj["Answer3"]; ?>' /></td>
<td class="answer">
<input type="text" name="Answer4" value='<?php echo $obj["Answer4"]; ?>' /></td>
My update button code :
if(isset($_POST["update_question"]))
{
$Question_Id=$_POST["update_question"];
$Question_Name=$_POST["Question_Name"];
$Answer1=$_POST["Answer1"];
$Answer2=$_POST["Answer2"];
$Answer3=$_POST["Answer3"];
$Answer3=$_POST["Answer4"];
$update_question="UPDATE `tblquestions` SET `Question_Name`='".$Question_Name."', `Answer1`='".$Answer1."', `Answer2`='".$Answer2."', `Answer3`='".$Answer3."', `Answer4`='".$Answer4."',`ModifiedDate`=NOW() WHERE `Question_Id`='".$Question_Id."'";
$update_result=mysqli_query($con,$update_question);
if($update_result)
{
echo "<script> window.location.href='question.php?msg=sucmsg';</script>";
}
else
{
echo "<script> window.location.href='question.php?msg=errmsg';</script>";
}
}
<button type="submit" name="update_question" class="button" value="<?php echo $obj["update_question"]; ?>">Update</button>
When i enter all the field value , and when i press nothing update in my database.Thanks in advance !
You miss these fields in the form:
<input type="hidden" name="Question_Id" value='<?php echo $obj["Question_Id"]; ?>' /></td>
//just to set any value inside to update_question:
<input type="hidden" name="update_question" value='1' /></td>
Change also the button this way:
<input type="submit" class="button">Update</input>
Then in the script:
if(isset($_POST["update_question"]))
{
$Question_Id=$_POST["Question_Id"];
...
}
There's no update_question column in your table, that's the name of the submit button. The column name is Question_Id, so you should use $obj['Question_Id'] instead of $obj['update_question'].
I have a page with mixed sources of content. The top half of it is hard coded html with values echo'd from a db like so:
Part Number: <input type="text" name="pn" size="25" id="1" value="<?php
echo "$STH->pn"; ?>"/>
Part Nomenclature: <input type="text" id="partnomen" name="part_nomenclature"
size="35" value="<?php echo "$STH->part_nomenclature"; ?>"/>
Quantity:<input type="text" name="qty" size="3" value="<?php echo "$STH->qty";
?>"/><br />
Serial Number <input type="text" name="sn" size="25" value="<?php echo "$STH->sn";
?>"/>
ATA Code: <input type="text" name="ata" size="12" value="<?php echo "$STH->ata"; ?>"/>
Control Order: xxxxxx
Engine Model: xxxxxxxx<br />
Engine Serial Number: xxxxxxxx
Removed From A/C Serial# <input type="text" name="acsn" value="<?php echo
"$STH->acsn"; ?>"/>
TT / TC: ___________________-->
<input type="hidden" name="db_date" value="<?php echo "$STH->db_date"; ?>"/>
<h3 id="addinfo">Reason For Workorder: </h3>
The middle contains html and values that are both echo'd onto the page:
echo "
<div id='addlinfo'>
<input type='hidden' name='wo_id' value='$wo_id'/>
Sequence<input type='text' name='sel_id[]' size='1' value='$i'/>
Repair ID:<input type='text' name='repair_id[]' size='1'
value='$STH->repair_id'readonly/>
Part Nomenclature: <input type='text' name='' size='35'
value='$STH->part_nomenclature'readonly/>
Repair Name:<input type='text' name='repair_name[]' size='20'
value='$STH->repair_name' readonly/><br />
Location: <input type='text' name='location[]' size='20' value='$STH->location'
readonly/>
Description:<br /> <textarea id='' rows='5' cols='100' name='description[]'
id='text'>$STH->description</textarea>
</div>";
The bottom half is pulled in from a separate php page using a jquery ajax call like so:
$(document).ready(function(){
$('#button1').click(function(){
$.ajax({
url: 'http://localhost/php_site_copy/process.php',
type: 'POST',
data: {part_name: $('#partnomen').val()},
success: function(msg){
$('#result').html(msg);
}
}); //event handler
});
});
<div id="result"></div><br />
<button id="button1">Add Repairs</button>
The goal here is to collect all of the data displayed into a $_POST from the page but I'm finding that I only get part of the array. The bottom part form elements are not picked up in the post at all and only some of the upper form elements.
You would think that this would work but I'm beginning to think I'm traveling down the wrong road when it comes to mixing content from different sources. Is there a standard that I'm missing or should I just put my nose back to the grindstone?
Edit: to answer quids' question, I'm using Firefox and the form arrangement is like so:
<form action='test_page.php' method='post'/>
<top html inputs/>
<middle inputs/>
<bottom inputs/>
<input type='submit' value='submit'/>
</form>
I am trying to get data from my database to appear in a textbox or textarea so that it can be easily edited, ready to be submitted to the database. For some reason the data displays but not in a textarea, and therefore cant be edited. This could be a syntax issue. Can anyone help? Thank you.
My code is:
while($row = mysqli_fetch_array($result))
{
echo "<div id='item'>";
echo "<form action='updateproductmain.php' method='post'";
echo "<textarea rows='5' cols='20' name='quote' wrap='physical'>" . $row['product_name'] . "</textarea>";
echo "<input type='submit' value='Submit'>";
echo "</form>";
echo "</div>";
}
Missing the end > on your form tag:
while($row = mysqli_fetch_array($result))
{
echo "<div id='item'>";
echo "<form action='updateproductmain.php' method='post'>";
echo "<textarea rows='5' cols='20' name='quote' wrap='physical'>" . $row['product_name'] . "</textarea>";
echo "<input type='submit' value='Submit'>";
echo "</form>";
echo "</div>";
}
Your data probably contains characters that break the html, like < or >.
You should escape your data using htmlspecialchars():
echo "<textarea rows='5' cols='20' name='quote' wrap='physical'>" . htmlspecialchars($row['product_name']) . "</textarea>";
<form action="" method="post" enctype="multipart/form-data">
<table style="border:2px solid black;" >
<tr><td> <input type="text" name="id" value="<?php echo $edit; ?>" style="display:none;"></td><tr></tr>
<tr><td> <input type="text" name="firstname" value="<?php echo $firstname; ?>"></td><tr></tr>
<td> <input type="text" name="lastname" value="<?php echo $lastname; ?>"></td><tr></tr>
<td> <input type="text" name="contact" value="<?php echo $contact; ?>"></td><tr></tr>
<td> <textarea name="address" rows="" cols="" value="<?php echo $address; ?>"></textarea></td><tr></tr>
<tr><td><input type="file" name="image" ></td></tr>
<tr><td><input type="text" name="image" style="display:none;" value="<?php echo $image?>"></td><tr></tr>
<td> <input type="submit" name="update" value="update"></td>
</table>
</form>