Issue with php and xml in Linux Instance - php

I currently have a Linux Instance running CentOS and I am trying to create a php form that takes input and updates an xml file with what is submitted.
It works on my local network exactly how I want it to but when I run it from the server it does not update the xml file.
The server is running php 5.3 and it php works.
Is there something different I need to do?
The php file is below:
<?php
if (isset($_POST['submit']))
{
$ID = $_POST['ID'];
$name = $_POST['name'];
$email = $_POST['email'];
$phone = $_POST['phone'];
$xml = simplexml_load_file("test.xml");
$sxe = new SimpleXMLElement($xml->asXML());
$entry = $sxe->addChild("item");
$entry->addChild("name", $name);
$entry->addChild("email", $email);
$entry->addChild("phone", $phone);
$sxe->asXML("test.xml");
}
?>
<!doctype html>
<head>
</head>
<body>
<form method="POST" action=''>
ID# <input type="text" value="" name="ID"/>
Name <input type="text" value="" name="name"/>
Email <input type="text" value="" name="email"/>
Phone <input type="text" value="" name="phone"/>
<input name="submit" type="submit" />
</form>
</body>

Make sure you have write permissions to that file. Set chmod value to 666 if you want to write to that file.

Related

HTML Form not posting to PHP file

I am currently creating an HTML form that has 2 fields; name and an address. It also has a way of selecting one of 2 options. The form will either be used to look up the address of a person. In this case, only the name field is required to be filled out. The other option is to add a person to the file. In this case both fields need to be filled out. For some reason, I am not able to get the values that inputted from the form into my PHP file. Please help.
Here is my HTML Form
<html>
<head>
<title> Form </title>
</head>
<body>
<form action="action_page.php" method="post">
<div>
<label for="name">Name: </label>
<input id="name" type="text" name="name"><br>
</div>
<div>
<label for=address">Address: </label>
<input id="address" type="text" name="address"><br>
<input type="radio" name="action" value="lookup">Lookup<br>
<input type="radio" name="action" value="add">Add<br>
<input type="submit" name="submit"><br>
</form>
</body>
</html>
Here is my PHP file
<html>
<head>
<title> PHP </title>
</head>
<body>
<?php
$name = $_POST['name'];
echo "<p>",$_POST["name"],"</p>";
echo "<p>",$_POST["action"],"</p>";
echo "<p>",$_POST["address"],"</p>";
$address = array();
if($_POST["action"]=="lookup"){
$fh = fopen("address.txt","r") or die("No such file found.");
while(!feof($fh)) {
$line = fgets($fh);
$info = explode("|",$line);
$address[$info[0]]=$info[1];
}
if(array_key_exists($_POST["name"],$address)) {
echo "<p>",$_POST["name"],"<p>";
echo "<p>",$address[$_POST["name"]],"</p>";
}
?>
<body>
</html>
The error was in
echo "<p>",$_POST["name"],"</p>";
It should be
echo "<p>".$_POST["name"]."</p>";
and same for others

Server Won't Display Body of HTML or PHP

I'm using GoDaddy's CPanel hosting and just finished developing a submission website locally however when I upload it to the server, it won't display the body of the index.php file.
I don't think it has to do with the index.php file because verything works fine locally on localhost with Wamp however my CPanel server will refuse to work. http://submit.arhsj.com/ is where the index.php is. You can see the title of the page has changed and you can Inspect Element to see that the head contains stuff however the body is empty.
Here are the files located in the submit.arhsj.com folder.
I can provide more information if you think it's required. I'm just really confused as to why it's not working when it works perfectly on localhost. Even the HTML form in the middle of the 2 PHP sections won't display.
index.php code:
<!DOCTYPE html>
<html>
<head>
<title>Submission Website</title>
<script src='https://www.google.com/recaptcha/api.js'></script>
</head>
<body>
<?php
require('/recaptcha/src/autoload.php');
require_once "recaptchalib.php";
$siteKey = 'XXXXXXXXXXXXXX';
$secret = 'XXXXXXXXXXXXX';
$lang = 'en';
$response = null; // empty response
$reCaptcha = new ReCaptcha($secret); // check secret key
if (isset($_POST['g-recaptcha-response'])) { // if submitted check response
$response = $reCaptcha->verifyResponse(
$_SERVER['REMOTE_ADDR'],
$_POST['g-recaptcha-response']
);
}
if ($response != null && $response->success) {
echo "Thanks for your submission!";
} else {
?>
<form action="upload.php" method="post" enctype="multipart/form-data">
Select image to submit*:
<input type="file" accept=".gif,.png,.jpg,.jpeg" name="submission" id="submission" required>
<br>Allowed file types: .png .jpg .jpeg .gif
<br><input type="text" name="first_name" id="first_name" placeholder="First Name*" maxlength="56" required>
<br><input type="text" name="last_name" id="last_name" placeholder="Last Name*" maxlength="56" required>
<br><input type="text" name="email" id="email" placeholder="Email Address*" maxlength="128" required>
<br><input type="checkbox" id="rights" value="rights" required>I created this meme or found this meme online but have not changed anything (such as removing watermarks).
<br><input type="checkbox" id="age" value="rights" required>I am 13 years of age or older.
<br><br>By clicking "Submit", you have read, accepted, and agreed to adhere to our Terms of Submission.
<div class="g-recaptcha" data-sitekey="XXXXXXXXXXXXXX"></div>
<input type="submit" value="Submit" name="submit">
<br><br>* Required
</form>
<?php
}
?>
</body>
</html>
If who post give some answer maybe somebody can help him but here semms become a "
last chance" :)
The page is crashed this is sure how is sure that is crashed from the php code.
Maybe the code start with an invisible byte order mark (BOM). So try to open with your editor or notepad++ setting the encoding to UTF-8 (no BOM). Other problem could be the path so the require try in this way and if work you can check the reason.
require $_SERVER['DOCUMENT_ROOT'] . '/recaptcha/src/autoload.php';
require_once $_SERVER['DOCUMENT_ROOT'] . '/recaptchalib.php';
Anyway and repeat this point if you post try to follow the reply maybe somebody can help you.

XAMPP : My input (name and pass) always has root and password inside of it..how so?

Today I was trying to create a login page with PDO class in PHP. It worked fine but my problem is my input always have a "root" string value for my first input, and a password inside my second input. Why and how can I erase that? I tried to put a "placeholder" inside of each input, and it still doesn't replace it. Oh, by the way, my input has a "yellow" background...kinda weird. And when I erase it manually, they return white as usual..
This is my code :
<?php
include_once('user.php');
if (isset($_POST['submit'])) {
$name = $_POST['username'];
$pass = $_POST['password'];
$object = new User();
$object->Login($name,$pass);
}
?>
<html>
<head>
</head>
<body>
<form method="post" action="<?= $_SERVER['PHP_SELF']; ?>">
Username: <input type="text" name="username"><br><br>
Password: <input type="password" name="password"><br><br>
<input type="submit" name="submit" value="Log In">
</form>
</body>
</html>
Cache, or saved credentials problem.
Try:
<input type="text" name="username" value="" placeholder="" autocomplete="off">

adding data to xml using php

have a form that a name has been entered and need to add it to xml file.
index.html
<form name="form" action="insert.php" method="post">
<label for="name">Name:</label> <br />
<input type="text" name="name" id="name" /> <br />
<button type="submit" id="button">Submit</button>
<br />
<span id="validate"></span>
</form>
insert.php
header('Location:index.php');
$xmldoc = new DOMDocument();
$xmldoc->load('recentUploads.xml');
$Name = $_POST['name'];
$root = $xmldoc->firstChild;
$fileName = $xmldoc->createElement('name');
$root->appendChild($fileName);
$newText1 = $xmldoc->createTextNode($Name);
$fileName->appendChild($newText1);
$xmldoc->save('recentUploads.xml');
but i can not add anything to the xml file?
Help!
You are placing a lot of burden on poor variable $fileName:
$fileName = $_POST['name'];
$fileName = $xmldoc-> createElement('name');
On the other hand, $Name is not defined when you use it in line
$newText1 = $xmldoc->createTextNode($Name);
Me thinks these two incidents are related and one $fileName should actually be a $Name.
http://www.php.net/manual/en/domdocument.save.php
Are you remembering to save() it back?
I don't see that in your example code...
Do you need to call $xmldoc->saveXML();?

document object confusion

In file1.php, I execute file2.php with
<form action="file2.php" method="POST">
Within file2, I want to access html elements from file1, but their document objects are different.
How can I access file1's elements from within file2?
well rather then using javascript you can access what you need via PHP's $_POST function so if you had the elements name and password you could access them with:
$_POST['name'];
$_POST['password'];
so something like this for file2.php:
<?php
if(array_key_exists('submit', $_POST))
{
$username = $_POST['name'];
$password = $_POST['password'];
echo("Hello $username, your password is $password");
}
?>
That goes on the assumption of file1.php looking like:
<form action="file2.php" method="post">
Username:
<input type="text" name="name" />
<br />
Password:
<input type="password" name="password" />
<br />
<input type="submit" name="submit" />
</form>
Why don't you try hiding in file2.php the elements that you still need?.
Just render them again with php in file2.php, and hide them via CSS, then they will be easily accesible through javascript.

Categories