I am in the middle of creating a CMS in PHP & MySQL for the company I work for and have hit a bump in the road.
So I have a table that fetches and lists everything from a table, then next to each record is an edit button.
This button has the following code:
<?php
echo '<td><form method="POST" action="editRecord.php?id='.$id.'">
<input type="submit" name="Edit"></form></td>';
?>
Which then obviously goes to that page, however on the next page i have the following code and it's not running anything.
I don't understand why it's not fetching the information from the database if I have given it the ID...
include 'login/connection.php';
$id = $row['id'];
$result = $db->query("SELECT * FROM vehicleOrderForm WHERE id = ' $id ' ");
$row = mysqli_fetch_array($result);
That code is at the start and then further down is this;
<?php
echo $row["id"];
$id = $row["id"];
$make = $row["make"];
$varient = $row["varient"];
$stockno = $row["stockno"];
$transmission = $row["transmission"];
$cc = $row["cc"];
$colour = $row["colour"];
$delivery = $row["delivery"];
$stock = $row["stock"];
$sold = $row["sold"];
$customer = $row["customer"];
$tax = $row["tax"];
$comments = $row["comments"];
?>
<div>
<h1><?php echo $id; ?></h1>
</div>
<form method="POST" action="">
<p>Make:</p>
<?php echo '<input type="text" name="make" value="'.$make.'" />;' ?>
<p>Varient:</p>
<input type="text" name="varient" value=" <?php echo $varient; ?>" /> <br />
<p>Stock Number:</p>
<input type="email" name="stockno" value="<?php echo $stockno; ?>" /> <br />
<p>Transmission:</p>
<input type="number" name="transmission" value="<?php echo $transmission; ?>" /> <br />';
<p>CC:</p>
<input type="username" name="cc" value="<?php echo $cc; ?>" /> <br />';
<p>Colour:</p>
<input type="text" name="colour" value="<?php echo $colour; ?>" /> <br />';
<p>Expected Delivery:</p>
<input type="text" name="delivery" value="<?php echo $delivery; ?>"/> <br />';
<p>In Stock:</p>
<input type="text" name="stock" value="<?php echo $stock; ?>"/> <br />';
<p>Status:</p>
<input type="text" name="sold" value="<?php echo $sold; ?>"/> <br />';
<p>Customer:</p>
<input type="text" name="customer" value="<?php echo $customer; ?>"/> <br />';
<p>Tax:</p>
<input type="text" name="tax" value="<?php echo $tax; ?>"/> <br />';
<p>Comments:</p>
<input type="text" name="comments" value="<?php echo $comments; ?>"/> <br />';
<input type="Submit" name="Edit" value="Edit">';
</form>
If anyone can understand it, that would be great.
That form around the Edit button looks like it's totally useless.. You can't sent the form with POST method, and attach an id to the action url: that param won't be sent.
Solution 1: If you can, I would suggest you to switch to GET param and use an anchor. Like this:
<?php echo '<td>Edit</td>'; ?>
And edit your code on page editRecord.php as follows:
$id = $_GET['id']; // you need to receive the param from the url
Solution 2: If you want to keep the <form>, you should write the following code:
<?php
echo '<td><form method="POST" action="editRecord.php"> '.
'<input type="hidden" name="id" value="'.$id.'" />'.
'<input type="submit" name="Edit"></form></td>';
?>
And on page editRecord.php:
$id = $_POST['id']; // you need to receive the param from the url
Related
I am trying to submit multiple inputs with data using one submit button with an ajax request. However the the response returns an empty array.
What could be the problem?
jQuery
$('#setup').click(function(){
var formData = new FormData(jQuery('#form8')[0]);
xhr_post(formData,'./ajax/SendUsers.php','SVRMSG');
});
PHP and HTML:
echo '<form id="form8" method="POST">';
$gen = generateRandomString();
include('connection.php');
$stmt = $conn->prepare('SELECT * FROM `clients_table`,`client_education_system` WHERE id = edu_client_id ORDER BY id ASC');
$stmt->execute();
$result = $stmt->get_result();
$num_rows = mysqli_num_rows($result);
while ($row = $result->fetch_assoc()) {
if ($row['edu_course_D'] == 6 ){
?>
ID: <input style="border:0;" type="text" disabled="disabled" name="id[]" value="<?php echo $row['id']; ?>"/>
<br>
Valid Until : <input style="border:0;" disabled="disabled" type="text" name="valid[]" placeholder="validity date" value="<?php echo getLinks('24'); ?>"/>
<br>
Conference date: <input style="border:0;" disabled="disabled" type="text" name="cdate[]" placeholder="conference date" value="<?php echo getContent('24'); ?>"/>
<br>
Serial number : <input style="border:0;" disabled="disabled" type="text" name="serial[]" placeholder="serial" value="<?php echo $row['id'].$gen; ?>"/>
<br>
<input type="text" name="" value=""/>
<br>
<?php
echo '<center>';
echo '<button id="cancelSetup" style="background:white;color:red;" type="button" name="cancelsu">Cancel</button> ';
echo '<button id="setup" style="background:white;color:red;" type="button" >Send</button>';
echo '<div id="SVRMSG"></div>';
echo "</form>";
?>
sendusers.php file
<?php
require_once('..\inc\backend-func.php');
if( $_SERVER['REQUEST_METHOD'] == 'POST'){
print_r($_POST);
}
?>
I am trying to fill a html form with data being received out of my mysql database. However I cannot set the forms to display on-load the variables being extracted from the database. I would like the form on-load to hold the data last entered into the forms which have been added to the database previously.
$query = "SELECT FROM character_tbl WHERE character_player
='".$_SESSION["user"]."' character_tbl";
$result = mysql_query($query);
while($row = mysql_fetch_array($result)){
$name = $row['character_name'];
$race = $row['character_race'];
$class = $row['character_class'];
$alignment = $row['character_alignment'];
$hp = $row['character_hp'];
$str = $row['character_str'];
$dex = $row['character_dex'];
$con = $row['character_con'];
$int = $row['character_int'];
$wis = $row['character_wis'];
$cha = $row['character_cha'];
$ac = $row['character_ac'];
$touch = $row['character_touch'];
$flat = $row['character_flat'];
$fort = $row['character_fort'];
$ref = $row['character_ref'];
$will = $row['character_will'];
}
echo $will;
mysql_close();
?>
<!DOCTYPE html>
<html>
<body>
<div id="nav">
<form action="user.php">
<input type="submit" value="Back">
</form>
</div>
<div id="section">
<form action="update.php" method="POST">
Character Name:<br>
<input type="text" name="name" value="<?php echo $name;?>">
<br>
Race<br>
<input type="text" name="race" value="<?php echo $race;?>">
<br>
Class<br>
<input type="text" name="class" value="<?php echo $class;?>">
<br>
Alignment<br>
<input type="text" name="alignment" value="<?php echo $alignment;?>">
<br>
HP<br>
<input type="text" name="hp" value="<?php echo $hp;?>">
<br>
STR<br>
<input type="number" name="str" value="<?php echo $str;?>">
<br>
DEX<br>
<input type="number" name="dex" value="<?php echo $dex;?>">
<br>
CON<br>
<input type="text" name="con" value="<?php echo $con;?>">
<br>
INT<br>
<input type="text" name="int" value="<?php echo $int;?>">
<br>
WIS<br>
<input type="text" name="wis" value="<?php echo $wis;?>">
<br>
CHA<br>
<input type="text" name="cha" value="<?php echo $cha;?>">
<br>
AC<br>
<input type="text" name="ac" value="<?php echo $ac;?>">
<br>
Touch AC<br>
<input type="text" name="touch" value="<?php echo $touch;?>">
<br>
Flat-Footed AC<br>
<input type="text" name="flat" value="<?php echo $flat;?>">
<br>
Fortitude<br>
<input type="text" name="fort" value="<?php echo $fort;?>">
<br>
Reflex<br>
<input type="text" name="ref" value="<?php echo $ref;?>">
<br>
Will<br>
<input type="text" name="will" value="<?php echo $will;?>">
</br>
<input type="submit" value="Update">
</form>
I think the SQL has error:
SELECT FROM character_tbl WHERE character_player
try:
SELECT * FROM character_tbl WHERE character_player
You have syntax error in your mysql query. You have not place field or columns name or (*) for all columns to extract.
Try like this..
$query = "SELECT * FROM character_tbl WHERE character_player ='".$_SESSION['user']."'";
I am echo values by the codes below. but i want to create for each values form for saving to database.
How can i insert form inside echo ?
I am beginer in php and i want form like this and it must replace with all echo values.
----FORM----
Thumbnail url :
url :
description:
submit Button
----FORM----
this is the code
foreach($posts as $post){
if ($post){
echo $post->thumbnail . "<br />";
echo $post->url . "<br />";
echo $post->description . "<br />";
}
}
I solved how to add.
foreach($posts as $post){
if ($post){
echo '<input id="title" class="form-control" type="text" name="title" value="'.htmlspecialchars($post->thumbnail).'">';
echo '<input id="teaser" class="form-control" type="text" name="teaser" value="'.htmlspecialchars($post->Url).'">';
echo '<input id="text" class="form-control" type="text" name="text" value="'.htmlspecialchars($post->description).'">';
echo '<button class="btn btn-primary" type="submit">add</button>';
}
}
this works fine... My second question is how i can add the code below codes to inside echo in a same way ?
i tried to add same way but (if isset line ) gives error
<input type="hidden" name="mode" value="news" />
<input type="hidden" name="edit_news_submit" value="true" />
<?php if(isset($edit_news['id'])): ?>
<input type="hidden" name="id" value="<?php echo $edit_news['id']; ?>" />
<?php endif; ?>
How do I integrate paybox system to handle deferred payment?
I learned that PBX_DIFF parameter is used to mention no. of days to delay the transaction. Thats exactly what I wanted. But there seems no working code for php with deferred payment for Paybox.
The following code is working fine without mentioning the deferred payment parameter (PBX_DIFF). But when I add that parameter, its not working
<form name="paybox_frm" id="paybox_frm" method="GET" action="<?php echo $payboxUrl;?>">
<input type="hidden" name="PBX_SITE" value="<?php echo $PBX_SITE; ?>">
<input type="hidden" name="PBX_RANG" value="<?php echo $PBX_RANG; ?>">
<input type="hidden" name="PBX_IDENTIFIANT" value="<?php echo $PBX_IDENTIFIANT; ?>">
<input type="hidden" name="PBX_TOTAL" value="<?PHP echo $MONTANT;?>">
<input type="hidden" name="PBX_DEVISE" value="<?php echo $PBX_DEVISE; ?>">
<input type="hidden" name="PBX_CMD" value="<?PHP echo $REFERENCE;?>">
<input type="hidden" name="PBX_PORTEUR" value="<?PHP echo $PORTEUR;?>">
<input type="hidden" name="PBX_RETOUR" value="<?php echo $PBX_RETOUR;?>">
<input type="hidden" name="PBX_HASH" value="<?php echo $PBX_HASH;?>">
<input type="hidden" name="PBX_TIME" value="<?PHP echo $datetime;?>">
<input type="hidden" name="PBX_HMAC" value="<?PHP echo $pbx_hmac;?>">
<!-- Code added for return url-->
<input type="hidden" name="PBX_REFUSE" value="<?PHP echo $PBX_REFUSE;?>" />
<input type="hidden" name="PBX_ANNULE" value="<?PHP echo $PBX_ANNULE;?>" />
<input type="hidden" name="PBX_EFFECTUE" value="<?PHP echo $PBX_EFFECTUE;?>" />
<input type="hidden" name="PBX_LANGUE" value="<?PHP echo $PBX_LANGUE;?>" />
Any help greatly appreciated. Thanks in advance.
<section class="rl-box">
<div class="container padd-xs-0">
<div class="content-section1">
<div class="left-cont col-md-12 col-sm-12"
<div class="container-fluid">
<?php
$PBX_SITE = "1999888";
$PBX_RANG = "32";
$PBX_IDENTIFIANT = "your identifiant id";
$secretKeyTest = "0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF";
$PBX_PORTEUR = "your-email";
$PAYBOX_DOMAIN_SERVER = "tpeweb.paybox.com";
$dateTime = date("c");
$PBX_TOTAL = 4000; //$_POST["PBX_TOTAL"]; // Amount
$PBX_DEVISE = 978;
//$PBX_CMD = $_POST["PBX_CMD"]."|".$_POST["user"]."|".$_POST["typed"]."|".$_POST["period"]."|".$_POST["id"]; // order ID no.
$PBX_CMD = 1; // order ID no.
$PBX_RETOUR = "Mt:M;Ref:R;Auto:A;Erreur:E";
$PBX_HASH = "SHA512";
$PBX_TIME = $dateTime;
//$PBX_EFFECTUE = "http://www.leader-underwriting.eu/payment/payment.php";
$msg = "PBX_SITE=$PBX_SITE" .
"&PBX_RANG=$PBX_RANG" .
"&PBX_IDENTIFIANT=$PBX_IDENTIFIANT" .
"&PBX_TOTAL=$PBX_TOTAL" .
"&PBX_DEVISE=$PBX_DEVISE" .
"&PBX_CMD=$PBX_CMD" .
"&PBX_PORTEUR=$PBX_PORTEUR" .
"&PBX_RETOUR=$PBX_RETOUR" .
"&PBX_HASH=$PBX_HASH" .
"&PBX_TIME=$PBX_TIME";
$binKey = pack("H*", $secretKeyTest);
$hmac = strtoupper(hash_hmac('sha512', $msg, $binKey));
$cuu = str_replace(",", "", $ramount);
?>
<form method="POST" name="form_payment" action="https://preprod-tpeweb.paybox.com/cgi/MYchoix_pagepaiement.cgi">
<input type="hidden" name="PBX_SITE" value="<?php echo $PBX_SITE; ?>">
<input type="hidden" name="PBX_RANG" value="<?php echo $PBX_RANG; ?>">
<input type="hidden" name="PBX_IDENTIFIANT" value="<?php echo $PBX_IDENTIFIANT; ?>">
<input type="hidden" name="PBX_TOTAL" value="<?php echo $PBX_TOTAL; ?>"> <!--dynamic-->
<input type="hidden" name="PBX_DEVISE" value="<?php echo $PBX_DEVISE; ?>">
<input type="hidden" name="PBX_CMD" value="<?php echo $PBX_CMD; ?>"> <!--dynamic-->
<input type="hidden" name="PBX_PORTEUR" value="<?php echo $PBX_PORTEUR ?>">
<input type="hidden" name="PBX_RETOUR" value="<?php echo $PBX_RETOUR; ?>">
<input type="hidden" name="PBX_HASH" value="<?php echo $PBX_HASH; ?>">
<input type="hidden" name="PBX_TIME" value="<?php echo $PBX_TIME; ?>">
<input type="hidden" name="PBX_HMAC" value="<?php echo $hmac; ?>">
<button type="submit" class="btn btn-primary payment">
Payer
</button>
</form>
<center>
</center>
</div>
</div>
</div> <!-- .container-fluid -->
</div>
</div>
</div>
</section>
I want to check if either of my search fields are empty, and if they are i write out a failure message. For some reason the following code doesn't work when I try to submit empty values in both search fields, or leaving the q2 search field empty. It only writes out the failure message when I only insert a value into the first field. Hope you guys can help.
<div id="searchField">
<form name="searchField" action="" method="get">
<input type="search" name="q" id="submitQuery" autofocus="autofocus" value="<?= $_GET['q']; ?>" placeholder="enter one movie"/>
<input type="search" name="q2" id="submitQuery2" value="<?= $_GET['q2']; ?>" placeholder="and then another one"/>
<input type="hidden" id="v" name="v" value="2" />
<input type="hidden" id="b" name="b" value="" />
<button type="submit" id="loop" style="border:0px; background:transparent; vertical-align:middle; margin-left:-85px; margin-top:-3px;">
<img src="images/loop.png" width="75" height="75" alt="submit" />
</button>
</form>
</div>
<div id="theData">
<?
if(str_replace(" ", "",$_GET['q'])!="" && str_replace(" ","",$_GET['q2'])!=""){
$qContent = $_GET['q'];
$succes = mysql_query("SELECT*FROM film WHERE name='".$qContent."'");
include("searchMaster.php");
if(mysql_num_rows($succes)) {
while($o = mysql_fetch_array($succes)){
echo $o['name'];
if($o['trailer']){
echo '<div id="ytplayerWrap">';
echo '<iframe id="ytplayer" type="text/html" width="640" height="390"
src="http://www.youtube.com/embed/'.$o['trailer'].'?http://amnestic.ueuo.com"
frameborder="0"/>';
echo '</div>';
}else {
echo '<span style="font-size:20px;">';
echo '<br /><br /> No trailer was found for <em>'.$_GET['q'].'</em> :(';
echo '</span>';
}
}
}else{
echo 'You did the fuckup :(';
}
}else{
echo 'You did the fuckup :(';
}
?>
The name and id of your input fields must be same
Like this
<input type="text" name="submitQuery" id="submitQuery" autofocus="autofocus" value="<?= $_GET['q']; ?>" placeholder="enter one movie"/>
<input type="text" name="submitQuery2" id="submitQuery2" value="<?= $_GET['q2']; ?>" placeholder="and then another one"/>