Jump to content

Recommended Posts

Hey guys,

 

I am having some trouble writing an edit page for this project I am working on. Kinda noobish sorry

 

Here is my thought path though...

 

I would like to allow the users to select a tuple with my edit button. Then I want to check the db for a match, then use an if statement that will echo a form to edit the tuple if it was found in the db. I dont know what the right way to do this is but here is what I have.

 

I am now trying to figure out how to make the first form tell the second form which tuple was chosen. I am figuring I have to post the selected tuple then use get to bring it down for use in the rest of  the code.

<?php
session_start();
?>

<?php  
		  if ($_SESSION['username'])
  {
echo "You are logged in as <u>".$_SESSION['username']."</u>!</p>";
}
else 
{
	echo "Log In";
}

?>
 <?php
if ($_SESSION['username'])
  {$con = mysql_connect("localhost","root","c3rb3ru5");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }
mysql_select_db("gpj_asset", $con);
if(!empty($_GET["start"])){
    $start  = $_GET['start'];// To take care global variable if OFF
}else{
    $start   = 0;
}
if(!($start > 0)) { // This variable is set to zero for the first page
    $start = 0;
}

$eu   = ($start - 0);
$limit           = 5; // No of records to be shown per page.
$whathis      = $eu + $limit;
$back          = $eu - $limit;
$next          = $eu + $limit;

