Results 1 to 3 of 3

Thread: Adding Data Into A MySQL Table

  1. #1
    Join Date
    Apr 2006
    Posts
    584
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Adding Data Into A MySQL Table

    Hi All,

    I can easily pull data about my members using this page, not sure if you can see from the code but I also have textfields, in each column. I want to just be able to type in these and then click Submit/Update and the user get's added... Anyone have any idea?

    PHP Code:
    <?php

    /* connect to the mysql database and use different queries for the count of members */

    include 'library/config.php';
    include 
    'library/opendb.php';

    //navigation
    include("nav.php");

    $info mysql_query("SELECT * FROM tbladministrators");

    echo 
    '<table border="1" cellpadding="3" cellspacing="1">
      <tr valign="top">
        <td>First Name</td>
        <td>Last Name</td>
        <td>Username</td>
        <td>Password</td>
        <td>Super User</td>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
      </tr><tr valign="top">
        <td><input type="text" name="firstname" /></td>
        <td><input type="text" name="lastname" /></td>
        <td><input type="text" name="username" /></td>
        <td><input type="text" name="password" /></td>
        <td><select name="select">
          <option value="0">Yes</option>
          <option value="1">No</option>
        </select></td>
        <td>&nbsp;</td>
        <td>Insert</td>
      </tr>'
    ;
        
    if (
    mysql_num_rows($info) < 1) {
    echo 
    '<tr valign="top">
      <td colspan="4">There are no members that match the query. Please go back and try again</td>
        </tr>'
    ;
    }

    else {
       while (
    $qry mysql_fetch_array($info)) {

    //create the layout
    ?>
    <link href="cs_style.css" rel="stylesheet" type="text/css" />

      <tr valign="top">
        <td><?php echo $qry['firstname']; ?></td>
        <td><?php echo $qry['lastname']; ?></td>
        <td><?php echo $qry['username']; ?></td>
        <td><?php echo $qry['password']; ?></td>
        <td><?php echo $qry['superuser']; ?></td>
        <td><a href="showAdminEdit.php?record_id=<?php echo $qry['id']; ?>">Edit</a></td>
        <td>Delete</td>
      </tr>
    <?php
       
    }
    }

    echo 
    '</table>';

    include 
    'library/closedb.php';

    ?>

  2. #2
    Join Date
    Apr 2006
    Posts
    584
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    I was able to build the query, just not sure where to add it to the page?

    PHP Code:
    $query "INSERT INTO tbladministrators (firstname, lastname, username, password, superuser) VALUES ($value1$value2$value3$value4$value5)";
    mysql_query($query) or die('Error, insert query failed');

    $query "FLUSH PRIVILEGES";
    mysql_query($query) or die('Error, insert query failed'); 

  3. #3
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    Code:
    $sqldata = array_map('mysql_real_escape_string', $_GET);
    mysql_query("insert into tbladministrators (firstname, lastname, username, password, superuser) values ('{$sqldata['firstname']}', '{$sqldata['lastname']}', '{$sqldata['username']}', '{$sqldata['password']}', '{$sqldata['select']}')" or die('Insert query failed.');
    Anywhere after including opendb.php.
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •