PHP doenst catch a simple POST - php

Here below is my code, i get strange results, for example the POST is not being caught by the PHP. If i add ($_SERVER['REQUEST_METHOD'] == 'POST') it is still not caught. It hould be a simple POST, what did i do wrong? The best i get out of this is the error message:
$url_message = 'Something went wro, please try again.';
Please help
if(isset($_POST["submit"])) {
$btc = $_POST['bitcoin'];
$eur = $_POST['euro'];
echo '1';
echo $btc;
echo '2';
echo $eur;
if($btc != "" && $eur != ""){
$user_idr = $_GET['id'];
$user_idreal = $LS->get_CU();
echo $LS->get_CU();
echo $user_idr;
if($user_idr == $user_idreal){
echo 'jemoder';
$cur = $btc;
$eur = $eur;
$user = $user_id;
$datetime = date('Y-m-d H:i:s');
$ip = $_SERVER['REMOTE_ADDR'];
if($LS->store_val($cur, $eur, $user, $datetime, $ip) != false){
$url_message = 'Gelukt';
header('Location: home.php?id=' . $header_n . '&mas=' . $url_message);
}else{
$url_message = 'niet gelukt';
header('Location: home.php?id=' . $header_n . '&mas=' . $url_message);
}
}else{
$header_n = $LS->get_CU();
$url_message = 'Something went wro, please try again.';
header('Location: home.php?id=' . $header_n . '&mas=' . $url_message);
}
}else{
$header_n = $LS->get_CU();
$url_message = 'Some fields were left blank.';
header('Location: home.php?id=' . $header_n . '&mas=' . $url_message);
}
}else{
echo 'hallo';
}
?>
<div class="col-md-9">
<div class="span9">
<div class="space-6"></div>
<div class="row-fluid">
<div class="span12">
<form class="form-horizontal formproperties" action="<?php echo $_SERVER['PHP_SELF'] ?>#form-textfield" method="POST">
<fieldset>
<div class="container">
<div class="row-fluid">
<div class="col-xs-12 col-sm-12 col-lg-12">
<div class="col-xs-12 col-sm-12 col-lg-6 logintextsupport text-center">
<h3 class="text-left">Buy <?php echo $form_titel;?></h3>
<hr />
<div class="form-group">
<label class="col-md-1 control-label" for="password"></label>
<div class="col-md-9">
<input id="<?php echo $form_id;?>" name="<?php echo $form_name;?>" type="text" placeholder="<?php echo $form_placeholder;?> *" class="form-control input-md" required="">
</div>
</div>
<div class="form-group">
<label class="col-md-1 control-label" for="password"></label>
<div class="col-md-9">
<input id="euro" name="euro" type="text" placeholder=" *" class="form-control input-md" required="">
</div>
</div>
<legend>Payment Method</legend>
<div class="form-group">
<label class="col-md-1 control-label" for="password"></label>
<div class="col-md-5">
<input type="radio" name="radio" id="radio1" /> <label for="radio1" class="inline">iDeal</label><br />
</div>
<div class="col-md-4">
<input type="radio" name="radio" id="radio3" /> <label for="radio3" class="inline">Ban Contact</label>
</div>
</div>
<hr />
<div class="form-group loginboxsupport">
<label class="col-md-12 col-lg-12" for="proceed"></label>
<div class="col-md-12 col-lg-12">
<button id="proceed" type="submit" name="submit" class="btn btn-success buttonali">SUBMIT</button>
</div>
</div>
<div style="height:0.5vw;"></div>
</div>
</div>
</div>
</div>
</fieldset>
</form>

The problem was in the HTML code, at the action there is the following code
action="<?php echo $_SERVER['PHP_SELF'] ?>#form-textfield"
So the action would be a link to itself, nothing on it. Had to add a user ID:
?id=<?php echo $user_id ?>
The complete action became:
action="<?php echo $_SERVER['PHP_SELF'] ?>?id=<?php echo $user_id ?>#form-textfield"
The total start of the form:
<form class="form-horizontal formproperties" action="home.php?id=<?php echo $user_id ?>#form-textfield" method="POST">

Related

Opencart contact form sends data via get method instead of post

