i am learning but i need your help
08-17-2007, 07:08 AM
|
i am learning but i need your help
|
Posts: 77
Name: adam
Location: UK
|
hello i new to this website and i am currently learning how to use php. i decided to take a CMS apart and see what each function does. but i strumbled across these bits of code.
Code:
*/
$sql = "CREATE TABLE ".$db_prefix."news (
id int(3) NOT NULL auto_increment,
dates varchar(50) NOT NULL default '',
nickname varchar(255) NOT NULL default '',
topic varchar(50) NOT NULL default '',
newspost text NOT NULL,
newstype varchar(15) NOT NULL default '',
news_cat int(4) NOT NULL default '0',
PRIMARY KEY (id)
);";
Code:
$sql = "CREATE TABLE ".$db_prefix."news_cat (
news_cat int(3) NOT NULL auto_increment,
news_type varchar(255) NOT NULL default '',
PRIMARY KEY (news_cat)
);";
my first question is what does that id int(3) do on the section of code and also on the first section of code it has news_cat int(4) NOT NULL default '0',
which is also the name of the second peice of code but on the second peice of code it has news_cat int(3), and lastly how would i store data to the tables though a form.
sorry if i am not clear on what i am trying to ask. thanks in advance
|
|
|
|
08-17-2007, 07:52 AM
|
Re: i am learning but i need your help
|
Posts: 25
|
Quote:
Originally Posted by mintuz
hello i new to this website and i am currently learning how to use php. i decided to take a CMS apart and see what each function does. but i strumbled across these bits of code.
Code:
*/
$sql = "CREATE TABLE ".$db_prefix."news (
id int(3) NOT NULL auto_increment,
dates varchar(50) NOT NULL default '',
nickname varchar(255) NOT NULL default '',
topic varchar(50) NOT NULL default '',
newspost text NOT NULL,
newstype varchar(15) NOT NULL default '',
news_cat int(4) NOT NULL default '0',
PRIMARY KEY (id)
);";
Code:
$sql = "CREATE TABLE ".$db_prefix."news_cat (
news_cat int(3) NOT NULL auto_increment,
news_type varchar(255) NOT NULL default '',
PRIMARY KEY (news_cat)
);";
my first question is what does that id int(3) do on the section of code and also on the first section of code it has news_cat int(4) NOT NULL default '0',
which is also the name of the second peice of code but on the second peice of code it has news_cat int(3), and lastly how would i store data to the tables though a form.
sorry if i am not clear on what i am trying to ask. thanks in advance
|
Not 100% sure what you mean but anyway. I think id int(3) is like this: id is the name of the field, it is a integer (number) and it can have a value up to 3 figures- 999 being the max. news_cat is the same thing really.
That is SQL, so when that code it run it will make a table. Careful not to run that code more than once, you should just copy and paste it into PHPmyadmin to the part were you can input raw SQL and run it.
Storing data into the tables is PHP and is quite basic. I could give you some help with it if you'd like?
|
|
|
|
08-17-2007, 08:01 AM
|
Re: i am learning but i need your help
|
Posts: 77
Name: adam
Location: UK
|
but in the news table it has a news_cat field with a int of 4 but the news_cat table has a int of 3. i dont understand how they r linked together.
|
|
|
|
08-17-2007, 10:06 AM
|
Re: i am learning but i need your help
|
Posts: 25
|
mmm.... i'm not sure. It can be difficult to understand some PHP scripts when you aren't the author. Everyone has their own style of coding, and that CMS seems a little more complex than something that'd be good to learn from.
How much PHP do you know?
A CMS is simple, try making your own simple CMS like this:
1. Create a table in PHPmyadmin with a few fields (like ID, title, description.)
2. Make a form in which you will input the data that'll be placed in this table.
3. Make a script to $_POST the data from the form and insert it into the table.
Thats the main bit. Then you can create a script that will select the data from the table and display it, and thats your first CMS done
From that you can add new features and whatever, but aslong as you get those basics covered you're on fire 
|
|
|
|
08-17-2007, 11:21 AM
|
Re: i am learning but i need your help
|
Posts: 77
Name: adam
Location: UK
|
could u give me a quick example of the $_POST function. so when i type data into a form it will go into my database. and how would the script look for selecting the data from the database would it be something like
mysql_query(SELECT * from NEWS);
or something along those lines.
Last edited by mintuz; 08-17-2007 at 11:30 AM..
|
|
|
|
08-17-2007, 12:42 PM
|
Re: i am learning but i need your help
|
Posts: 182
|
The int(3) / int(4) issue is probably just a mistake. extra.account was right about what those meant.
I agree, reverse engineering a cms is not the best way to learn. I would recommend following a beginner php tutorial or something. Here are some links I usually recommend:
http://webmonkey.com/webmonkey/programming/php/ - a bunch of very simple tutorials.
http://www.phpfreaks.com/tutorial_cat/2/PHP.php - a list of different tutorials that are easy to follow along with.
I would start with something from webmonkey then move to phpfreaks. If you have any questions about the tutorials, we will gladly help you here....
|
|
|
|
08-17-2007, 01:03 PM
|
Re: i am learning but i need your help
|
Posts: 77
Name: adam
Location: UK
|
cheers guys.
|
|
|
|
08-17-2007, 01:19 PM
|
Re: i am learning but i need your help
|
Posts: 25
|
As for the $_POST code you wanted, this might help you. Say we made a form with only 1 input field and called that field "name" the code would be like this:
PHP Code:
$name = $_POST['name'];
// Connect to the DB (I wont write the code here) //Insert into DB
$query = "INSERT INTO table (name) VALUES ('$name')"; $execute = mysql_query($query);
That was rushed so sorry if i made an error (i dont think i did though). Follow bhgchris's advice and check some tutorials.
Dont do what I did and try to learn so many functions at once. Learn them when you need them. Its better to learn on a project than just by reading.
Check this video, its good for beginners http://video.google.co.uk/videoplay?...16151695694058 and try to replicate / copy it.
|
|
|
|
08-17-2007, 02:04 PM
|
Re: i am learning but i need your help
|
Posts: 77
Name: adam
Location: UK
|
woow that really helped thanks
|
|
|
|
08-17-2007, 04:54 PM
|
Re: i am learning but i need your help
|
Posts: 25
|
Sure, anything else you need a hand with dont hesitate to ask
|
|
|
|
08-18-2007, 05:03 AM
|
Re: i am learning but i need your help
|
Posts: 77
Name: adam
Location: UK
|
after i submit something in a form and my php page processes it. it stays on the same file but also becomes a white screen. what should i do to redirect the person back to the previous page.
PHP Code:
<?php //connects you to your database. include('../_dbconnect.php'); //Only allows data to be added to the database, if the submit button has been been pressed. if($_POST['submit']) { //Varibles. Do Not Edit $title=$_POST['title']; $author=$_POST['author']; $date=$_POST['date_added']; $content=$_POST['content']; //Insert information into database $query = "INSERT INTO table about_me ('title', 'author', 'date_added', 'content') VALUES ('$title', '$author', '$date', '$content')"; } ?>
Last edited by mintuz; 08-18-2007 at 05:48 AM..
|
|
|
|
08-18-2007, 07:26 AM
|
Re: i am learning but i need your help
|
Posts: 25
|
At the end of the script use this code:
PHP Code:
header ("Location: page.php");
That usually does it, if you get an error about headers already being sent then just google HTML refresh code and you can do it with HTML.
|
|
|
|
08-18-2007, 08:17 AM
|
Re: i am learning but i need your help
|
Posts: 77
Name: adam
Location: UK
|
ok i have a new problem now. i have designed my mysql tables etc etc but i want the data to show up on a page but it wont.. it says this error
Quote:
|
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in C:\wamp\www\MintuzProductions\aboutme.php on line 38
|
this is the code i have for that page.
PHP Code:
<?php include("_dbconnect.php"); ?> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <title>Mintuz Portfolio</title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> <link href="_style.css" rel="stylesheet" type="text/css"> </head> <body> <table width="100%" border="0" cellspacing="0" cellpadding="0"> <tr> <td height="102" align="left" valign="top" background="images/extra_banner.jpg"><table width="100%" border="0" cellspacing="0" cellpadding="0"> <tr> <td width="52%" height="97"><img src="images/index_r2_c1.jpg" width="405" height="102"></td> <td width="48%"><div align="center"><img src="images/index_r3_c6.jpg" width="233" height="53"></div></td> </tr> </table></td> </tr> <tr> <td height="30" background="images/extra_nav.jpg"><div align="center"><a href="index.php"><img src="images/index_r5_c1.jpg" width="152" height="30" border="0"></a><a href="aboutme.php"><img src="images/index_r5_c3.jpg" width="103" height="30" border="0"></a><a href="webdesign.php"><img src="images/index_r5_c4.jpg" width="118" height="30" border="0"></a><a href="scripts.php"><img src="images/index_r5_c5.jpg" width="75" height="30" border="0"></a><img src="images/index_r5_c7.jpg" width="84" height="30"><a href="contactme.php"><img src="images/index_r5_c8.jpg" width="126" height="30" border="0"></a></div></td> </tr> <tr> <td height="257" align="left" valign="top" background="images/extra_content.jpg"><table width="100%" border="0" cellspacing="0" cellpadding="0"> <tr> <td width="33" height="33"><img src="images/index_r6_c1.jpg" width="33" height="33"></td> <td background="images/index_r6_c2.jpg"> </td> <td width="33" height="33"><img src="images/index_r6_c9.jpg" width="33" height="33"></td> </tr> <tr> <td background="images/index_r7_c1.jpg"> </td> <td><table width="100%" border="0" cellspacing="0" cellpadding="2"> <tr> <td height="297" align="left" valign="top"><?php $result=mysql_query("SELECT * FROM news WHERE id = '".intval($_GET['id'])."' LIMIT 1"); while($read=mysql_fetch_array($result)) { $id =$read["id"]; $title =$read["title"]; $author =$read["author"]; $date =$read["date"]; $content =$read["content"]; $uid = $id; global $id, $uid; } ?> <table width="100%" border="0" cellspacing="0" cellpadding="2"> <tr> <td><?=$title?> </td> <td><?=$author?> </td> <td><?=$date?> </td> </tr> <tr> <td colspan="3"><?=$content?> </td> </tr> </table></td> </tr> </table></td> <td background="images/index_r7_c9.jpg"> </td> </tr> <tr> <td width="33" height="33"><img src="images/index_r8_c1.jpg" width="33" height="33"></td> <td align="left" valign="top" background="images/index_r8_c2.jpg"><div align="center" class="style1">Copyright 2007-2008 © All Rights Reserved</div></td> <td width="33" height="33"><img src="images/index_r8_c9.jpg" width="33" height="33"></td> </tr> </table> </td> </tr> </table> </body> </html>
and lastly once ive posted the information though the form and i get redirected back to the previous page, my information is not in the forms.. is this normal its just on some CMS they keep the data in the forms which is something i want mine to be able to do
|
|
|
|
08-18-2007, 08:26 AM
|
Re: i am learning but i need your help
|
Posts: 6,521
Name: Dan
Location: Swindon
|
The "html" version is meta refresh
Code:
<meta http-equiv="refresh" content="0; page.php" />
i did the snippet of memory, so might be a bit wrong, but its soemthing vERY similar to that
Dan
Talkupation apprieciated 
__________________
Discounted Web Hosting With XDnet! >> Get 25% of hosting~ Promo: Webmaster-talk <<
|
|
|
|
08-18-2007, 08:35 AM
|
Re: i am learning but i need your help
|
Posts: 6,521
Name: Dan
Location: Swindon
|
Ok, firstly whats with all Webmaster-talk images? i sense nicked code.
Alot of the html is now, out dated.
if you want the info to show in the form you set the value=""
soemthing like this
PHP Code:
<?php $table_query = mysql_query("SELECT * FROM table WHERE soemthing='somin'") or die("error getting info". mysql_error()); $row=mysql_fetch_array($table_query); echo ' <form name="some form" blah blah > <input type="text" value="'.$row['info1'].'" name="info1" /> </form>
that get sthe info and shows in the fields.
__________________
Discounted Web Hosting With XDnet! >> Get 25% of hosting~ Promo: Webmaster-talk <<
|
|
|
|
08-18-2007, 08:53 AM
|
Re: i am learning but i need your help
|
Posts: 77
Name: adam
Location: UK
|
what do you mean webmaster-talk images. i completely did them myself in fireworks mx.... :S
|
|
|
|
08-18-2007, 09:44 AM
|
Re: i am learning but i need your help
|
Posts: 6,521
Name: Dan
Location: Swindon
|
strange how they all had urls of http://webmaster-talk/images/index....
and now they dont...
__________________
Discounted Web Hosting With XDnet! >> Get 25% of hosting~ Promo: Webmaster-talk <<
|
|
|
|
08-18-2007, 10:01 AM
|
Re: i am learning but i need your help
|
Posts: 77
Name: adam
Location: UK
|
it must of been a bug because honestly all i did was copy my source from my web editor into the site browser.
|
|
|
|
08-18-2007, 10:18 AM
|
Re: i am learning but i need your help
|
Posts: 6,521
Name: Dan
Location: Swindon
|
Ok, sorry for the acusation.
__________________
Discounted Web Hosting With XDnet! >> Get 25% of hosting~ Promo: Webmaster-talk <<
|
|
|
|
08-20-2007, 01:23 AM
|
Re: i am learning but i need your help
|
Posts: 730
Name: John
Location: United States of America, California
|
That is SQL code and it is using php to add it to SQL
|
|
|
|
|
« Reply to i am learning but i need your help
|
|
|
| Thread Tools |
Search this Thread |
|
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|