Go Back   vb.org Archive > vBulletin Article Depository > Read An Article > Programming Articles
FAQ Community Calendar Today's Posts Search

Reply
 
Thread Tools
INSERT INTO database
flup's Avatar
flup
Join Date: Jan 2002
Posts: 872

 

Maastricht, NL
Show Printable Version Email this Page Subscription
flup flup is offline 05-01-2003, 10:00 PM

In this tuturial a lot of mySQL and PHP will become clear to you.
This tutorial was posted on www.webmeesteres.nl and is very good for the novice (like me, i started yesterday with it, and im now getting the clue of mySQL and PHP together)

__________________________________________________ _

Start:
In this articel, i'll explain how to add text into a database.
The articel is wroten for newbies, and I think you know how to create a table in a database, though, i'm still explaining that part a bit.

The Tutorial:
To put text in a database, first of al you need a database and a tabel, we assume you already have a database, so you have to create your tabel

[sql]CREATE TABLE table (
naam VARCHAR(35) NOT NULL,
email VARCHAR(50) NOT NULL,
titel VARCHAR(30) NOT NULL,
info TEXT NOT NULL
);[/sql]

This table is called: table (woow, how did i get this ;P)
And the fields are called: naam, email, title, info (dutch)

Naam is a regular field to enter your name and may contain various characters (varchar) with 35 chars (35)
For email and titel is the same, but with info, it could be anything, this has been marked with TEXT, text hasn't got any preset length.
This code is easy to add in a database, just copy and paste the code in PHPmyAdmin

ok, second, we are going to make a form wich is called insertcode.php but that could be anything.

PHP Code:
<?php
Add text
<br>
<
form action="addcode.php" method="post">
Naam:<br><input type="text" name="naam" size="20" maxlength="20"><br>
E-mail:<br><input type="text" name="email" size="30"><br>
Titel:
<
input type="text" name="titel" size="30"><br>
Info:<br><textarea rows="7" name="info" cols="39">
</
textarea><br>
<
input type="submit" name="submit" value="Add"></form>
Ok, now you've got your table we are heading to the next part of this tutorial, because, with only a form you cant add anything.
PHP Code:
<?php

if($submit) {

mysql_connect("localhost","user","paswoord");
mysql_select_db("databasenaam");

$insert "INSERT INTO tabel (naam,email,titel,info) 
VALUES ('','
$naam','$email','$titel','$info')";
$query mysql_query($insert)or die(mysql_error());

?>
To explain this part, we've to talk a bit weird, but that explains best:

If: Add
Do: Connect Database, Add content of form to database


Just a notice:

Naam:
Code:
<input type="text" name="naam" size="20" maxlength="20">
In this piece of code, it says the name of naam is naam. The content of naam will be put in the table naam.
Is doesn't mather how your form is called, only that everything is put in the right table.
PHP Code:
$query mysql_query($insert)or die(mysql_error());

In this code, it makes a mysql_query, called $insert, if it can't doe this query it will report an error.

I hope you know now a bit of the working of mySQL
Good Luck
Reply With Quote
  #2  
Old 05-02-2003, 09:02 AM
flup's Avatar
flup flup is offline
 
Join Date: Jan 2002
Location: Maastricht, NL
Posts: 872
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

<a href="https://vborg.vbsupport.ru/showthread.php?s=&postid=390345#post390345" target="_blank">Click here for SELECT FROM database tutorial</a>
Reply With Quote
  #3  
Old 06-04-2006, 07:40 AM
vietkieu_cz vietkieu_cz is offline
 
Join Date: Dec 2005
Posts: 120
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Could you write a tutorial about "How to Update Database" ?
Reply With Quote
  #4  
Old 06-13-2006, 12:16 AM
Bubble #5 Bubble #5 is offline
 
Join Date: Apr 2005
Posts: 984
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Joshua good stuff

Is there anyway to display the new table data that you've made in a post on the forum? For example; someone sends the data to the table and the forum then creates a new post and displays it. Each time someone sends this data to the table the forum posts a new post. How hard would it be to do this?
Reply With Quote
  #5  
Old 08-12-2009, 12:39 PM
Come2Daddy Come2Daddy is offline
 
Join Date: May 2008
Posts: 128
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Do we have to use the user and password to connect to the database
this is not vbulletin style of connecting to database
I've seen lots of hacks don't use the user and password

otherwise how could they publish it to share it with others boards
Reply With Quote
  #6  
Old 08-12-2009, 01:56 PM
Lynne's Avatar
Lynne Lynne is offline
 
Join Date: Sep 2004
Location: California/Idaho
Posts: 41,180
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by Come2Daddy View Post
Do we have to use the user and password to connect to the database
this is not vbulletin style of connecting to database
I've seen lots of hacks don't use the user and password

otherwise how could they publish it to share it with others boards
This article if from 2003.

No, you don't need to use a user/password to connect to the database.
Reply With Quote
  #7  
Old 08-13-2009, 07:49 AM
ragtek ragtek is offline
 
Join Date: Mar 2006
Location: austria, croatia
Posts: 1,630
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Also this article shouldn't be in the vb section because it isn't using vb methods
Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 06:31 PM.


Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2025, vBulletin Solutions Inc.
X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.03984 seconds
  • Memory Usage 2,266KB
  • Queries Executed 20 (?)
More Information
Template Usage:
  • (1)SHOWTHREAD
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (1)ad_showthread_beforeqr
  • (1)bbcode_code
  • (3)bbcode_php
  • (1)bbcode_quote
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)modsystem_article
  • (1)navbar
  • (4)navbar_link
  • (120)option
  • (7)post_thanks_box
  • (7)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (7)post_thanks_postbit_info
  • (6)postbit
  • (7)postbit_onlinestatus
  • (7)postbit_wrapper
  • (1)spacer_close
  • (1)spacer_open
  • (1)tagbit_wrapper 

Phrase Groups Available:
  • global
  • inlinemod
  • postbit
  • posting
  • reputationlevel
  • showthread
Included Files:
  • ./showthread.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/functions_bigthree.php
  • ./includes/class_postbit.php
  • ./includes/class_bbcode.php
  • ./includes/functions_reputation.php
  • ./includes/functions_post_thanks.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • showthread_start
  • showthread_getinfo
  • forumjump
  • showthread_post_start
  • showthread_query_postids
  • showthread_query
  • bbcode_fetch_tags
  • bbcode_create
  • showthread_postbit_create
  • postbit_factory
  • postbit_display_start
  • post_thanks_function_post_thanks_off_start
  • post_thanks_function_post_thanks_off_end
  • post_thanks_function_fetch_thanks_start
  • post_thanks_function_fetch_thanks_end
  • post_thanks_function_thanked_already_start
  • post_thanks_function_thanked_already_end
  • fetch_musername
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • post_thanks_function_can_thank_this_post_start
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete