Jump to content

MySQL/PHP/HTML data retrieval and modification forms pre global_variable.


paddyhaig

Recommended Posts

I created these scripts 7 years ago and believe they were created on a system allowing global variables. They seemed to work fine at the time, but now they are all kinds of funky. I am hoping that some one can help me clean them up and get them working again.

 

Abstract: The form is designed to connect to a mySQL database and pull up a table of all the Users and their information. i.e. Id, Edit, Name, Login, Privilege.

The way it used to work was if you clicked on the 'Id' of a specific user then another form would come up with their specific details that you could then edit and resubmit.

What I would really like and hope to be working towards, is an initial table without the 'Id' column. The User details to be presented in columns in this order (From left to right) Name (First and last), Login, Privilege. I would also like the name (First and Last) to be a link, when clicked on, taking you to another page where you can edit the details or completely remove the account/db row. Also the privilege on this same page to have a drop down list offering the options Manager, Staff, Suspended.

I believe actually the was also a page for creating new accounts at some point.

Anyway, if the is anyone that can help me out there with this I would be very grateful.

 

This is what used to work. The common error being: Undefined variable

 

edit.php

<?php

mysql_connect('localhost','example','example') or die ("Problem connecting to DataBase");
$query = "select * from auth";
$result = mysql_db_query("example", $query);


if ($result) {
echo "<table width=90% align=center border=1 bordercolor=#808080 cellspacing=0 cellpadding=0 bordercolorlight=#808080 bordercolordark=#283A86><tr>
<td align=center bgcolor=#283A86><font color=#FFFFFF><b>Edit:</b></td>
<td align=center bgcolor=#283A86><font color=#FFFFFF><b>Name:</b></td>
<td align=center bgcolor=#283A86><font color=#FFFFFF><b>Login:</b></td>
<td align=center bgcolor=#283A86><font color=#FFFFFF><b>Privilege:</b></td>
</tr>";



while ($r = mysql_fetch_array($result)) {
$id = $r["id"];
$first_name = $r["first_name"];
$last_name = $r["last_name"];
$login = $r["login"];
$password = $r["password"];
$privilege = $r["privilege"];

echo "<tr>
<td align=center>
<a href=\"editing.php?id=
$id&first_name=
$first_name&last_name=
$last_name&login=
$login&password=
$password&privilege=
$privilege\">
$id
</a>
</td>

<td>$first_name $last_name</td>
<td>$login</td>
<td>$privilege</td>
</tr>";

}
echo "</table>";

} else {

echo "No data.";

}

mysql_free_result($result);

?>

 

editing.php

<?php
?>


<form method="POST" action="editdb.php">

<center>


      <table width="226" border="1" bordercolor="#808080" cellspacing="0" cellpadding="0" bordercolorlight="#808080" bordercolordark="#283A86">
        <tr>
          <td align="center" width="93" bgColor="#283a86" height="4"><font color="#ffffff"><b>First
            name</b></font></td>
          <td width="141" bgColor="#283a86" height="4" align="center"><input type="text" name="first_name" size="20"
          value="<?php echo "$first_name";?>"></td>
          </tr>
        <tr>
        
        
          <td align="center" width="93" bgColor="#283a86" height="3"><b><font color="#FFFFFF">Last
            name</font></b></td>
          <td width="141" bgColor="#283a86" height="3" align="center"><input type="text" name="last_name" size="20"
          value="<?php echo "$last_name";?>"></td>
        </tr>
        <tr>
        
          <td align="center" width="93" bgColor="#283a86" height="13"><font color="#ffffff"><b>Login </b></font></td>
          <td width="141" bgColor="#283a86" height="13" align="center"><input type="text" name="login" size="20"
           value="<?php echo "$login";?>"></td>
          </td>
        </tr>
        <tr>
        
          <td align="center" width="93" bgColor="#283a86" height="27"><font color="#ffffff"><b>Password </b></font></td>
          <td width="141" bgColor="#283a86" height="27" align="center"><input type="password" name="password" size="20"
          value="<?php echo "$password";?>"></td>
          </td>
        </tr>
        <tr>
        
        
          <td align="center" width="93" bgColor="#283a86" height="14"><font color="#ffffff"><b>Privilege </b></font></td>
          <td width="141" bgColor="#283a86" height="14" align="center"><select size="1" name="privilege">
              <option selected value="receptionist">Receptionist</option>
              <option value="manager">Manager</option>
              <option value="administrator">Administrator</option>
              <option value="<?php echo "$privilege";?>" selected><?php echo "$privilege";?></option>
              <option value="suspended">Suspended</option>
              nbsp; </select></td>
        </tr>
      </table>
      <div align="center">
        <table border="0" cellpadding="0" cellspacing="0" width="198">
          <tr>
            <td width="196">
              <p align="center"><font color="#283A86">.</font></td>
          </tr>
          <tr>
            <td width="196">

                <input type=hidden name=id value="<?php echo "$id";?>">


              <p align="center">
