How can I remove query string from URL? - php

Here is my code. It is a simple html form with two inputs. All data is saved into xml file using DOMDocument a then all data from XML file is inserted into the table below the form. I added two buttons edit and delete (x). Now I can edit and delete any user/player from the table. And here is my problem. I need to remove query string from URL after deleting or editing. I want to add a new user/player into the table after deleting. When I delete manually query string from URL everything works fine again. But I want to delete query string automatically after deleting some user. Sorry for my English hoping you understand me. Thanks in advance!
<?php
if ($_SERVER["REQUEST_METHOD"] == "POST") {
$xml = new DOMDocument("1.0", "utf-8");
if (is_file('database.xml')) {
$xml->load("database.xml");
$db = $xml->getElementsByTagName('db')->item(0);
} else {
$db = $xml->createElement("db");
$xml->appendChild($db);
$db = $xml->getElementsByTagName('db')->item(0);
}
$newPlayer = $xml->createElement("player");
foreach ($_POST as $key => $value) {
$playerStuff = $xml->createElement($key, $value);
$newPlayer->appendChild($playerStuff);
}
$db->appendChild($newPlayer);
$xml->save("database.xml");
}
$name = $number = "";
if (isset($_GET['action']) && $_GET['action'] == 'edit') {
$xml = new DOMDocument("1.0", "utf-8");
$xml->load("database.xml");
$player = $xml->getElementsByTagName('player')->item($_GET['id']);;
$name = $player->getElementsByTagName('name')->item(0)->nodeValue;
$number = $player->getElementsByTagName('number')->item(0)->nodeValue;
}
if (isset($_GET['action'])) {
switch ($_GET['action']){
case 'edit':
$xml = new DOMDocument("1.0", "utf-8");
$xml->load("database.xml");
$player = $xml->getElementsByTagName('player')->item($_GET['id']);
$nameEl = $player->getElementsByTagName('name')->item(0);
$numberEl = $player->getElementsByTagName('number')->item(0);
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
$newName = $xml->createElement("name", $_POST["name"]);
$nameEl->parentNode->replaceChild($newName, $nameEl);
$newNumber = $xml->createElement("number", $_POST["number"]);
$numberEl->parentNode->replaceChild($newNumber, $numberEl);
$db = $xml->getElementsByTagName('db')->item(0);
$lastElement = $db->lastChild;
$lastElement->parentNode->removeChild($lastElement);
}
$xml->save("database.xml");
break;
case 'delete':
$xml = new DOMDocument("1.0", "utf-8");
$xml->load("database.xml");
//$xml = $dokument->getElementsByTagName('xml')->item(0);
$player = $xml->getElementsByTagName('player')->item($_GET['id']);
$player->parentNode->removeChild($player);
$xml->save("database.xml");
break;
}
}
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>PLAYERS</title>
<link rel="stylesheet" href="stylesss.css">
</head>
<body>
<form action="" method="POST">
<input type="text" name="name" value="<?php echo $name ?>">
<input type="text" name="number" value="<?php echo $number ?>">
<input type="submit" value="INSERT">
</form>
<?php
$xml = new DOMDocument("1.0", "utf-8");
if (is_file('database.xml')) {
$xml->load('database.xml');
$players = $xml->getElementsByTagName("player");
echo "<table>";
echo "<tr><th>" . "Player Name" . "</th><th>" . "Number". "</th></tr>";
foreach($players as $key => $player){
echo "<tr>";
foreach($player->childNodes as $data) {
echo "<td>". $data->nodeValue ."</td>";
}
echo "<td>
<a href='?id={$key}&action=edit' class='buttons edit'>EDIT</a>
<a href='?id={$key}&action=delete' class='buttons delete'>&#10006</a>
</td>";
echo "</tr>";
}
}
echo "</table>";
?>
</body>
</html>

