Stefano Mtangoo 455 Senior Poster

This is my first post in over 2 years. I'm not sure how to mark it "solved".

Link at the bottom

Stefano Mtangoo 455 Senior Poster

There is topic going on about the same issue:
http://www.daniweb.com/web-development/php/threads/370883

Stefano Mtangoo 455 Senior Poster

LOL! @WaltP: Pretty good timing for this thread! Don't you think?

Yet another example of "I compile this with DevC++ and it doesn't work, but it works with other IDEs like ..".

:D

But I would also recommend you pick another IDE besides DevC++, like Code.Blocks or Visual Studio, and try to pick a recent version.

Duh! DevCpp dies hard :)

Stefano Mtangoo 455 Senior Poster

Updating your Mingw and [getting] rid of what came with your IDE will not help. The problems will still occur with an updated compiler.

You overlooked this below ;)

WaltP nailed it

Stefano Mtangoo 455 Senior Poster

DevCpp again! WaltP nailed it, plus you need to update your Mingw and get rid of what came with your IDE. Alternatively use wxDevCpp which is updated version of DevCpp plus wxWidgets RAD

Hi!
I am using Dev-C++ and when I am trying to compile a program in it, it is showing many errors. All the settings seems to be right. Can I compile a program including header files like conio.h and iostream.h and using namespace std in Dev-C++? If not please suggest a good compiler in which I can do a program containing the header files mentioned above. I tried doing the same program in turbo C++ and microsoft visual studio 2010 express and it is working properly. If this problem in Dev-C++ is due to any settings that has to be done, please tell. I have installed Dev-C++ correctly.

Someone, please help me out!:confused:

Stefano Mtangoo 455 Senior Poster
Stefano Mtangoo 455 Senior Poster

oh so when there are multiple constructors you are overloading the constructors

Constructor is a "special" method. It can be overloaded like any other method. Note that Constructor should not return anything!

Stefano Mtangoo 455 Senior Poster

PHP is on server side and HTML page is on client. So practically impossible unless you do echo the variable either hold in session or file to include. Then keep modify that between pages!

Stefano Mtangoo 455 Senior Poster

Method that get called automatically when objects get created from Class. You can perfom initialization there

class Person{
    public int height, weight;
    //Ctor - Can be more than one aka overloaded
    public void Person(){
	//Do init here
	height = 100;
	weight = 250;
	
    }



};

see:
http://en.wikipedia.org/wiki/Class_%28computer_programming%29#Special_methods
http://www.cplusplus.com/doc/tutorial/classes/

Stefano Mtangoo 455 Senior Poster

The thread starter admits he's a noob, so he doesn't understand the php solution - nice though it is.

I hope I have not added to confusion :)

Stefano Mtangoo 455 Senior Poster

I would suggest:
1. Use $_SERVER for your action
2. At the top of your file put something like
if(your_form_is_submitted){
//do your stuffs
}
3. Validate using REGEX and PHP's preg_match
$match = "/[0-9]/";
$input_from_form = $_POST;
if(!preg_match($match, $input_from_form)){
//echo error here
}

Stefano Mtangoo 455 Senior Poster

somthing like:

pseudo code:

<?php
$fileurl = 'www.somedomain.com/somefile.file'
<?
<html>

.......s1.addVariable("file", echo $fileurl)........
</html>

?

What are you trying to accomplish?

Stefano Mtangoo 455 Senior Poster

@evstevemd can it handle variables between php and htl?

To send Variable to HTML just echo it, to send it to PHP however you either us POST/GET or use AJAX.

Stefano Mtangoo 455 Senior Poster

Have you checked $_SERVER?

echo $_SERVER['PHP_SELF'];
Stefano Mtangoo 455 Senior Poster

take your pick

My Fav is this one

<link rel="stylesheet" type="text/css" href="/menu/menu_style.css">
Stefano Mtangoo 455 Senior Poster

I would use following steps:
1. Put Tables in array

mysql_connect($server, $login, $password);
$res = mysql_query("SHOW TABLES FROM $db");
$tables = array();
while($row = mysql_fetch_array($res, MYSQL_NUM)) {
    $tables[] = "$row[0]";
}

2. Loop the array and query each table.
Now it is up to you to test my "workable" theory!
Also for (1) you can use mysql_list_table

Stefano Mtangoo 455 Senior Poster

A note to take, there is no such a thing as true random in real world.
That said, there is pseudo random. That said, check rand

