PHP help and tutroials Created 19 years ago2005-07-20 14:40:41 UTC by Luke Luke

Created 19 years ago2005-07-20 14:40:41 UTC by Luke Luke

Posted 19 years ago2005-07-20 14:40:41 UTC Post #122322
Ok, so i went to W3 Schools, learned some stuff there. THat explained a lot. But i want a little bit more and to be more specific.

I googled stuff but couldnt exactly find what i was looking for.

I was wondering if someone could help me. What im trying to do is make (possibly a text based. I can use mysql, though) a news system. I also wish to make a login system with each member having their own profile.

What you could help me with is directing me to a PHP tutorial site or acctualy tell me what to do (tutorial probably is better).

This would help me greatly in a site im making for my friend. Thanks.
Luke LukeLuke
Posted 19 years ago2005-07-20 15:08:24 UTC Post #122332
I highly personally recommend this book. It would probably be a good idea to get a book on basic database concepts, too, or even an SQL-specific one (SQL being the de facto database handling language for online databases).
Seventh-Monkey Seventh-MonkeyPretty nifty
Posted 19 years ago2005-07-20 15:13:39 UTC Post #122334
Posted 19 years ago2005-07-20 15:22:25 UTC Post #122336
... isn't really very useful for a complete beginner, in my opinion. I much preferred having a book.
Seventh-Monkey Seventh-MonkeyPretty nifty
Posted 19 years ago2005-07-20 15:35:14 UTC Post #122339
With books you can clip cool looking bookmarks inside and look stylish :cool:
Habboi HabboiSticky White Love Glue
Posted 19 years ago2005-07-20 16:11:15 UTC Post #122348
I would buy the book, but i have no moneys. :

And i agree, seventh, thats only references :
Luke LukeLuke
Posted 19 years ago2005-07-20 16:33:02 UTC Post #122351
manual is good too. I learned php from it :)
Posted 19 years ago2005-07-20 16:45:19 UTC Post #122353
I wanna know where m0p learned. He looks like he has a news script on his site.
Luke LukeLuke
Posted 19 years ago2005-07-20 17:07:17 UTC Post #122354
news are easy :P
Posted 19 years ago2005-07-20 17:11:45 UTC Post #122355
What about one where you can login, go to a seperate panel, edit/add/delete news. Then have it where you can use BBcode in the news. And have it so it goes with your site.

Tell me where i can learn this.
Luke LukeLuke
Posted 19 years ago2005-07-20 17:11:59 UTC Post #122356
Get money then. News scripts are very simple, text-file or database-based (text-file more so). Here's a script which might show news text only:
<?php

$dbconnection = mysql_connect ("localhost", "username", "password");
mysql_select_db ("iemc_database", $dbconnection);

$news = mysql_query ("SELECT text FROM newstable");
$newscount = mysql_num_rows ($news);

for ($i=0; $i > $newscount; $i++) {

$newsitemtext = mysql_result ($news, 0);

print $newsitemtext;

}

print "Done!";

?>


That should work. Not checked, of course, but it's only an example.

BBCode like bold and italic, things which have exact equivalents, are very easy to do, you just, for example, replace "[bold]" with "<b>" in the news post. Voila.
Seventh-Monkey Seventh-MonkeyPretty nifty
Posted 19 years ago2005-07-20 17:14:59 UTC Post #122358
I kinda see what to do with that and what everything does.

I just need a little more instruction.
Luke LukeLuke
Posted 19 years ago2005-07-20 17:15:28 UTC Post #122359
Save up and buy that book is my advice. That's where I learnt that.
Seventh-Monkey Seventh-MonkeyPretty nifty
Posted 19 years ago2005-07-20 17:26:37 UTC Post #122360
start from easyer things like hello world stuff :) then start making news and stuff
Posted 19 years ago2005-07-20 17:27:18 UTC Post #122361
hello world stuff? wtf are you on about?
Luke LukeLuke
Posted 19 years ago2005-07-20 17:29:54 UTC Post #122362
that's the first script you learn on php :) echo "hello world"; nah i was just joking about that one but you should really start from easyer stuff.
Posted 19 years ago2005-07-20 17:35:43 UTC Post #122363
C'mon, it's a book. How can you not afford one book?
Seventh-Monkey Seventh-MonkeyPretty nifty
Posted 19 years ago2005-07-20 17:36:49 UTC Post #122364
Im lazy.

