//let's say I type Joe in username field of form
if (!isset($_SESSION['username'])){
if (empty($_POST['username']))
printErrorMessage("Username is not filled in"); // no error
//echo strlen($_POST['username']); // prints 3
$username = mysql_real_escape_string($_POST['username']);
//echo strlen($username); // prints 0
if (strlen($username) > 20)
printErrorMessage("Username cannot contain more than 20 symbols");
} else
$username = $_SESSION['username'];
Any help would be appreciated
$_POST worker well on local server (wamp 2.1) but doesn't work on remote server
Started by thatsme, Sep 01 2011 04:28 AM
12 replies to this topic
#1
Posted 01 September 2011 - 04:28 AM
Hi, the following code should get data from from. This code worked well on local server (wamp 2.1), but when i bought domain and hosting nonsenses started to happen. Now all the code is uploaded into remote server and line $username = mysql_real_escape_string($_POST['username']); fails to read field's value into variable (see comments).
|
|
|
#2
Posted 01 September 2011 - 04:40 AM
Did you open a mysql_connect before using the mysql_real_esapce_string?
if mysql_connect isn't open, mysql_real_escape_string will try to open one with no arguments, this is maybe why it worked on your localhost, but not on your server
if mysql_connect isn't open, mysql_real_escape_string will try to open one with no arguments, this is maybe why it worked on your localhost, but not on your server
#3
Posted 01 September 2011 - 05:31 AM
oh, i didn't. So I need to connect to database?
#4
Posted 01 September 2011 - 05:32 AM
yes, to sanitize with mysql_real_escape_string you need a connection to the database
#5
Posted 01 September 2011 - 12:32 PM
Looks like it works weel now but here comes more problems:
1) $id = $_GET['id']; - this line fails to read value passes by another page
2) file_put_contents($fileName, $xml->asXML()); - this line fails to save updated xml's structure into file
Both these things worker well on wamp 2.1 but fail to work on remote server
1) $id = $_GET['id']; - this line fails to read value passes by another page
2) file_put_contents($fileName, $xml->asXML()); - this line fails to save updated xml's structure into file
Both these things worker well on wamp 2.1 but fail to work on remote server
#6
Posted 01 September 2011 - 02:59 PM
Well, I'm gonna need a little bit more code than 2 separated line
For the first one, I can't help you
For the second one, my guess is that $fileName work on wamp because windows isn't case sensitive, and your server is probably linux and linux is case sensitive, but it would help to have more code
For the first one, I can't help you
For the second one, my guess is that $fileName work on wamp because windows isn't case sensitive, and your server is probably linux and linux is case sensitive, but it would help to have more code
#7
Posted 01 September 2011 - 11:29 PM
Yes, server is linux. For the first question the code is:
<?php
require_once("stdlib.php");
$con = connectToDatabase();
$id = $_GET['id'];
$category = $_GET['category'];
echo $id; //this line prints nothing, but the browser's address window shows that id is passed
For the secon question code is
$fileName = "";
$redirectLocation = "";
$commentId = 0;
$commentElement = NULL;
switch ($category){
case "battles":
$fileName = "battles/battles.xml";
$xml = simplexml_load_file($fileName);
$commentsList = $xml->xpath("/battlesList/battle[@id=$id]/comments/comment");
$commentId = count($commentsList) + 1;
$commentElement = addAndGetNewComment($xml, "battlesList", "battle", $id);
$redirectLocation = "loadBattle.php";
break;
.... $ip = $_SERVER['REMOTE_ADDR'];
$date = '20' . date("y-m-d");
date_default_timezone_set("Europe/Vilnius");
$time = getDate();
$time = $time['hours'] . ':' . $time['minutes'];
$commentElement->addAttribute("id", $commentId);
$commentElement->addChild("username", $username);
$commentElement->addChild("ip", $ip);
$commentElement->addChild("date", $date);
$commentElement->addChild("time", $time);
$commentElement->addChild("text", $commentText);
file_put_contents($fileName, $xml->asXML());
mysql_close($con);
header("Location: " . $redirectLocation . '?id=' . $id);
function addAndGetNewComment($xml, $rootName, $commentsNodeParentName, $id){
$commentsNodeXpath = "/" . $rootName . "/" . $commentsNodeParentName . "[@id=" . $id . "]/comments";
$commentsListXpath = "/" . $rootName . "/" . $commentsNodeParentName . "[@id=" . $id . "]/comments/comment";
$commentsNode = $xml->xpath($commentsNodeXpath);
$commentsNode[0]->addChild("comment");
$commentsList = $xml->xpath($commentsListXpath);
//echo count($commentsList); i think that until this line code works correctly because after the addition of new comment element the count of comment nodes ir printed correctly
return $commentsList[count($commentsList) - 1];
}
The whole code for the second question is large so i hope that this will be enough
#8
Posted 02 September 2011 - 02:51 AM
First question: insted of doing an echo $id; do a var_dump($id);
Something when int are alone php try to convert them to string and it's not working
And if you don't even have the var_dump it's because you script get kill somewhere before that.
For your xml, I have 2-3 guess
is simplexml really installed on your server?
Do you have permission to write in the folder battle (different permission than on windows or on your ftp)
And once again try to do an var_dump($xml->asXML()); to see if it's simplexml the problem or when you write to the file.
But I would bet on the permission
Look at your apache error log (if you have access to it), on shared hosting sometime it's in the cpanel, sometime it's in the root directory and sometime you just don't have access
Ps. for your date insted of using $date = '20' . date("y-m-d"); you should use $date = date("Y-m-d"); with a capital Y (4 digit years)
Something when int are alone php try to convert them to string and it's not working
And if you don't even have the var_dump it's because you script get kill somewhere before that.
For your xml, I have 2-3 guess
is simplexml really installed on your server?
Do you have permission to write in the folder battle (different permission than on windows or on your ftp)
And once again try to do an var_dump($xml->asXML()); to see if it's simplexml the problem or when you write to the file.
But I would bet on the permission
Look at your apache error log (if you have access to it), on shared hosting sometime it's in the cpanel, sometime it's in the root directory and sometime you just don't have access
Ps. for your date insted of using $date = '20' . date("y-m-d"); you should use $date = date("Y-m-d"); with a capital Y (4 digit years)
#9
Posted 02 September 2011 - 07:11 AM
First question: that was silly mistake in another place. sorry
Second question: line var_dump($xml->asXML()); prints nothing. However before this line code is executed correctly (i think so, because when i had put echo "ok"; one line above var_dump, it echoed ok into screen)
Second question: line var_dump($xml->asXML()); prints nothing. However before this line code is executed correctly (i think so, because when i had put echo "ok"; one line above var_dump, it echoed ok into screen)
#10
Posted 02 September 2011 - 07:17 AM
This is probably because your xml have an error in it somewhere, did you take a look at the error log?
Or you could enable the error output (only for development purpose)
Or you could enable the error output (only for development purpose)
error_reporting(E_ALL | E_STRICT);Put that at the start of your script
#11
Posted 02 September 2011 - 07:31 AM
I have just found out that var_dump prints all data of xml (including appended data). However appended data isn't being saved into file at line file_put_contents($fileName, $xml->asXML()); I think that simplexml is installed on server because my script reads xml files well.
#12
Posted 02 September 2011 - 12:58 PM
It looks that i don't have permission to write files. php function chmod does not work :bad: so it looks that i am going to mess with putty to fix it
1 user(s) are reading this topic
0 members, 1 guests, 0 anonymous users


Sign In
Create Account


Back to top









