Jump to content

INSERT INTO MySql does not insert


jose

Recommended Posts

Hi there,

 

Anybody can tell why it is not possible to insert any data in MySql database? It is located in my machine, apparently everything is fine, but something is wrong and I cannot localize it.

 

Here the script:

 

 

<?php

 

  require_once('connectvars.php');

 

  // Connect to the database

  $dbc = mysqli_connect('localhost', 'root', 'zam', 'entrepreneurial')

    or die ('Error connecting to MySQL server');

 

  if (isset($_POST['submit'])) {

    // Grab the profile data from the POST

 

    $username = mysqli_real_escape_string($dbc, trim($_POST['username']));

    $password1 = mysqli_real_escape_string($dbc, trim($_POST['password1']));

    $password2 = mysqli_real_escape_string($dbc, trim($_POST['password2']));

 

    if (!empty($username) && !empty($password1) && !empty($password2) && ($password1 == $password2)) {

      // Make sure someone isn't already registered using this username

      $query = "SELECT * FROM entrepreneurial_user WHERE username = '$username'";

      $result = mysqli_query($dbc, $query);

      if ($result->num_rows == 0) {

        // The username is unique, so insert the data into the database

        $query = "INSERT INTO entrepreneurial_user (username, password1) VALUES ('username', SHA ('password1'))";

        $row_cnt = $result->num;

 

        // Confirm success with the user

        echo '<p>Your new account has been successfully created. You\'re now ready to <a href="login.php">log in</a>.</p>';

 

        mysqli_close($dbc);

        exit();

      }

      else {

        // An account already exists for this username, so display an error message

        echo '<p class="error">An account already exists for this username.</p>';

        $username = "";

      }

    }

    else {

      echo '<p class="error">You must enter all of the sign-up data, including the desired password twice.</p>';

    }

  }

 

  mysqli_close($dbc);

?>

 

Thanks

 

Link to comment
Share on other sites

the rest of the code

 

<!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" xml:lang="en" lang="en">

<head>

  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

  <title> Entrepre - Sign Up</title>

  <link rel="stylesheet" type="text/css" href="style.css" />

 

<?php

 

  require_once('connectvars.php');

 

  // Connect to the database

  $dbc = mysqli_connect('localhost', 'root', 'zamb', 'entrepreneuria')

    or die ('Error connecting to MySQL server');

 

  if (isset($_POST['submit'])) {

    // Grab the profile data from the POST

 

    $username = mysqli_real_escape_string($dbc, trim($_POST['username']));

    $password1 = mysqli_real_escape_string($dbc, trim($_POST['password1']));

    $password2 = mysqli_real_escape_string($dbc, trim($_POST['password2']));

 

    if (!empty($username) && !empty($password1) && !empty($password2) && ($password1 == $password2)) {

      // Make sure someone isn't already registered using this username

      $query = "SELECT * FROM entrepreneurial_user WHERE username = '$username'";

      $result = mysqli_query($dbc, $query);

      if ($result->num_rows == 0) {

        // The username is unique, so insert the data into the database

        $query = "INSERT INTO entrepreneurial_user (username, password1) VALUES ('username', SHA ('password1'))";

        $row_cnt = $result->num;

 

        // Confirm success with the user

        echo '<p>Your new account has been successfully created. You\'re now ready to <a href="login.php">log in</a>.</p>';

 

        mysqli_close($dbc);

        exit();

      }

      else {

        // An account already exists for this username, so display an error message

        echo '<p class="error">An account already exists for this username.</p>';

        $username = "";

      }

    }

    else {

      echo '<p class="error">You must enter all of the sign-up data, including the desired password twice.</p>';

    }

  }

 

  mysqli_close($dbc);

?>

 

<style type="text/css">

<!--

body,td,th {

font-size: 16px;

font-family: Tahoma, Geneva, sans-serif;

}

#wrapper {

width: 860px;

margin-right: auto;

margin-left: auto;

padding: 10px;

background-color: #FFF;

font-size: 12px;

}

body,td,th {

font-family: Tahoma, Geneva, sans-serif;

color: #000;

background-color: #FFF;

}

