Jump to content

Recommended Posts

For some reason this code is not changing anything in the database. I am 99% sure I am typing in the right info into the text boxes, and even if I wasn't it should give me error messages.

Kinda stumped. Hopefully a new pair of eyes can help.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Member System Install</title>
</head>

<body>
<form id="form1" name="form1" method="post" action="">
  <h2><center>Fill in the following info properly   to install required databases.</center></h2>
  <p>
    <label>Host:
      <input type="text" name="host" id="host" />
    </label>
  </p>
  <p>
    <label>Database User:
      <input type="text" name="dbUser" id="dbUser" />
    </label>
  </p>
  <p>
    <label>Database Password:
      <input type="text" name="dbPass" id="dbPass" />
    </label>
  </p>
  <p>
    <label>Desired Admin Username:
      <input type="text" name="adminName" id="adminName" />
    </label>
  </p>
  <p>
    <label>Desired Admin Password:
      <input type="text" name="adminPass" id="adminPass" />
    </label>
  </p>
  <p>
    <label>Email:
      <input type="text" name="adminEmail" id="adminEmail" />
    </label>
  </p>
  <p>
    <input type="submit" name="submitBtn" id="submitBtn" value="Submit" />
  </p>
</form>
<?php
if(isset($_POST['submit'])){
   $hostName = $_POST['host'];
   $dbUserName = $_POST['dbUser'];
   $dbPassword = $_POST['dbPass'];
   $adminUserName = $_POST['adminName'];
   $adminPassword = $_POST['adminPass'];
   $email = $_POST['adminEmail'];
   
   $sqlLink = mysql_connect('$hostName','$dbUserName','$dbPassword');
   if(!$sqlLink){
      die('Could not connect: ' .mysql_error());
      mysql_close();
   } else {
      $queryCreate = 'CREATE DATABASE member_db';
      echo 'Connected successfully!';
      if(mysql_query($queryCreate,$link)){
         echo 'Created database!';
         mysql_select_db('member_db');
         $createAdminTable = "CREATE TABLE " .$adminUserName. " (`secLvl` tinyint(1) default NOT NULL,`rank` tinyint(2) default NOT NULL,`username` varChar(32) NOT NULL UNIQUE,`password` varChar(32) NOT NULL,`email` varChar(32) NOT NULL UNIQUE";
         $insertAdminInfoQuery = "UPDATE " .$adminUserName. " SET `secLvl` = '5', `rank` = '10', `username` = '$adminUserName', `password` = '$adminPassword', `email` = '$email' WHERE '$adminUserName' LIMIT 1";
         mysql_query($createAdminTable) or die("ERROR: " .mysql_error());
         mysql_query($insertAdminInfoQuery) or die("ERROR: " .mysql_error());
      } else {
         echo 'Error: '.mysql_error();
      }
   }
} 
?>
</body>
</html>

Thanks,

Brandon :)

Link to comment
https://forums.phpfreaks.com/topic/220975-database-is-not-being-modified/
Share on other sites

You need:

 

if(isset($_POST['submitBtn']))

 

Also, you've got your logic backwards.  With PHP, you always attempt to handle incoming POST data first, then show the form.  Your form should still send the data with the way you have it now, but you're coding yourself into a corner with your current script structure.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.