I can not get my form to $_POST. Does anyone have any ideas?
<?php
require_once ($_SERVER['DOCUMENT_ROOT'].'/functions/requirements.php');
if ($_SESSION['loggedin'] != true){
forceRedirect('./hub.php?page=login', 0);
}else{
$row = DB::queryFirstRow("SELECT status FROM app_vendor WHERE user_id=%i LIMIT 1", $_SESSION['user_id']);
$status = ($row['status'] - 1);
if (isset($_POST['submit'])){
echo "worked";
//forceRedirect('./hub.php?page=dashboard', 0);
//die();
}else{
include ($_SERVER['DOCUMENT_ROOT'].'/vendor_template/top.php');
function label($url,$file){
$html =<<<EOF
<li>
<img width="250" height="300" alt="---Non Viewable PDF DOCUMENT---"" src="$url" />
<div class="text">
<!-- <div class="inner">Sample Caption on Hover</div> -->
</div>
<input type="text" name ="$file" id="form-field-1" placeholder="Document name" class="col-xs-10 col-sm-30">
</li>
EOF;
return $html;
}
if ($documents = DB::query("SELECT name, url FROM files WHERE user_id=%i AND status=%i", $_SESSION['user_id'] , $row['status'])){
echo '<h3> <center> Please label your documents </center> </h3>';
echo '<form method = "POST">';
echo '<ul class="ace-thumbnails clearfix">';
foreach ($documents as $document){
$file = substr($document['name'], 0, -4);
echo label('../'.$document['url'],$file);
}
echo '</ul>';
echo '<center>';
echo '<br>';
echo '<br>';
echo '<br>';
//echo '<button type="submit" value ="submit" class="btn btn-primary" data-toggle="button" aria-pressed="false">Submit</button>';
echo '<input type="submit" name="sumbit" value="submit" />';
echo '</center>';
echo '</form>';
}
include ($_SERVER['DOCUMENT_ROOT'].'/vendor_template/bottom_label.php');
}
}else{
// not logged in
}
?>
Ask me for any questions. When I submit the form I get no return from $_POST['submit']. I hope I am missing something I over looked. Any help would be appreciated.
SOLVED. RE Wrote the code and it fixed it. Removed the function and combined the html with the php. Thanks everyone for the help!
Related
How to make that at the push of a button
"<input type ='submit' name='delete' value='Delete messages'>"
deleted messages selected by a checkbox? All messages and checkboxes appear through the counter "for" as messages are received. What im doing wrong? I think i have mistake with foreach and form action. Please, help me
my code is:
<php function display_list($auth_user, $accountid, $messageid, $fullheaders) {
if(!$accountid) {
echo "<p style=\"padding-bottom: 100px\">No mailbox selected.</p>";
} else {
$imap = open_mailbox($auth_user, $accountid);
if($imap) {
$headers = imap_headers($imap);
$messages = count($headers); ?>
<div class="view-mailbox-block">
<div class="new-message">
<form action="index.php?action=new-message" method="post">
<input type ='submit' value='Write a letter'>
</form>
</div>
<form action="" method="post">
<input type ='submit' name='delete' value='Delete messages'>
</form>
</div>
<div class="incoming-sent-messages-mail">
<p>Почта</p>
</div>
<div class="incoming-sent-messages">
<div class="incoming-sent-messages-p">
<p>
<?php echo "<a href='index.php?action=view-mailbox'>"; ?> View </a>
</p>
<p>
<?php echo "<a href='index.php?action=view-mailbox-sent'>"; ?> Sent </a>
</p>
</div>
</div>
<div>
<div class="senders overflow">
<form class="sender-checkbxes">
<?php echo '<input type="checkbox" name="deleteall" value="checkbox-all">'; ?>
<?php for ($i = 0; $i < $messages; $i++) {
echo "<div><div>";
echo '<input type="checkbox" name="delete[]" value="<?php echo $delete ?>">';
echo "</form>";
echo "</div></div>\n";
} ?>
<form action='index.php?action=delete&messageid='<?php echo $check;?>'>
<?php if(!empty($_POST['delete'])) {
foreach($_POST['delete'] as $check) {
imap_delete($imap, $check);
imap_expunge($imap);
imap_close($imap);
return true;
}
} ?>
</form>
</div>
I have tried to solve it and look around but not even sure what I should be searching for.
I have made a product grid through a while loop, in the loop with each product and input-tag has been used for users to mark how many items of each product is wanted.
The product grid
However I have trouble distinguishing the value of each input field and what "name" it should be stored under to be able to retrieve it when running the second script of processing the order? I also need to be able to connect an id with each value.
The code for the grid:
I know I need to make a unique name in the input name, however how and which makes sense?
<div id="content">
<h1>Products</h1>
<form action="processorder.php" method="post">
<table align="center">
<?php
$db = include "connect2db.php";
mysqli_set_charset($db,"utf8");
$query = 'SELECT * FROM products_josie';
$result = $db->query($query);
$count = 0;
while($res=$result->fetch_assoc())
{
if($count==3)
{
echo '</tr>';
$count = 0;
}
if($count==0)
echo '<tr>';
echo '<td>';
?>
<a href="productsdetails.php?clickedid=<?php echo $res['product_id']?>">
<img src="products/<?php echo $res['photo']; ?>" width="200" height="150"/>
</a>
<br/>
<?php
echo '<p>';
echo $res['product_name'];
echo '</br>';
echo 'DKK ';
echo $res['price'];
echo '</p>';
echo '<p>';
echo '<input type="number" name="amount" min="0"';
echo '</p>';
$count++;
print '</td>';
}
if($count>0)
print '</tr>';
?>
</table>
<input type="submit" value="Submit Order">
</form>
</div>
I think what you are looking for is how to get the amounts for different products. If so, something like this might do it:
$prod = $res['product_name'];
echo '<input type="number" name="amount[$prod]" min="0"';
This is my code I want to add one input field for every image preview and save it to db.. the field is coming but I'm not getting any data.. can anyone suggest how can I post them???
$fetch_imgid=$con->prepare("SELECT * FROM attempt010 where link='$rand'");
$fetch_imgid->setFetchMode(PDO:: FETCH_ASSOC);
$fetch_imgid->execute();
?>
<ul class="reorder_ul reorder-photos-list" id="previewImg">
<?php
while($row = $fetch_imgid->fetch()):
$delid = $row['id'];
//echo $row['id'].' '.$row['name'].'<br/>';?>
<li id="image_li_<?php echo $row['id']; ?>" class="ui-sortable-handle" data-image-id="<?php echo $delid; ?>">
<img src="uploads/<?php echo $row['name']; ?>" alt="">
<input type="submit" class="del_btn" value="Delete Image" />
<input type="text" id="cap" name="cap[]" placeholder="Enter Caption Here" />
<input type="hidden" id="cap_id" value="<?php echo $row['id']; ?>" />
<?php
endWhile;
?>
</ul>
<input type="submit" value="Add Caption" name="addcap" /> <?php include('addcap.php'); ?>
and this is addcap.php
<?php
error_reporting(E_ALL);
ini_set('display_errors',1);
if(isset($_POST['addcap'])){
foreach($_POST['cap'])
{
$imgcap = $_POST['cap'];
if($imgcap!=empty())
{
try
{
$con=new PDO("mysql:host=localhost;dbname=newimg","root","");
$sql=$con->prepare("UPDATE attempt010 SET caption='$imgcap' WHERE id='$cap_id'");
$sql->execute();
}
catch(PDOException $e)
{
echo $sql . "<br>" . $e->getMessage();
}
}
}
}
?>
<input type="hidden" id="cap_id" value="<?php echo $row['id']; ?>" />
Must have unique id. You can't send multiple fields with same id. You will get only last one.
For example:
$fetch_imgid=$con->prepare("SELECT * FROM attempt010 where link='$rand'");
$fetch_imgid->setFetchMode(PDO:: FETCH_ASSOC);
$fetch_imgid->execute();
?>
<form action="addcap.php" method="post">
<ul class="reorder_ul reorder-photos-list" id="previewImg">
<?php
$id_array="";
while($row = $fetch_imgid->fetch()):
$id_array = $id_array.$row['id'].",";
$delid = $row['id'];
//echo $row['id'].' '.$row['name'].'<br/>';?>
<li id="image_li_<?php echo $row['id']; ?>" class="ui-sortable-handle" data-image-id="<?php echo $delid; ?>">
<img src="uploads/<?php echo $row['name']; ?>" alt="">
<input type="text" id="cap_<?php echo $row['id']; ?>" placeholder="Enter Caption Here" />
<?php
endWhile;
$id_array = substr($id_array, 0, -1);
?>
<input type="hidden" id="cap_ids" value="<?php echo $id_array ; ?>" />
</ul>
<input type="submit" value="Add Caption" name="addcap" />
</form>
<!--addcap.php-->
<?php
error_reporting(E_ALL);
ini_set('display_errors',1);
if(isset($_POST['addcap'])){
if(isset($_POST['cap_ids'])){
$ids_array = explode(",", $_POST['cap_ids']);
foreach($ids_array as $ids)
{
$idcap = 'cap_'.$ids;
$imgcap = $_POST[$idcap];
if($imgcap!=empty())
{
try
{
$con=new
PDO("mysql:host=localhost;dbname=newimg","root","");
$query = "UPDATE attempt010 SET
caption='$imgcap' WHERE id='$ids'";
echo $query;
$sql=$con->prepare($query);
$sql->execute();
}
catch(PDOException $e)
{
echo $sql . "<br>" . $e->getMessage();
}
}
}
}
}
?>
This code looks like it can't work. Because you have submit and form handling code in same page. The idea behind form is to post data to different page(set in form action) and this page will do something with this data and display results to the user. For your example to work make form in your first file like:
<form action="addcap.php">
<inputs here>
</form>
Nowadays it is common that database operations are done asynchronic on server side, when user can continue using the page/app.
So learn how to use jQuery and AJAX. Maybe nodeJS or other new stuff.
This is kind of the error I'm getting:
Database query failed.
I've uploaded this webpage: http://widgetcorp.bugs3.com/public/edit_subject.php?subject=1
Here's my file:
<?php require_once("../includes/session.php"); ?>
<?php require_once("../includes/db_connection.php"); ?>
<?php require_once("../includes/functions.php"); ?>
<?php require_once("../includes/validation_functions.php"); ?>
<?php find_selected_page(); ?>
<?php
if (!$current_subject)
{
// subject ID was missing or invalid or
// subject couldn't be found in database
redirect_to("manage_content.php");
}
?>
<?php
if (isset($_POST['submit']))
{
// validations
$required_fields = array("menu_name", "position", "visible");
validate_presences($required_fields);
$fields_with_max_lengths = array("menu_name" => 30);
validate_max_lengths($fields_with_max_lengths);
if (empty($errors))
{
// Perform Update
$id = $current_subject["id"];
$menu_name = mysql_prep($_POST["menu_name"]);
$position = (int) $_POST["position"];
$visible = (int) $_POST["visible"];
$query = "UPDATE subjects SET ";
$query .= "menu_name='{$menu_name}', ";
$query .= "position={$position}, ";
$query .= "visible={$visible} ";
$query .= "WHERE id={$id} ";
$query .= "LIMIT 1";
$result = mysqli_query($connection, $query);
if ($result && mysqli_affected_rows($connection) >= 0)
{
// Success
$_SESSION["message"] = "Subject updated.";
redirect_to("manage_content.php");
}
else
{
// Failure
$message = "Subject update failed.";
}
}
}
// else
// {
// // This is probably a GET request
// }
?>
<?php include("../includes/layouts/header.php"); ?>
<div id="main">
<div id="navigation">
<?php
echo navigation($current_subject, $current_page);
?>
</div>
<div id="page">
<?php
// echo message();
// $message is just a variable, doesn't use the SESSION
if(!empty($message))
{
echo "<div class=\"message\">" . htmlentities($message) . "</div>";
}
?>
<?php echo form_errors($errors); ?>
<h2>Edit Subject: <?php echo htmlentities($current_subject["menu_name"]); ?></h2>
<form action="edit_subject.php?subject=<?php echo htmlentities($current_subject["menu_name"]); ?>" method="post">
<p>Menu name:
<input type="text" name="menu_name" value="<?php echo htmlentities($current_subject["menu_name"]); ?>" />
</p>
<p>Position:
<select name="position">
<?php
$subject_set = find_all_subjects();
$subject_count = mysqli_num_rows($subject_set);
for ($count=1; $count <= $subject_count; $count++)
{
echo "<option value=\"{$count}\"";
if ($current_subject["position"] == $count)
{
echo " selected";
}
echo ">{$count}</option>";
}
?>
</select>
</p>
<p>Visible:
<input type="radio" name="visible" value="0" <?php if ($current_subject["visible"] == 0) { echo "checked"; } ?> /> No
<input type="radio" name="visible" value="1" <?php if ($current_subject["visible"] == 1) { echo "checked"; } ?> /> Yes
</p>
<input type="submit" name="submit" value="Edit Subject" />
</form>
<br />
Cancel
Delete Subject
</div>
The problem is somewhere else and not with your UPDATE query actually. If you see the link you posted, you are passing subject parameter with url, whose value is 1 which is integer.
Now when you click submit it's changing the url to http://widgetcorp.bugs3.com/public/edit_subject.php?subject=About%20Widget%20Corp .
Here as you see the subject parameter is not integer but string value name of subject. And that is causing the problem.
You are getting error as it's not retrieving the subject data from database correctly because of wrong id type. You just need to make sure the form is being posted to right url, which would be http://widgetcorp.bugs3.com/public/edit_subject.php?subject=1.
You need to correct the action parameter on the <form> tag for that.
Look for the line below in your code:
<form action="edit_subject.php?subject=<?php echo htmlentities($current_subject["menu_name"]); ?>" method="post">
And change it to
<form action="edit_subject.php?subject=<?php echo htmlentities($current_subject["id"]); ?>" method="post">
If you see, now the form will be submitted to http://widgetcorp.bugs3.com/public/edit_subject.php?subject=1, which is the correct url.
I have a field set and inside it i have a form . it does not work . i mean to say . when i see the tags using firebug , the form tags will not be there at all..how do u i get over it.
this is how the code goes...its a php code..
<div id="dialog-form_surg_couns" title=" Surgical Counselling">
<?php
$surgCount = 0;
foreach($this->surgery as $surgery) {
$surgCount++;
$newId = str_replace(' ','',$surgery->getSurgeryname());
?>
<div class='fieldreq1Pct'>
<div class='fieldItemLabel'>
<label for=''><?php echo $surgery->getSurgeryname() ?></label>
</div>
<div class='fieldItemValue'>
<input type='checkbox' class='surg_couns_tests' id="<?php echo $newId ?>" name='surg_couns_tests' value="<?php echo $surgery->getSurgeryname() ?>" <?php echo (($showValue && strstr($visitRecord->getSurgcounstests(),$surgery->getSurgeryname())) ? 'checked' : "" ); ?> onClick="javascript:showBlock(this.id);">
</div>
</div>
<?php
if(($surgCount % 3) == 0)
{
?>
<div class='clear'></div>
<?php
}
}
?>
<div class='clear'></div>
<hr/>
<?php
foreach($this->surgery as $surgery) {
$newId = str_replace(' ','',$surgery->getSurgeryname());
$fieldCount = 0;
?>
<div id='<?php echo $newId ?>_block' style='display:none;' class='check_block'>
<form method='POST' action ='' id ='<?php echo $newId ?>_form'>
<table border='0' class='surg_table'>
<?php
foreach($this->surgeryTemplate as $surgerytemplate) {
if($surgery->getSurgeryid() == $surgerytemplate->getSurgeryid())
{
$fieldCount++;
$fieldName = 'field'.$fieldCount;
$fieldId = $surgerytemplate->getFieldid();
if($surgerytemplate->getRequired() == 'Y')
{
$required = 'required';
}
else
{
$required = '';
}
if($surgerytemplate->getType() == 'AN')
{
$validation = 'alpha';
}
else
{
$validation = '';
}
?>
<tr>
<td>
<?php echo $surgerytemplate->getFieldname(); ?>
</td>
<td>
<?php
if($surgerytemplate->getType() == 'B')
{
echo '<input type=\'radio\' name=\''.$fieldName.'\' value=\'Yes\'>Yes';
echo '<input type=\'radio\' name=\''.$fieldName.'\' value=\'No\'>No';
}
else
{
echo '<input type=\'text\' name=\''.$fieldName.'\' id=\''.$fieldName.'\' class=\''.$required.' '.$validation.'\' onblur="checkValid(this.id)"><div id=\''.$fieldName.'error\'></div>';
}
?>
</td>
</tr>
<?php
}
}
?>
</table>
<center><input type='button' name='submit' value='submit' onclick='javascript:submitSurgeryForm("<?php echo $newId ?>")'></center>
</form>
</div>
<?php
}
?>
</div>
You can't have a form tag inside another form. The following HTML is invalid:
<form>
<fieldset>
<form>
<input>
</form>
</fieldset>
</form>
The browser will silently ignore the second form, and instead will interpret your page as:
<form>
<fieldset>
<input>
</fieldset>
</form>