Jump to content

updating database with password


franknu

Recommended Posts

ugh... the query is slightly off. my bad. here's a revised query for you to change it to, and you should be golden:
[code]
<?php
$query = "UPDATE  business_info SET `BusinessName`= '$BusinessName', `Slogan`='$Slogan', " .
              "`Business_Address`='$Business_Address', `Tel`='$Tel', `Website`='$Website', " .
              "`Email`='$Email', `Member_Status`='$Member_Status', `Fax`='$Fax', `type`='$type', " .
              "`make`='$make', `Categories`='$Categories', `Keyword`='$Keyword', `Picture1`='$Picture1', " .
              "`Headline`='$Headline', `Slogan2`='$Slogan2', `Description1`='$Description1', " .
              "`Description2`='$Description2', `Description3`= '$Description3', `Contact2`='$Contact2', " .
              "`Picture2`='$Picture2', `Picture3`='$Picture3', `User_Name` ='$user', " .
              "`Password`='$Password' WHERE `User_Name`='$user'";
?>
[/code]
Link to comment
Share on other sites

I am getting (Couldn't update! )

after i type in Password and User_ Name

any idea. thank you again

[code=php:0]

<?php
$host    = "localhost";
$username = "localhost";
$password = "abc123";
$database = "contacts";

$db = mysql_connect($host, $username, $password) or die(mysql_error());
mysql_select_db($database) or die(mysql_error());

$BusinessName = (isset($_POST['BusinessName']) ? $_POST['BusinessName'] : '');
$Slogan = (isset($_POST['Slogan']) ? $_POST['Slogan']:'');
$Business_Address = (isset($_POST['Business_Address']) ? $_POST['Business_Address']:'');
$Tel = (isset($_POST['Tel']) ? $_POST['Tel']:'');
$Website = (isset($_POST['Website']) ? $_POST['Website']:'');
$Email = (isset($_POST['Email']) ? $_POST['Email']:'');
$Member_Status = (isset($_POST['Member_Status']) ? $_POST['Member_Status']:'');
$Fax =(isset($_POST['Fax']) ? $_POST['Fax']:'');
$type = (isset($_POST['type']) ? $_POST['type']:'');
$make = (isset($_POST['make']) ? $_POST['make']:'');
$Categories = (isset($_POST['Categories']) ? $_POST['Categories']:'');
$Keyword = (isset($_POST['Keyword']) ? $_POST['Keyword']:'');
$Picture1 =  (isset($_POST['Picture1']) ? $_POST['Picture1']:'');
$Headline =  (isset($_POST['Headline']) ? $_POST['Headline']:'');
$Slogan2 = (isset($_POST['Slogan2']) ? $_POST['Slogan2']:'');
$Description1 = (isset($_POST['Description1']) ? $_POST['Description1']:'');
$Description2 = (isset($_POST['Description2']) ? $_POST['Description2']:'');
$Description3= (isset($_POST['Description3']) ? $_POST['Description3']:'');
$Contact2 = (isset($_POST['Contact2']) ? $_POST['Contact2']:'');
$Picture2 =  (isset($_POST['Picture2']) ? $_POST['Picture2']:'');
$Picture3 = (isset($_POST['Picture3']) ? $_POST['Picture3']:'');
$Picture4 =  (isset($_POST['Picture4']) ? $_POST['Picture4']:'');
$User_Name = (isset($_POST['User_Name']) ? $_POST['User_Name']:'');
$Password = (isset($_POST['Password']) ? $_POST['Password']: '');
$user = (isset($_POST['User_Name']) ? $_POST['User_Name']:'');

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

  foreach ($_POST as $key => $val) {
    $$key = mysql_real_escape_string($val);
  }

  $q = "SELECT `Password` FROM business_info WHERE User_Name = '$user'";
  $sql = mysql_query($q) or die(mysql_error() . "<br />$q");
  if (mysql_num_rows($sql) == 1) {
    $confPass = mysql_result($sql, 0, 'Password');
    if ($Password == $confPass) {
     
  $query = "UPDATE  business_info SET `BusinessName`= '$BusinessName', `Slogan`='$Slogan', " .
              "`Business_Address`='$Business_Address', `Tel`='$Tel', `Website`='$Website', " .
              "`Email`='$Email', `Member_Status`='$Member_Status', `Fax`='$Fax', `type`='$type', " .
              "`make`='$make', `Categories`='$Categories', `Keyword`='$Keyword', `Picture1`='$Picture1', " .
              "`Headline`='$Headline', `Slogan2`='$Slogan2', `Description1`='$Description1', " .
              "`Description2`='$Description2', `Description3`= '$Description3', `Contact2`='$Contact2', " .
              "`Picture2`='$Picture2', `Picture3`='$Picture3', `User_Name` ='$user', " .
              "`Password`='$Password' WHERE `User_Name`='$user'";



      if (!mysql_query($query)) {
        echo "Record updated!";
      } else {
        echo "Couldn't update!<br />" . mysql_error();
      }
    }

else
{
      // Passwords don't match
      echo "$pass != $confPass";
    }
  } else {
    // didn't get any records
    echo "No records for query: <b>$q</b>";
  }
}
?>
[/code]