Stefano Mtangoo 455 Senior Poster

I always try to warn anybody new to PHP to beware of the problems that I encountered when I first started.

PHP is easy. Too easy. You code some rubbish, and it works (after a fashion). Before long you're 'coding' complicated stuff with the use of about 10 different built-in functions and a couple of if/elseif/else and switch control structures. Then it hits you.

You're duplicating code all over the place. As your project gets more complicated, you find that you can't scale it and you have to rethink the wiring and start again. Your database needs altering, but this means your data handling routines need to be to be rewritten.

When you look at your code, it's all very messy, mixed up with your html. It's not good.

So, I suggest that you get stuck into creating functions as quickly as possible to avoid duplication of code and then start creating OOP code, using classes. This is something I really struggle with now after a lifetime of 'lazy' procedural coding.

Learn the basics first though:

variables, data types and constants
control structures (if, switch)
arrays
functions
mysql (or whichever DB you're using) functions and data handling
*thorough understanding of (X)HTML and CSS is a must*

After this, you may find using templating engines help you to separate your php from your html. Just a thought.

BTW, I like books. I find them far more relaxing. They are peer-reviewed and are *generally* accurate. Any idiot …

Stefano Mtangoo 455 Senior Poster

I bought a book a few years back:

"Essential PHP Security" Chris Shiflett (O'Reilly) isbn0-596-00656-x

Good

Yeah, Shiflett is one of the experts on the field. I have learned a lot on his web. Here it is with some helpful security websites:
http://shiflett.org/
http://phpsec.org/projects/guide/

Stefano Mtangoo 455 Senior Poster

Ok i tried it, it stills gives me an empty row.

And what i just said its working im using the same codes i posted. But you now what i did i went to the database added a row with nothing in it, so whatever username or password i write it just shows me that row with age and address 0 since that what the database has.

Post the form Code as well as your table and its contents

Stefano Mtangoo 455 Senior Poster

How do you delete Emails? Do you list Emails with link to delete or one fills address and the form submission does delete?
If you list Emails, add Id to delete link. If you use form, that is easy. Since email is unique it can be used instead of ID!

Stefano Mtangoo 455 Senior Poster


But when i change the ...username = '$username'"); it gives me an empty row.

I always use something like this, and it works!

$sql = "SELECT * FROM users WHERE username='{$username}' AND password='{$password}'";
Stefano Mtangoo 455 Senior Poster

I gues no shortcut,
Learn HTML/CSS-->JS-->PHP-->MySQL and if you want AJAX
Then you can opt to go to frameworks if you want.
Practice is what makes you good programmer. Note, there is security issues, and that is different beast altogether :)

Stefano Mtangoo 455 Senior Poster

sanitize ALL input data.

It is huge process actually. I plan to do little series on security by the end of this month, God willing (Not expert at all but learning) But here is my suggestion on angles to check:
1. As ardav pointed out, always suspect user - Sanitize and validate ALL external data
2. Secure your session and site against CSRF, XSS and other common attacks
3. Escape all outputs
4. Guard your Database against SQL injection
5. Add DoD, that is in case one thing is compromised (like session variable) then intruder can still be delayed to get in
6. Log all login attempts and if username applies lock after several attempts and alert user with unlock link. If user does not exist, send email to admin.

Actually there are more to that but those are the one I can think for a moment

Stefano Mtangoo 455 Senior Poster

session_start(); -->Should be at very top of the file, before anything else. That is the best practice to avoid headers already sent error!
try rectifying this and post any error/warning you get

Stefano Mtangoo 455 Senior Poster

Thanks Cuonic For Your Help I Will try It

Thanks I Love The Function Thing

Can You Write The Full Function Code For Me Plz

Including The DB Code To Select The Table And Column

It is just a normal connect and query Ops

Stefano Mtangoo 455 Senior Poster

if it is solved, mark it so ;)

Stefano Mtangoo 455 Senior Poster

Hello,
Those errors I am facing when I try to connect with MySQL Administrator GUI(MySQL WorkBench). MySQL server is working. In server, MyphpAdmin is installed and then I installed Mysql server and then Mysql Administrator. MySQL command prompt is working but GUI is not working and when I try to login, I am facing those errors which I attached before.

That have something to do with installation than PHP/MySQL. Just uninstall the whole thing and reinstall it!

Stefano Mtangoo 455 Senior Poster

