Thursday, July 9, 2009

PHP Parse error: syntax error, unexpected T_STRING in C:\Inetpub\wwwroot\example.php on line 8?

Hi


I get the above error in the following code, the line with the error seems to be:


$test-%26gt; sql = "SELECT body FROM test.articles";





full code:


%26lt;?php


phpinfo();





include("C:\Inetpub\wwwroot\my_pagina_...


$_SERVER['DOCUMENT_ROOT'] = "C:\Inetpub\wwwroot\";





$test = new MyPagina;


$test-%26gt; sql = "SELECT body FROM test.articles";


$result = $test-%26gt;get_page_result();


$num_rows = $test-%26gt;get_page_num_rows();


$nav_links = $test-%26gt;navigation(" | ", "currentStyle");


$nav_info = $test-%26gt;page_info("to");


$simple_nav_links = $test-%26gt;back_forward_link();


$total_recs = $test-%26gt;get_total_rows();


?%26gt;





when i refresh the example.php page i get the following error:





Error in my_thread_global_end(): 1 threads didn't exit PHP Parse error: syntax error, unexpected T_STRING in C:\Inetpub\wwwroot\example.php on line 8





global variables parameter in php.ini is on, so i dont understand why it doesnt work.





I am a php newbie,


Thanks in advance





kind regards





Tovia Singer

PHP Parse error: syntax error, unexpected T_STRING in C:\Inetpub\wwwroot\example.php on line 8?
There's a space in "$test-%26gt; sql" when it should be "$test-%26gt;sql." Remove it. :-)





#########


Update:





Okay, since that doesn't fix the error, the error is triggered before it gets to that part! (The space thing would have also caused an error.)





In the line before it:


$test = new MyPagina;


Try adding parentheses:


$test = new MyPagina();





I didn't think that's necessary, but it's worth a shot.





###########


Update 2:





Maybe the problem is on the line we can't see?


include(...
Reply:Hello jam,





Error in my_thread_global_end(): 1 threads didn't exit PHP Parse error: syntax error, unexpected T_STRING in C:\Inetpub\wwwroot\example.php on line 8





The my_thread_global_end() error message above refers to one of two things (and hopefully not both!). The problem is either your PHP script or your MySQL version. If it's your PHP code, the problem is that somewhere mysql_thread_init() is being called to create a new MySQL thread but mysql_thread_end() is not being called to close it when it's not needed anymore. MySQL won't automatically close this for you and therefore throws the error that you see.





Try checking your mypagina class for the mysql_thread_init() function and see if the thread is being correctly closed. If you can't find it, at the end of the method which calls the MySQL query, add a mysql_thread_end() function call anyway, to make sure the thread is closed. Just because you can't find any calls to mysql_thread_init() doesn't mean it's not being used: it's also called by some other core PHP functions.





If it is your MySQL version, you will need to apply this patch: http://lists.mysql.com/commits/25160. Or just upgrade to the latest stable release.





For more information there is a long discussion on this error/bug at http://bugs.mysql.com/bug.php?id=25621. It will most likely be worth you reading this.





The 'PHP Parse error: syntax error, unexpected T_STRING' error message may or may not be related: it usually refers to a PHP command declaration not being following by a semi colon (all lines in PHP must be finished by a semi colon (;)).





And BTW, you don't necessarily need to follow class instantiations with paranthesis' (mypagina or mypagina() are the same unless the mypagina class has a constructor which requires arguments).





Hope it helps,


Refined.
Reply:$test-%26gt; sql = "SELECT body FROM test.articles";





it should be


$test-%26gt;sql = "SELECT `body` FROM test";
Reply:Remove space here: $test-%26gt; sql


~~~~~


C++ List class remove?

Hi I have a class defined as shown, I am using this in a list.


Within main I am adding in some data to the class, that works fine. I am trying to remove a value from the class as shown below the compiler doesn't like that.





OR How do I remove a value from the class?





#include "stdafx.h"


#using %26lt;mscorlib.dll%26gt;


#include %26lt;list%26gt;


#include %26lt;string%26gt;


#include %26lt;iostream%26gt;








using namespace std;





class person


{


public:


string Name;


int age;





public:


person () {


Name = "";


age = 0;


}





person(char *n,int a){





Name=n;


age = a;





}











void report() {





cout %26lt;%26lt; "Name: \n" %26lt;%26lt; Name;


cout %26lt;%26lt; "Age: \n" %26lt;%26lt; age;





}





};








void main()


{





list%26lt;person%26gt; pers;


pers.push_back(person("Siva", 35));


pers.push_back(person("Ram", 30));


pers.push_back(person("SS", 30));


pers.push_back(person("RR", 30));


while(p != pers.end()) {


p-%26gt;report();


p++;


}





pers.remove("Siva");

C++ List class remove?
The problem is finding the proper instance in the list. The function list::remove expects an object of the same type as stored in the list. You have a list of person, but you pass remove a null terminated character string.





To use remove, you need to construct a person object with the exact same values:


pers.remove(person("Siva", 35));





What you are trying to do is to look for a person instance that happens to have a particular name, irrespective of the age. To do this, you have to write a comparison object that takes a person and compares the person's name with the target name. Then use this comparison object in std::find





class NameSearch {


public:


NameSearch(string target) : m_target(target) {}


bool operator () (person const %26amp; p)


{ return person.name == m_target }


private:


string m_target;


};





NameSearch ns("Siva");


list%26lt;person%26gt;::iterator it;


it = std::find(pers.begin(), pers.end(), ns);


if (it != pers.end()) // check if "Siva" is found in list


pers.erase(it);





Read up on iterators, they are necessary for using standard collection classes and algorithms. Once you understand them you'll see how nicely the algorithms and collections work together.
Reply:I would suspect you need to supply a person instance detailing which element you wish to remove.
Reply:check the syntax for the remove function of the list.





what i think is that the pointer (p) is pointing to the end of the list after the while loop terminates. then since you try to remove it, it does not exist.





i do not know how the remove is actually defined so im only making a guess as to what happened. if the remove does not search the list for the specific item then this is what happened.





however, if the list searches for the item then deletes it, then i don't know what happened :-)





find out how the remove is actually defined then you will know the problem





i personally just make my own list and not rely on predefined lists.
Reply:yeah WHAT?! makes nooooooooooooooooooooooo since to me................


Who can help me about doing a lab in c++ Class Kids{ protected:?

Class Kids{


protected:


String name;


int age;


bool height;


void Reg();


void disp();


};


my program will contain the fallowing functions:


1) write a function called Reg() . this function will register names and agas of the children and save them into a array of object


2) write function move() which will move the girls from the main arrayof objects into a new link list. The new class, called Girls , will be inhereted from the Kids class. Derivation will be public.


3) write function disp() to d,splay the names, ages , and the genders of the children.


4) write a main()function with a menu for invoking other fucktions .