Link to comment
Share on other sites

Are you getting a MySQL error after the "Couldn't update!" line?

If not, is it not because the lines

[code]
<?php

if (!mysql_query($query)) {
        echo "Record updated!";
      } else {
        echo "Couldn't update!<br />" . mysql_error();
      }
    }

?>

[/code]

should actually read

[code]
<?php

if (!mysql_query($query)) {
        echo "Couldn't update!<br />" . mysql_error();
      } else {
        echo "Record updated!";
      }
    }

?>

[/code]

I just think you had them the wrong way around. Try that, I could be wrong...

HTH
Link to comment
Share on other sites

ok i am getting record updated but i am not updating anything actually whenever i go into the database manually and look into the row where is passwaord and user_name there is nothing it actually seems to delete what was there. i should log into the database and made changes to the colums it is just saying Record updated. but for some reason it is just deleting everything in the row except for the Password and the User_Name please help
Link to comment
Share on other sites

if you're running it from the test form i wrote up, it's because the only $_POST field that is there is the username. the password is being pulled from the database before update. you've got to use your full form to update the entire record. you've got to expect that only those two would be left if you're updating from a form that only gives those two values. it means the logic [b]is working correctly[/b]. now, go back and add it to your form where you have ALL the columns represented, and see what you get.
Link to comment
Share on other sites

That's where the "value" attribute on your input fields comes in to play. Anything you place in that value shows up in the text box. So, when they want to edit their profile, just show them all their info in the form, and when they save changes, you update with whatever is in the form.
Link to comment
Share on other sites

ok, i can insert info into the database with the password and user name but this is working  more like that just an insert into the database, i want to see what is actually in the database so i can change it if there is a typo or somehting like that just like i update manually.. any idea what i need to change
Link to comment
Share on other sites

i am not getting that part.
this is my form

[code=php:0]

<form action="Update_Page.php" method="post" name="loginForm">


                    <tr>
    <td>First Name</td>
                      <td><input type="text" name="First_Name" Size="30"></td>
 
    <td>Last Name</td>
                      <td><input type="text" name="Last_Name" Size="30"></td>
  </tr>


<tr>
                     
                      <td>Address</td>
                      <td><input type="text" name="Owner_Address" Size="30"></td>
                      <td>State</td>
                      <td><input type="text" name="State" size="25"></td>
                    </tr>
                    <tr>
                      <td>City</td>
                      <td><input type="text" name="City"></td>
                      <td>Zip</td>
                      <td><input type="text" name="Zip"></td>
                    </tr>
                    <tr>
                      <td>Tel</td>
                      <td><input type="text" name="Tel"></td>
                      <td>Email</td>
                      <td><input type="text" name="Email"></td>
                    </tr>
                    <tr>
                      <td>Business Position</td>
                      <td><input type="text" name="Position"></td>
                      <td>Comments</td>
                      <td><input type="text" name="Comments"></td>
                    </tr>
                  </table>


