vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vB3 Programming Discussions (https://vborg.vbsupport.ru/forumdisplay.php?f=15)
-   -   MySQL Connection (https://vborg.vbsupport.ru/showthread.php?t=41739)

globalwin 07-31-2002 03:53 PM

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.

Admin 07-31-2002 04:23 PM

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);

?>


globalwin 07-31-2002 04:24 PM

cheers, :D

globalwin 07-31-2002 04:43 PM

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>


Admin 07-31-2002 04:49 PM

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);

?>


globalwin 07-31-2002 04:57 PM

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. :D

Admin 07-31-2002 05:03 PM

You need to use VARCHAR (or CHAR) for string types, and TINYINT / SMALLINT / INT for integers.

globalwin 07-31-2002 05:17 PM

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.

Admin 07-31-2002 05:19 PM

You will need to enter the data again.

globalwin 07-31-2002 05:23 PM

hehe :D, 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! :)


All times are GMT. The time now is 06:11 AM.

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.01517 seconds
  • Memory Usage 1,740KB
  • Queries Executed 10 (?)
More Information
Template Usage:
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (1)bbcode_code_printable
  • (3)bbcode_php_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (10)printthreadbit
  • (1)spacer_close
  • (1)spacer_open 

Phrase Groups Available:
  • global
  • postbit
  • showthread
Included Files:
  • ./printthread.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/class_bbcode_alt.php
  • ./includes/class_bbcode.php
  • ./includes/functions_bigthree.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
  • printthread_start
  • bbcode_fetch_tags
  • bbcode_create
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • printthread_post
  • printthread_complete