Jump to content

Recommended Posts

I'm looking for a password script to keep out the regular user but I have searched through the internet most of today found a few but everytime I try to add them into this script they dont work.

 

I would like a small login box where it gives u access to this page otherwize your cant access it. I'm stuck at the moment :(

 

I have little php knowledge

 

<?php 
$host="xxxxxxx"; // Host name  
$username="xxxx"; // Mysql username  
$password="xxxxx"; // Mysql password  
$db_name="xxxxx"; // Database name  
$tbl_name="xxxxxx"; // Table name  

// Connect to server and select databse. 
mysql_connect("$host", "$username", "$password")or die("cannot connect");  
mysql_select_db("$db_name")or die("cannot select DB"); 

$sql="SELECT * FROM $tbl_name ORDER BY scan ASC"; 

$result=mysql_query($sql); 

$count=mysql_num_rows($result); 

?> 
<table align="center" width="100%" border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td><table width="100%" border="0" cellspacing="3" cellpadding="0">
  <tr>
    <td><img src="sclogo.gif" width="210" height="29"></td>
  </tr>
</table>

<form name="form1" method="post" action=""> 
<table border="0" cellpadding="2" cellspacing="2"> 
<tr> 
<td width="35"  nowrap="nowrap" bgcolor="391d4c"><font color="#6cba00" size="1" face="Verdana">Scan</font></td> 
<td width="250"  nowrap="nowrap" bgcolor="391d4c"><font color="#6cba00" size="1" face="Verdana">Manufacturer</font></td> 
<td width="250"  nowrap="nowrap" bgcolor="391d4c"><font color="#6cba00" size="1" face="Verdana">Description </font></td> 
<td  width="45"  nowrap="nowrap" bgcolor="391d4c"><font color="#6cba00" size="1" face="Verdana">Code</font></td> 
<td width="200" nowrap="nowrap" bgcolor="391d4c"><font color="#6cba00" size="1" face="Verdana">Part Number</font></td> 
<td width="60" nowrap="nowrap" bgcolor="391d4c" align="center"><font color="#6cba00" size="1" face="Verdana">Delete</font></td> 
</tr> 
<?php 
while($rows=mysql_fetch_array($result)){ 
?> 
<tr class="data"> 
<td><? echo $rows['scan']; ?></td> 
<td><? echo $rows['manufacturer']; ?></td> 
<td><? echo $rows['description']; ?></td> 
<td><? echo $rows['code']; ?></td> 
<td><? echo $rows['partno']; ?></td>
<td align="center"><input name="checkbox[]" type="checkbox" id="checkbox[]" value="<? echo $rows['id']; ?>"></td> 
</tr> 
<?php 
} 
?> 
<tr> 
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td align="center"  class="data"><input name="delete" type="submit" id="delete" value="Delete"></td>
</tr> 
<?php

if(isset($_POST['delete']))
{
foreach($_POST['checkbox'] as $row_id)
        {
                $sql = "DELETE FROM $tbl_name WHERE id='$row_id'";
                $result = mysql_query($sql);
                if($result === FALSE)
                        die("Error occured deleting row ".$row_id."!");
        }
        echo "<meta http-equiv=\"refresh\" content=\"0;URL=sc_testing_with_delete.php\">"; 
} 

?>
</table> 
</form> 
<?php
if (!isset($_POST['submit'])) {
?>
<form action="" method="post">
<table border="0" cellpadding="2" cellspacing="2">
	<tr>
			<td width="35" nowrap="nowrap" bgcolor="391d4c"><font color="#6cba00" size="1" face="Verdana">Scan</font></td>
    		<td width="250" nowrap="nowrap" bgcolor="391d4c"><font color="#6cba00" size="1" face="Verdana">Manufacturer</font></td>
    		<td width="250" nowrap="nowrap" bgcolor="391d4c"><font color="#6cba00" size="1" face="Verdana">Description</font></td>
    		<td width="45" nowrap="nowrap" bgcolor="391d4c"><font color="#6cba00" size="1" face="Verdana">Code</font></td>
    		<td width="200" nowrap="nowrap" bgcolor="391d4c"><font color="#6cba00" size="1" face="Verdana">Part number</font></td>
		    		<td width="60" nowrap="nowrap" bgcolor="391d4c"><font color="#6cba00" size="1" face="Verdana">Submit</font></td>
</tr>
	<tr class="data">
			<td ><font color="#6cba00" size="1" face="Verdana"><input name="scan" type="text" size="5" maxlength="4" class="data"></font></td>
    		<td><font color="#6cba00" size="1" face="Verdana"><input name="manufacturer" type="text" class="data" size="40">
    		</font></td>
    		<td><font color="#6cba00" size="1" face="Verdana"><input name="description" type="text" class="data" size="40">
    		</font></td>
    		<td><font color="#6cba00" size="1" face="Verdana"><select name="code" class="data">
  <option value="1">1</option>
  <option value="2">2</option>
  <option value="3">3</option>
  <option value="4">4</option>
  <option value="5">5</option>
  <option value="6">6</option>
  <option value="7">7</option>
  <option value="8">8</option>
  <option value="9">9</option>
</select></font></td>
    		<td><font color="#6cba00" size="1" face="Verdana"><input name="partno" type="text" class="data" size="32">
    		</font></td>
		<td><font color="#6cba00" size="1" face="Verdana"><input type="submit" name="submit" value="Add Part" class="data">
</font></td>
</tr>
</table>
</form>

<?php
} else {
$scan = $_POST['scan'];
$manufacturer = $_POST['manufacturer'];
$description = $_POST['description'];
$code = $_POST['code'];
$partno = $_POST['partno'];
mysql_query("INSERT INTO scontrol (scan, manufacturer, description, code, partno) VALUES ('$scan', '$manufacturer', '$description', '$code', '$partno')");
echo "<br><p class=\"style1\">";
echo "The new part has been added to the database!!";
echo "<br>";
echo "<br>";
echo "<a href=\"sc_testing_with_delete.php\" title=\"Sc_testing_with_delete page\">Click here to add another part</a><br/>";
echo "</p>";
}
?>

</td>
  </tr>
</table>
<p> </p>

<?php

}

?>

Link to comment
https://forums.phpfreaks.com/topic/71826-password-script-to-my-code/
Share on other sites

  • 2 weeks later...

You have a lot of code everywhere, I have a couple tips that might help you out.

 

1st Create a connect.php file that handles the database connetion

2nd Do most of you coding on top above the doctype when you can and do forget to use functions when you can

3rd When doing a query and looping through to generate HTML keep the select and result with the while loop it will be easier to read

4th Use sessions to maintain login information and create a file that checks the login and keep that on top of the page.

 

I hope this helped you out. :)

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.