I have a php file that does a whole sleuth of user account stuff. It's purely being used to test if the features are working. However the script stops before the first feature is output. I have determined that the code is failing somewhere in this code:
...more above...
Authentication Form<br>
<br>
<?php if($this->session->userdata('authenticated')):?>
Welcome back <?php echo $this->session->userdata('userid');?><br>
<form action="<?php echo base_url();?>/account/logout" method="post">
<input type="submit" value="Log Out"/>
</form>
<?php else:?>
<form action="<?php echo base_url();?>/account/login" method="post">
Username: <input type="text" name="username"/><br>
Password: <input type="text" name="password"/><br>
<input type="submit" value="Login"/>
</form>
<?php endif;?><br>
...more below...
What i can not figure out is why this code if not executing. No errors are being outputted and i have used code similar to this before with no problem. Any help would be greatly appreciated.
One last note:
I'm using xampp running on my laptop and using codeigniter. newest of both.
The really snazzy way is to use xdebug http://www.xdebug.org/
The brute force way might be to lace your file with
echo __FILE__, ":", __LINE__, "\n<br/>";
and
var_dump(get_defined_vars());
plus also read up on setting error_reporting to an appropriate level for debugging plus show_errors in the PHP manual # php.net
Related
So I have been browsing trough a lot of threads, and the only suitable solution for my situation I found was this:
PHP:
<?php
if(isset($_POST["submit"])) {
my php code goes here
}
?>
HTML:
<form id="usp-form-23" class="usp-form" method="post" enctype="multipart/form-data" action="" data-validate="parsley" data-persist="garlic" novalidate>
<input name="usp-title" type="text" value="" data-required="true" required="required" maxlength="99999" placeholder="Answer" class="usp-input usp-input-title" />
<input name="submit" id="submit" type="submit" class="usp-submit usp-submit-default" value="Send Message" />
</form>
But it doesn't work.
Maybe I'm missing something?
Need help.
P.S. I can't use an external php file. Only php code inside the same file, because of the variables I need to grab from the post.
I also can't use $_GET, because if a person refreshes the page, my php will be repeated, which I don't want. I only need to run my php once.
I'm trying to build an small script.
I have one textarea for the user's code and one submit button.
My target is when the user submit the button, the code that he wrote, must appear as a result, working.
I want to build a small php compiler, how can i do that?
Code
<form method="GET">
<textarea name="php">
<?php
echo '$texto';
?>
</textarea>
<input name="code" type="submit" />
</form>
<br>
<br>
Result
<br>
<?php
if (isset($_GET["code"])) {
echo $_GET["php"];
}
?>
You are looking for the eval() control structure. However, please be aware that this is a very dangerous piece of code you're attempting to use. Basically you're allowing anyone to execute any type of code on the server. For example, someone could write "rm('file.php')" and basically get rid of your file. Or far worse things like stealing all passwords stored on the server.
<form method="GET">
<textarea name="php">
<?php
echo '$texto';
?>
</textarea>
<input name="code" type="submit" />
</form>
<br>
<br>
Result
<br>
<?php
if (isset($_GET["code"])) {
echo eval($_GET["php"]);
}
?>
Again: PLEASE do not use this! It is very dangerous what you're trying to do.
So I am extremely new to PHP and am probably making a stupid mistake. I have searched for quite a while, though, and have not been able to figure out what is going wrong.
Using XAMPP all of the PHP works fine. When I load it onto my web server, however, the if statement regulating the log in form displays both the 'log in' form and the 'log out' form at the same time. Obviously not what I want!
Here is the code snippet:
<?php
if ( isset( $_SESSION['email'] ) ) { // Check to see if user is logged in. If so, display log out button.
?>
<form class="navbar-form pull-right" action="logout.php" method="POST">
<button name="submit" type="submit" class="btn btn-success">Log Out</button>
</form>
<?php
} else { // display log in form
?>
<form class="navbar-form pull-right" action="login.php" method="POST">
<input name="email" type="text" class="span2" placeholder="email">
<input name="password" type="password" class="span2" placeholder="password">
<button name="submit" type="submit" class="btn btn-success">Log In</button>
</form>
<?php
}
?>
This is contained in a file index.php
The basic logic is test to see if an email variable has been created for the session (done in a login.php execution) to check if the user is logged in.
I have no idea if this is the best way to create a log in, but that's what I've tried to do.
Again, I am very new to this, so any insight on where to look next would be greatly appreciated!
Thank you!
Do a view source and make sure your PHP code is actually being interpreted. If you see your PHP tags in the source of the browser then your web server is not configured properly.
Try
if(!empty( $_SESSION['email'] ))
and I hope you did session_start() at the beginning.
I think your *.php files does not behave like PHP files. You should check your web server settings.
You didn't use echo. Is it OK to try displying text without an echo statement before?
I've been following this tutorial to learn php so I have a html script:
<html>
<body>
<form name="form" method="post" action="registernext.php">
<p>Username: <input type="text" name="username" size="15" maxlength="20" value="megaman"></p>
<p><input type="submit" name="submit" value="register"></p>
</form>
</body>
</html>
and the php script:
<?php
echo file_get_contents('php://input');
$test = $_POST["username"];
echo " testname = (".$_POST["username"].")";
?>
But what I get when I run it is:
username=megaman testname = ()
My problem is that the name (megaman) get's sent to POST but doesn't show up in the php script.
Also, I haven't made any changes to the php.ini as oppose to some others that had problems when they did so.
I don't know if this helps but I'm running this via xampp (fresh download).
Help would be deeply appreciated, as searching for solutions haven't been successful.
try replacing all the PHP code with
<?php
var_dump($_POST);
?>
submit the form. if anything comes up then nothing is wrong with PHP.
I'm new to web development and have been wrestling with this problem for several hours now, so I've decided to turn to your wisdom. I'm trying to design a little webpage with a database for my wife to store her recipes in, but I'm having trouble getting form submission to work. Here is the code for the webpage where I take the form information in:
<html><body>
Enter the information below to add a new ingredient for use in your recipes.
<form action="add_to_database.php" method="post">
Name: <input name="name" type="text" />
Serving: <input type="text" name="serving" />
Calories: <input type="text" name="calories" />
<input type="submit" />
</form>
</body></html>
And here is some silly code I've been trying to display on the page to see if I can even get the form submission to work:
<html><body>
<?php
$name = $_POST['name'];
echo $name."<br />";
?>
</body></html>
Unfortunately, the page comes back as completely back (after I hit the submit button). What's absolutely baffling to me is that I've copied and pasted the examples from this page into some files and everything seems to work fine. So it seems as though apache and php are working correctly, but I'm messing up somewhere along the way. My apologies in advance if this seems like a stupid question but for the life of me I can't figure it out.
Do you name the other file as add_to_database.php where the form is submitted. Instead you can test on teh same page by removing the add_to_database.php from the form action.
form action="" method="post">
Name: <input name="name" type="text" />
Serving: <input type="text" name="serving" />
Calories: <input type="text" name="calories" />
<input type="submit" />
</form>
and write the php code on the same page as
$name = $_POST['name'];
echo $name;
If this is not working for you. Create a php file named test.php and type phpinfo(); there.
Verify that your page is indeed being processed by PHP - obvious question, but does your PHP file have a .php extension? Do other things like phpinfo() or echo "Test"; work?
Check the error log in /var/log/apache2/error.log or similar (if on Linux, dunno where that'd be on Windows).
Try turning display_errors on in the PHP configuration (this is a good idea only for a development install, not a production server).
a bit of a longshot, but if you can verify that php is pro essing the page. Clean up your html, you are missing the dtd, head, and encoding. . hard to say how a browser is going to interpret a form (missing a name attribute) without these.