Register

If this is your first visit, please click the Sign Up now button to begin the process of creating your account so you can begin posting on our forums! The Sign Up process will only take up about a minute of two of your time.

Results 1 to 6 of 6
  1. #1
    Member tlcook's Avatar
    Join Date
    Nov 2006
    Posts
    38
    Member #
    14386
    Hi all,

    I've been trying to get information inputted in a HTML form to insert into a MySQL database table. All the configuration and appropriate commands are correct and in order. The only problem is that it will not insert. Below is the code I have used for the page:

    PHP Code:
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    </head>

    <body>
    <?php
    if(isset($_POST['add']))
    {
    include 
    'dbconn.php';
    include 
    'dbopen.php';

    $username $_POST['username'];
    $password $_POST['password'];


    $query "INSERT INTO 'user' (host, username, password, select_priv, insert_priv, update_ priv) VALUES ('localhost', '$username', PASSWORD('$password'), 'Y', 'Y', 'Y')";
    mysql_query($query) or die('Error, insert query failed 1');


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

    include 
    'dbclose.php';
    echo 
    "New MySQL user added";
    }
    else
    {
    ?>
    <form method="post">
    <table width="400" border="0" cellspacing="1" cellpadding="2">
    <tr> 
    <td width="100">Username</td>
    <td><input name="username" type="text" id="username"></td>
    </tr>
    <tr> 
    <td width="100">Password</td>
    <td><input name="password" type="password" id="password"></td>
    </tr>
    <tr> 
    <td width="100">&nbsp;</td>
    <td>&nbsp;</td>
    </tr>
    <tr> 
    <td width="100">&nbsp;</td>
    <td><input name="add" type="submit" id="add" value="Add New User"></td>
    </tr>
    </table>
    </form>
    <?php
    }
    ?>
    </body>
    </html>

  2.  

  3. #2
    Senior Member
    Join Date
    May 2003
    Location
    UK
    Posts
    2,354
    Member #
    1326
    Do you get any errors/any ofyour echo statements?

    If not, display all warnings and errors while developing.

  4. #3
    Senior Member filburt1's Avatar
    Join Date
    Jul 2002
    Location
    Maryland, US
    Posts
    11,774
    Member #
    3
    Liked
    21 times
    Also, have you verified that MySQL is successfully being connected?

    PHP Code:
    error_reporting(E_ALL); 
    ...is very useful for debugging. I can't believe it's not on by default.

    edit: you also have a serious security problem with SQL injection. Any user-provided string data must be wrapped with [phpfunction]mysqlrealescapestring[/phpfunction].
    filburt1, Web Design Forums.net founder
    Site of the Month contest: submit your site or vote for the winner!

  5. #4
    Member tlcook's Avatar
    Join Date
    Nov 2006
    Posts
    38
    Member #
    14386
    MySQL is being successfully connected. Where do I put
    PHP Code:
    error_reporting(E_ALL); 
    in my script so that it displays the debug information?

    I'm too new to this to be able to know exactly what you're talking about I'm afraid :$

  6. #5
    Senior Member
    Join Date
    May 2003
    Location
    UK
    Posts
    2,354
    Member #
    1326
    Put that line of code before all of your PHP code.

    PHP Code:
    error_reporting(E_ALL);
    // now connect to database
    // now do queries
    // etc 

  7. #6
    Member tlcook's Avatar
    Join Date
    Nov 2006
    Posts
    38
    Member #
    14386
    Thanks. I get no error reports at all though :S Here is an update of the main bit of the script, I have the database setup with a table named &quot;user&quot; and fields of &quot;username&quot;, &quot;password&quot; and &quot;email&quot; :
    PHP Code:
    error_reporting(E_ALL);   include 'dbconn.php'; include 'dbopen.php';   $username $_POST['username'];   $password $_POST['password'];   $email $_POST['email'];      $query = &quot;INSERT INTO 'user' (usernamepasswordemailVALUES ($usernamePASSWORD($password), $email)&quot;   mysql_query($query) or die('Error, insert query failed 1');     $query = &quot;FLUSH PRIVILEGES&quot;; mysql_query($query) or die('Error, insert query failed 2');    include 'dbclose.php'
    I also found that removing the ' (single quotes) from the &quot;VALUES&quot; worked! But it will not work for the $variables. I am now confused! Any ideas? EDIT: Okay so the PHP quote thing didn't work the line breaks...Sorry if it's painful to read


Remove Ads

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
All times are GMT -6. The time now is 02:24 AM.
Powered by vBulletin® Version 4.2.3
Copyright © 2019 vBulletin Solutions, Inc. All rights reserved.
vBulletin Skin By: PurevB.com