Jump to content

Advice Me Please


Net123

Recommended Posts

how are you managing your files? in filesystem or in database?

Link to comment
Share on other sites

i am managing my files through an filesystemi wanna admin panel for adding link and text and i have not managing my entire site in one databasei wanna make that manually

Link to comment
Share on other sites

you may store the file links,name,timestamp in a table. and you can query your database for last some number of data depending on your timestampif you are using any custom uploading scirpt to upload in your file system then you can insert that above info in your db simultanously at the time of uploading. but if you are using FTP uploading (eg ftp software) i think you need to put it manually later.

Link to comment
Share on other sites

Creating a news portal based on PHP / MySQL 1. º Step - Creating and preparing the database (MySQL) Start by creating a database dedicated to this tutorial. For example, named news if you are already in the MySQL client, type the following: create database news; Therefore, open the database created: use news; Now is to create a table to record their stories. You can follow the example below, superprático: CREATE TABLE news ( id int (5) NOT NULL auto_increment, name char (30) NOT NULL, surname char (30) NOT NULL, city char (50) NOT NULL, state char (2) NOT NULL, email char (80), date date NOT NULL, hour time NOT NULL, title char (100) NOT NULL, subtitle char (200), text text NOT NULL, see char (3) DEFAULT 'off', PRIMARY KEY (id); UNIQUE id (id) ); If you already have a basic knowledge in SQL, you know what each line up to perform. I will specify what you will register in each field: • id = Field identification of news (is not necessary to register any data, because it is already enabled with the auto_increment function that automatically will insert new values) • name = First name of author news • Author last name = news • City = City of author • state = City State (specified with only 2 characters) • email author = Email for contacts • data = Data used to know when the registration was done (no need any registration, because we do this in php automatically inserting the current date) • Time = Time used in the registration of news (is not necessary to register because it will be done automatically with PHP) • title = Story Title (maximum 100 characters) • caption = Small summary of your story (maximum 200 characters) • text = yes Now, the text of the news with unlimited characters • view = This field is curious. It will be used to power the webmaster to allow each news because if it had not a field like this, all news would registered for the site. It's like a control of news. The pattern here is off, so any news will be passed first to the webmaster, then to be validated. * Are required fields in the record now with the database ready, it's time to create the registration system news on your site. This will be the second. First step! Step 2 - Creating the system of registration of notíciasEste is an important step, where a script created in PHP to insert data into MySQL database Here we will use past knowledge in the previous tutorial on basic questions of PHP / MySQL. Firstly the file will be created in HTML (form) for the registration of news. Here we go: ARCHIVE cadastra.php Php $ Date = date ("Y-m-d"); $ Hour = date ("H: i: s"); $ Novadata = substr ($ date, 8,2). "/." Substr ($ date, 5,2). "/". substr ($ date, 0,4); $ Novahora = substr ($ hour, 0.2). "H." Substr ($ time, 3,2). "Min"; echo "<h1> Registration System News </ h1>"; echo "<hr> <br>"; echo "<form action='inserir.php' method='post'>"; echo "Name: <input name='nome' type='text' size=30> <br> *"; echo "Surname: <input name='sobrenome' type='text' size=30> <br> *"; echo "City: <input name='cidade' type='text' size=30> <br> *"; echo "Status: <i> (Example: SP, SR, BA) </ i> <input name='estado' type='text' size=5> <br> *"; echo "Email: <i> (Example: feitosac@yahoo.com) </ i> <input name='email' type='text' size=30> <br>"; echo "Title Text: <input name='titulo' type='text' size=30> <br> *"; echo "Caption Text: <textarea name='subtitulo' rows=5 cols=30> </ textarea> <br>"; echo "Text: <textarea name='texto' rows=10 cols=30> </ textarea> * <br>"; echo "<input name = 'date' type = 'hidden' value = '$ date' <> input name = 'time' type = 'hidden' value = '$ hours'>"; echo "<input type='submit' value='Cadastrar'>"; echo "</ form>"; echo "<hr>"; echo "<i> Fields marked with * <b> </ b> are required to register. <br>"; echo "<b> Note </ b>: will be inserted in your registration today's date and the current time of registration <br>"; echo "Date: $ Novadata - Time: $ novahora <br>"; ?> END OF FILE cadastra.php • Let's do a little analysis on this file. Note that the form data is sent to the script "inserir.php", this, therefore, will be responsible for adding this news in MySQL Another point is that there are no fields id, do they, as I explained, automatically inserted by MySQL, and the fields date, time, will be inserted by PHP. • Now is time to create the PHP script responsible for it all. Let's go: ARCHIVE inserir.php Php / / Let's define the variables date and time / / For inclusion in database / / Now with the variables date and time created / / Let's create a special variable for the SQL queries $ Sql = "INSERT INTO news (name, surname, city, state, email, date, time, title, subtitle, text) VALUES ('$ name', '$ surname', '$ city', '$ state', '$ Email', '$ date', '$ hours', '$ title', '$ caption', '$ text') "; / / Now it's time to contact mysql $ Db = mysql_connect ("localhost", "root", "root") or die ("Database Configuration Wrong!") / / Replace the values above if you do not agree with your machine / / Selecting the database ... $ Db = mysql_select_db ("news") or die ("Database None"); / / Inserting data $ Sql = mysql_query ($ sql) or die ("There was an error in recording data, please click back and check the required fields!") echo "successfully effected <h1> Register </ h1>"; ?> END OF FILE inserir.php • You can improve a lot more script. For example, customize the error message and successfully insert a link to register again, etc.. • Now on to the next and final step, "Recovering the data registered." 3 rd Step - Recovering data cadastradosIrei show how to select, for example, the latest 15 stories included in MySQL, that is very useful for sites that have sections like "Latest News". This is done with PHP again, do as the example below, and save as a file in PHP. ARCHIVE noticias.php Php / / We need to tell MySQL again $ Db = mysql_connect ("localhost", "root", "root"); $ Db = mysql_select_db ("news"); / / Now you do the search queries in the database $ Sql = "SELECT * FROM news WHERE ver = 'on' ORDER BY id DESC LIMIT 15"; / / Will select the latest news in 15 / / The interesting thing here is that he will only select the fields where / / = On is to see, behind this was discussed as a / / Control of news by webmaster / / By default, MySQL laid off, but the webmaster will have to / / Review the news and change the field to see who want to validate. $ Result = mysql_query ($ sql) or die ("Could not perform the query to the database"); / / Now we will "catch" each field news / / HTML and organize while ($ row = mysql_fetch_array ($ result)) { $ Id = $ row ["id"]; $ Name = $ row ['name']; $ Last = $ row ["surname"]; $ City = $ row ["city"]; $ Status = $ row ["state"]; $ Email = $ row ['email']; $ Data = $ row ['date']; $ Hour = $ row ["hours"]; $ Title = $ row ["title"]; $ Caption = $ row ['caption']; $ Text = $ row ['text']; $ Ver = $ row ['view']; $ Novadata = substr ($ date, 8,2). "/." Substr ($ date, 5,2). "/". substr ($ date, 0,4); $ Novahora = substr ($ hour, 0.2). "H." Substr ($ time, 3,2). "Min"; echo "Code <b> NEWS </ b>: $ id"; echo ""; echo "Author: $ name $ surname - ($ email)"; echo ""; echo "City: $ city - Status: $ status"; echo ""; echo "Date: $ Novadata - Hours: $ novahora"; echo ""; echo "News Title: $ title"; echo ""; echo "Subtitle NEWS: <i> $ caption </ i>"; echo ""; echo "News: $ text"; echo ""; echo "Validated by webmaster:"; if ($ ver = on) {echo "Yes"} else {echo "No";} echo "<hr>"; } ?> END OF FILE noticias.php • See how simple it is super? In this script we create a variable for each field of the table, so it's easier to handle data in any way. In variávels Novadata, novahora, create a function to display variables in a better way. (Thanks to REINDEER - Big Man!) • You can even customize these reports, leaving the layout of your way! • NOTE: To display all the news instead of just the last 15, just create a new variable $ sql like this below: $ Sql = "SELECT * FROM news WHERE ver = 'on' ORDER BY id DESC"; • Ready! It was just pull "LIMIT 15". :) 4. º Step - Check the News WebmasterNeste step will explain how to show all the table data so we can modify them, delete them, etc.. First we create a PHP file to display all data on the screen, and then we can handle them. Do as the example below: ARCHIVE controle.php Php $ Db = mysql_connect ("localhost", "root", "root"); $ Db = mysql_select_db ("news"); $ Sql = "SELECT * FROM news ORDER BY id DESC"; $ Result = mysql_query ($ sql) or die ("Could not perform the query to the database"); echo "<table width=740 border=1 cellpadding=1 cellspacing=1>"; echo "<tr>"; echo "<th width=15> ID: </ th>"; echo "<th width=100> Name: </ th>"; echo "<th width=100> Last Name: </ th>"; echo "<th width=100> City: </ th>"; echo "<th width=15> UF: </ th>"; echo "<th width=100> Email: </ th>"; echo "<th width=30> Date: </ th>"; echo "<th width=30> Time: </ th>"; echo "<th width=100> Title: </ th>"; echo "<th width=50> Available </ th>"; echo "<th width=50> Change </ th>"; echo "<th width=50> Delete </ th>"; echo "</ tr>"; while ($ row = mysql_fetch_array ($ result)) { $ Id = $ row ["id"]; $ Name = $ row ['name']; $ Last = $ row ["surname"]; $ City = $ row ["city"]; $ Status = $ row ["state"]; $ Email = $ row ['email']; $ Data = $ row ['date']; $ Hour = $ row ["hours"]; $ Title = $ row ["title"]; $ Ver = $ row ['view']; $ Novadata = substr ($ date, 8,2). "/." Substr ($ date, 5,2). "/". substr ($ date, 0,4); $ Novahora = substr ($ hour, 0.2). "H." Substr ($ time, 3,2). "Min"; echo "<tr>"; echo "$ id <br> <th width=15> </ th>"; echo "$ name <br> <th width=100> </ th>"; echo "$ last <br> <th width=100> </ th>"; echo "$ city <br> <th width=100> </ th>"; echo "$ state <br> <th width=15> </ th>"; echo "$ email <br> <th width=100> </ th>"; echo "$ <th width=30> Novadata <br> </ th>"; echo "$ <th width=30> novahora <br> </ th>"; echo "$ title <br> <th width=100> </ th>"; echo "$ <th width=50> see <br> </ th>"; echo "<a <th width=50> href='alterar.php?id=$id'> Change </ a> <br> </ th>"; echo "<a <th width=50> href='excluir.php?id=$id'> Delete </ a> <br> </ th>"; echo "</ tr>"; echo ""; } echo "</ table>"; ?> END OF FILE controle.php The next step is to create the files and alterar.php excluir.php responsible for the alteration and deletion of data. It's very simple code, like this: ARCHIVE excluir.php Php $ Db = mysql_connect ("localhost", "root", "root"); $ Db = mysql_select_db ("news"); $ Sql = "DELETE FROM news WHERE id = '$ id'"; $ Result = mysql_query ($ sql) or die ("Unable to perform the deletion of data.") echo "<h1> The news was deleted successfully </ h1>"; ?> END OF FILE excluir.php ARCHIVE alterar.php Php $ Db = mysql_connect ("localhost", "root", "root"); $ Db = mysql_select_db ("news"); $ Sql = "SELECT * FROM news WHERE id = '$ id'"; $ Result = mysql_query ($ sql) or die ("Could not perform the query to the database"); while ($ row = mysql_fetch_array ($ result)) { $ Id = $ row ["id"]; $ Name = $ row ['name']; $ Last = $ row ["surname"]; $ City = $ row ["city"]; $ Status = $ row ["state"]; $ Email = $ row ['email']; $ Data = $ row ['date']; $ Hour = $ row ["hours"]; $ Title = $ row ["title"]; $ Caption = $ row ['caption']; $ Text = $ row ['text']; $ Ver = $ row ['view']; $ Novadata = substr ($ date, 8,2). "/." Substr ($ date, 5,2). "/". substr ($ date, 0,4); $ Novahora = substr ($ hour, 0.2). "H." Substr ($ time, 3,2). "Min"; echo "Change Registration <h1> ...</ h1>"; echo "<hr> <br>"; echo "<form action='alterar_db.php?id=$id' method='post'>"; echo "Code News: <input name='id_novo' type='text' value='$id' size=20> <br>"; echo "Date: $ Novadata <br>"; echo "Time: $ novahora <br>"; echo "Name: <input name='nome_novo' type='text' value='$nome' size=30> <br> *"; echo "Surname: <input name='sobrenome_novo' type='text' value='$sobrenome' size=30> <br> *"; echo "City: <input name='cidade_novo' type='text' value='$cidade' size=30> <br> *"; echo "Status: <i> (Example: SP, SR, BA) </ i> <input name = 'estado_novo' type = 'text' value = '$ state' size = 5> * <br> "; echo "Email: <i> (Example: feitosac@yahoo.com) </ i> <input name = 'email_novo' type = 'text' value = '$ email' size = 30> <br> "; echo "Title Text: <input name='titulo_novo' type='text' value='$titulo' size=30> <br> *"; echo "Caption Text: <textarea name='subtitulo_novo' rows=5 cols=30> $ caption </ textarea> <br>"; echo "Text: <textarea name='texto_novo' rows=10 cols=30> $ text </ textarea> * <br>"; echo "make available" (on or off): <input name='ver_novo' type='text' value='$ver' size=5> <br> "; echo "<input type='submit' value='Alterar'>"; echo "</ form>"; echo "<hr>"; } ?> END OF FILE alterar.php Now just create the file alterar_db.php that will receive the data from this file (alterar.php) and amend their data in MySQL is very simple: ARCHIVE alterar_db.php Php $ Db = mysql_connect ("localhost", "root", "root"); $ Db = mysql_select_db ("news"); $ Sql = "UPDATE news SET id = '$ id_novo' name = '$ nome_novo' , Last = '$ sobrenome_novo', city = '$ cidade_novo', status = '$ estado_novo' , Email = '$ email_novo' title = '$ titulo_novo' caption = '$ subtitulo_novo' , Text = '$ texto_novo' ver = '$ ver_novo' WHERE id = '$ id' "; $ Result = mysql_query ($ sql) or die ("Could not perform the query to the database"); echo "<h1> News successfully changed </ h1>"; ?> END OF FILE alterar_db.php

Link to comment
Share on other sites

i can't create this table in my server i am getting an server "#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 14 "How can i fix this ??CREATE TABLE news (id int (5) NOT NULL auto_increment,name char (30) NOT NULL,surname char (30) NOT NULL,city char (50) NOT NULL,state char (2) NOT NULL,email char (80),date date NOT NULL,hour time NOT NULL,title char (100) NOT NULL,subtitle char (200),text text NOT NULL,see char (3) DEFAULT 'off',PRIMARY KEY (id);UNIQUE id (id));

Link to comment
Share on other sites

see char (3) DEFAULT 'off',PRIMARY KEY (id);UNIQUE id (id)

should instead be

see char (3) DEFAULT 'off',PRIMARY KEY (id)

because the primary key is unique by definition, and furthermore, you use "," to separate definition statements, not ";".

Link to comment
Share on other sites

can try writing one on your own? The tutorials have examples of creating forms using PHP and also include content related to using PHP to execute SQL. Everything you want to display should be a field in the table. Make sure you have a specific field to maintain a unique ID for each record, making it the primary key and auto incrementing.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...