I am using Opencart version 2.1.0.1. There is nothing changed in the contact form much. The contact form is sending the data in the GET method but it is supposed to send the data in POST method as the validations are being done for POST data.
Can someone please tell me what could be the issue. https://www.ijminc.com/index.php?route=information/contact is the website link for the contact page I am talking about.
if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validate()) {
// echo $this->request->post['is_redirect'];
if(empty($this->request->post['is_redirect'])){
$mail = new Mail();
$mail->protocol = $this->config->get('config_mail_protocol');
$mail->parameter = $this->config->get('config_mail_parameter');
$mail->smtp_hostname = $this->config->get('config_mail_smtp_hostname');
$mail->smtp_username = $this->config->get('config_mail_smtp_username');
$mail->smtp_password = html_entity_decode($this->config->get('config_mail_smtp_password'), ENT_QUOTES, 'UTF-8');
$mail->smtp_port = $this->config->get('config_mail_smtp_port');
$mail->smtp_timeout = $this->config->get('config_mail_smtp_timeout');
$mail->setTo($this->config->get('config_email'));
$mail->setFrom($this->request->post['email']);
$mail->setSender(html_entity_decode($this->request->post['name'], ENT_QUOTES, 'UTF-8'));
$mail->setSubject(html_entity_decode(sprintf($this->language->get('email_subject'), $this->request->post['name']), ENT_QUOTES, 'UTF-8'));
$mail->setText($this->request->post['enquiry']);
$mail->send();
$this->response->redirect($this->url->link('information/contact/success'));
}
In contact.tpl, the form code is as
<form action="<?php echo $action; ?>" method="post" enctype="multipart/form-data" class="form-horizontal">
<fieldset>
<legend><?php echo $text_contact; ?></legend>
<div class="form-group required">
<label class="col-sm-2 control-label" for="input-name"><?php echo $entry_name; ?></label>
<div class="col-sm-10">
<input type="text" name="name" value="<?php echo $name; ?>" id="input-name" class="form-control" />
<?php if ($error_name) { ?>
<div class="text-danger"><?php echo $error_name; ?></div>
<?php } ?>
</div>
</div>
<div class="form-group required">
<label class="col-sm-2 control-label" for="input-email"><?php echo $entry_email; ?></label>
<div class="col-sm-10">
<input type="text" name="email" value="<?php echo $email; ?>" id="input-email" class="form-control" />
<?php if ($error_email) { ?>
<div class="text-danger"><?php echo $error_email; ?></div>
<?php } ?>
</div>
</div>
<div class="form-group required">
<label class="col-sm-2 control-label" for="input-enquiry"><?php echo $entry_enquiry; ?></label>
<div class="col-sm-10">
<textarea name="enquiry" rows="10" id="input-enquiry" class="form-control"><?php echo $enquiry; ?></textarea>
<?php if ($error_enquiry) { ?>
<div class="text-danger"><?php echo $error_enquiry; ?></div>
<?php } ?>
</div>
</div>
<?php echo $captcha; ?>
</fieldset>
<div class="buttons">
<div class="pull-right">
<input class="btn btn-primary" type="submit" value="<?php echo $button_submit; ?>" />
</div>
</div>
</form>
Note : I have been working on this issue for 2 days now and did a lot of google search. I couldn't get any relevant answer that could solve my problem. If you guys have any link that could solve my issue, please post it.
Thanks for the help in advance.

For loop showing only the final result

I have the following PHP query:
<?php
$row='';
$access = 0;
$user = (isset($_POST['nume']) && !empty($_POST['nume'])) ? $_POST['nume'] : "" ;
$email = (isset($_POST['email']) && !empty($_POST['email'])) ? $_POST['email'] : "" ;
$telefon = (isset($_POST['telefon']) && !empty($_POST['telefon'])) ? $_POST['telefon'] : "" ;
$cnp = (isset($_POST['cnp']) && !empty($_POST['cnp'])) ? $_POST['cnp'] : "" ;
$serieci = (isset($_POST['serieci']) && !empty($_POST['serieci'])) ? $_POST['serieci'] : "" ;
$mesaj = (isset($_POST['mesaj']) && !empty($_POST['mesaj'])) ? $_POST['mesaj'] : "" ;
$email_status=1;
$db = pg_connect("host=local port=5432 dbname=login_robinson user=robinson password=123");
$query = "INSERT INTO tcheckin(nume,email,telefon,cnp,serieci,mesaj) VALUES ('$user','$email','$telefon','$cnp','$serieci','$mesaj')";
$result = pg_query($query);
$test=$_SESSION[PRE.'nume'];
$test1=$_SESSION[PRE.'uid'];
?>
<html lang="en" xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
<link href="https://fonts.googleapis.com/css?family=Playfair+Display:400,700,900|Rubik:300,400,700" rel="stylesheet">
<title>Efectueaza check-in</title>
<?php
include('include/links.php');
include('include/scripts.php');
?>
</head>
<?php
$i=1;
$conn = pg_connect("host=local port=5432 dbname=login_robinson user=robinson password=123");
$test1=$_SESSION[PRE.'uid'];
$result = pg_query($conn, "SELECT nume FROM tregister WHERE id = '$test1'");
if (!$result) {
echo "An error occurred.\n";
exit;
}
$row = pg_fetch_row($result);
$result1 = pg_query($conn, "SELECT nr_camere FROM tregister WHERE nume = '$user'");
if (!$result1) {
echo "An error occurred.\n";
exit;
}
$camere = pg_fetch_row($result1);
echo $row[0];
for($i=1; $i<$camere[0]; $i++){
if(isset($_POST['submit'])){
echo "<script>
alert('Check-in efectuat cu success! Daca ai rezervat mai multe camere te rog sa completezi si check-in-ul pentru celelalte camere.');
window.location.href='acasa';
</script>";
echo "<script>
alert('S-a produs o eroare! Te rog mai verifica odata formularul!');
</script>";
}
}
?>
<body style="display: block !important;" ng-cloak="" ng-class="{ 'layout-fixed' : app.layout.isFixed, 'layout-boxed' : app.layout.isBoxed, 'layout-dock' : app.layout.isDocked, 'layout-material': app.layout.isMaterial, 'aside-offscreen' : app.sidebar.isOffscreen, 'aside-mini' : app.sidebar.isMini, 'aside-right' : app.sidebar.isRight, 'footer-hidden': app.footer.hidden, 'in-app': !$state.includes('page')}">
<div class="animated fadeOutZoom">
<div class="container container-sm animated fadeInDown">
<div class="app-view-header">Bine ai venit, <?php echo $row[0]; ?>!</div>
<div class="center-block mt-xl">
<div class="panel">
<div class="panel-body">
<p class="pv text-bold">Check-in pentru camera cu numarul <?php echo $i; ?></p>
<form action="#" method="post">
<div class="row">
<div class="col-md-12 form-group">
<label for="nume">Nume</label>
<input type="text" id="text " value=" <?php echo $row[0]; ?>" class="form-control " name="nume" disabled="disabled">
</div>
</div>
<div class="row">
<div class="col-md-12 form-group">
<label for="telefon">Telefon</label>
<input type="phone" id="telefon " class="form-control " name="telefon" required>
</div>
</div>
<div class="row">
<div class="col-md-12 form-group">
<label for="email">Email</label>
<input type="email" id="email" class="form-control " name="email" required>
</div>
</div>
<div class="row">
<div class="col-md-12 form-group">
<label for="cnp">CNP</label>
<input type="text" id="text " class="form-control "name="cnp" required>
</div>
</div>
<div class="row">
<div class="col-md-12 form-group">
<label for="serie">Serie de buletin</label>
<input type="text" id="text " class="form-control " name="serieci" required>
</div>
</div>
<div class="row">
<div class="col-md-12 form-group">
<label for="message">Scrie un mesaj *Optional</label>
<textarea name="mesaj" id="message" class="form-control " cols="5" rows="4"></textarea>
</div>
</div>
<div class="row">
<div class="col-md-6 form-group">
<input type="submit" value="Rezerva acum" class="btn btn-primary" name="submit">
</div>
</div>
</form>
</div>
</div>
</div>
</div>
</div>
<script src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datepicker/1.8.0/js/bootstrap-datepicker.min.js"></script>
<script>
$('#arrival_date, #departure_date').datepicker({format: 'dd/mm/yyyy'});
</script>
</body>
</html>
<?php
ob_end_flush();
?>
What I want to do it's to see a page for a number of times. For example, if a user selected 4 rooms, I need make the check-in process 4 times, once for each room, I tried with a for loop but it's showing only the final result..what can I do? It's a little bit weird, I tried also with a while but still doesn't work..

Customer Name,Mobile Number and Description Fetch but not fetch address why?

<?php
if(isset($_POST['updatecustomer'])){
$customerID=trim($_POST['customerID']);
$customername=trim($_POST['customername']);
$mobilenumber=trim($_POST['mobilenumber']);
$Description=trim($_POST['description']);
$area=trim($_POST['area']);
if(empty($customername)){
$errorcustomername="Please Enter Customer Name";
}
elseif (empty($mobilenumber)) {
$Errormobilenumber="Please Enter Mobile Number";
}
elseif (empty($Description)) {
$Errordescription="Please Enter Description";
}
elseif (empty($area)) {
$Errorarea="Please Enter Address";
}
else
{
try {
if (trim($_FILES["image"]["name"])!=""){
$base=explode(".", strtolower(basename($_FILES["image"]["name"])));
$ext=end($base);
if($ext=="png" or $ext=="jpg" or $ext=="jpeg"){
$image1 = getimagesize($_FILES["image"]["tmp_name"]);
$width = $image1[0];
$height = $image1[1];
if($width<256 || $height<256){
$error = true;
$ErrorImage = "Please select an image with minimum resolution of 256x256 !";
}else{
$image1=uniqid().".".$ext;
move_uploaded_file($_FILES["image"]["tmp_name"], "picture/" . $image1);
$image1="picture/".$image1;
$con->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
/update Query/
$sql="UPDATE customer SET shopID='$shopID',name='$customername',
mobile='$mobilenumber',area='$area',description='$Description',picture='$image1' WHERE customerID='$customerID'";
$con->exec($sql);
$sql1="UPDATE customerdetails SET area='$area' WHERE customerID='$customerID' ";
if (mysqli_query($conn,$sql1)) {
$success="Customer Updated Successfully";
}
else
{
$errorSubmit="Customer not Updated";
}
}
}
else {
}
$error = true;
$ErrorImage="invalid image extension !";
}
else {
$con->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$sql="UPDATE customer SET shopID='$shopID',name='$customername',mobile='$mobilenumber,area='$area',description='$Description' WHERE customerID='$customerID'";
$con->exec($sql);
$sql1="UPDATE customerdetails SET area='$area' WHERE customerID='$customerID' ";
if (mysqli_query($conn,$sql1)) {
$success="Customer Updated Successfully";
}
else
{
$errorSubmit="Customer not Updated";
}
}
}
catch(PDOException $e)
{
$errorSubmit= $e->getMessage();
}
}
}
?>
<div class="boxed">
<div id="content-container">
<div id="page-title">
<h1 class="page-header text-overflow">Update Customer</h1>
</div>
<ol class="breadcrumb">
<li>Dashboard</li>
<li>Customer</li>
<li class="active">Update Customer</li>
</ol>
<div id="page-content">
<div class="col-sm-12" style="padding-bottom: 5%">
<div class="panel">
<div class="panel-heading">
<h3 class="panel-title">Update Customer Details</h3>
</div>
<form class="form-horizontal" method="POST" enctype="multipart/form-data">
<div class="panel-body">
<?php
/join Query/
$id=mysqli_real_escape_string($conn,$_GET['id']);
$sql="SELECT customer.*,customerdetails.* FROM customer JOIN customerdetails ON customer.customerID=customerdetails.customerID WHERE customer.customerID='$id'";
$read=mysqli_query($conn,$sql);
while ($row1=mysqli_fetch_assoc($read)) {
# code...
?>
<input type="hidden" name="customerID" value="<?php echo $row1['customerID']; ?>">
<div class="form-group">
<label class="col-sm-3 control-label" for="demo-hor-inputemail">Customer Name</label>
<div class="col-sm-9">
<input type="text" name="customername" class="form-control" placeholder="Customer Name" value="<?php echo $row1['name']; ?>"
oninput="this.value = this.value.replace(/[^A-Za-z ]/g, ''); this.value = this.value.replace(/(\..*)\./g, '$1');" maxlength="60" required="">
<?php if (!empty($errorcustomername)) { ?> <p class="label label-danger"><?php echo $errorcustomernamee; ?></p> <?php } ?>
</div>
</div>
<div class="form-group">
<label class="col-sm-3 control-label" for="demo-hor-inputemail">Mobile Number</label>
<div class="col-sm-9">
<input type="text" class="form-control" name="mobilenumber" placeholder="Mobile Number" value="<?php echo
$row1['mobile'];?>" oninput="this.value = this.value.replace(/[^0-9- ]/g, ''); this.value = this.value.replace(/(\..*)\./g, '$1');" maxlength="10"/>
<?php if (!empty($Errormobilenumber)) { ?> <p class="label label-danger"><?php echo $Errormobilenumber; ?></p> <?php } ?>
</div>
</div>
<div class="form-group">
<label class="col-sm-3 control-label" for="demo-hor-inputemail">Address</label>
<div class="col-sm-9">
<input type="text" class="form-control" name="area" placeholder="Address" value="<?php echo $row1['area'];?>" />
<?php if (!empty( $Errorarea)) { ?> <p class="label label-danger"><?php echo $Errorarea; ?></p> <?php } ?>
</div>
</div>
<div class="form-group">
<label class="col-sm-3 control-label" for="demo-hor-inputemail">Description</label>
<div class="col-sm-9">
<input type="text" class="form-control" name="description" placeholder="Description" value="<?php echo $row1['description'];?>" />
<?php if (!empty($Errordescription)) { ?> <p class="label label-danger"><?php echo $Errordescription; ?></p> <?php } ?>
</div>
</div>
<div class="form-group">
<label class="col-sm-3 control-label" for="demo-hor-inputemail">Picture</label>
<div class="col-sm-9">
<input type="file" class="form-control" name="image" placeholder="Password" value="<?php echo $row1['image'];?>"
/>
<?php if (!empty($Errorimage)) { ?> <p class="text text-danger"><?php echo $Errorimage; ?></p> <?php } ?>
</div>
</div>
<?php
}
?>
</div>
<div align="center">
<?php if (!empty($success)) { ?> <span class="label label-success"><?php echo $success; ?></span> <?php } ?>
<?php if (!empty($errorSubmit)) { ?> <span class="label label-danger"><?php echo $errorSubmit; ?></span> <?php } ?>
</div>
<div class="panel-footer text-right">
<button class="btn btn-success" type="submit" name="updatecustomer">Update Customer</button>
</div>
</form>
</div>
</div>
</div>
</div>
<?php
include 'include/sidebar.php';
include 'include/footer.php';
?>
<?php
}
else
{
header('location:login.php');
}
?>
please check first area is inserting to DB or not?