I would say to redirect header("Location: your-page.php"); The page you redirect to can be the same page but without the query string. It means that if someone refreshes you will not repeat the same action. So, something like this. You have to use the header function before anything is written to the page, it will not work if it is used after HTML or after something is print or echo to the page.
if (isset($_GET['action'])) {
switch ($_GET['action']){
case 'edit':
$xml = new DOMDocument("1.0", "utf-8");
$xml->load("database.xml");
$player = $xml->getElementsByTagName('player')->item($_GET['id']);
$nameEl = $player->getElementsByTagName('name')->item(0);
$numberEl = $player->getElementsByTagName('number')->item(0);
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
$newName = $xml->createElement("name", $_POST["name"]);
$nameEl->parentNode->replaceChild($newName, $nameEl);
$newNumber = $xml->createElement("number", $_POST["number"]);
$numberEl->parentNode->replaceChild($newNumber, $numberEl);
$db = $xml->getElementsByTagName('db')->item(0);
$lastElement = $db->lastChild;
$lastElement->parentNode->removeChild($lastElement);
}
$xml->save("database.xml");
break;
case 'delete':
$xml = new DOMDocument("1.0", "utf-8");
$xml->load("database.xml");
//$xml = $dokument->getElementsByTagName('xml')->item(0);
$player = $xml->getElementsByTagName('player')->item($_GET['id']);
$player->parentNode->removeChild($player);
$xml->save("database.xml");
break;
}
header("Location: your-page.php");
}

Related

Store random value, $_SESSION and $_POST issue

I'm making something similar a captha, the not working part is the IF, under if(isset($_POST['submit'])), that always returns false. I think.
Tried a lot ways with no luck...
Anyway, I have followed this solution https://stackoverflow.com/a/21504949/4167976 without success.
Here is my test php and html:
<?php
session_start();
$char = "abcdefghijklmnopqrstuvwxyz1234567890";
$code = $char[rand(0,35)].$char[rand(0,35)].$char[rand(0,35)].$char[rand(0,35)].$char[rand(0,35)].$char[rand(0,35)];
$_SESSION["testcode"] = $code;
echo $_SESSION["testcode"]."<br>"; // echo here only for testing
if(isset($_POST['submit'])) {
$code1 = mb_substr($_POST['fullcode'], 0, 5);
$code2 = mb_substr($_POST['fullcode'], -6);
if ($code2 == $_SESSION["testcode"])
{echo "The code is correct!";}
else
{echo "Wrong code!";}
// unset($_SESSION['testcode']); // ???
}
?>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
<body>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
<input type="text" name="fullcode">
<input type="Submit" name="submit" value="Submit!">
</form>
</body>
</html>
Please, tell me what and where I'm wrong... Thanks! :)
EDIT:
<?php
session_start();
if (!isset($_SESSION["testcode"])) {
$char = "abcdefghijklmnopqrstuvwxyz1234567890";
$code = $char[rand(0,35)].$char[rand(0,35)].$char[rand(0,35)].$char[rand(0,35)].$char[rand(0,35)].$char[rand(0,35)];
$_SESSION["testcode"] = $code;
}
if(isset($_POST['submit'])) {
$code1 = mb_substr($_POST['fullcode'], 0, 5);
$code2 = mb_substr($_POST['fullcode'], -6);
if ($code2 === $_SESSION["testcode"])
{echo "The code is correct!<br>";}
else
{echo "Wrong code!<br>";}
unset($_SESSION['testcode']);
$char = "abcdefghijklmnopqrstuvwxyz1234567890";
$code = $char[rand(0,35)].$char[rand(0,35)].$char[rand(0,35)].$char[rand(0,35)].$char[rand(0,35)].$char[rand(0,35)];
$_SESSION["testcode"] = $code;
}
?>
Finally, get a new code IF the condition is false!
<?php
session_start();
// first request.
// if not set session 'testcode' and set it, else do nothing.
// prevent session be covered.
if (!isset($_SESSION["testcode"])) {
reFreshCode();
}
if(isset($_POST['submit'])) {
$code1 = mb_substr($_POST['fullcode'], 0, 5);
$code2 = mb_substr($_POST['fullcode'], -6);
if ($code2 == $_SESSION["testcode"])
echo "The code is correct!";
else {
// get a new code IF the condition is false!
echo "Wrong code!";
echo “new code:”.reFreshCode();
}
}
function reFreshCode() {
$char = "abcdefghijklmnopqrstuvwxyz1234567890";
$code = $char[rand(0,35)].$char[rand(0,35)].$char[rand(0,35)].$char[rand(0,35)].$char[rand(0,35)].$char[rand(0,35)];
return $_SESSION["testcode"] = $code;
}

dom cant use variables to store data in xml