You want the title stored in your database to appear as the page title if I understood correctly :

<?php

$page = 1; //page ID

//Connect to Server
$title_query = mysql_query("SELECT title FROM table_name WHERE page='$page'");
list($page_title) = mysql_fetch_row($title_query);

?>
<head>
<title><?php echo $page_title; ?></title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<link href="http://www.e-alriyadh.com/favicon.ico" rel="icon" type="image/x-icon" />
<link rel="stylesheet" type="text/css" href="Style.Css" />

</head>

If he uses this, he have to put it on top of each page. The function thing is easy and reflects any change to all pages it is included!

Stefano Mtangoo 455 Senior Poster

I wonder how you guys understood the question. Am I that dumb?

Stefano Mtangoo 455 Senior Poster

I will pretend that I have understood and open to correction :)
I will assume also that you can query the database. There might be several way to do that but one of them is this for procedure (a bit different and easy for OOP)

index.php

<?php
include("functions.php");
?>
<html>
<head>
<title><?php echo getTitleFromDbFunction($argumentIfAny); ?></title>
</head>
<body>
<!---put your body stuffs here-->
</body>
</html>

functions.php

<?php
function getTitleFromDbFunction($argumentIfAny){
//get the title from database.argumentIfAny can be ID of title from Get or whatever
return $theRetrievedTitle;

}
?>

Note: this is to give Idea, untested and so unwarranted!

-==Zero==- commented: Thanks So Much -==Zero==- +2
Stefano Mtangoo 455 Senior Poster
Stefano Mtangoo 455 Senior Poster

Get MySQL workbench and give it a go. If you use netbeans it have services tab and there you can connect

Stefano Mtangoo 455 Senior Poster

Please rephrase your question. I have not even got a clue of what you want! Try to be specific and give more data like schema et al

Stefano Mtangoo 455 Senior Poster

The link I gave above teaches step by step exactly what OP is trying to do and he/she completely ignored it!

Stefano Mtangoo 455 Senior Poster

First use Code tags in your posts. Secondly try to read tutorial in this link, since you are new, to get rough Idea of what you are supposed to do!

Stefano Mtangoo 455 Senior Poster

Why waste all the time while you can solve the problem by removing space? I cannot see what is so peculiar about that space. as Ardav said, remove it and you will be fine!

Stefano Mtangoo 455 Senior Poster

I have no idea too what is your problem!

Stefano Mtangoo 455 Senior Poster

Sounds like Homework and I will help you with this:
http://lmgtfy.com/?q=sql+like+operator

Stefano Mtangoo 455 Senior Poster

U're welcome.
Mark it solved then

Stefano Mtangoo 455 Senior Poster

redirec with header
Beware of headers already sent thing ;)

Stefano Mtangoo 455 Senior Poster

Could you post your schema? I can guess it is not well designed. just my guess

Stefano Mtangoo 455 Senior Poster
Stefano Mtangoo 455 Senior Poster

Ok i got wxwidgets but have no clue how to install help!!!

Check this Wiki entry. The best way for newbie would be using precompiled version called wxPack. Use wxDevC++. It is updated version of DevCpp and have RAD for wxWidgets.
Hope that helps!

jonsca commented: wxPack was the word I was looking for, thanks! +7
Stefano Mtangoo 455 Senior Poster

I would suggest you go for wxWidgets. You can use wxPanel/wxGLCanvas to draw your stuff depending on whether OGL or just pure wxStuffs. It is not that hard to draw images on wxPanel once you are used to wxWidgets. Good tutorial to begin with is here and good support at wxForum

jonsca commented: I saw your name as having responded to the thread, and I knew immediately what you'd be posting about. :) +7
Stefano Mtangoo 455 Senior Poster

Not a software engineer but you have big project and I wonder what angle do you want suggestion!

Stefano Mtangoo 455 Senior Poster
Stefano Mtangoo 455 Senior Poster

Welcome!

Stefano Mtangoo 455 Senior Poster

Does user login? If yes then when user logs in query his current stats into session. Then when he adds then by clicking a form submit, just take submitted value, add to session value and update database!

Stefano Mtangoo 455 Senior Poster

What is function of this line? AFAIK it is useless!

if(session_id()==$_SESSION["userid"])

EDIT:
I would make an Authentication class and in it put method that check if user is login then do something like

if($AuthObj->isLoggedIn()){
   //user is logged in do stuffs
}else{
    //redirect user to login page or out errors
}