473,394 Members | 1,812 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

What is wrong with this code?

80
Hi this one is hurtin' me!!

Expand|Select|Wrap|Line Numbers
  1. <?php 
  2. $strID = $_GET["id"];
  3.  
  4. $filename = "c:\somedir\somedir\" . $strID . ".php";
  5. if (file_exists($filename)) {
  6.     $strIncPage = "somedir/" . $strID . ".php";
  7. } else {
  8.     $strIncPage = "somedir/error404.php";
  9. }
  10. ?>
Ig get the error

Expand|Select|Wrap|Line Numbers
  1. Parse error: parse error in C:\xampp\htdocs\index2.php on line (....x)
The problem persists with the "$filename" variable, I have tried jusing "'" characters instead of """ But then I get
Expand|Select|Wrap|Line Numbers
  1. Warning: Unexpected character in input: ''' (ASCII=39) state=1 in C:\xampp\htdocs\index2.php on line 6
  2. c:\xampp\htdocs\insert_pages' . $strID . php 
I cant seem to find out when to use either "'" or """, and when and how to use "." in these statements...

Expand|Select|Wrap|Line Numbers
  1. $filename = 'c:\somedir\somedir\' . $strID . '.php';
Expand|Select|Wrap|Line Numbers
  1. $filename = 'c:\somedir\somedir\$strID.php';
Expand|Select|Wrap|Line Numbers
  1. $filename = "c:\somedir\somedir\$strID.php";
Frederik
Jun 13 '09 #1
6 1506
Dormilich
8,658 Expert Mod 8TB
\ is used as escape character so if you have a certain combination (like \n which is the new line character) you end up having invalid characters in your file path.

EDIT: \" escapes the quotation mark, so that it is not treated as string closing character.
Jun 13 '09 #2
Pheddy
80
Thank you!

I edited the \ to / characters...
Jun 13 '09 #3
prabirchoudhury
162 100+
1. what Dormilich mention about your invalid character that always you have to remenber in writing script.

2. you could put all the seperated part of the link in a variable and then call as a complate file name

Expand|Select|Wrap|Line Numbers
  1. if (file_exists($filename)) { 
  2.  
  3. $filename = "";
  4. $filename  .= "c:\somedir\somedir\";
  5. $filename  .= $strID;
  6. $filename  .= ".php";
  7. }else{
  8.  
  9. $filename  = somedir/error404.php";
  10. }
  11.  
:)
Jun 13 '09 #4
Dormilich
8,658 Expert Mod 8TB
@prabirchoudhury
would result in a parse error.

EDIT: thank god I'm using posix (unix, linux, bsd, ...)
Jun 13 '09 #5
Atli
5,058 Expert 4TB
@prabirchoudhury
Line #4 in that code would fail, for the exact same reason the OP's original code failed.

And why would you test if the file path stored in $filename exists, and then construct it? Makes no sense.

Edit:
Dormilich beat me to it :)
Jun 13 '09 #6
prabirchoudhury
162 100+
ya sry guys, you both right .. i have bn in illusion with \ and / ... it will brk on line 4..
Jun 13 '09 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

125
by: Sarah Tanembaum | last post by:
Beside its an opensource and supported by community, what's the fundamental differences between PostgreSQL and those high-price commercial database (and some are bloated such as Oracle) from...
72
by: E. Robert Tisdale | last post by:
What makes a good C/C++ programmer? Would you be surprised if I told you that it has almost nothing to do with your knowledge of C or C++? There isn't much difference in productivity, for...
121
by: typingcat | last post by:
First of all, I'm an Asian and I need to input Japanese, Korean and so on. I've tried many PHP IDEs today, but almost non of them supported Unicode (UTF-8) file. I've found that the only Unicode...
51
by: WindAndWaves | last post by:
Can anyone tell me what is wrong with the goto command. I noticed it is one of those NEVER USE. I can understand that it may lead to confusing code, but I often use it like this: is this...
46
by: Keith K | last post by:
Having developed with VB since 1992, I am now VERY interested in C#. I've written several applications with C# and I do enjoy the language. What C# Needs: There are a few things that I do...
13
by: Jason Huang | last post by:
Hi, Would someone explain the following coding more detail for me? What's the ( ) for? CurrentText = (TextBox)e.Item.Cells.Controls; Thanks. Jason
1
by: GS | last post by:
I got a combobox box that I load at load time. the Item and vales ended up in reverse order of each other, what went wrong? the database table has the following row code value ebay ...
98
by: tjb | last post by:
I often see code like this: /// <summary> /// Removes a node. /// </summary> /// <param name="node">The node to remove.</param> public void RemoveNode(Node node) { <...> }
9
by: Pyenos | last post by:
import cPickle, shelve could someone tell me what things are wrong with my code? class progress: PROGRESS_TABLE_ACTIONS= DEFAULT_PROGRESS_DATA_FILE="progress_data" PROGRESS_OUTCOMES=
20
by: Daniel.C | last post by:
Hello. I just copied this code from my book with no modification : #include <stdio.h> /* count characters in input; 1st version */ main() { long nc; nc = 0;
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.