Please help me i dont write programs for a year so i cant remember what to do .

Who can help me about doing a lab in c++ Class Kids{ protected:?
Hi,


Here is the link to C++ forum http://forum.cpplc.net/


If you could post this problem in this forum, somebody might be able to help you out.





Here is another link http://www.developer.be/forums/index.cfm...





Good luck

nobile

Getting input from a text file using c strings in c++?

How do i get input from a text file using c strings, not the standard string class. Is it possible?

Getting input from a text file using c strings in c++?
Sure, as long as you use the #include%26lt;fstream%26gt; header, and name the file you want to use as input. When you parse the data, just store it to a C-String, which as you should know is an array made exclusively of characters.


C++ class/array program?

For this program, you will create a student class and a main program that reads student information from a file and outputs the students' names in groups based on grades.





name grade





Name is a string type and grade is a char type from the set {A,B,C,D,E}.


Requirements:





Your main function should should read in the file until eof is reached, instantiate a new object for each student using your student class, and output the results.


Your student class consists of 2 private variables (name and grade), one constructor and the following 3 functions:


void setGrade(char);


string getName();


char getGrade();


The constructor for your class should set the student's name - student(string)


After constructing an object for a student, you need to read in the grade and call the setGrade(char) function to set the grade for that student.


To form the output, you need to call the getName() and getGrade() functions for each student.

C++ class/array program?
[UPDATED AGAIN. SORRY THERE WAS AN ERROR WITH MY CONSTRUCTORS. TRY AGAIN]





Ok, yes you can place everything in one file. Here is how:





#include %26lt;fstream%26gt;


#include %26lt;string%26gt;





using namespace std;





class Student


{


public:


Student();


Student(string someName);


void setName(string someName);


string getName();


char getGrade();


void setGrade(char someGrade);


private:


string Name;


char Grade;


};





Student::Student()


{


Name = " ";


Grade = ' ';


}





Student::Student(string someName)


{


Name = someName;


Grade = ' ';


}





void Student::setName(string someName)


{


Name = someName;


}





void Student::setGrade(char someGrade)


{


Grade = someGrade;


}





string Student::getName()


{


return Name;


}





char Student::getGrade()


{


return Grade;


}








int main()


{


ifstream inFile;


ofstream outFile;


const int MAX_STUDENTS = 50;


const int NUM_GRADES = 5;


Student arrayList[MAX_STUDENTS];


char grades[] = {'A', 'B', 'C', 'D', 'E'};


int count = 0;


string name;


char grade;





inFile.open("C:\\students.txt");





while(!inFile.eof() %26amp;%26amp; count %26lt; MAX_STUDENTS)


{


inFile %26gt;%26gt; name %26gt;%26gt; grade;


arrayList[i] = Student(name);


arrayList[i].setGrade(grade);


count++;


}





inFile.close();


outFile.open("C:\\groups.txt.");





for(int i = 0; i %26lt; NUM_GRADES; i++)


{


outFile %26lt;%26lt; grades[i] %26lt;%26lt; " ";


for(int j = 0; j %26lt; count; j++)


{


if(arrayList[j].getGrade() == grades[i])


outFile %26lt;%26lt; arrayList[j].getName() %26lt;%26lt; " ";


}


outFile %26lt;%26lt; endl;


}


outFile.close();


return 0;


}





// Please copy %26amp; run the code. It should work. Let me know


// if it works or not, please. Also, let me know if you need


// anything else.





// One more thing though, you are not checking whether or not


// opening the input %26amp; output files fails. Do you want me to


// show you how?





Hey Lisa, you said you owe me, and I agree. I need a favor from you. I want you to learn the following because you made mistakes related to these:





1) When you open a file don't close it until you are done with it. "Done with it" means that you already read data from the file or wrote data to the file.





