Go Back   vb.org Archive > vBulletin 3 Discussion > vB3 Programming Discussions
  #1  
Old 07-31-2002, 04:53 PM
globalwin's Avatar
globalwin globalwin is offline
 
Join Date: Jun 2002
Posts: 85
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default MySQL Connection

Hi people, can anyone tell me how I would connect to my DB, to a table called domains, and add data to it, then disconnect, the database is also called domains, and the user is root.
Reply With Quote
  #2  
Old 07-31-2002, 05:23 PM
Admin's Avatar
Admin Admin is offline
Coder
 
Join Date: Oct 2023
Location: Server
Posts: 1
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Roughly:
PHP Code:
<?php

$cid 
mysql_connect('localhost''root''PASSWORD');
mysql_select_db('domains'$cid);

mysql_query('
    INSERT INTO domains
    SET field1 = "somestring", field2 = 14, field3 = "someotherstring
'
);

mysql_close($cid);

?>
Reply With Quote
  #3  
Old 07-31-2002, 05:24 PM
globalwin's Avatar
globalwin globalwin is offline
 
Join Date: Jun 2002
Posts: 85
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

cheers,
Reply With Quote
  #4  
Old 07-31-2002, 05:43 PM
globalwin's Avatar
globalwin globalwin is offline
 
Join Date: Jun 2002
Posts: 85
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

come to try it, but i failed , here is my code:

PHP Code:
<?php 

$cid 
mysql_connect('localhost''root'''); 
mysql_select_db('domains'$cid); 

mysql_query(
INSERT INTO domains 
SET field1 = "fname", field2 = "lname", field3 = "email", field4 = "domain", field5 = "length", field6 = "address"
'
); 

mysql_close($cid); 

?>
and my form:

Code:
  <form action="db.php" method="post" enctype="multipart/form-data" name="domains" target="_self" class="bodytext" id="domains">
  <table width="525" border="0">
    <tr>
        <td>First Name:</td>
      <td><input type="text" name="fname" /></td>
    </tr>
    <tr>
        <td>Last Name:</td>
      <td><input type="text" name="lname" /></td>
    </tr>
    <tr>
        <td>Email Address:</td>
      <td><input type="text" name="email" /></td>
    </tr>
    <tr>
      <td>Domain Name:</td>
      <td><input type="text" name="domain" /></td>
    </tr>
    <tr> 
      <td><p>Registration Years:</p>
          </td>
      <td><input type="text" name="length" /></td>
    </tr>
	    <tr>
      <td valign="top">Mailing Address:</td>
      <td><textarea name="address" cols="40" rows="5"></textarea></td>
    </tr>
  </table>
    <p>* - All Fields Required</p>
    <p> 
    <input type="submit" name="Submit" value="Submit" />
    <input type="reset" name="Reset" value="Reset" />
  </p>
</form>
Reply With Quote
  #5  
Old 07-31-2002, 05:49 PM
Admin's Avatar
Admin Admin is offline
Coder
 
Join Date: Oct 2023
Location: Server
Posts: 1
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

PHP Code:
<?php

$cid 
mysql_connect('localhost''root''');
mysql_select_db('domains'$cid);

$fields = array('fname''lname''email''domain''length''address');

$fieldlist '';
foreach (
$fields as $field) {
    if (!empty(
$fieldlist)) {
        
$fieldlist .= ', ';
    }
    
$fieldlist .= "$field = '".addslashes($_POST["$field"])."'";
}

mysql_query("
INSERT INTO domains
SET 
$fieldlist
"
);

mysql_close($cid);

?>
Reply With Quote
  #6  
Old 07-31-2002, 05:57 PM
globalwin's Avatar
globalwin globalwin is offline
 
Join Date: Jun 2002
Posts: 85
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

YAY, data got inserted into the DB, it was all 0 though, can anyone please tell me what type of field i want because I am using TINYINTs at the min and it doesnt work. Cheers Chen.
Reply With Quote
  #7  
Old 07-31-2002, 06:03 PM
Admin's Avatar
Admin Admin is offline
Coder
 
Join Date: Oct 2023
Location: Server
Posts: 1
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

You need to use VARCHAR (or CHAR) for string types, and TINYINT / SMALLINT / INT for integers.
Reply With Quote
  #8  
Old 07-31-2002, 06:17 PM
globalwin's Avatar
globalwin globalwin is offline
 
Join Date: Jun 2002
Posts: 85
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

ok, getting there and thanx for the help, now, as before i could see 0's, not MySQL Front says the data is there, but I cant view it.
Reply With Quote
  #9  
Old 07-31-2002, 06:19 PM
Admin's Avatar
Admin Admin is offline
Coder
 
Join Date: Oct 2023
Location: Server
Posts: 1
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

You will need to enter the data again.
Reply With Quote
  #10  
Old 07-31-2002, 06:23 PM
globalwin's Avatar
globalwin globalwin is offline
 
Join Date: Jun 2002
Posts: 85
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

hehe , is there anyway I can make the page display a redirection note like vB and then take them back to my homepage? Thanks for the intense help!
Reply With Quote
Reply

Thread Tools
Display Modes

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 02:17 AM.


Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2024, vBulletin Solutions Inc.
X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.08824 seconds
  • Memory Usage 2,260KB
  • Queries Executed 13 (?)
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)ad_showthread_firstpost
  • (1)ad_showthread_firstpost_sig
  • (1)ad_showthread_firstpost_start
  • (1)bbcode_code
  • (3)bbcode_php
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)navbar
  • (3)navbar_link
  • (120)option
  • (10)post_thanks_box
  • (10)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (10)post_thanks_postbit_info
  • (10)postbit
  • (10)postbit_onlinestatus
  • (10)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_postinfo_query
  • fetch_postinfo
  • 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