Link to home
Create AccountLog in
Avatar of Ian Webb
Ian WebbFlag for United Kingdom of Great Britain and Northern Ireland

asked on

php pagination $_GET $_POST FORM Problem

I have a form that uses <form action="<?php echo $_SERVER["PHP_SELF"]; ?>" method="get">
<input type="submit" value="Edit" name="strAction" class="Button" style="color:White;"/>
This edits the contents of a textbox and updates the field 'html' in table 'tblPages' in the 'AdminDB' database.
I have pagination on the page: tempDefault0.php?page=1 etc,etc..
The problem is, when clicking on 'Edit' the 'page=' is lost and causes following error:
echo '#'.$_GET['page'].'#';  // line 35
$inc = $_GET['page'];  //line 36
Notice: Undefined index: page in tempDefault0.php on line 35
Notice: Undefined index: page in tempDefault0.php on line 36
Query failed. You have an error in your SQL syntax; near '' at line 1
Thanks in Advance for any help given.
For clarity, below i am listing full code for php & sql to create table:
Please see files attachements.
tempDefault0.php
sqlScript.sql
ASKER CERTIFIED SOLUTION
Avatar of Julian Hansen
Julian Hansen
Flag of South Africa image

Link to home
membership
Create an account to see this answer
Signing up is free. No credit card required.
Create Account
You need to use the isset to ensure that the $_GET['page'] has been defined/initalised before utilising it.
You need to use the isset to ensure that the $_GET['page'] has been defined/initalised before utilising

see above. Empty is better - if page is set to blank isset will return true but that might not be the desired behaviour if you want to set a default page. Empty will allow you to pick up blank submissions and instances where page is not set.

$page = empty($_GET['page'])? 'defaultpage' : $_GET['page'];
Avatar of Ian Webb

ASKER

Thank you both for the suggestions. The working code I now have is below:
<form action="<?php echo $_SERVER["PHP_SELF"]; ?>" method="GET">
<input type="submit" value="Edit" name="strAction" class="Button" style="color:White;"/>
<input type="hidden" name="page" value="<?php echo $_GET['page'];?>" />
Then:
$inc = empty($_GET['page'])? $page : $_GET['page'];
echo 'page='.$inc.'#';
You are welcome - thanks for the points.