body {

background-color: #E6FFFE;

 

.regist {

font-weight: bold;

}

.regist {

font-weight: bold;

font-size: 18pt;

}

.u {

font-size: 12pt;

}

.user {

font-size: 12px;

}

.user {

font-size: 12pt;

}

.signup {

font-size: 12pt;

font-weight: bold;

}

</style></head>

<body>

<div id="wrapper">

<p><img src="images/entrepreneurs banner.jpg" width="860" height="60" alt="banner" /></p>

 

<?php

  // If the cookie is empty, show any error message and the log-in form; otherwise confirm the log-in

  if (empty($_COOKIE['user_id'])) {

    echo '<p class="error">' . $error_msg . '</p>';

?>

 

<form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">

    <fieldset>

      <legend class="sign">Sign Up    </legend>

      <table width="400" border="0">

        <tr>

          <td class="user" style="font-size: 12pt"><label for="username">Username:</label></td>

          <td><input name="username" type="text" value="<?php if (!empty($user_username)) echo $user_username; ?>" size="25" maxlength="15" />

       

          <br /></td>

        </tr>

        <tr>

          <td class="user" style="font-size: 12pt"><label for="password1">Password:</label></td>

          <td><input type="password" id="password1" name="password1" />

          <br /></td>

        </tr>

        <tr>

          <td class="user" style="font-size: 12pt"><label for="password2">Password (retype):</label></td>

          <td><input type="password" id="password2" name="password2" />

          <br /></td>

        </tr>

        <tr>

          <td> </td>

          <td><input type="submit" value="Sign Up" name="submit" /></td>

        </tr>

      </table>

    </fieldset>

  </form>

    <table width="662" border="0">

    <tr>

    <?php

  }

  else {

    // Confirm the successful log-in

    echo('<p class="login">You are logged in as ' . $_COOKIE['username'] . '.</p>');

  }

?>

 

</body>

</html>

Link to comment
Share on other sites

Hi there,

 

Anybody can tell why it is not possible to insert any data in MySql database? It is located in my machine, apparently everything is fine, but something is wrong and I cannot localize it.

 

Here the script:

 

<?php

  require_once('connectvars.php');

  // Connect to the database
  $dbc = mysqli_connect('localhost', 'root', 'zam', 'entrepreneurial')
    or die ('Error connecting to MySQL server');

  if (isset($_POST['submit'])) {
    // Grab the profile data from the POST

    $username = mysqli_real_escape_string($dbc, trim($_POST['username']));
    $password1 = mysqli_real_escape_string($dbc, trim($_POST['password1']));
    $password2 = mysqli_real_escape_string($dbc, trim($_POST['password2']));

    if (!empty($username) && !empty($password1) && !empty($password2) && ($password1 == $password2)) {
      // Make sure someone isn't already registered using this username
      $query = "SELECT * FROM entrepreneurial_user WHERE username = '$username'";
      $result = mysqli_query($dbc, $query);
      if ($result->num_rows == 0) {
        // The username is unique, so insert the data into the database
        $query = "INSERT INTO entrepreneurial_user (username, password1) VALUES ('username', SHA ('password1'))";
        $row_cnt = $result->num;

        // Confirm success with the user
        echo '<p>Your new account has been successfully created. You\'re now ready to <a href="login.php">log in</a>.</p>';

        mysqli_close($dbc);
        exit();
      }
      else {
        // An account already exists for this username, so display an error message
        echo '<p class="error">An account already exists for this username.</p>';
        $username = "";
      }
    }
    else {
      echo '<p class="error">You must enter all of the sign-up data, including the desired password twice.</p>';
    }
  }

  mysqli_close($dbc);
?>


Thanks<form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
    <fieldset>
      <legend class="sign">Sign Up    </legend>
      <table width="400" border="0">
        <tr>
          <td class="user" style="font-size: 12pt"><label for="username">Username:</label></td>
          <td><input name="username" type="text" value="<?php if (!empty($user_username)) echo $user_username; ?>" size="25" maxlength="15" />
       
          <br /></td>
        </tr>
        <tr>
          <td class="user" style="font-size: 12pt"><label for="password1">Password:</label></td>
          <td><input type="password" id="password1" name="password1" />
          <br /></td>
        </tr>
        <tr>
          <td class="user" style="font-size: 12pt"><label for="password2">Password (retype):</label></td>
          <td><input type="password" id="password2" name="password2" />
          <br /></td>
        </tr>
        <tr>
          <td> </td>
          <td><input type="submit" value="Sign Up" name="submit" /></td>
        </tr>
      </table>
    </fieldset>
  </form>
    <table width="662" border="0">
    <tr> 

 

Thanks

 

Link to comment
Share on other sites

i hope u r missing the basic thing of using the mysql_query in this one

  $query = "INSERT INTO entrepreneurial_user (username, password1) VALUES ('username', SHA ('password1'))";
        $row_cnt = $result->num;

 

 

Link to comment
Share on other sites

i hope u r missing the basic thing of using the mysql_query in this one

  $query = "INSERT INTO entrepreneurial_user (username, password1) VALUES ('username', SHA ('password1'))";
        $row_cnt = $result->num;

 

What do you mean?

 

Link to comment
Share on other sites

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.