LiveWire Network Peer Answers Peer Support Teen Forums Tech Forums College Forums 474 users online 225454 members 691 active today Advertise Here Sign In
TeenCollegeTechPhotos | Quizzes | LiveSecret | Memberlist | Dictionary | News | FAQ
Member Spotlight
Uptown Swag
Movies: Harry Potter HBP, Public Enemies, G.I....
Mood: Silly
You have 1 new message.
Emergency Help
Until you sign up you can't do much. Yes, it's free.

Sign Up Now
Membername:
Password:
Already have an account?
Invite Friends
Active Members
Groups
Contests
Moderators
3 online / 32 MPM
Fresh Topics
  LiveWire / Technical Forums / Programming & Application Development / Viewing Topic

PHP Help
Replies: 10Last Post Aug. 6 5:09am by allsmiles
Welcome to LiveWire!
We're Stronger Together.
Join the Community
Single page for this topic Email Print Favorite
( DaveH )


Wealthy Hobo

Patron
Reply
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
Code:
$_POST['position']
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
Reply
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


8:48 am on Aug. 5, 2009 | Joined: July 2009 | Days Active: 104
Join to learn more about carelesmind is back Russia | Straight Male | Posts: 4,562 | Points: 6,628
carelesmind is back


Connoisseur

Ad Free
Tech Support Leader
Reply
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!

-------
S Ξ G


8:56 am on Aug. 5, 2009 | Joined: July 2009 | Days Active: 104
Join to learn more about carelesmind is back Russia | Straight Male | Posts: 4,562 | Points: 6,628
( DaveH )


Wealthy Hobo

Patron
Reply
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
Code:
!is_int()
"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
Reply
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
Code:
!is_int()
"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

9:07 am on Aug. 5, 2009 | Joined: July 2009 | Days Active: 104
Join to learn more about carelesmind is back Russia | Straight Male | Posts: 4,562 | Points: 6,628
( DaveH )


Wealthy Hobo

Patron
Reply
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.


9:11 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
Reply
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'

-------
S Ξ G

9:15 am on Aug. 5, 2009 | Joined: July 2009 | Days Active: 104
Join to learn more about carelesmind is back Russia | Straight Male | Posts: 4,562 | Points: 6,628
( DaveH )


Wealthy Hobo

Patron
Reply
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
allsmiles


Enlightened One

Patron
Reply
I think you're missing an operand... Shouldn't the line read:

Code:
elseif (!isset($Position) || empty($Position) || is_string($Position) ) {

At the moment, it's got two functions not delimited, as a single arguement for an elseif. This is what's causing the parse error.

-------
When they leave me, they're all smiles.
When they leave you, they're in tears.


10:46 am on Aug. 5, 2009 | Joined: Aug. 2007 | Days Active: 593
Join to learn more about allsmiles England, United Kingdom | Male | Posts: 9,125 | Points: 16,393
carelesmind is back


Connoisseur

Ad Free
Tech Support Leader
Reply
Quote: from allsmiles at 10:46 am on Aug. 5, 2009

I think you're missing an operand... Shouldn't the line read:

Code:
elseif (!isset($Position) || empty($Position) || is_string($Position) ) {

At the moment, it's got two functions not delimited, as a single arguement for an elseif. This is what's causing the parse error.


that is what i sugested up iun my post, but since he is using the "$_POST" command, he would need to declare the new variable "$Position = $_POST[position']"

-------
S Ξ G

2:32 pm on Aug. 5, 2009 | Joined: July 2009 | Days Active: 104
Join to learn more about carelesmind is back Russia | Straight Male | Posts: 4,562 | Points: 6,628
allsmiles


Enlightened One

Patron
Reply
Quote: from carelesmind is back at 10:32 pm on Aug. 5, 2009

Quote: from allsmiles at 10:46 am on Aug. 5, 2009

I think you're missing an operand... Shouldn't the line read:  

 
Code:
elseif (!isset($Position) || empty($Position) || is_string($Position) ) {
 

 At the moment, it's got two functions not delimited, as a single arguement for an elseif. This is what's causing the parse error.


that is what i sugested up iun my post, but since he is using the "$_POST" command, he would need to declare the new variable "$Position = $_POST[position']"

Not necessarily... it depends on how PHP has been configured on the machine.

-------
When they leave me, they're all smiles.
When they leave you, they're in tears.


5:09 am on Aug. 6, 2009 | Joined: Aug. 2007 | Days Active: 593
Join to learn more about allsmiles England, United Kingdom | Male | Posts: 9,125 | Points: 16,393
Single page for this topic Email Print Favorite

Quick Reply

You are signed in as our guest.

Looking for something else?
 

  LiveWire / Technical Forums / Programming & Application Development / Viewing Topic