I got an error when trying to post user input data from html to php and saved into xml file. It gives me this error Catchable fatal error: Argument 1 passed to DOMNode::appendChild() must be an instance of DOMNode, null given. Here is the code
register.htm
<!DOCTYPE html>
<html lang="en">
<head>
<title>test</title>
</head>
<body>
<form id="regform" method="post" action="register.php">
<fieldset id="person">
<legend>Your details:</legend>
<p><label for="fname">First Name:</label><input type="text" name="fname"/></p>
<p><label for="lname">Last Name:</label><input type="text" name="lname"/></p>
<p><label for="password">Password:</label><input type="password" name="password"/></p>
<p><label for="cpassword">Confirm Password:</label><input type="password" name="cpassword"/></p>
<p><label for="email">Email:</label><input type="email" id="email" name="email"/></p>
<p><label for="phone">Phone:</label><input type="text" name="phone"/></p>
<input type="submit" value="Register"/>
</fieldset>
</form>
</body>
</html>
relevant parts of register.php (whole code is too long)
$fname = #trim($_POST["fname"]);
$lname = #trim($_POST["lname"]);
$password = #trim($_POST["password"]);
$cpassword = #trim($_POST["cpassword"]);
$phone = #trim($_POST["phone"]);
$email = #trim($_POST["email"]);
if(file_exists('../../customer.xml'))
{
$xml2 = file_get_contents('../../data/customer.xml');
}
if(!file_exists('../../customer.xml'))
{
$dir = "../../data";
$f = fopen("$dir/customer.xml", "w");
$doc = new DOMDocument('1.0');
$doc->formatOutput = true;
$root = $doc->createElement('customer');
$doc->appendChild($root);
$user = $doc->createElement('user');
$root->appendChild($user);
$fname = $doc->createElement('fname');
#override - if I change this to 'brian' then it works, doesnt work with $variable
$fnameValue = $doc->createTextNode($fname);
$fname->appendChild($fnameValue);
$user->appendChild($fname);
$lname = $doc->createElement('lname');
$lnameValue = $doc->createTextNode($lname);
$lname->appendChild($lnameValue);
$user->appendChild($lname);
echo $doc->save('../../data/customer.xml');
//$doc->load('customer.xml');
echo ' Registration Successful!';
}
Just like the error suggests, appendChild needs a DOMNode. Just create that element, then use the second paramter from the user input. Example:
$fname = #trim($_POST["fname"]);
$lname = #trim($_POST["lname"]);
$password = #trim($_POST["password"]);
$cpassword = #trim($_POST["cpassword"]);
$phone = #trim($_POST["phone"]);
$email = #trim($_POST["email"]);
if(file_exists('../../customer.xml')) {
$xml2 = file_get_contents('../../data/customer.xml');
}
if(!file_exists('../../customer.xml')) {
$dir = "../../data";
$f = fopen("$dir/customer.xml", "w");
$doc = new DOMDocument('1.0');
$doc->formatOutput = true;
$root = $doc->createElement('customer');
$doc->appendChild($root);
$user = $doc->createElement('user');
$root->appendChild($user);
$fname_node = $doc->createElement('fname', $fname);
$user->appendChild($fname_node);
$lname_node = $doc->createElement('lname', $lname);
$user->appendChild($lname_node);
echo $doc->save('../../data/customer.xml');
//$doc->load('customer.xml');
echo ' Registration Successful!';
}
You are re-using the $fname variable. That's why you get the error. It's a simple, typographical mistake. One thing you can do is to prefix the input variables with input, e.g. $input_fname so it's clear that you obtain them from there. Or even create a stdclass like $input = new stdClass; and then assign the $_POST variables to it: $input->fname = #trim($_POST["fname"]); - that way it's clear what it stands for and you can pass the input around more easily, too.
Example:
$input = new stdClass;
$input->fname = #trim($_POST["fname"]);
$input->lname = #trim($_POST["lname"]);
$input->password = #trim($_POST["password"]);
$input->cpassword = #trim($_POST["cpassword"]);
$input->phone = #trim($_POST["phone"]);
$input->email = #trim($_POST["email"]);
$doc = new DOMDocument('1.0');
$doc->formatOutput = true;
$root = $doc->createElement('customer');
$root = $doc->appendChild($root);
foreach ($input as $key => $value) {
$element = $doc->createElement($key, $value);
$root->appendChild($element);
}
$doc->save('php://output');
Exemplary output:
<?xml version="1.0"?>
<customer>
<fname>Waltraud</fname>
<lname>Van Hömpenstetten</lname>
<password></password>
<cpassword></cpassword>
<phone></phone>
<email></email>
</customer>
Online Demo: https://eval.in/private/29c08d9fafec22

