I'm trying to create an update form. When I send the form it shows me that the variable person has not been defined. It's important to say that this variable contains the information obtained in the first query that is used to fill out the first table.
So far everything works well. However, when the user presses the button modify, a message saying that the variable person has not been defined. When i try to re-use the variable serial in the last query it tells me that isn't defined either. I don't really know why if i did at the beginning of the script.
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>CTE Modificar Registro</title>
<?php
include "conexiondblocal.php";
if(!isset($_POST['submit'])){
$serial = mysqli_real_escape_string($con,$_GET['numeroorden']);
$qry= "SELECT * FROM producto WHERE numeroorden = $serial";
$muestra = mysqli_query($con,$qry);
$person=$muestra->fetch_array();
}
?>
<style type="text/css">
#cuerpo form table {
text-align: center;
}
</style>
<link href="../CTE/estilospaginas.css" rel="stylesheet" type="text/css">
<style type="text/css">
body {
background-color: #FFF;
}
</style>
</head>
<body>
<div id="cuerpo">
<script>
$( "#entregaacliente,#fecharecepcion").datepicker();
</script>
<div id="formulario">
<form action="<?php echo $_SERVER['PHP_SELF'];?>" method="post">
<div> <label for="inputproducto">Producto</label> <input name="inputproducto"type="text" class="tabla" id="producto" value = "<?php echo $person['producto']; ?>" />
</div>
<div> <label for="inputproducto">Orden número</label> <input name="inputcedula"type="text" class="tabla" id="inputcedula" value = "<?php echo $person['cedula']; ?>" />
</div>
<div> <label for="inputtipodeservicio">Cedula</label> <input name="inputtipodeservicio"type="text" id="inputtipodeservicio" value = "<?php echo $person['tipodeservicio']; ?>" />
</div>
<div> <label for="inputnumeromarca">Numero de Marca</label> <input name="inputnumeromarca"type="text" id="inputnumeromarca" value = "<?php echo $person['numeromarca']; ?>" />
</div>
<div> <label for="inputmarca">Marca</label> <input name="inputmarca"type="text" id="inputmarca" value = "<?php echo $person['marca']; ?>" />
</div>
<div> <label for="inputtelefono">Modelo</label> <input name="inputmodelo"type="text" id="inputmodelo" value = "<?php echo $person['modelo']; ?>" /> </div>
<div> <label for="inputproducto">Almacen</label> <input name="inputalmacen"type="text" id="inputalmacen" value = "<?php echo $person['almacen']; ?>" /> </div>
<div> <label for="inputmarca">Dano</label> <input name="inputdano"type="text" id="inputdano" value = "<?php echo $person['dano']; ?>" /> </div>
<div> <label for="inputfecharecepcion">Fecha de Recepción</label> <input name="inputfecharecepcion"type="text" id="inputfecharecepcion" value = "<?php echo $person['fecharecepcion']; ?>" />
</div>
<div> <label for="inputfecharecepcion">Técnico</label>
<textarea name="inputtecnico" cols="30" id="inputtecnico" /><?php echo $person['tecnico']; ?>
</textarea> </div>
<div> <label for="inputestado">Estado</label> <select name="inputestado"type="text"value = "<?php echo $person['estado']; ?>" id="inputestado"> <option>Reparado </option>
<option>Pendiente </option>
<option>Entregado</option>
</select> </div>
<div> <label for="inputsede">Sede</label> <select name="inputsede"value = "<?php echo $person['sede']; ?>"type="text" id="inputsede"> <option>Centro </option>
<option>Calipso </option>
</select> </div>
<div> <label for="inputentregaacliente">Entrega a Cliente</label> <input name="inputentregaacliente"type="text" id="inputentregaacliente" value = "<?php echo $person['entregaacliente']; ?>" /> </div>
<div id="enviarboton">
<input type = "submit" name = "submit" value= "Modificar"/>
</div>
<input type="hidden" name="numeroorden" value="<?php echo $serial;?>"/>
</form>
</div>
<?php
if (isset($_POST['submit'])){
$producto=
"UPDATE producto
SET producto = '$_POST[inputproducto]',
cedula = '$_POST[inputcedula]',
tipodeservicio = '$_POST[inputtipodeservicio]',
numeromarca = '$_POST[inputnumeromarca]',
marca = '$_POST[inputmarca]',
modelo = '$_POST[inputmodelo]',
almacen = '$_POST[inputalmacen]',
dano = '$_POST[inputdano]',
fecharecepcion = '$_POST[inputfecharecepcion]',
tecnico = '$_POST[inputtecnico]',
estado = '$_POST[inputestado]',
sede = '$_POST[inputsede]',
entregaacliente = '$_POST[inputentregaacliente]',
numeroorden = '$_POST[numeroorden]'
WHERE numeroorden = $serial";
mysqli_query($con,$producto);
echo "El usuario ha sido modificado";
}
?>
</body>
</html>
Related
I'm updating my post with an image field. Every thing is going fine, but i lose the path of the image, son if i leave the field empty the image path is null.
I have been trying different ways of including the old path to the field image. Those are the lines that have the old path and the new path.
<input type="file" name="image" value="<?php echo $row['image']; ?>">
<input type="hidden" name="old_image" value="<?php echo $row['image']; ?>" >
I tried also with <input type="file" name="image" value="<?php echo $image; ?>"> but it doesn't work.
Any suggestion?
Thanks in advance!
:)
This is my code:
<?php
require 'database.php';
$db = mysqli_connect("", "", "", "");
$id=$_GET["id"];
$title='';
$image='';
$image_text='';
$category='';
$result = mysqli_query($db, "SELECT * FROM `images` WHERE `id` = $id ");
while ($row = mysqli_fetch_array($result))
{
$title=$row['title'];
$image=$row['image'];
$papayos = $row['papayos'];
$cantidad = $row['cantidad'];
$image_text=nl2br($row['image_text']);
$category=$row['category'];
}
?>
<!DOCTYPE html>
<html lang="en" dir="ltr">
<head>
<meta charset="utf-8">
<title>Modificar. Lapapaya.org Educación y colaboración </title>
<meta name="keywords" content="colaboracion, economía del bien común, emprendimiento"/>
<meta name="description" content="Plataforma para desarrollo de proyectos productivos con bonos de intercambio"/>
<link rel="stylesheet" href="css/style.css">
<link rel="shortcut icon" type="image/png" href="images/favicon.png">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bulma#0.8.0/css/bulma.min.css">
<script defer src="https://use.fontawesome.com/releases/v5.3.1/js/all.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
</head>
<body>
<section class="section has-background-white">
<div class="container">
<div class="columns is-centered">
<img class="logo-intro" src="images/logo.png" alt="Logo">
<br>
</div>
</div>
</section>
<form method="POST" action='' enctype="multipart/form-data">
<div class="container">
<h1>Título del artículo</h1>
<br>
<div class="field">
<div class="control">
<input class="input is-warning is-fullwidth" type="text" name="title" value="<?php echo $title; ?>" placeholder="Título">
</div>
<br>
<br>
<div>
<div class="notification"> <h1>Imagen</h1>
<input type="hidden" name="size" value="1000000">
<div class="field">
<div class="control">
<input type="file" name="image" value="<?php echo $row['image']; ?>">
<input type="hidden" name="old_image" value="<?php echo $row['image']; ?>" >
</div>
</div>
<div>
<h1>Descripción</h1>
<textarea class="textarea" name="image_text" rows="8" cols="80"><?php echo $image_text; ?></textarea>
<br>
<h1>Categoría</h1>
<div class=" select is-warning is-fullwidth">
<select type="text" class="" name="category" value="<?php echo $category; ?>">
<option value="1 ">Productos agrícolas</option>
<option value="2 ">Servicio</option>
<option value="3 ">Artesanía</option>
<option value="4 ">Arte</option>
<option value="5">Diseño Industrial</option>
<option value="6 ">Ciudad</option>
<option value="7 ">Economía</option>
<option value="8 ">Emprendimiento</option>
<option value="9 ">Programación</option>
<option value="10 ">Reflexión</option>
<option value="11">Río</option>
<option value="12 ">Seguridad alimentaria</option>
<option value="13 ">Vivienda</option>
</select>
</div>
<h1>Precio</h1>
<br>
<div class="field">
<div class="control">
<input class="input is-warning" type="number" name="papayos" value="<?php echo $papayos; ?>" placeholder="Papayos">
</div>
<br>
<h1>Cantidad</h1>
<br>
<div class="field">
<div class="control">
<input class="input is-warning" type="number" name="cantidad" value="<?php echo $cantidad; ?>" placeholder="Cantidad">
</div>
<br>
<br>
<div>
<button class="button is-outlined is-medium is-fullwidth" type="update" name="update">Modificar</button>
</div>
</div>
</form>
</body>
</html>
<?php
$server = '';
$username = '';
$password = '';
$database = '';
if (isset($_POST['update'])) {
$title=$_POST['title'];
$image_text=nl2br($_POST['image_text']);
$category=$_POST['category'];
$papayos =$_POST['papayos'];
$cantidad =$_POST['cantidad'];
$total = $papayos * $cantidad;
$old_image = $_POST['old_image'];
if(isset($_FILES['image']['name']) && ($_FILES['image']['name']!="")) {
$size=$_FILES['image']['size'];
$temp=$_FILES['image']['tmp_name'];
$type=$_FILES['image']['type'];
$image_name=$_FILES['image']['name'];
unlink("images/$old_image");
move_uploaded_file($temp, "images/$image_name");
}else {
$image_name=$old_image;
}
$update=mysqli_query($db, "UPDATE images SET title = '$title', image = '$image_name', image_text = '$image_text', category = '$category', papayos = '$papayos', cantidad = '$cantidad', total = '$total' WHERE id = $id");
if ($update) {
echo "<script>alert('Datos actualizados exitosamente')</script>";
echo "<script>window.open('index.php', '_self')</script>";
}
else {
echo "<script>alert('Inserción fallida')</script>";
}
} ?>
I fixed adding this above the imput file:
<img src="images/<?php echo $image; ?>">
:)
im having a problem when trying to implement a edit page in php.
Getting items from the database doesent pose any problem, yet trying to update it tells me that i have missed a field and trying to skip the check just leaves me with a unedited table.
To explain more, there is a page that directs to this one while passing on a id (propertyID) veriable and from that we use it to grab the desired variables.
Can anyone look at the code and tell me what i have done wrong, i have prevously got a similar page working and am getting quite flustered trying to figure out why this one isent.
<?php
// Start sessions
include('includes/security.inc.php');
authorise();
if (!isset($_GET['propertyID']) || !is_numeric($_GET['propertyID']))
{
header('Location:./houselist.php');
}
else
{
// Include connection file
include('includes/connection.inc.php');
// Get details
connect();
$propertyID = $_GET['propertyID'];
$sql = "SELECT * FROM Properties WHERE propertyID='$propertyID' LIMIT 1";
$result = #mysql_query($sql) or die('Unable to run query');
$record = mysql_fetch_object($result);
mysql_close();
// Check to see if the form has been submitted
if (isset($_POST['submit']))
{
// Check to see all fields have been completed
$address = $_POST['address'];
$categoryID = $_POST['categoryID'];
$price = $_POST['price'];
$landlordName = $_POST['landlordName'];
$img = $_POST['img'];
$description= $_POST['description'];
if (!empty($address) && !empty($categoryID) && !empty($price) && !empty($landlordName) && !empty($img) && !empty($description))
{
// Create an SQL query to add the comment
$sql = "UPDATE property SET propertyID = '$propertyID', img = '$img', address = '$address', price = '$price', landlordName = '$landlordName', description = '$description' WHERE propertyID = $propertyID";
// Connect to the database
connect();
// Run the query and store the result in a variable
$result = mysql_query($sql) or die("Could not run query1");
// Close connection to the database
mysql_close();
// Check if query was successful
if ($result)
{
$message = '<div class="success"><p>You have successfully edited Article details.</p><p>Please Click Here to view the Animal list.</p></div>';
}
else
{
$message = '<div class="error"><p>There was an error editing details, please try again</p></div>';
}
}
else
{
$message = '<div class="error"><p>Please make sure you fill all fields in before submitting the form.</p></div>';
}
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link rel="stylesheet" type="text/css" href="css/960.css"/>
<link rel="stylesheet" type="text/css" href="css/demo.css"/>
<link rel="stylesheet" type="text/css" href="css/960_24_col.css"/>
<link rel="stylesheet" type="text/css" href="css/reset.css"/>
<link rel="stylesheet" type="text/css" href="css/text.css"/>
<link rel="stylesheet" type="text/css" href="css/style.css"/>
<title>Complete Property Solutions</title>
<title>Homescreen - Complete Property Solutions</title>
</head>
<body>
<div class="container_24" id="container">
<div class="grid_24" id="banner">
<img src="img/banner.png" width="960" height="92" />
</div>
<div class="grid_18" id="nav" align="right">
<ul id="topnav">
<li>Home</li>
<li>Properties</li>
<li>Landlords</li>
<li>Tenants</li>
<li>Logout</li>
</ul>
</div>
<div class="grid_6" id="search" align="right">
<form action="search.php" method="GET">
<input type="text" name="term" size="15">
<input type="submit" value="Search">
</form>
</div>
</div>
<div class="container_24" id="container" align="center">
<div id="container">
<form id="PropertyEdit" name="PropertyEdit" method="post" action="<? echo $_SERVER['PHP_SELF'] . "?propertyID=" . $propertyID; ?>">
<input type="hidden" name="propertyID" id="propertyID" value="<?php echo $propertyID; ?>" />
<?php
if (isset($message))
{
echo $message;
}
else
{
?>
<div class="label"><label for="propertyID"></label></div>
<div class="input"><input type="hidden" name="propertyID" id="propertyID" tabindex="1" value="<? echo $record->propertyID; ?>" /></div>
<br />
<div class="label"><label for="categoryID">Category</label></div>
<div class="input"><input type="text" name="categoryID" id="categoryID" tabindex="1" value="<? echo $record->categoryID; ?>" /></div>
<br />
<div class="label">
<label for="address">Address:</label></div>
<div class="input"><input type="text" name="address" id="address" tabindex="1" value="<? echo $record->address; ?>" /></div>
<br />
<div class="label"><label for="price">Price:</label></div>
<div class="input"><input type="text" name="Price" id="price" tabindex="3" value="<? echo $record->price; ?>" /></div>
<div class="label"><label for="landlordName">Landlord</label></div>
<div class="input"><input type="text" name="landlordName" id="landlordName" tabindex="1" value="<? echo $record->landlordName; ?>" /></div>
<br />
<div class="label"><label for="img">Image</label></div>
<div class="input"><input type="text" name="img" id="img" tabindex="1" value="<? echo $record->img; ?>" /></div>
<br />
<div class="label"><label for="description">Description:</label></div>
<div class="input"><textarea name="description" id="description" cols="50" rows="10" tabindex="5"><? echo $record->description; ?></textarea></div>
<br />
<div class="label"> </div>
<div class="input">
<input type="reset" name="reset" id="reset" value="Reset" tabindex="6" />
<input type="submit" name="submit" id="submit" value="Submit" tabindex="7" />
</div>
<p class="normal">Click Here to Return to the Home page</p>
<?php
}
?>
</form> </div>
</div>
</body>
</html>
<?php
}
?>
my best guess for the problem would revolve around
// Check to see if the form has been submitted
if (isset($_POST['submit']))
{
// Check to see all fields have been completed
$address = $_POST['address'];
$categoryID = $_POST['categoryID'];
$price = $_POST['price'];
$landlordName = $_POST['landlordName'];
$img = $_POST['img'];
$description= $_POST['description'];
if (!empty($address) && !empty($categoryID) && !empty($price) && !empty($landlordName) && !empty($img) && !empty($description))
{
// Create an SQL query to add the comment
$sql = "UPDATE property SET propertyID = '$propertyID', img = '$img', address = '$address', price = '$price', landlordName = '$landlordName', description = '$description' WHERE propertyID = $propertyID";
// Connect to the database
connect();
// Run the query and store the result in a variable
$result = mysql_query($sql) or die("Could not run query1");
// Close connection to the database
mysql_close();
// Check if query was successful
if ($result)
{
$message = '<div class="success"><p>You have successfully edited Article details.</p><p>Please Click Here to view the Animal list.</p></div>';
}
else
{
$message = '<div class="error"><p>There was an error editing details, please try again</p></div>';
}
}
else
{
$message = '<div class="error"><p>Please make sure you fill all fields in before submitting the form.</p></div>';
}
}
And the below section, my problem is that im not sure where exactly
<div class="container_24" id="container" align="center">
<div id="container">
<form id="PropertyEdit" name="PropertyEdit" method="post" action="<? echo $_SERVER['PHP_SELF'] . "?propertyID=" . $propertyID; ?>">
<input type="hidden" name="propertyID" id="propertyID" value="<?php echo $propertyID; ?>" />
<?php
if (isset($message))
{
echo $message;
}
else
{
?>
<div class="label"><label for="propertyID"></label></div>
<div class="input"><input type="hidden" name="propertyID" id="propertyID" tabindex="1" value="<? echo $record->propertyID; ?>" /></div>
<br />
<div class="label"><label for="categoryID">Category</label></div>
<div class="input"><input type="text" name="categoryID" id="categoryID" tabindex="1" value="<? echo $record->categoryID; ?>" /></div>
<br />
<div class="label">
<label for="address">Address:</label></div>
<div class="input"><input type="text" name="address" id="address" tabindex="1" value="<? echo $record->address; ?>" /></div>
<br />
<div class="label"><label for="price">Price:</label></div>
<div class="input"><input type="text" name="Price" id="price" tabindex="3" value="<? echo $record->price; ?>" /></div>
<div class="label"><label for="landlordName">Landlord</label></div>
<div class="input"><input type="text" name="landlordName" id="landlordName" tabindex="1" value="<? echo $record->landlordName; ?>" /></div>
<br />
<div class="label"><label for="img">Image</label></div>
<div class="input"><input type="text" name="img" id="img" tabindex="1" value="<? echo $record->img; ?>" /></div>
<br />
<div class="label"><label for="description">Description:</label></div>
<div class="input"><textarea name="description" id="description" cols="50" rows="10" tabindex="5"><? echo $record->description; ?></textarea></div>
<br />
<div class="label"> </div>
<div class="input">
<input type="reset" name="reset" id="reset" value="Reset" tabindex="6" />
<input type="submit" name="submit" id="submit" value="Submit" tabindex="7" />
I have some PHP code in which is using codeigniter. How can I check validation on the filed that are marked check? My code is below.
Can you please let me know how can I check if item is checked and force the validation accordingly?
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<script type="text/Javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script>
<link rel="stylesheet" type="text/css" href="<?php echo base_url(); ?>/site.css"></link>
</head>
<body>
<script type="text/Javascript">
$(function () {
$('.checkall').click(function () {
$(this).parents('fieldset:eq(0)').
find(':checkbox').attr('checked', this.checked);
});
});
</script>
<? $attributes = array('class' => '', 'id' => ''); ?>
<? echo form_open('ShoppingListController', $attributes); ?>
<div class="divTable">
<fieldset>
<!-- these will be affected by check all -->
<div class="divRow">Product Name | Quantity | Packages</div>
<div class="divRow"><input type="checkbox" size="100" class="checkall"> Check all</div>
<br>
<?php foreach ($records as $rec) {
?>
<div class="divRow"><input type="checkbox">
<input size="5" type="hidden" value="<? echo $rec->id; ?>" name="id"></input>
<input size="20" type="text" value="<? echo $rec->name; ?>" name="name"></input>
<label for="quantity">Value <span class="required">*</span></label>
<span class="required"><?php echo form_error('quantity'); ?></span>
<input size="5" type="text" value="" name="quantity"></input>
<select name="package">
<option name="case">Case</option>
<option name="box">Box</option>
<option name="box">Single Bottle</option>
</select>
</div>
<br>
<?
}
?>
</fieldset>
</div>
<div><input type="submit" name="submit"/></div>
</form>
</body>
you can use code below:
var divRows = $('.divRow');
var count = divRows.length;
divRows.each(function() {
if ($(this).find('input[type=checkbox]').is(':checked')) {
count--;
}
});
if (count != 0) {
alert(count + ' checkboxes not checked');
}
http://jsfiddle.net/SKgA8/
this is my form, my input reset don't reset all my input and submit don't send my form,
when I press input reset it doesn't work and dont know why and the same happening with submit
what should i do??
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Agregar Publicidad</title>
<link rel="stylesheet" type="text/css" href="../css/EstiloLocales.css"/>
<link rel="stylesheet" type="text/css" href="../libs/css/ui-lightness/jquery-ui-1.8.18.custom.css"/>
<script src="../libs/js/jquery-ui-1.8.18.custom.min.js" type="application/javascript"></script>
<script src="../libs/js/jquery-1.7.1.min.js" type="application/javascript"></script>
<script type="text/javascript">
$(document).ready(function(){
$('.checkin').click(function(){
var labelId = $(this).attr('name');
var colorActual = $('#'+labelId).css('color');
var checkeo = $(this).attr('checked');
$('#COLOSH').val(checkeo);
if(checkeo == 'checked'){
$('#'+labelId).css('color','#f00');
}else{
$('#'+labelId).css('color','#000');
}
var n = $("input:checkbox").length;
var str = '';
for(var cj=1; cj < n; cj++){
var check = document.getElementById(cj+'1').checked;
if(check == true){
str += cj+' ';
}
}
$('#myArr').val(str);
});
});
function cargarCategorias(cadena){
var ar= cadena.split(" ");
if(ar.length < 3){
$('#'+ar+'1').prop("checked", true);
$('#label'+ar).css("color", "#f00");
}else{
ar = ar.split(' ');
for(var i=0;i < ar.length; i++){
$('#'+ar[i]+'1').prop("checked", true);
$('#label'+ar[i]).css("color", "#f00");
}
}
}
function porDefecto(){
$('.label').css('color','#000');
//$(':input').attr('value','');
//$('#descripcion').attr('value','');
}
function loaddefimages(Id)
{
//this.src='../Info/Fotos/fotogenerica.jpg
document.getElementById(Id).src="../Info/Fotos/fotogenerica.jpg";
}
</script>
</head>
<body>
<?php
include "../src/defines.php";
$numero = $_GET['numero'];
$doc = new DOMDocument;
$doc->load(DIR_LOCALES);
$xpath = new DOMXPath($doc);
$elements = $xpath->query('//item[#numero="'.$numero.'"]');
//if ($elements->length >= 1) {
$element = $elements->item(0);
$ar = buscar_categorias( $element->getAttribute('nombre'),DIR_PUBLICIDADES);
if($ar != ''){
$t= implode(' ',$ar);
?>
<script language="javascript">
var cadena = <?php echo $t;?>
cargarCategorias(cadena);
</script>
<?php
}
// }
?>
<form id="form1" name="form1" enctype="multipart/form-data" method="post" action="add_local.php">
<input type="hidden" id="myArr" name="myArr" value="">
<input type="hidden" id="oldvalue" name="oldvalue" value="">
<input type="hidden" id="accion" name="accion" value="1">
<input type="hidden" id="oldName" name="oldName" value="">
<div class="div_principal">
<div class="contenido">
<div class="contenido-uno">
<div class="datos"><!--BEGIN DATOS -->
<div class="datos-uno"><!--BEGIN DATOS UNO -->
<div>
<label for="nombre">Nombre</label>
<input name="nombre" type="text" id="nombre" maxlength="21" style="margin-left:15px;" value="<?php if($element->getAttribute('nombre') == ''){ echo "NO ASIGNADO";}else{echo $element->getAttribute('nombre');} ?>" />
</div>
<div>
<label for="telefono">Teléfono</label>
<input type="text" name="telefono" id="telefono" style="margin-left:10px;" value="<?php if($element->getAttribute('telefono') == ''){ echo "NO ASIGNADO";}else{echo $element->getAttribute('telefono');} ?>"/>
</div>
<div>
<label for="web">Web</label>
<input type="text" name="web" id="web" value="<?php if($element->getAttribute('web') == ''){ echo "NO ASIGNADO";}else{echo $element->getAttribute('web');} ?>" />
</div>
<div>
<label for="correo">Correo:</label>
<input type="text" name="correo" id="correo" value="<?php if($element->getAttribute('correo') == ''){ echo "NO ASIGNADO";}else{echo $element->getAttribute('correo');} ?>"/>
</div>
<div>
<label for="encargado">Encargado</label>
<input type="text" name="encargado" id="encargado" value="<?php if($element->getAttribute('encargado') == ''){ echo "NO ASIGNADO";}else{echo $element->getAttribute('encargado');} ?>"/>
</div>
</div><!--END DATOS UNO -->
<div class="datos-dos"><!--BEGIN DATOS DOS -->
<div>
<label for="numero">Número</label>
<input type="text" disabled="disabled" style="margin-left:30px;" name="numero" id="numero" value="<?php echo $element->getAttribute('numero') ?>" />
</div>
<div>
<div>
<label for="descripcion"> Descripción</label>
</div>
<div style=" position:relative; top:-20px; left:100px;">
<textarea name="descripcion" id="descripcion" style="width:240px; height:100px;" ><?php if($element->getAttribute('descripcion') == ''){ echo "NO ASIGNADO";}else{echo $element->getAttribute('descripcion');} ?></textarea>
</div>
</div>
<div>
<label for="promocion">Promoción</label>
<input type="text" name="promocion" id="promocion" value="<?php if($element->getAttribute('promocion') == ''){ echo "NO ASIGNADO";}else{echo $element->getAttribute('promocion');} ?>" style="margin-left:15px;" />
</div>
</div>
</div><!-- FIN DATOS -->
<div class="imagenes"><!-- BEGIN IMAGENES -->
<div class="ima-uno">
<div class="div-foto">
<img id="foto" onerror="javascript:loaddefimages(this.id);" src="../Info/Fotos/Localimg/<?php echo strtolower($element->getAttribute('numero').'jpg'); ?>" alt="Foto" name="foto" width="310" height="115" />Imagen 297 x 110 px
</div>
<div class="div-btn">
<img src="../src/Img/paneldecontrol-15.png" width="23" height="23" style="position:absolute;" />
<input style="width:67px; z-index:2; opacity:0;" type="file" name="dir_foto" />
</div>
</div>
<div class="ima-dos">
<div class="div-logo">
<img id="logo" src="../Info/Fotos/logos/<?php echo strtolower($element->getAttribute('numero').'png'); ?>" onerror="javascript:loaddefimages(this.id);" alt="logo" width="150" height="115" /></div>
<div class="div-btn-logo">
<img src="../src/Img/paneldecontrol-15.png" width="23" height="23" style="position:absolute;" />
<input style="width:67px; z-index:2; opacity:0;" type="file" name="dir_logo" />
</div>
</div>
</div>
</div>
<div class="contenido-dos">
<div class="div_cat">
<?php
$docCat = new DomDocument;
$docCat->preserveWhiteSpace = FALSE;
$docCat->load(DIR_CATEGORIAS);
$parCat = $docCat->getElementsByTagName('categoria'); // Find Sections
$contador=0;
foreach($parCat as $parametro){
?>
<div>
<input id="<?php echo $parCat->item($contador)->getAttribute('id'); ?>1" class="checkin" type="checkbox" name="label<?php echo $parCat->item($contador)->getAttribute('id'); ?>" />
<label id="label<?php echo $parCat->item($contador)->getAttribute('id'); ?>" class="label" for="a"><?php echo $parCat->item($contador)->getAttribute('nombre'); ?></label>
</div>
<?php
$contador++;
}
?>
</div>
<div class="form-buttons">
<img src="../src/Img/paneldecontrol-17.png" width="23" height="23" style="position:absolute; left: 2px; top: 1px;" />
<input type="reset" onclick="javascript:porDefecto();" style=" z-index:2; width:25px; margin-right:7px; height:23px; opacity:0; " value="Limpiar" />Limpiar campos
<input type="submit" value="Guardar" style="margin-left:30px; margin-right:7px; width:27px; height:23px; z-index:3; opacity:0; " />Guardar
<img src="../src/Img/paneldecontrol-16.png" width="23" height="23" style="position:absolute; left: 152px; top: 1px;" />
</div>
</div>
</div>
</div>
</form>
</body>
</html>
div form-buttons has the input that doesn't work
Your 'reset' has an 'onclick' event, which is wrong. I bet that prevents the reset..
Some of the input elements are disabled, and I doubt wether disabled elements are posted.
For the generated elements, I think it's best to load your page and check the output (the generated source). I will tell you more easily if there's any error in the PHP code, than staring at the PHP source.
<?php
function VerifyForm(&$values, &$errors)
{
if (strlen($values['fname']) == 0)
$errors['fname'] = 'Enter First Name';
if (strlen($values['lname']) == 0)
$errors['lname'] = 'Enter Last Name';
if (strlen($values['mname']) == 0)
$errors['mname'] = 'Enter Middle Name';
if (strlen($values['address']) == 0)
$errors['address'] = 'Enter Address';
if (strlen($values['terms']) == 0)
$errors['terms'] = 'Please Read Terms and Agreement and Check the box.';
if (!ereg('.*#.*\..{2,4}', $values['email']))
$errors['email'] = 'Email address invalid';
else if (strlen($values['email']) < 0)
$errors['email'] = 'Enter Email Address';
return (count($errors) == 0);
}
function DisplayForm($values, $errors)
{
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>GIA Soap » Products » Customer Informations</title>
<link href="stylesheet/style.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="js_files/jquery.js"></script>
<script type="text/javascript" src="js_files/sliding_effect.js"></script>
<script type="text/javascript" src="js_files/slideshow.js"></script>
</head>
<body>
<div class="bg_top">
<div class="bg_bottom">
<div class="wrapper">
<div class="header">
<div class="logo">
</div>
<div class="logo_text">
<div class="logo_head_text">Gia Soap Making</div>
<div class="logo_sub_text">Sub text here</div>
</div>
</div>
<div class="h_nav">
<div class="h_nav_dash">
</div>
</div>
<div class="container">
<div class="content_term">
<div class="content_terms">
<br />
<h1><p>Customer Information</p></h1><br />
<p>Please the following correctly.</p>
<div class="customer_info">
<?php
if (count($errors) > 0)
echo "<p>There were some errors in your submitted form, please correct them and try again.</p>";
?>
<form method="post" action="<?= $_SERVER['PHP_SELF'] ?>">
<!-- hidden values -->
<input type="hidden" value="<?php echo $papaya; ?>" name="papaya" />
<input type="hidden" value="<?php echo $carrot; ?>" name="carrot" />
<input type="hidden" value="<?php echo $guava; ?>" name="guava" />
<label for="customer_fname">First Name (<i>Required</i>)</label>
<input type="text" class="textbox" id="customer_fname" name="customer_fname" value="<?= htmlentities($values['fname']) ?>" />
<span class="error_msg"><?= $errors['fname'] ?></span>
<label for="customer_lname">Last Name (<i>Required</i>)</label>
<input type="text" class="textbox" id="customer_fname" name="customer_fname" value="<?= htmlentities($values['lname']) ?>" />
<span class="error_msg"><?= $errors['lname'] ?></span>
<label for="customer_mname">Middle Name (<i>Required</i>)</label>
<input type="text" class="textbox" id="customer_fname" name="customer_fname" value="<?= htmlentities($values['mname']) ?>" />
<span class="error_msg"><?= $errors['mname'] ?></span>
<label for="customer_add">Address (<i>Required : Complete Address Please</i>)</label>
<input type="text" class="textbox" id="customer_add" name="customer_add1" value="<?= htmlentities($values['address']) ?>" /><br />
<input type="text" class="textbox" id="customer_add" name="customer_add2" /><br />
<input type="text" class="textbox" id="customer_add" name="customer_add3" />
<span class="error_msg"><?= $errors['address'] ?></span>
<label for="customer_email">Email Address (<i>Required</i>)</label>
<input type="text" class="textbox" id="customer_email" name="customer_email" value="<?= htmlentities($values['email']) ?>" />
<span class="error_msg"><?= $errors['email'] ?></span>
<label for="customer_phone">Phone Number </label>
<input type="text" class="textbox" id="customer_phone" name="customer_phone" />
<label for="customer_mobile">Mobile Number </label>
<input type="text" class="textbox" id="customer_mobile" name="customer_mobile" />
<br /><br />
<div class="terms">
<center>
<h1>Terms and Agreement</h1><br />
<p>Please read the following.</p><br />
</div>
<br />
<input type="checkbox" name="terms" value="<?= htmlentities($values['terms']) ?>" /> I Read the Terms and Agreement<br /><br />
<span class="error_msg"><?= $errors['terms'] ?></span>
<input type="submit" value="Send Order" class="prod_subbtn" />
</center>
</form>
</div>
</div>
</div>
<div class="clear"></div>
</div>
<?php include ('includes/footer.php'); ?>
</div>
</div>
</div>
</body>
</html>
<?php
}
function ProcessForm($values)
{
$papaya = $_POST['papaya'];
$carrot = $_POST['carrot'];
$guava = $_POST['guava'];
$fname = $_POST['fname'];
$lname = $_POST['lname'];
$mname = $_POST['mname'];
$address = $_POST['address'];
}
if ($_SERVER['REQUEST_METHOD'] == 'POST')
{
$formValues = $_POST;
$formErrors = array();
if (!VerifyForm($formValues, $formErrors))
DisplayForm($formValues, $formErrors);
else
ProcessForm($formValues);
}
else
DisplayForm(null, null);
?>
The output is:
Problem
The PHP code that is supposed to put in the field values can be seen by users.
Chances are short_open_tags is off. Use <?php echo ...; ?> instead of <?=... ?>, like this:
<?php echo htmlentities($values['lname']); ?>
<?= $errors['fname'] ?> is equal to <?php echo $errors['fname'] ?>.
<?= are called 'short tags', which were removed (deprecated) from php.
Use <?php echo $errors['fname']; ?> to see the actual variable value.
The directive short tags is set to off in the php.ini. That disallows <? $phpcode ?> and <?=$monkey?>
The only one allowed is <?php $monkeybusiness ?>
either change <?= to <?php echo or turn short_open_tags = on in the php.ini