I would rather look for a tutorial on the intraweb. Or experiment.. either one.
Luke LukeLuke
Posted 19 years ago2005-07-20 18:05:18 UTC Post #122365
jaardsi had already told you where t find manual so if you don't want to buy a book RTFM :P
Posted 19 years ago2005-07-20 18:15:15 UTC Post #122367
I don't have a news script, I write it staticly in an HTML file and include it :) I am working on a CMS though, which will use MySQL. And feature news comments, etc etc. I really should do more work on it. Too lazy to even finish the tables.
m0p m0pIllogical.
Posted 19 years ago2005-07-20 18:38:22 UTC Post #122369
oh :

Thats what i currently do and its mainly why i dont update the news.

ok, i have an idea of what to do.

Now, is there a way to have something that you can make a news post and have it be sent to a .php page and be saved there in a new row in a table everytime you make a new news post?

If so, what kind of commands would i use?
Luke LukeLuke
Posted 19 years ago2005-07-21 16:49:50 UTC Post #122579
Get a book, cheap-arse :P.

m0p: that's pretty amateurish :glad:.
Seventh-Monkey Seventh-MonkeyPretty nifty
Posted 19 years ago2005-07-21 17:08:11 UTC Post #122584
NO DAMNIT~ JUST TELL ME!~!!!11
Luke LukeLuke
Posted 19 years ago2005-07-21 17:31:42 UTC Post #122591
Use forms (html) and handle them with a php script that does some mysql inserting. Search for the mysql_query function to execute queries on your selected database.
Posted 19 years ago2005-07-21 17:40:54 UTC Post #122592
Book... :glad:
Habboi HabboiSticky White Love Glue
Posted 19 years ago2005-07-22 00:58:25 UTC Post #122614
IEMC, it wouldn't help you in the slightest.

You want MYSQL_QUERY().

See?
Seventh-Monkey Seventh-MonkeyPretty nifty
Posted 19 years ago2005-07-22 02:13:09 UTC Post #122622
You guys are anoying! :x He doesn't want to buy that book so can you please tell him how!! :furious:

Seventh: If a book can teach you why can't you? :P
Posted 19 years ago2005-07-22 02:49:08 UTC Post #122623
I don't have the time, that's why. Really, do you know PHP? Are you offering to explain everything to him?
Seventh-Monkey Seventh-MonkeyPretty nifty
Posted 19 years ago2005-07-22 03:26:03 UTC Post #122626
Seconded, PHP is quite complex. A single person can't just go "oh write this and compile this and save this" unless they're willing to devote lots of time, something most members of this forum really don't have D:

If he wants the best quality reference, text book format is the way to go.
RabidMonkey RabidMonkeymapmapmapfapmap
Posted 19 years ago2005-07-22 08:49:55 UTC Post #122676
I learnt from the online manual myself, and some help from #php on freenode.
m0p m0pIllogical.
Posted 19 years ago2005-07-22 09:59:13 UTC Post #122691
ok, heres the start of the page where after youve put the news in a form, you submit it and it goes here for proccessing. Now, some of this i did myself, then some other stuff i took from you, seventh:

[quote]<?php
	$dbconnection=mysql_connect("localhost", "username", "password");
	if (!$dbconnection)
	{
	exit("MYSQL Connection Attempt Failed: " . $dbconnection);
	}
	mysql_select_db("my_database", $dbconnection); [/quote]
I realise this is just the connection to the mysql, but as of right now, im lost. I kinda have some what of an idea of what to put to take the forms and send it to the database, but i need a little help.

I was jsut wondering if someone could help me now.
Luke LukeLuke
Posted 19 years ago2005-07-22 11:00:00 UTC Post #122718
Look up form design and the $_POST superglobal variable on php.net. You will also want the mysql_query function a lot, that being, well, the function to run a query on a MySQL database.
Seventh-Monkey Seventh-MonkeyPretty nifty
Posted 19 years ago2005-07-22 11:16:31 UTC Post #122719
Ok, thanks. I found a tutorial explaining that stuff.