</td>
  </tr>
  <tr>
    <td background="../images/fondo2.jpg" bgcolor="#999966"><div align="center"><strong>Business Info</strong></div></td>
  </tr>
  <tr>
    <td><table width="100%" border="0" cellspacing="1" cellpadding="1">
        <tr>
          <td width="17%">Business Name</td>
          <td width="22%"><input type="text" name="BusinessName"></td>
          <td width="16%">Status</td>
          <td width="45%"><input type="text" name="Member_Status"></td>
        </tr>
        <tr>
          <td>Slogan</td>
          <td><input type="text" name="Slogan"></td>
          <td>Website</td>
          <td><input type="text" name="Website"></td>
        </tr>
        <tr>
          <td>Tel</td>
          <td><input type="text" name="Tel"></td>
          <td>Key Words</td>
          <td><input type="text" name="Keyword"></td>
        </tr>
        <tr>
          <td>Fax</td>
          <td><input type="text" name="Fax"></td>
          <td>Address</td>
          <td><input type="text" name="Business_Address"></td>
        </tr>
      </table></td>
  </tr>
  <tr>
    <td>

<table width="101%" height="35" border="0" cellpadding="0" cellspacing="0">
        <tr>
          <td width="13%">State</td>
          <td width="7%"> <select name="make" style="width:160px;"></td>
         
          <td width="16%">City</td>
          <td width="8%"><select name="type" style="width:160px;">
                  </select>
 
  </td>
          <td width="9%">Category</td>
          <td width="16%"><input type="text" name="Categories"> </td>
       
        </tr>
      </table><br>
  <table width="100%" border="0" cellspacing="1" cellpadding="1">
        <tr>
          <td background="../images/fondo2.jpg" bgcolor="#CCCCCC"><div align="center"><strong><font color="#000000">Business
                          Webpage</font></strong></div></td>
        </tr>
        <tr>
          <td>Headline</td>
        </tr>
        <tr>
          <td><input type="text" name="Headline"></td>
        </tr>
        <tr>
          <td>Slogan </td>
        </tr>
        <tr>
          <td><input type="text" name="Slogan2"></td>
        </tr>
        <tr>
                      <td>Description1 </td>
        </tr>
        <tr>
          <td><TEXTAREA ROWS=5 COLS=65 NAME="Description1"></TEXTAREA></td>
        </tr>
        <tr>
          <td>Description2</td>
        </tr>
        <tr>
          <td><TEXTAREA ROWS=5 COLS=65 NAME="Description2"></TEXTAREA></td>
        </tr>
        <tr>
          <td>Description3</td>
        </tr>
        <tr>
          <td><TEXTAREA ROWS=5 COLS=65 NAME="Description3"></TEXTAREA></td>
        </tr>
        <tr>
          <td>Contact
            <TEXTAREA ROWS=3 COLS=40 NAME="Contact2"></TEXTAREA></td>
        </tr>
        <tr>
          <td>
 

          Picture1
  <input name="Picture1" type="file">

   
  </td>
        </tr>
        <tr>
          <td>
  </td>
        </tr>
        <tr>
          <td></td>
        </tr>
        <tr>
          <td><table width="100%" border="1" cellspacing="1" cellpadding="1">
              <tr>
                <td>User Name</td>
                <td>Username: <input type="text" name="User_Name" /></td>
                <td>Password</td>
                <td><input type="password" name="Password" /></td>
              </tr>
            </table></td>
        </tr>
      </table> </td>
  </tr>
  <tr>
    <td background="../images/fondo2.jpg"> <div align="right">
      <input type="submit" name="submit" value="Login" />
        <input type="reset" value="Reset fields" />
      </div><td>
  </form>
[/code]

anyone has access to this form.

and only the person who password and user name match will be able to update his /her row and now

please a little help to just finish this that been working for weeks
Link to comment
Share on other sites

"value" attribute

I am really not understanding how i can have asses to the text that is already there so  when i make a change i can change anything in there like a typo or add more text if they need to for now i can add text on the where the passwoerd and user name match ....


please help i am almost done here.. I think
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.