|
Until you sign up you can't do much. Yes, it's free.
|
|
|
|
|
|
|
 | / / / Viewing Topic
|  |
( DaveH )
Wealthy Hobo
Patron
|
Hello everyone. i'm hoping someone can give me a hand with some PHP. | Code: | <?php // validation if (!isset($_POST['menu_name']) || empty($_POST['menu_name'])) { $error = "Subject"; redirect_to("new_subject.php?error={$error}"); } elseif (!isset($_POST['position']) || empty($_POST['position']) ) { $error = "position"; redirect_to("new_subject.php?error={$error}"); } elseif (!isset($_POST['visible'])) { $error = "Visible"; redirect_to("new_subject.php?error={$error}"); } ?> | The above code validates data which has been inputted by the user, it's working fine. however there is one more check i'd like to do. i'd like to check whether is a string, and if it is i'd like to reject it. So i've changed the code a little to add the function | Code: | | is_string($_POST['position']) | http://us2.php.net/manual/en/function.is-string.php here's my error i keep getting after i include the is_string function. | Code: | Parse error: parse error in C:\wamp\www\Content Management System\admin\create_subject.php on line 12 | Line 12 is the line i added the function too. here it is' | Code: | | elseif (!isset($_POST['position']) || empty($_POST['position']) is_string($_POST['position']) ) { | Post edited at 8:42 am on Aug. 5, 2009 by DaveH
|
8:37 am on Aug. 5, 2009 | Joined: Mar. 2008 | Days Active: 326 Join to learn more about DaveH England, United Kingdom | Male | Posts: 1,588 | Points: 4,964
|
|
| |
|
|
|
|
 LiveWire Humor
|
|
carelesmind is back
Connoisseur
Ad Free
Tech Support Leader
|
have you tryed, in that page, to say (im a little rusty on php right now, but you will get the jist i hope.) | Code: | | $Position = $_POST['position'] | then use | Code: | | elseif (!isset($Position) || empty($Position) is_string($Position) ) { | then, it does not have to keep grabbing the variable using _POST and a parse error is like a ' missing or something of the sort if i am wrong, correct me, as i said, i am a liite bit rusty, and the above code was just to get rid of the single quotes, you never know, might work
------- S Ξ G
|
|
|
|
|
( DaveH )
Wealthy Hobo
Patron
|
Quote: from carelesmind is back at 4:56 pm on Aug. 5, 2009
OH! i remember how i used to fix errors like these, split the code! | Code: | elseif ( !isset($_POST['position']) || empty($_POST['position']) is_string($_POST['position']) ) { | then see where the parse error is on, and you can keep spliting till you have narrowed it down to the part of the string of code that is truly creating the error! 
I can try splitting the code, but i doubt it will fix the problem, only make it more readable. I tried using "is_int" checks whether it's an integer. adding a ! infront if it reverses it. so it would check if it's NOT an integer. which should also work, but it didn't. Post edited at 9:04 am on Aug. 5, 2009 by DaveH
|
9:03 am on Aug. 5, 2009 | Joined: Mar. 2008 | Days Active: 326 Join to learn more about DaveH England, United Kingdom | Male | Posts: 1,588 | Points: 4,964
|
|
| |
|
|
carelesmind is back
Connoisseur
Ad Free
Tech Support Leader
|
Quote: from Daveh at 9:03 am on Aug. 5, 2009
Quote: from carelesmind is back at 4:56 pm on Aug. 5, 2009
OH! i remember how i used to fix errors like these, split the code! | Code: | elseif ( !isset($_POST['position']) || empty($_POST['position']) is_string($_POST['position']) ) { | then see where the parse error is on, and you can keep spliting till you have narrowed it down to the part of the string of code that is truly creating the error! 
I can try splitting the code, but i doubt it will fix the problem, only make it more readable. I tried using "is_int" checks whether it's an integer. adding a ! infront if it reverses it. so it would check if it's NOT an integer. which should also work, but it didn't. 
the point of spliting the code, as i said, is not to imediately fix the problem, its to identify where the problem is in the code.
------- S Ξ G
|
|
|
|
|
|
|
( DaveH )
Wealthy Hobo
Patron
|
Quote: from carelesmind is back at 5:15 pm on Aug. 5, 2009
Quote: from Daveh at 9:11 am on Aug. 5, 2009
I've found a solution to my problem, although isn't really the way i want to do it. currently the only way i can see of someone inputting invalid data, and then for it to actually get processed is when choosing the "position". however that's a drop down menu showing only valid options. however if in the case someone did enter invalid code it would just break the query, in which case i can simply use this code. | Code: | if(mysql_query($query, $connection )) { //Sucsess! redirect_to("content.php"); } else { $error = "Position"; redirect_to("new_subject.php?error={$error}"); } | anyways like i said, it's not the way i'd like to do it. i'd much rather have all my validation checks together. 
its good to hear you got a solution, hopefully it all works good for ya'
Cheers.
|
9:16 am on Aug. 5, 2009 | Joined: Mar. 2008 | Days Active: 326 Join to learn more about DaveH England, United Kingdom | Male | Posts: 1,588 | Points: 4,964
|
|
| |
|
|
|
|
|
|
|
|
|
| Looking for something else?
|
|
|
|
|
|
 | / / / Viewing Topic |  |
|