Passing information using post method without session variables

I will admit immediately that this is homework. I am only here as a last resort after I cannot find a suitable answer elsewhere. My assignment is having me pass information between posts without using a session variable or cookies in php. Essentially as the user continues to guess a hidden variable carries over all the past guesses up to that point. I am trying to build a string variable that holds them all and then assign it to the post variable but I cannot get anything to read off of the guessCounter variable i either get an undefined index error at the line of code that should be adding to my string variable or im just not getting anything passed over at all. here is my code any help would be greatly appreciated as I have been at this for awhile now.
<?php
if(isset($_POST['playerGuess'])) {
echo "<pre>"; print_r($_POST) ; echo "</pre>";
}
?>
<?php
$wordChoices = array("grape", "apple", "orange", "banana", "plum", "grapefruit");
$textToPlayer = "<font color = 'red'>It's time to play the guessing game!(1)</font>";
$theRightAnswer= array_rand($wordChoices, 1);
$passItOn = " ";
$_POST['guessCounter']=$passItOn;
$guessTestTracker = $_POST['guessCounter'];
$_POST['theAnswer'] = $theRightAnswer;
if(isset($_POST['playerGuess'])) {
$passItOn = $_POST['playerGuess'];
if ($_SERVER['REQUEST_METHOD'] == 'GET') {
$guessTestTracker = $_GET['guessCounter'];
$theRightAnswer = $_GET['theAnswer'];
}
else if ($_SERVER['REQUEST_METHOD'] == 'POST') {
if(isset($_POST['playerGuess'])) {
if(empty($_POST['playerGuess'])) {
$textToPlayer = "<font color = 'red'>Come on, enter something(2)</font>";
}
else if(in_array($_POST['playerGuess'],$wordChoices)==false) {
$textToPlayer = "<font color = 'red'>Hey, that's not even a valid guess. Try again (5)</font>";
$passItOn = $_POST['guessCounter'].$passItOn;
}
if(in_array($_POST['playerGuess'],$wordChoices)&&$_POST['playerGuess']!=$wordChoices[$theRightAnswer]) {
$textToPlayer = "<font color = 'red'>Sorry ".$_POST['playerGuess']." is wrong. Try again(4)</font>";
$passItOn = $_POST['guessCounter'].$passItOn;
}
if($_POST['playerGuess']==$wordChoices[$theRightAnswer]) {
$textToPlayer = "<font color = 'red'>You guessed ".$_POST['playerGuess']." and that's CORRECT!!!(3)</font>";
$passItOn = $_POST['guessCounter'].$passItOn;
}
}
}
}
$_POST['guessCounter'] = $passItOn;
$theRightAnswer=$_POST['theAnswer'];
for($i=0;$i<count($wordChoices);$i++){
if($i==$theRightAnswer) {
echo "<font color = 'green'>$wordChoices[$i]</font>";
}
else {
echo $wordChoices[$i];
}
if($i != count($wordChoices) - 1) {
echo " | ";
}
}
?>
<h1>Word Guess</h1>
Refresh this page
<h3>Guess the word I'm thinking</h3>
<form action ="<?php echo $_SERVER['PHP_SELF']; ?>" method = "post">
<input type = "text" name = "playerGuess" size = 20>
<input type = "hidden" name = "guessCounter" value = "<?php echo $guessTestTracker; ?>">
<input type = "hidden" name = "theAnswer" value = "<?php echo $theRightAnswer; ?>">
<input type = "submit" value="GUESS" name = "submitButton">
</form>
<?php
echo $textToPlayer;
echo $theRightAnswer;
echo $guessTestTracker;
?>
This is a minimal functional example of what you need to do. There are still a couple of minor bugs (like duplicate entries in the history), but I've left these as an exercise for you. Treat this as a starting point and build up what you need from it.
I've added comments to explain what's happening, so hopefully it is clear to you.
$answer = null;
$history = [];
$choices = ['apple', 'grape', 'banana'];
$message = '';
// check if a guess has been made.
if (!empty($_POST) && !empty($_POST['guess'])) {
// check if previous guesses have been made.
if (!empty($_POST['history'])) {
$history = explode(',', $_POST['history']);
}
// check guess.
if (!empty($_POST['answer']) && !empty($_POST['guess'])) {
// check guess and answer are both valid.
if (in_array($_POST['guess'], $choices) && isset($choices[$_POST['answer']])) {
if ($_POST['guess'] == $choices[$_POST['answer']]) {
// correct; clear history.
$history = [];
$message = 'correct!';
} else {
// incorrect; add to history and set previous answer to current.
$history[] = $_POST['guess'];
$answer = $_POST['answer'];
$message = 'incorrect!';
}
} else {
// invalid choice or answer value.
}
}
}
if (empty($answer)) {
// no answer set yet (new page load or correct guess); create new answer.
$answer = rand(0, count($choices) - 1);
}
?>
<p>Guess the word I'm thinking:</p>
<p><?php echo implode(' | ', $choices) ?></p>
<form method="POST">
<input type="hidden" name="answer" value="<?php echo $answer; ?>">
<input type="hidden" name="history" value="<?php echo implode(',', $history); ?>">
<input type="text" name="guess">
<input type="submit" name="submit" value="Guess">
</form>
<p><?php echo $message; ?></p>