Php Prepared Statement Fails to insert data into database through form

I'm trying to insert data into a database, the script executes all the way down and redirect the user to the page but no record gets inserted. I've been trying to figure out why for hours. I keep creating new scripts but i'm missing something apparently.
init.php
<?php
/*for error 1045 config.inc.php*/
define("DB_HOST", "localhost");
define("DB_USER", "root");
define("DB_PASSWORD", "");
define("DB_DATABASE", "databasename");
$db = mysqli_connect(DB_HOST, DB_USER, DB_PASSWORD, DB_DATABASE);
if(mysqli_connect_errno()){
echo "database failed to connect with following errors:". mysqli_connect_error();
die();
}
require_once $_SERVER['DOCUMENT_ROOT'].'/ecommerce/config.php';
require_once BASEURL.'helpers/helpers.php';
form.php
<?php
ob_start();
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
require_once $_SERVER['DOCUMENT_ROOT'].'/HeleneQuirion/core/init.php';
include 'includes/header.php';
if(isset($_GET['add'])){
$parentQuery = $db->query("SELECT * FROM categories WHERE parent= 0" );
if (isset($_POST['submit'])) {
// prepare and bind
$stmt = $db->prepare("INSERT INTO product (prod_name, categories, list_price, price,prod_width,prod_depth,prod_height,prod_material,quantity,image_1,image_2,image_3,image_4,description,care_instructions) VALUES (?,?, ?,?,?,?,?,?,?,?,?,?,?,?,?)");
$stmt->bind_param("ssiiiiisissssss" ,$prod_name, $child,$list_price,$price,$prod_width,$prod_depth,$prod_height,$prod_material,$quantity,$image_1,$image_2,$image_3,$image_4,$description,$care_instructions);
// set parameters and execute
if(isset($_POST['prod_name']))
{
$prod_name = sanitize($_POST)['prod_name'];
}
if(isset($_POST['child']))
{
$categories = sanitize($_POST)['child'];
}
if(isset($_POST['list_price']))
{
$prod_name = sanitize($_POST)['list_price'];
}
if(isset($_POST['price']))
{
$price = sanitize($_POST)['price'];
}
if(isset($_POST['prod_width']))
{
$prod_width = sanitize($_POST)['prod_width'];
}
if(isset($_POST['prod_depth']))
{
$prod_depth = sanitize($_POST)['prod_depth'];
}
if(isset($_POST['prod_height']))
{
$prod_height = sanitize($_POST)['prod_height'];
}
if(isset($_POST['prod_material']))
{
$prod_material = sanitize($_POST)['prod_material'];
}
if(isset($_POST['quantity']))
{
$quantity = sanitize($_POST)['quantity'];
}
if(isset($_POST['care_instructions']))
{
$care_instructions = sanitize($_POST)['care_instructions'];
}
if(isset($_POST['image_1']))
{
$image_1 = $_FILES['image_1'];
}
if(isset($_POST['image_2']))
{
$image_2 = $_FILES['image_2'];
}
if(isset($_POST['image_3']))
{
$image_3 = $_FILES['image_3'];
}
if(isset($_POST['image_4']))
{
$image_4 = $_FILES['image_4'];
}
if(isset($_POST['description']))
{
$description = sanitize($_POST)['description'];
}
$stmt->execute() or die(mysqli_error($db));
header('Location: products.php');
$stmt->close();
$conn->close();
}
?>
<form action="products.php?add=1" method="POST" enctype="multipart/form-data">
<div class='container_12'>
<div class="form-group col-md-3">
<label for="prod_name">Product Name*:</label>
<input type="text" name="prod_name" id="prod_name" class="form-control" value="<?=((isset($_POST['prod_name']))?sanitize($_POST['prod_name']):' ');?>">
</div>
<div class="form-group col-md-3">
<label for="parent">Parent Category*:</label>
<select class="form-control" id="parent" name="parent">
<option value=""<?=((isset($_POST['parent']) && $_POST['parent'] == '')?'selected':'');?>></option>
<?php while($parent = mysqli_fetch_assoc($parentQuery)): ?>
<option value=" <?=$parent['id'];?>"<?=((isset($_POST['parent']) && $_POST['parent'] == $parent['id'])?' select':'');?>><?=$parent['category_name'];?></option>
<?php endwhile; ?>
</select>
</div>
<div class='form-group col-md-3'>
<label for='child'>Second Category*:</label>
<select id='child' name='child' class='form-control'></select>
</div>
</div>
<div class='container_12'>
<div class='form-group col-md-3'>
<label for='list_price'>List Price(OPTIONAL): </label>
<input type="text" id="list_price" name="list_price" class="form-control" value="<?=((isset($_POST['list_price']))?sanitize($_POST['list_price']):'');?>">
</div>
<div class="form-group col-md-3">
<label for="price">Price*:</label>
<input type="text" id="price" name="price" class="form-control" value="<?=((isset($_POST['price']))?sanitize($_POST['price']):'');?>">
</div>
<div class='form-group col-md-3'>
<label for='prod_width'>Width* (in inches):</label>
<input type="text" id="prod_width" name="prod_width" class="form-control" value="<?=((isset($_POST['prod_width']))?sanitize($_POST['prod_width']):'');?>">
</div>
<div class='form-group col-md-3'>
<label for='prod_depth'>Height*(in inches):</label>
<input type="text" id="'prod_depth" name="'prod_depth" class="form-control" value="<?=((isset($_POST['prod_depth']))?sanitize($_POST['prod_depth']):'');?>">
</div>
</div>
<div class='container_12'>
<div class='form-group col-md-3'>
<label for='prod_height'>Depth*(in inches):</label>
<input type="text" id="prod_height" name="prod_height" class="form-control" value="<?=((isset($_POST['prod_height']))?sanitize($_POST['prod_height']):'');?>">
</div>
<div class='form-group col-md-3'>
<label for='prod_material'>Construction Material:</label>
<input type="text" id="prod_material" name="prod_material" class="form-control" value="<?=((isset($_POST['prod_material']))?sanitize($_POST['prod_material']):'');?>">
</div>
<div class='form-group col-md-6'>
<label>Quantity * :</label>
<input type="text" id="quantity" name="quantity" class="form-control" value="<?=((isset($_POST['quantity']))?sanitize($_POST['quantity']):'');?>">
</div>
</div>
<div class='container_12'>
<div class="form-group col-md-3"> <label for="image_1">Product Photo #1:</label>
<input type="file" name="image_1" id="image_1" class="form-control">
</div>
<div class="form-group col-md-3"> <label for="image_2">Product Photo #2:</label>
<input type="file" name="image_2" id="image_2" class="form-control">
</div>
<div class="form-group col-md-3"> <label for="image_3">Product Photo #3:</label>
<input type="file" name="image_3" id="image_3" class="form-control">
</div>
<div class="form-group col-md-3"> <label for="image_4">Product Photo#4:</label>
<input type="file" name="image_4" id="image_4" class="form-control">
</div>
</div>
<div class='container_12'>
<div class="form-group col-md-6">
<label for="description">Description:</label>
<textarea id="description" name="description" class="form-control" rows="6"><?=((isset($_POST['description']))?sanitize($_POST['description']):'');?></textarea>
</div>
<div class="form-group col-md-6">
<label for="care_instructions">Care Instructions*:</label>
<textarea id="care_instructions" name="care_instructions" class="form-control" rows="6"><?=((isset($_POST['care_instructions']))?sanitize($_POST['care_instructions']):'');?></textarea>
</div></div>
<div class='container_12'>
<div class="form-group pull-right">
<input type='submit' name='submit' value='Add Product' class='form-control btn-success pull-right'>
</div></div>
</form>
This is just to clarify one of the points in the comments above...
So I knocked up some test code to check what is going on...
<?php
$_POST['prod_name'] = 'fred';
function sanitize($thing){
var_dump("Inside Sanitize- ", $thing);
return $thing;
}
// Original Code - sends an array to sanitize
if(isset( $_POST['prod_name'] )) {
$prod_name = sanitize($_POST)['prod_name'];
}
var_dump('Original Version '.$prod_name);
// New Code 1 - Sends a String to sanitize
if(isset( $_POST['prod_name'] )) {
$prod_name = sanitize($_POST['prod_name']);
}
// New Code 2 - Should use this one, or could make this a function.
$prod_name = isset($_POST['prod_name'])? sanitize($_POST['prod_name']):'';
var_dump($prod_name);

Submit button won't work in PHP

PHP Code
<?php
if (!isset($_SESSION)) { session_start(); }
include "connect.php";
include "functions.php";
if (!isset($_SESSION['login']) || $_SESSION['login'] !== true) {
header('location: no_acces.php');
exit();
} else {
$id_user = $_SESSION['userid'];
$q_user = mysqli_query($conn, "SELECT * FROM users WHERE id = $id_user");
if (mysqli_num_rows($q_user) === 1) {
$r_user = mysqli_fetch_assoc($q_user);
} else {
unset($_SESSION['login']);
unset($_SESSION['userid']);
header('location: no_acces.php');
exit();
}
}
$error = "";
$userQuery = mysqli_query($conn, "SELECT username FROM users");
$user = mysqli_fetch_assoc($userQuery);
$id = $_GET['id'];
if (isset($_POST['edit_contact'])) {
$roepnaam = $_POST['roepnaam'];
$naam = $_POST['naam'];
$land = $_POST['land'];
$bedrijf = $_POST['bedrijf'];
$adres1 = $_POST['adres1'];
$adres2 = $_POST['adres2'];
$stad = $_POST['stad'];
$postcode = $_POST['postcode'];
$provincie = $_POST['provincie'];
$telefoon = $_POST['telefoon'];
$email = $_POST['email'];
$captcha= $_POST['g-recaptcha-response'];
if(!$captcha){
$error = "Er is een fout opgetreden";
}
if ($error == "") {
$insertUser = ("UPDATE address SET
roepnaam = '$roepnaam', naam = '$naam', bedrijf = '$bedrijf', telefoon = '$telefoon', email = '$email', adres1 = '$adres1', adres2 = '$adres2', stad = '$stad', postcode = '$postcode', provincie = '$provincie', land = '$land' WHERE id = $id");
if (mysqli_query($conn, $insertUser)) {
$_SESSION['edit_contact'] = true;
header('location: address_book.php');
} else {
$error = "Er is een fout opgetreden";
}
}
}
?>
HTML Code
<!DOCTYPE html>
<html lang="en">
<body>
<form action="" method="post">
<?php if ($error !== "") { ?>
<div class="row">
<div class="col-md-12 error">
<?php echo $error; ?>
</div>
</div>
<?php } ?>
<label for="firstName" class="control-label">Naam:</label>
<div class="row ">
<div class="col-md-6">
<input type="text" class="form-control" id="firstName" placeholder="Roepnaam" name="roepnaam" value="<?php if (isset($_POST['roepnaam'])) { echo $_POST['roepnaam']; } ?>" required/>
</div>
<div class="col-md-6">
<input type="text" class="form-control" id="lastName" placeholder="Naam" name="naam" value="<?php if (isset($_POST['naam'])) { echo $_POST['naam']; } ?>" required/>
</div>
</div>
<label for="username" class="control-label">Bedrijf:</label>
<div class="row ">
<div class="col-md-12">
<input type="text" class="form-control" id="username" placeholder="Bedrijf" name="bedrijf" value="<?php if (isset($_POST['bedrijf'])) { echo $_POST['bedrijf']; } ?>" required/>
</div>
</div>
<label for="password" class="control-label">Telefoonnummer:</label>
<div class="row ">
<div class="col-md-12">
<input type="text" class="form-control" id="password" placeholder="Telefoonnummer" name="telefoon" value="<?php if (isset($_POST['telefoon'])) { echo $_POST['telefoon']; } ?>" required/>
</div>
</div>
<label for="email" class="control-label">Email:</label>
<div class="row ">
<div class="col-md-12">
<input type="text" class="form-control" id="email" placeholder="E-mailadres" name="email" value="<?php if (isset($_POST['email'])) { echo $_POST['email']; } ?>" required/>
</div>
</div>
<label for="adres1" class="control-label">Adres:</label>
<div class="row">
<div class="col-md-12">
<input type="text" class="form-control" id="adres1" placeholder="Adres 1" name="adres1" value="<?php if (isset($_POST['adres1'])) { echo $_POST['adres1']; } ?>" required/>
</div>
</div>
<div class="row padding-top-10">
<div class="col-md-12">
<input type="text" class="form-control" id="adres2" placeholder="Adres 2" name="adres2" value="<?php if (isset($_POST['adres2'])) { echo $_POST['adres2']; } ?>"/>
</div>
</div>
<div class="row">
<div class="col-md-3">
<label for="postcode" class="control-label">Postcode:</label>
</div>
<div class="col-md-5">
<label for="city" class="control-label">Stad:</label>
</div>
<div class="col-md-4">
<label for="regio" class="control-label">Regio:</label>
</div>
</div>
<div class="row ">
<div class="col-md-3">
<input type="text" class="form-control" id="postcode" placeholder="Postcode" name="postcode" value="<?php if (isset($_POST['postcode'])) { echo $_POST['postcode']; } ?>" required/>
</div>
<div class="col-md-5">
<input type="text" class="form-control" id="city" placeholder="Stad" name="stad" value="<?php if (isset($_POST['stad'])) { echo $_POST['stad']; } ?>" required/>
</div>
<div class="col-md-4">
<input type="text" class="form-control" id="regio" placeholder="Provincie" name="provincie" value="<?php if (isset($_POST['provincie'])) { echo $_POST['provincie']; } ?>" required/>
</div>
</div>
<label for="land" class="control-label">Land:</label>
<div class="row ">
<div class="col-md-12">
<input type="text" class="form-control" id="password" placeholder="Land" name="land" value="<?php if (isset($_POST['land'])) { echo $_POST['land']; } ?>" required/>
</div>
</div>
<div class="row">
<div class="col-md-8 padding-top-10 ">
<div class="g-recaptcha " data-sitekey="6LcCsBoTAAAAAK72uzyJSrgWwD8xuF6jFIfgFaHX"></div>
</div>
</div>
<div class="row">
<div class="col-md-2 padding-top-10">
<input type="submit" name="edit_contact" class="btn btn-succes" value="Wijzigen">
</div>
<div class="col-md-2 padding-top-10">
<input type="text" name="delete_contact" action="delete_contact.php" class="btn btn-succes" value="Contact verwijderen">
</div>
</div>
</form>
</body>
</html>
PHP Code
<?php
if (!isset($_SESSION)) { session_start(); }
include "connect.php";
include "functions.php";
if (!isset($_SESSION['login']) || $_SESSION['login'] !== true || !isset($_SESSION['userid']) || $_SESSION['userid'] == "") {
header('location: login.php');
exit();
} else {
session_regenerate_id();
}
$id = $_GET['id'];
$query = "DELETE FROM address WHERE id= $id";
mysqli_query ($query);
if (mysql_affected_rows() == 1) {
header('location: addressbook.php');
} else {
echo "Verwijderen mislukt";
}
?>
I'm trying to make a delete button for my contacts within the addressbook. but everytime I click "Contact verwijderen" the webpage resets it self and the contact won't be deleted. Could anyone help me to fix this?
You input is a text input and you don't have a form asociated with it,create one and change the type of submit to submit
<form action="delete_contact.php" method="post">
//other inputs
<input type="submit" name="delete_contact" class="btn btn-succes" value="Contact verwijderen">
</form>
You are mixing MySQL and MySQLi functions:
mysqli_query ($query);
if (mysql_affected_rows() == 1)
You cannot mix MySQL with MySQLi, your code should be:
mysqli_query ($query);
if (mysqli_affected_rows($conn) == 1)
Add a normal link to delete the contact, you don't need a form.
<a href="delete_contact.php?id=<?php echo $id ?>">
Contact verwijderen
</a>

Categories