2) All of your constructors have to have the same name as the name of the class (case sensitive). In your case, all of them have to be named "Student" not "student".





3) When your member function does not require parameters such as your getName function, here is how you declare it:





string getName();





NOT





string getName(void);





4) When your function requires a parameter such as your setGrade function, this is how it should look like:





void setGrade(char someGrade);





NOT





void setGrade(char);





Always name your parameters.
Reply:#Include %26lt;fstream.h%26gt;


#include %26lt;string.h%26gt;





void main()


{


ifstream ifs("students.txt");


string line;


Student S[100];


while(!ifs.eof()) {


getline(ifs,line);


cout %26lt;%26lt; "[ " %26lt;%26lt; line %26lt;%26lt; " ]" %26lt;%26lt; endl;


//put ur logic like


S(First 10 Charecter name , Rest all charets Number)


then call a sort Program


}


if you can wait then pls. I can write program after 5:30. as if I am in office now.


C++ help with strings?

What are the major differences between (C strings) and the (string) class?

C++ help with strings?
The difference between living in a universe with a sun and one with eternal darkness.





string class is


easily expanable


easily copyable


has built in equality operators


has a multitude of insert, replace, etc., methods;


has iterators and revere iterators


can be passed to many stardard library algorithms





just off the top of my head.

flower girl dresses

C++ string functions help?

I need to write a library similar to the %26lt;string.h%26gt; header file. I need help writing the following functions. They are included in my own class called "string".





void resize(unsigned int, char);


//resizes character array "Buffer" to number specified by


//first parameter


//fills extra space by the second parameter character





void insert(unsigned int, string %26amp;);


//Inserts a string into "Buffer" a character array.


//First parameter: Place to insert


//Second parameter: string to insert.








void remove(unsigned int, unsigned int);


//removes characters from "Buffer", a character array.


//First parameter : Starting position,


//Second parameter : number of characters to remove.

C++ string functions help?
Okay, this is pretty obviously homework. I won't show any code here, but I'll give you an idea how to implement the functions listed.





First, void resize(unsigned int, char); It has to do these things in approximately this order:


Validate int as greater than zero, or the operation is over before it starts. Next, it needs to allocate memory for a new Buffer with the extra space. Oh-oh. How do you find the buffer if it doesn't return a pointer or a reference to it? Better change the return type to char%26amp; or char *. Okay, now the new characters are written into the new buffer and then the old characters ... Oh-oh, we need to know where that things at too. Better include a reference or pointer to the old buffer as a parameter. So we take the old buffer and move the old characters over into the new buffer behind(?!) the new characters. Rats! Do we need to consider that the new characters should always be prepended or appended or does it change?





void insert(unsigned int, string %26amp; old_string, string %26amp; new_string); maybe?





void remove(unsigned int, unsigned int, string %26amp; buffer);





Unless you MUST follow these exact prototypes for your assignment, you may want to consider these modifications.





I think you can work these last two from the first walk through I gave you. They aren't really any different as to the mechanics of the problem, just what information is needed to operate from. Good luck!
Reply:I can understand that. Next time post partial code with specific questions and I (we?) can take the sting out of those sticky points. Sorry to be a drag. Cheers! Report It

Reply:Sounds like homework to me...


And if you can't do these simple things, you are in trouble!


Do it as a for(i=..;i%26lt;..;i++) loop, and use Buffer[i].


(or review the use of pointers: that's the beauty of C)