about the code i need time to digest.
| SitePoint Sponsor |
about the code i need time to digest.
I used the code to add record using the first form you did.
am geting error.
Parse error: parse error, unexpected T_GLOBAL, expecting '{' in E:\Practise\test3\common.php on line 16
PHP Code:function my_query($sql)
/*error*/ GLOBAL $_SERVER["PHP_SELF"];
GLOBAL $db;
PHP Code:function my_query($sql)
{//note this ;)
GLOBAL $_SERVER["PHP_SELF"];
GLOBAL $db;
-- Jelena --
Trust me, code can be even more cleanerOriginally Posted by hisham777
As far as I know, you can do it through control panel on your server. I don't use Windows server so, I'm not good enough to advise you on that, but it should be fairly simple.Originally Posted by hisham777
Btw, why windows hosting?
-- Jelena --
its not windows hosting
am using my computer to learn (localhost) I know its better to use linux
soon all migrate am geting sick with Micros**k .
i dont have hosting at the moment planning to buy one soon.
and about ,htacces IIS does not support it i just got this info
from a site.
sorry, what do you mean by
PHP Code:{//note this ;)
You have to add { where I have placed it.Originally Posted by hisham777
-- Jelena --
Then no need to worry, you will setup htaccess as soon as you find a proper hosting. I'm developing under Windows, tooOriginally Posted by hisham777
![]()
-- Jelena --
may i ask what editer do you use ?
now am geting this error
Parse error: parse error, unexpected '[', expecting ',' or ';' in E:\Practise\test3\common.php on line 15
Revised version of common.php
Sorry, I haven't checked for syntax errors.PHP Code:<?php
include_once "config.php";
include_once "functions.php";
session_start();
//connect to the base
if(!($db = @mysql_pconnect(BASESERVER, BASEUSER, BASEPASS))) //connect to base host
die("Cannot connect to the base server.");
if(!@mysql_select_db(BASENAME,$db)) //select base
die("Database doesn't exist!!!");
//common functions
function my_query($sql)
{
GLOBAL $PHP_SELF;
GLOBAL $db;
if(($result = @mysql_query($sql,$db)) == 0) //Execute SQL query
{
echo "\n<hr>Database error: <strong>".mysql_error()."</strong><br /><br />\n";
die("Query was (<strong>$sql</strong>) in file <strong>".$PHP_SELF."</strong>");
}
else
return $result;
}
?>
-- Jelena --
I use Zend mostly, but code I have wrote here I did in UltraEdit, that is the main reason I haven't checked for syntax errors.Originally Posted by hisham777
Zend marka parts of code that have syntax errors, so it's much easier to fix them.
-- Jelena --
ok i changed the the code.
i got error session cant start
so i repliced session_start at the top, worked
but i got massage
Cannot connect to the base server.
so i changed the config.php from
ToPHP Code:define("DBHOST","localhost");
define("DBUSER","roots");
define("DBPASS", "555456");
define("DBNAME","site");
PHP Code:define("BASESERVER","localhost");
define("BASEUSER","roots");
define("BASEPASS", "555456");
define("BASENAME","site");
Its WorkingCool
Well spotted! You are getting into it pretty fast![]()
-- Jelena --
Do you mean Zend Studio ?
you have to pay for that !?
Yes, that is exactly what I meanOriginally Posted by hisham777
. And yes again, you have to pay for it
Check out this thread: http://www.sitepoint.com/forums/showthread.php?t=346481, maybe you'll find something that suit you.
Also, search PHP forum for PHP editors. We have disccussed them so many times before.
-- Jelena --
thanks to you.
now i have to face the bigger problem is
to use the code with the othere parts like editing and deleting.
and this will make me ask a Q. you have seen my level in coding
there are so many things i just dont get it in PHP.
so my Q is whats your advaces on this (practise(true)), shall
i just continue starting with projects, or i go back to the basics,
like how to build functions, make use of arrays....etc. ?
by the way have you ever considered to open a site for tutorials![]()
(i noticed your blog) am a first member.
As I've already noticed, you are progressing very well, but reading about basics would be great. Most thing you can find inOriginally Posted by hisham777
PHP Manual. But learning while you are making this system would be the fastest solution.
Actually, I have. That is on my 2DO list for so long as it has low priority. I just can't find the time to do itOriginally Posted by hisham777
.
-- Jelena --
hi there, its a rainy day.
jelena i tryed to follow your style of coding. am not lucky
i just cant it the moment, building a new functions for editing, viewing
and deleting.
do you recommend making function for each feature. ?
am bad with functions so am reading about it in
http://www.developertutorials.com/tu...620/page1.html
and her
http://www.webmasterworld.com/forum88/6411.htm
![]()
![]()
Last edited by hisham777; Mar 30, 2006 at 23:46.
Yes, I do recommend making functions, especially if one can be used on more then one place.
Paste your code and let's see where's the problem![]()
-- Jelena --



Better still, learn object-oriented programming and make classes.Originally Posted by jelena
As with functions you can give your classes names which describe their purpose. But you can also associated a number of related functions. This is referred to as encapsulation.
For example, you have functions related to connecting to the database, running a query and then retrieving the results of that query. I'm not going to reveal the sort of code you'd find in the classes, but here's an example of how you might use them:The class definition is in the file loaded by require_once(). It has several "methods" (that's the name we give to a class's functions) which are concerned with making a connection to a database and selecting a table.PHP Code:require_once('path/to/class.MysqlConnection.php');
$db =& new MysqlConnection($host, $username, $password); //create connection object
$db->connect($dbname); //connect and select database
The variable $db represents the object you just created and the nomenclature '->' allows you to call its methods. In the example above, the method is 'connect', so I call the object's method with $db->connect($dbname);
When you come to use the class, you create an "object" from it. The first line initializes the object with the parameters you pass to the creation function. The second line connects and selects the database. In two lines you've done what previously took you many lines. All that other stuff still happens in the background (that is, in the class's own methods), but once you've got your class working you don't have to wade through all that code to see what's it's doing. The script which creates and uses such an object has code, like that I wrote above, which expresses what is happening much more succinctly.
Want to find articles? Define an article "model' class which makes use of a db connection object and runs specific queries on it. Code to do that might look like:orPHP Code:$articleModel =& new ArticleModel($db);
$articleModel->findAll();
orPHP Code:$articleModel->findById($article_id);
orPHP Code:$articleModel->add($article_data);
Want to tie that all together with displaying a list of articles?PHP Code:$articleModel->delete($article_id);
Now, learning how to write classes (basic OOP) and then learning how to use them and make sure you write them well is a very steep learning curve, but one worth learning. It allows you to write more expressive code. I've put comments in the last example, but I bet you could tell what was going on even if I hadn't because I gave meaningful and descriptive names to the classes and the variables representing objects based on them.PHP Code:/* Connect to database */
$db =& new MysqlConnection($host, $username, $password);
$db->connect($dbname);
/* Fetch all articles */
$articleModel =& new ArticleModel($db);
$articles = $articleModel->findAll();
/* Give article data to the view to display */
$view =& new ArticleView('/path/to/html/template/for/displaying/articles');
$view->setData($articles);
$view->display();
And there wasn't any echo()-ing of HTML code. (That's inside the HTML template I gave to the ArticleView class.) It's so much easier to read.
Beautiful, isn't it?
Zealotry is contingent upon 100 posts and addiction 200?
auricle, I haven't suggested OO aproach, because hisham777 is a beginner. He would be confused to jump into OO right from the beginning. From my experience, people have hard time to go straight with classes if they haven't programmed before. I'm not sure if hisham777 programmed before, but from what I've seen, I would say no. He is having hard times to get along with things I have posted, although he is a great student so far and quick learner.![]()
Also, OO aproach on very simple systems like the one hi is building is in qustion.
-- Jelena --
auricle thanks for the info
i did learn OOP using C++ (theoritical)
Classes
Private
Public
encapsulation ...etc. and its benifites.
however OO is in my mind but i need to get a good grip of the
structorer programming specially the build in Functions,
and how to make my own which am really bad at it.
just starting to pick it up.
thats why jelena functions.php was an exellent example to
follow (am still trying to understand it still).
who know may when this done all may be do one more then move to OO![]()
Just tell me what confuses you, and I'll try to explainOriginally Posted by hisham777
![]()
-- Jelena --



I know, but one can aspire to greater things!Originally Posted by jelena
While I'm inclined to agree with you about the methodology, I guess I wouldn't necessarily have made that assumption. (Edit: in the meantime you and hisham777 sent a couple of posts while I couldn't connect to Sitepoint for a few minutes. Turned out I was right!)From my experience, people have hard time to go straight with classes if they haven't programmed before. I'm not sure if hisham777 programmed before, but from what I've seen, I would say no.Why? I venture to suggest that what I've written is much more illustrative of what he's trying to achieve than any example you've posted, especially where you've mixed in HTML, either by echo()-ing or delimiting PHP code with '<?php' and '?>'. Now, much of what you did post, such as showing the database queries, is probably what I'd put inside class methods, but it doesn't show how it's used. And consider a typical scenario: when you have to change the features of the web site in 6 months' time, how much of your code will you be able to follow and how quickly? Using functions reduces the problem, but OOP does that even more.Also, OO approach on very simple systems like the one hi is building is in qustion.
That doesn't mean that procedural coding can't do the job; of course it can. But once the scope of your application begins to increase, this sort of code becomes harder to follow. I remember trying to disable user registration in Postnuke -- it took me two days to find the code related to that! (And the scope has increased here -- we started with selecting articles and we're now onto inserting, updating and deleting them.)
Besides, there are others following this thread and they might see the benefits too.
Zealotry is contingent upon 100 posts and addiction 200?
Bookmarks