// to check the total number of records
$query         = mysql_query(" SELECT * FROM assets 
					WHERE location='Auburn Hills' SORT BY asset_id ASC ") or die (mysql_error());
$total_rows     = mysql_num_rows($query);

//select the record with limitation
$query         = mysql_query(" SELECT * FROM assets 
					WHERE location='Auburn Hills' SORT BY asset_id ASC limit $eu, $limit ") or die (mysql_error());

//code for previous
if($back >=0) {
echo "<a href='AH.php?start=$back'><font face='Verdana' size='2'>PREV</font></a>  ";
}
while($row = mysql_fetch_array($result))
	{
  echo "<form action = \'ah_select.php\'. method=\"POST\">";
  echo "<table border='1'>";
  echo "<tr>";
  echo "<td>" . $row['asset_id'] . "</td>";
  echo "<td>" . $row['location'] . "</td>";
  echo "<td>" . $row['active'] . "</td>";
  echo "<td>" . $row['platform'] . "</td>";
  echo "<td>" . $row['make'] . "</td>";
  echo "<td>" . $row['model'] . "</td>"; 
  echo "<td>" . $row['ram'] . "</td>";
  echo "<td>" . $row['warranty'] . "</td>";
  echo "<td>" . $row['active_user'] . "</td>";
  echo "<td>" . $row['notes'] . "</td>";
  echo "<input class=\"buttonSubmit\" type=\"submit\" name=\"select\" value=\"Edit\">";
  echo "</tr>";
  echo "</table>";
  echo "</form>";
	}
//code for the number of page with links
$i    = 0;
$x    = 1;
for($i=0;$i < $total_rows;$i=$i+$limit){
if($i != $eu){
    echo "<a href='AH.php?start=$i'><font face='Verdana' size='2'>$x</font></a> ";
}else { 
    echo "<font face='Verdana' size='4' color=red>$x</font>";
} // Current page is not displayed as link and given font color red

$x    = $x+1;
}
//code for next
if($whathis < $total_rows) {
echo "<a href='AH.php?start=$next'><font face='Verdana' size='2'>NEXT</font></a>";
}   
	}
 else  echo "please log in";
?>


 <?php 

 if ($_SESSION['username'])
  { 

{$con = mysql_connect("localhost","root","c3rb3ru5");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }

mysql_select_db("gpj_asset", $con);
  

//process the input into variables
$submit1 = $_POST['select'];
$submit2 = $_POST['change'];
$asset_id = strtolower(strip_tags(trim($_POST['asset_id'])));
$location = strip_tags(trim($_POST['location']));
$active = strip_tags(trim($_POST['status']));
$platform  = strip_tags(trim($_POST['type']));
$make  = strip_tags(trim($_POST['make']));
$model = strip_tags(trim($_POST['model']));
$Ram = strip_tags(trim($_POST['Ram']));
$warranty = strip_tags(trim($_POST['warranty']));
$active_user = strip_tags(trim($_POST['active_user']));
$notes = strip_tags(trim($_POST['notes']));

if($submit1)
{
// code to get the selected id to edit


echo " <form action = \'ah_edit.php\'. method=\"POST\">
<table border=1>
  

<tr><td>Location: *</td>
<td> <select name=\"location\"> 
<option value =\"Auburn Hills\"> Auburn Hills</option>
<option value =\"Los Angeles\"> Los Angeles</option>
<option value =\"San Carlos\"> San Carlos</option>
<option value =\"Boston\"> Boston</option>
<option value =\"Nashville\"> Nashville</option>
</td></tr>

<tr><td>Status: *</td>
<td> <select name=\"status\">
<option value =\"active\"> active</option>
<option value =\"spare\"> spare</option>
</td>

<td>Type: *</td>
<td> <select name=\"type\">
<option value =\"desktop\"> desktop</option>
<option value =\"laptop\"> laptop</option>
<option value =\"server\"> server</option>
</td></tr>

<td>Manufacturer:</td>
<td> <select name=\"make\">
<option value =\"Apple\"> Apple</option>
<option value =\"Dell\"> Dell</option>
<option value =\"HP\"> HP</option>
<option value =\"IBM\"> IBM</option>
<option value =\"Lenovo\"> Lenovo</option>
<option value =\"Custom\"> Custom</option>
</td>

<td>Model: *</td>
<td> <select name=\"model\">
<option value =\"MB Pro\">MacBook Pro</option>
<option value =\"Mac Pro\">Mac Pro</option>
<option value =\"Dimension D-620\">Dimension D-620</option>
<option value =\"Dimension D-630\">Dimension D-630</option>
<option value =\"Optiplex 745\">Optiplex 745</option>
<option value =\"Optiplex 780\">Optiplex 780</option>
<option value =\"Dimension M90\">Dimension M90</option>
<option value =\"Dimension M6500\">Dimension M6500</option>
<option value =\"Dimension E6410\">Dimension E6410</option>
<option value =\"Dimension E6420\">Dimension E6420</option>
</td>

<td>Amount of Ram:</td>
<td> <select name=\"Ram\">
<option value =\"not sure\"> not sure</option>
<option value =\"Under 1GB\"> under 1GB</option>
<option value =\"1 GB\"> 1 GB</option>
<option value =\"2 GB\"> 2 GB</option>
<option value =\"3 GB\"> 3 GB</option>
<option value =\"4 GB\"> 4 GB</option>
<option value =\"8 GB\"> 8 GB</option>
<option value =\"16 GB\"> 16 GB</option>
<option value =\"24 GB\"> 24 GB</option>
<option value =\"Above 24GB\"> Above 24GB</option>
</td></tr>

<tr><td>warranty:</td><td> <input type=\"text\" name=\"warranty\" maxlength=\"20\" size=\"20\"></td>
<td>username:</td><td> <input type=\"text\" name=\"active_user\" maxlength=\"8\" size=\"8\"></td></tr>

<tr><td>notes:</td><td> <input type=\"text\" name=\"notes\" maxlength=\"45\" size=\"45\"></td></tr>
</table>
<br>
<input class=\"buttonSubmit\" type=\"submit\" name=\"change\" value=\"Edit\">
</form>";
}
?>

<?php
if ($submit2)
{

// Check for an existing asset
$runThis = "SELECT * FROM assets WHERE asset_id = '$asset_id'";
//find the amount that match
$count = mysql_num_rows($runThis);


//Validate input
$error = false;
if ($count!=1)
{
 $error = "Don't Be rediculous, enter an existing id...";
}

else
{
   //No input errors, run query
$query = "UPDATE assets 
SET location = '$location',
SET active = '$active',
SET platform = '$platform',
SET make = '$make', 
SET model = '$model',
SET Ram = '$Ram',
SET warranty = '$warranty',
SET active_user = '$active_user', 
SET notes = '$notes')";

   $result = mysql_query($query);	
   if (!$result)
       {
	   die('Invalid query: ' . mysql_error());
       }   
}
}

//Check if any errors occured
if($error !== false)
{
    echo "<span style=\"color:red\"> {$error}</pan>\n";
}
else
{
    echo "Asset Added Successfully";
}
  }
}
  
  else echo " <form action=connect.php method=POST>
<h3>Please Login <img src=\"images/0.410.gif\" /></h3>

<table border=0>
<tr><td>Username:</td><td> <input type=text name=username></td></tr>
<tr><td>Password:</td><td> <input type=password name=password></td></tr></table>
<input class=buttonSubmit type=submit name=submit value=submit></form>";
  