Call function php uing jquery

Hello i want to call a function using jquery. I tried a lot of ways and I can't get it.
This my principal webpage.
I'am uploading a file csv and pressing 'Crear' button, it uplaod the file while call the function.
<html>
<head>
<script type="text/javascript" src="http://code.jquery.com/jquery-1.8.3.js"></script>
<script src="http://code.jquery.com/ui/1.9.2/jquery-ui.js"></script>
<SCRIPT type="text/javascript">
$(function (){
$('#btnxml').click(function (){
alert("aki");
$('#contenidos').load('csv.php');
});
});
</SCRIPT>
</head>
<body>
<form action="index.php" id="filecsv" method="post" enctype="multipart/form-data">
<input type="file" multiple="multiple" id="file" name="up_csv[]"/>
<input type="submit" value="Cargar" name="btnxml" id="btnxml" /><br />
</form>
<?php
global $archivocsv;
//tipos de archivos permitidos
$extensionxml = array('csv','txt');
//destino
$rutaupcsv = './csv/';
//multicargador de archivos
$vt=0;
for($i=0;$i<count($_FILES['up_csv']['size']);$i++){
for ($j=-1; $j<count($extensionxml); $j++) {
if (strripos($_FILES['up_csv']['name'][$i], $extensionxml[$j])!== false) {
$filename = 'lista';
$destino = $rutaupcsv.$_FILES['up_csv']['name'][$i];
$archivocsv = basename($_FILES['up_csv']['name'][$i]);
move_uploaded_file($_FILES['up_csv']['tmp_name'][$i],$destino);
$vt=$vt+1;
break;
}
$ns=1;
}
}
?>
<div id="contenidos"></div>
csv.php
<?php
echo '<html>';
echo '<head>';
echo '<meta content="text/html;charset=utf-8" http-equiv="Content-Type">';
echo '<meta content="utf-8" http-equiv="encoding">';
echo '</head>';
function makecsv() {
global $archivocsv;
$csv = './csv/' . $archivocsv;
$doc = new DOMDocument();
$row = 1;
$handle = fopen($csv, "r");
# Rows Counter
$csvxrow = file($csv);
$csvxrow[0] = chop($csvxrow[0]);
$anzdata = count($csvxrow);
while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) {
$num = count($data);
$row++;
#Load Predefined XML Template
$xml2 = $xml;
$xmlruta = './Templates/';
$xml = $xmlruta.$data[1].'.xml';
$doc->load($xml);
$xp = new DOMXPath($doc);
for ($c=0; $c < $num; $c++) {
foreach($xp->query('/ROOT/HEADER/#KEY[. != ""]') as $attrib)
{
$attrib->nodeValue = $data[0];
}
foreach($xp->query('/ROOT/DATA/SAPMES/LOIPRO/E1FKOL/#AUFNR[. != ""]') as $attrib)
{
$attrib->nodeValue = $data[0];
}
foreach($xp->query('/ROOT/DATA/SAPMES/LOIPRO/E1FKOL/#MATNR[. != ""]') as $attrib)
{
$attrib->nodeValue = $data[1];
}
foreach($xp->query('/ROOT/DATA/SAPMES/LOIPRO/E1FKOL/#GAMNG[. != ""]') as $attrib)
{
$attrib->nodeValue = $data[2];
}
foreach($xp->query('/ROOT/DATA/SAPMES/LOIPRO/E1AFFLL/E1FVOL/#MGVRG[. != ""]') as $attrib)
{
$attrib->nodeValue = $data[2];
}
foreach($xp->query('/ROOT/DATA/SAPMES/LOIPRO/E1FKOL/#GSTRS[. != ""]') as $attrib)
{
$attrib->nodeValue = $data[3];
}
foreach($xp->query('/ROOT/DATA/SAPMES/LOIPRO/E1FKOL/#GLTRS[. != ""]') as $attrib)
{
$fecha = new DateTime($data[3]);
$fecha->add(new DateInterval('P1M'));
$attrib->nodeValue = $fecha->format('Y-m-d');
}
}
$name = $data[0] .'-'. $data[1];
$doc->formatOutput = true;
echo $doc->saveXML();
$rutafinal = './XML/';
$doc->save($rutafinal.$name.'.xml');
}
fclose($handle);
echo $anzdata . " XML Creados" . "<br />";
return $data;
}
makecsv();
echo '</html>';
?>
I can't call the function.
it doesn't do anything when i try to call it.
EDIT: I think the problem is in my function. function edite
Javascript can´t play with php directly because JS is client side (only in browser) and PHP is server side (only in browser). What you can do is a PHP file that has the code you want to invoke, and make JS call that page.
Separate the CVS code from the form and make JS call the new php with the CVS php functionality.
jQuery runs in the client's browser whereas your PHP is running on your web server. If you wish to call a PHP function from your jQuery code, your best option is to do so using AJAX.
You can find documentation for implementing an AJAX call in jQuery here: https://api.jquery.com/jQuery.ajax/
You'll need to print the actual hmtl to do the function.
PHP
<?php
print '<script> makecsv() </script>';
?>