<input name="submit" type="image" id="submit" src="../../graphics/general/edit-staff-member_button.gif" alt="Edit Staff member" width="180" height="28" border="0"></p>


            </td>
          </tr>?>
          
</center>


include ('../../includes/scripts_footer.inc');
?>

 

editdb.php

<?php

mysql_connect('localhost','example','example') or die ("Problem connecting to DataBase");

$query = "update auth set
id='$id',first_name='$first_name',last_name='$last_name',login='$login' ,password='$password' ,privilege='$privilage' where
id='$id'";

$result = mysql_db_query("example", $query);
$query = "SELECT * FROM auth";
$result = mysql_db_query("example", $query);

if ($result) {
echo "<table width=100% align=center border=1 bordercolor=#808080 cellspacing=0 cellpadding=0 bordercolorlight=#808080 bordercolordark=#283A86><tr>
<td align=center bgcolor=#283A86><font color=#FFFFFF><b>Name:</b></td>
<td align=center bgcolor=#283A86><font color=#FFFFFF><b>Login:</b></td>
<td align=center bgcolor=#283A86><font color=#FFFFFF><b>Privilege:</b></td>
</tr>";

while ($r = mysql_fetch_array($result)) {
$id = $r["id"];
$first_name = $r["first_name"];
$last_name = $r["last_name"];
$login = $r["login"];
$password = $r["password"];
$privilage = $r["privilege"];

echo "<tr>

<td>$first_name $last_name</td>
<td>$login</td>

<td>$privilege</td>
</tr>";

}

echo "</table>";

} else {

echo "No data.";

}

mysql_free_result($result);


?>
      
<? include ('../../includes/scripts_footer.inc'); ?>

 

I have also attached a graphic of my database schema...

 

[attachment deleted by admin]

Link to comment
Share on other sites

No prob. (Although I do wish I had more of an insight.)

What happens is when I open the page using the editing.php script

The form fields are filled with:

 

<br /> <b>Notice</b>:  Undefined variable: first_name in <b>C:\wamp\www\concierge\admin\editing.php</b> on line <b>15</b><br />

<br /> <b>Notice</b>:  Undefined variable: last_name in <b>C:\wamp\www\concierge\admin\editing.php</b> on line <b>23</b><br />

<br /> <b>Notice</b>:  Undefined variable: login in <b>C:\wamp\www\concierge\admin\editing.php</b> on line <b>29</b><br />

This line is a password field so it's error is I am sure obscured by asterisks....

<br /> <b>Notice</b>:  Undefined variable: login in <b>C:\wamp\www\concierge\admin\editing.php</b> on line <b>47</b><br />

<br /> <b>Notice</b>:  Undefined variable: login in <b>C:\wamp\www\concierge\admin\editing.php</b> on line <b>47</b><br />

Link to comment
Share on other sites

Php no longer (the setting was turned off by default over 8 years ago in php4.2) populates (and overwrites) regular program variables from the form's $_POST variables. You need to either use the correct $_POST variable (i.e. $_POST['first_name']) or set your existing program variables from the correct $_POST variable (i.e. $first_name = $_POST['first_name'];.)

 

The same is true of any $_POST, $_GET, $_COOKIE, $_SESSION, $_FILES, $_SERVER, and $_ENV variable you might be using. The reason for this is because php made a huge blunder by including $_SESSION variables in this variable overwriting process (and in fact by automatically overwriting any variables with data from different sources) and it allowed hackers to set your session variables by simply sending your script same name post/get/cookie variables and a lot of sites where taken over.

 

Also, if you have any code that uses session_register(), session_is_registered(), or session_unregister(), you will need to make additional changes to use session_start() and the $_SESSION variables.

Link to comment
Share on other sites

Yes, I figured it had to be something to do with Global Variables!

Mmmmm, I really wasn't that hot at PHP 7 years ago, and I have been pretty wrapped up in the re-building (Construction) of New Orleans since, so I pretty much have forgotten everything I know. This is my first attempt to try and get back into programming, I really need someone to help me along. I know I can be something of a pain in the ass. But when I get rolling their ain't no stoppin me. What you have wrote somewhat makes sense and on the other hand it seems like Greek! Thanks for your input. I really do appreciate it.

Link to comment
Share on other sites

So I am not exactly sure where I would implement the changes you have suggested?

Can you possibly make the appropriate changes to the scripts I have supplied, then I might have a working model that I can emulate and learn from.

I have to use the database call and form post procedure a lot in the project I am building, so just one working model/template should get me started. You appear to be offered me two solutions, which one would you use as a programmer of experience?

Link to comment
Share on other sites

to no avail!

 

Depending on what your current code is and what you saw in front of you when you tried it, that could mean any of a dozen or so different things.

 

What you have done to pin down what your code is doing and at what point your code and data is as expected and at what point it is not?

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.