PHP Increment/Decrement

Discuss how to write good code, break bad code, your current pet projects, or the best way to approach novel problems

Re: PHP Increment/Decrement

Post by Shade_of_Gray on Wed Nov 21, 2012 9:36 am
([msg=71167]see Re: PHP Increment/Decrement[/msg])

Forms can be submitted either by POST or by GET. If you don't specify a "method" attribute, it'll default to GET.

Since your PHP script looks for the variable in the POST variable, it doesn't find it. Change your <form> tag to this:

Code: Select all
<form method="POST">
Shade_of_Gray
Experienced User
Experienced User
 
Posts: 60
Joined: Mon Oct 22, 2012 11:04 pm
Blog: View Blog (0)


Re: PHP Increment/Decrement

Post by jadecook on Wed Nov 21, 2012 9:46 am
([msg=71171]see Re: PHP Increment/Decrement[/msg])

Now it doesn't do anything but take me back to the top of the page /:
User avatar
jadecook
Experienced User
Experienced User
 
Posts: 75
Joined: Fri Aug 17, 2012 2:20 pm
Blog: View Blog (0)


Re: PHP Increment/Decrement

Post by not_essence2 on Wed Nov 21, 2012 10:07 am
([msg=71173]see Re: PHP Increment/Decrement[/msg])

I believe that what you just described means everything is correct except you just need to tell it to refresh to a different page, not the same one. (Taking you back to the top is most likely the web page being reloaded, now you just need to load a different page)
not_essence2
Poster
Poster
 
Posts: 189
Joined: Fri Sep 14, 2012 6:09 pm
Blog: View Blog (0)


Re: PHP Increment/Decrement

Post by jadecook on Wed Nov 21, 2012 11:18 am
([msg=71177]see Re: PHP Increment/Decrement[/msg])

But I don't want to reload a different page, I want to reload the same page with a different variable.
User avatar
jadecook
Experienced User
Experienced User
 
Posts: 75
Joined: Fri Aug 17, 2012 2:20 pm
Blog: View Blog (0)


Re: PHP Increment/Decrement

Post by Shade_of_Gray on Wed Nov 21, 2012 4:36 pm
([msg=71181]see Re: PHP Increment/Decrement[/msg])

It looks like your problem is that it doesn't know which page you're on. Try adding a hidden input field to your form.

http://www.tizag.com/htmlT/htmlhidden.php

Call the name of this hidden field "page", and use your PHP script to set the value to the $page variable in your code. That way, when you click "next" or "previous," it'll know which page you're on so it knows which page is actually next (or previous).
Shade_of_Gray
Experienced User
Experienced User
 
Posts: 60
Joined: Mon Oct 22, 2012 11:04 pm
Blog: View Blog (0)


Re: PHP Increment/Decrement

Post by not_essence2 on Wed Nov 21, 2012 5:53 pm
([msg=71188]see Re: PHP Increment/Decrement[/msg])

Oh. Never mind. Idiot me strikes again.
not_essence2
Poster
Poster
 
Posts: 189
Joined: Fri Sep 14, 2012 6:09 pm
Blog: View Blog (0)


Re: PHP Increment/Decrement

Post by jadecook on Sun Nov 25, 2012 4:21 pm
([msg=71323]see Re: PHP Increment/Decrement[/msg])

It keeps reloading the page and starting at the top, but won't go to the next page.
This is the URL:

Code: Select all

http://mysite.com/preview/preview.php?job=california



And this is what I got for the source:

Code: Select all

<?php
$location = $_REQUEST['nav'];
$page = $_POST['page'];
if (isset($_POST['next']))
{
   $page++;
}
else if (isset($_POST['previous']))
{
   $page--;
}

if ($page <= 1)
{
   echo "<script src='http://myblog.tumblr.com/tagged/" . $_REQUEST["job"] . "/js' type='text/javascript'></script>";
}
else
{
   echo "<script src='http://myblog.tumblr.com/tagged/" . $_REQUEST["job"] . "page/" . $_REQUEST["page"] . "/js' type='text/javascript'></script>";
}
?>
<form method="POST">
<input type="hidden" name="navigation" value="location" />
<input type="submit" name="previous" value="previous">
<input type="submit" name="next" value="next">
</form>

User avatar
jadecook
Experienced User
Experienced User
 
Posts: 75
Joined: Fri Aug 17, 2012 2:20 pm
Blog: View Blog (0)


Re: PHP Increment/Decrement

Post by Shade_of_Gray on Mon Nov 26, 2012 5:23 pm
([msg=71343]see Re: PHP Increment/Decrement[/msg])

Keep in mind that the name of the HTML tag is going to be the key in the PHP associative array. Since your hidden field's name is "navigation", you'll need to use $_POST['navigation'] to access it.

Also, to set the value of the tags with PHP:

Code: Select all
<input type="hidden" name="navigation" value="<? echo $location; ?>" />


-- Mon Nov 26, 2012 6:23 pm --

Keep in mind that the name of the HTML tag is going to be the key in the PHP associative array. Since your hidden field's name is "navigation", you'll need to use $_POST['navigation'] to access it.

Also, to set the value of the tags with PHP:

Code: Select all
<input type="hidden" name="navigation" value="<? echo $location; ?>" />
Shade_of_Gray
Experienced User
Experienced User
 
Posts: 60
Joined: Mon Oct 22, 2012 11:04 pm
Blog: View Blog (0)


Re: PHP Increment/Decrement

Post by jadecook on Fri Nov 30, 2012 5:12 am
([msg=71424]see Re: PHP Increment/Decrement[/msg])

I just can't seem to get this...
Keep doing little things here and there, but nothing seems to work.

Code: Select all
<?php
$location = $_REQUEST['nav'];
$page = $_POST['page'];
if (isset($_POST['next']))
{
   $page++;
}
else if (isset($_POST['previous']))
{
   $page--;
}

if ($page <= 1)
{
   echo "<script src='http://myblog.tumblr.com/tagged/" . $_REQUEST["job"] . "/js' type='text/javascript'></script>";
}
else
{
   echo "<script src='http://myblog.tumblr.com/tagged/" . $_REQUEST["job"] . "page/" . $page . "/js' type='text/javascript'></script>";
}
?>

<form method="POST">
<input type="hidden" name="navigation" value="location" />
<input type="submit" name="previous" value="previous">
<input type="submit" name="next" value="next">
<input type="hidden" name="navigation" value="<?php echo $location; ?>" />
</form>

</center>
User avatar
jadecook
Experienced User
Experienced User
 
Posts: 75
Joined: Fri Aug 17, 2012 2:20 pm
Blog: View Blog (0)


Re: PHP Increment/Decrement

Post by pickles0703 on Thu Dec 20, 2012 7:04 pm
([msg=71784]see Re: PHP Increment/Decrement[/msg])

Remove your first element with the name navigation. Then at the top of the page put $location = $_REQUEST['navigation']. It seems as if you are grabbing a form variable that doesn't exist. Try reviewing how to capture form inputs. I wrote a tutorial on this, I hope it helps PHP Get and Post Variables
pickles0703
New User
New User
 
Posts: 4
Joined: Thu Dec 20, 2012 3:10 am
Blog: View Blog (0)


PreviousNext

Return to Programming

Who is online

Users browsing this forum: No registered users and 0 guests

cron