?>

 

 

Thanks,

 

Clint

Ok well I dont know what I am doing wrong here

  <?php  
		  if ($_SESSION['username'])
  {
echo "You are logged in as <u>".$_SESSION['username']."</u>!</p>";
}
else 
{
	echo "Log In";
}

?>
 <?php
if ($_SESSION['username'])
  {$con = mysql_connect("localhost","root","c3rb3ru5");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }
mysql_select_db("gpj_asset", $con);
if(!empty($_GET["start"])){
    $start  = $_GET['start'];// To take care global variable if OFF
}else{
    $start   = 0;
}
if(!($start > 0)) { // This variable is set to zero for the first page
    $start = 0;
}

$eu   = ($start - 0);
$limit           = 5; // No of records to be shown per page.
$whathis      = $eu + $limit;
$back          = $eu - $limit;
$next          = $eu + $limit;

// to check the total number of records
$query         = mysql_query(" SELECT * FROM assets 
					WHERE location='Auburn Hills' SORT BY asset_id ASC ") or die (mysql_error());
$total_rows     = mysql_num_rows($query);

//select the record with limitation
$query         = mysql_query(" SELECT * FROM assets 
					WHERE location='Auburn Hills' SORT BY asset_id ASC limit $eu, $limit ") or die (mysql_error());

//code for previous
if($back >=0) {
echo "<a href='AH.php?start=$back'><font face='Verdana' size='2'>PREV</font></a>  ";
}
while($row = mysql_fetch_array($result))
	{
  echo "<form method=\"get\" action=\'ah_select.php\'>";
  echo "<table border='1'>";
  echo "<tr>";
  echo "<td>" . $row['asset_id'] . "</td>";
  echo "<td>" . $row['location'] . "</td>";
  echo "<td>" . $row['active'] . "</td>";
  echo "<td>" . $row['platform'] . "</td>";
  echo "<td>" . $row['make'] . "</td>";
  echo "<td>" . $row['model'] . "</td>"; 
  echo "<td>" . $row['ram'] . "</td>";
  echo "<td>" . $row['warranty'] . "</td>";
  echo "<td>" . $row['active_user'] . "</td>";
  echo "<td>" . $row['notes'] . "</td>";
  echo "<input class=\"buttonSubmit\" type=\"submit\" name=\"select\" value=\"Edit\">";
  echo "</tr>";
  echo "</table>";
  echo "</form>";
	}
//code for the number of page with links
$i    = 0;
$x    = 1;
for($i=0;$i < $total_rows;$i=$i+$limit){
if($i != $eu){
    echo "<a href='AH.php?start=$i'><font face='Verdana' size='2'>$x</font></a> ";
}else { 
    echo "<font face='Verdana' size='4' color=red>$x</font>";
} // Current page is not displayed as link and given font color red

$x    = $x+1;
}
//code for next
if($whathis < $total_rows) {
echo "<a href='AH.php?start=$next'><font face='Verdana' size='2'>NEXT</font></a>";
}   
	}
 else  echo "please log in";
?>


 <?php 

 if ($_SESSION['username'])
  { 

{$con = mysql_connect("localhost","root","c3rb3ru5");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }

mysql_select_db("gpj_asset", $con);
  

//process the input into variables
$submit1 = $_POST['select'];
$submit2 = $_POST['change'];
$asset_id = strtolower(strip_tags(trim($_POST['asset_id'])));
$location = strip_tags(trim($_POST['location']));
$active = strip_tags(trim($_POST['status']));
$platform  = strip_tags(trim($_POST['type']));
$make  = strip_tags(trim($_POST['make']));
$model = strip_tags(trim($_POST['model']));
$Ram = strip_tags(trim($_POST['Ram']));
$warranty = strip_tags(trim($_POST['warranty']));
$active_user = strip_tags(trim($_POST['active_user']));
$notes = strip_tags(trim($_POST['notes']));

if($submit1)
{
// code to get the selected id to edit
 $idvar = $_GET["asset_id"];

echo " <form action = \'ah_edit.php\'. method=\"POST\">
<table border=1>
  

<tr><td>Location: *</td>
<td> <select name=\"location\"> 
<option value =\"Auburn Hills\"> Auburn Hills</option>
<option value =\"Los Angeles\"> Los Angeles</option>
<option value =\"San Carlos\"> San Carlos</option>
<option value =\"Boston\"> Boston</option>
<option value =\"Nashville\"> Nashville</option>
</td></tr>

<tr><td>Status: *</td>
<td> <select name=\"status\">
<option value =\"active\"> active</option>
<option value =\"spare\"> spare</option>
</td>

<td>Type: *</td>
<td> <select name=\"type\">
<option value =\"desktop\"> desktop</option>
<option value =\"laptop\"> laptop</option>
<option value =\"server\"> server</option>
</td></tr>

<td>Manufacturer:</td>
<td> <select name=\"make\">
<option value =\"Apple\"> Apple</option>
<option value =\"Dell\"> Dell</option>
<option value =\"HP\"> HP</option>
<option value =\"IBM\"> IBM</option>
<option value =\"Lenovo\"> Lenovo</option>
<option value =\"Custom\"> Custom</option>
</td>

<td>Model: *</td>
<td> <select name=\"model\">
<option value =\"MB Pro\">MacBook Pro</option>
<option value =\"Mac Pro\">Mac Pro</option>
<option value =\"Dimension D-620\">Dimension D-620</option>
<option value =\"Dimension D-630\">Dimension D-630</option>
<option value =\"Optiplex 745\">Optiplex 745</option>
<option value =\"Optiplex 780\">Optiplex 780</option>
<option value =\"Dimension M90\">Dimension M90</option>
<option value =\"Dimension M6500\">Dimension M6500</option>
<option value =\"Dimension E6410\">Dimension E6410</option>
<option value =\"Dimension E6420\">Dimension E6420</option>
</td>

<td>Amount of Ram:</td>
<td> <select name=\"Ram\">
<option value =\"not sure\"> not sure</option>
<option value =\"Under 1GB\"> under 1GB</option>
<option value =\"1 GB\"> 1 GB</option>
<option value =\"2 GB\"> 2 GB</option>
<option value =\"3 GB\"> 3 GB</option>
<option value =\"4 GB\"> 4 GB</option>
<option value =\"8 GB\"> 8 GB</option>
<option value =\"16 GB\"> 16 GB</option>
<option value =\"24 GB\"> 24 GB</option>
<option value =\"Above 24GB\"> Above 24GB</option>
</td></tr>

<tr><td>warranty:</td><td> <input type=\"text\" name=\"warranty\" maxlength=\"20\" size=\"20\"></td>
<td>username:</td><td> <input type=\"text\" name=\"active_user\" maxlength=\"8\" size=\"8\"></td></tr>

<tr><td>notes:</td><td> <input type=\"text\" name=\"notes\" maxlength=\"45\" size=\"45\"></td></tr>
</table>
<br>
<input class=\"buttonSubmit\" type=\"submit\" name=\"change\" value=\"Edit\">
</form>";
}
?>

<?php
if ($submit2)
{

// Check for an existing asset
$runThis = "SELECT * FROM assets WHERE asset_id = '$idvar'";
//find the amount that match
$count = mysql_num_rows($runThis);


//Validate input
$error = false;
if ($count!=1)
{
 $error = "Don't Be rediculous, enter an existing id...";
}

else
{
   //No input errors, run query
$query = "UPDATE assets 
SET location = '$location',
SET active = '$active',
SET platform = '$platform',
SET make = '$make', 
SET model = '$model',
SET Ram = '$Ram',
SET warranty = '$warranty',
SET active_user = '$active_user', 
SET notes = '$notes'
WHERE asset_id = $idvar";

   $result = mysql_query($query);	
   if (!$result)
       {
	   die('Invalid query: ' . mysql_error());
       }   
}
}

//Check if any errors occured
if($error !== false)
{
    echo "<span style=\"color:red\"> {$error}</pan>\n";
}
else
{
    echo "Asset Updated Successfully";
}
  }
}
  
  else echo " <form action=connect.php method=POST>
<h3>Please Login <img src=\"images/0.410.gif\" /></h3>

<table border=0>
<tr><td>Username:</td><td> <input type=text name=username></td></tr>
<tr><td>Password:</td><td> <input type=password name=password></td></tr></table>
<input class=buttonSubmit type=submit name=submit value=submit></form>";
  
?>

 

Not sure if this has anything to do with your current problem, but if you revisit your last thread in the forum, you will find that someone pointed out that in your previous code (and also in the current code in this thread), that you are not executing the SELECT query that is checking if an asset already exists or not.

 

Someone also pointed out in that previous thread that you should have the error_reporting/display_errors settings set to specific values to get php to help you.

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.