But does my existing code look fine? And i forgot the include the:
if($submit) {
code. :o
Luke LukeLuke
Posted 19 years ago2005-07-22 11:44:23 UTC Post #122722
Looks fine.
Seventh-Monkey Seventh-MonkeyPretty nifty
Posted 19 years ago2005-07-22 12:14:23 UTC Post #122730
You should use "or die (blah)" instead of "if (!dbconnection) {blah}".
m0p m0pIllogical.
Posted 19 years ago2005-07-22 12:16:26 UTC Post #122733
Ok, ill change that.

But how does it make it better? Is it because that code is actualy used for if it doesnt work instead of the genereal "if" code?
Luke LukeLuke
Posted 19 years ago2005-07-22 13:46:28 UTC Post #122757
It's just tidier. I'm not entire sure how PHP handles it, but if you have a line like:

do(failed_function) or (giveerror)

it tries to make one side true if it can. Not sure if you can have more ORs in case of the second function failing.

Remember, for logic, that and and or (the actual words) have lower precedence than && and ||.
Seventh-Monkey Seventh-MonkeyPretty nifty
Posted 19 years ago2005-07-22 17:20:50 UTC Post #122805
[quote]<?php
	if($submit) {
	$dbconnection=mysql_connect("localhost", "username", "password");
	or die (!$dbconnection)
	{
	exit("MYSQL Connection Attempt Failed: " . $dbconnection);
	}
	mysql_select_db("my_database",$dbconnection);

	$sql = "INSERT INTO news (news_title,news_text) VALUES ('$news_title','$news_text')";
$result = mysql_query($sql);
	echo "News Entered Succesfuly.n";
	} else{

	?>[/quote]
Hows this looks? Would this write the news_title and the news_text to the mysql?

And how would i make it so whenver i write a news article, it gets its own number. It would go in numerical order. This way i can choose which one i want to delete or edit later.
Luke LukeLuke
Posted 19 years ago2005-07-22 17:29:15 UTC Post #122806
Yeah, works. Better would be to do this though:
if(mysql_query($sql))
{
echo "News entered successfully.n";
}
else
{
echo "Query failed.";
}
This ensures that you only see the successfull text when the query has actually been executed without any trouble.
Posted 19 years ago2005-07-22 17:38:26 UTC Post #122807
ok, will do
Luke LukeLuke
Posted 19 years ago2005-07-22 17:44:33 UTC Post #122808
Read up about databasing concepts, including primary keys.
Seventh-Monkey Seventh-MonkeyPretty nifty
Posted 19 years ago2005-07-22 17:50:12 UTC Post #122809
it would be better to -> mysql_query($sql) or die(ghai)
this is gay:
if(mysql_query($sql))
{
echo "News entered successfully.n";
}
else
{
echo "Query failed.";
}
Posted 19 years ago2005-07-22 17:52:35 UTC Post #122810
which one?!!? :o
Luke LukeLuke
Posted 19 years ago2005-07-22 18:03:49 UTC Post #122812
mysql_query($sql) or die(ghai)
^^ that one
User posted image
Posted 19 years ago2005-07-22 20:23:55 UTC Post #122844
Parse error: parse error, unexpected T_LOGICAL_OR in /home/iemc/public_html/nukesilo/news_add.php on line 13
Im getting this error when i test it.
Luke LukeLuke
Posted 19 years ago2005-07-23 01:50:48 UTC Post #122877
Post a link to the actual code (don't quote it or we won't necessarily be able to see where like 13 is).

Don't point us to a .PHP file on a PHP server!
Seventh-Monkey Seventh-MonkeyPretty nifty
Posted 19 years ago2005-07-23 02:35:35 UTC Post #122885
lol

http://iemc.nukesilo.net/thingy.txt

I put it in a text file ;O
Luke LukeLuke
Posted 19 years ago2005-07-23 04:10:49 UTC Post #122893
You shouldn't have the semi-colon before the "or die", it should go at the very end, like so:

$dbconnection=mysql_connect("localhost", "username", "password") or die (!$dbconnection);

By the way, I hugely recommend using Notepad++ (freeware, of course) to write your scripts. It offers things like colour coding, highlighting of related brackets, etc. Very useful.
Seventh-Monkey Seventh-MonkeyPretty nifty
Posted 19 years ago2005-07-23 10:38:59 UTC Post #122935
Good program indeed. Supports syntax highlighting for a variety of languages, including html, php, C++ and such. And it has a tab system similar to FireFox. Me likes tabs. :)
Posted 19 years ago2005-07-23 11:49:47 UTC Post #122958
It'll highlight the HTML and PHP too, both in their respective colours and formats, in the same document, so you can see where you've closed PHP tags and opened 'em again, etc.
Seventh-Monkey Seventh-MonkeyPretty nifty
You must be logged in to post a response.