How to iterate through an array then replace data of a matching id

Okay so what i am trying to do is Iterate through Json decoded array then search for an ID(key) then post that data into a form for editing then encode it then save it it seems like such an easy task however i am not using a data base or java or java script i have to do this using only Json, PHP and HTML my main code(Controller) file is as follows
<?php
$file_name = 'engagements.json'; // Serialized speaking engagments
/**
* Controller for Speaking Engagements
*/
if (!isset($_REQUEST['act']) || !$action = $_REQUEST['act']){
$action = 'list';
} //End If
switch ($action) {
case 'list': // List
$json_data = file_get_contents($file_name);
if (!$engagements = json_decode($json_data, true)) { // Convert serialized data to array
$engagements = array();
} //End If
include 'engagements_list.phtml';
break;
case 'view': // View
$json_data = file_get_contents($file_name);
$temp_array = json_decode($json_data);
foreach($temp_array as $key=>$id){
if($id->ID == 2){
echo "got it \n";
echo "ID: $id->ID \n";
echo "Title: $id->Title \n";
echo "Description: $id->Description \n";
}// End If
}
break;
case 'add': // Add
$temp_array = array();
$file = file_get_contents($file_name);
$json_data = json_decode($file);
$high_value = count($json_data);
$high_value++;
$temp_array['ID'] = $high_value;
$temp_array['Title'] = $_POST['Title'];
$temp_array['Description'] = $_POST['Description'];
$json_data[] = $temp_array;
file_put_contents($file_name, json_encode($json_data));
include 'engagements_add.phtml';
break;
case 'edit': // Edit
$file = file_get_contents($file_name);
$json_data = json_decode($file, true);
// what comes next here
include 'engagements_edit.phtml';
break;
case 'delete': // Delete
break;
default:
throw(new Exception('Invalid action given'));
break;
}//End Switch
exit;
<!-- Edit View -->
<form action="engagements.php?act=edit?ID=<?php $_GET['ID']?>" method="get">
<table>
<tr><td><input type="hidden" name="ID"></td></tr>
<tr><td><input type="text" style="width:500px;" name="Title"></td></tr>
<tr><td><textarea cols="40" rows="2" style="width: 500px; height:250px;" name="Description"></textarea></td></tr>
<tr><td><input type="submit" name="Submit" value="Submit"/></td></tr>
</table>
</form>
please help me i have searched everywhere for an answer but can find any resources that explain how to do this properly
Tiny one point.
<form action="engagements.php?act=edit?ID=<?php $_GET['ID']?>" method="get">
I'm assuming you meant to type like this:
<form action="engagements.php?act=edit&ID=<?php echo $_GET['ID']?>" method="get">
The $_GET statement was missing an echo, too.
UPDATE:
I notice php close tag ?> missing until EDIT VIEW. And 'view' part in switch, why you echo ID property? It might be following:
echo "ID: $id['ID'] \n";

Categories