PHP Edit Form Problem

I am creating an edit form in PHP and mysql. For some reason when I click on the link I have created on my display.php page, the edit page it is taking me to doesnt appear to exist (the website cannot be displayed message). The link is <a href='http://bu2003:83/php/systems/edit.php?id=$id'> and it is getting the correct ID and putting in the URL fine.
I have pasted the code for the edit page below. Connection file is good, and the sql queries are good, so i really cannt work out the problem. Any help would be appreciated.


editInfo.php
edit.php
booneballAsked:
Who is Participating?
 
Chris HarteConnect With a Mentor ThaumaturgeCommented:
I do not like the way you are doing your query. Try this. I have use an assoc instead of array just because I prefer them.

$sql = "SELECT * FROM it.system WHERE id='$id' LIMIT 1";

        $sql_result = mysql_query($sql);

        $row_num = mysql_num_rows($sql_result);

        for ($i = 0; $i < $row_num; $i++)
        {
            $row_out[$i] = mysql_fetch_assoc($sql_result);
        }

        foreach($row_out as $row)
        {
            $id = $row["id"];
            //etc.
            print_r($id); //To view the result
        }

Open in new window

0
 
Chris HarteThaumaturgeCommented:
This, from you edit.php, is wrong and I cannot tell what it is you are trying to do.


if ($count > 0)
{
         $row = mysql_fetch_array($sql)){ //Too many parentheses and no closing braces
         $id = $row["id"];


0
 
booneballAuthor Commented:
I fixed that error it was in the area you said. Only problem I am having with it now is that when i try updating changes in the edit form it tells me that the query is empty and consequently nothing happens.
0
 
Ray PaseurCommented:
It is helpful to use the code snippet when posting code.  That way we see the line numbers and can read the code in clear text without having to download it.

Here is "edit."
<?php



include_once("conn.php");

	$id = $_GET['id'];  
	
	// Generate SQL Insert Query
	$sql = mysql_query("SELECT * FROM it.system WHERE id='$id' LIMIT 1");
	$result = mysql_query($sql);
	$count = mysql_num_rows($sql); // count the output amount
    if ($count > 0) {
		$row = mysql_fetch_array($sql)){ 
	
	
	 		 $id = $row["id"];
			 $client_name = $row["client_name"];
			 $supplier = $row["supplier"];
			 $purchased_date = $row["purchased_date"];
			 $warranty_expires = $row["warranty_expires"];
			 $company = $row["company"];
			 $department = $row["department"];
			 $os = $row["os"];
			 $os_serial = $row["os_serial"];
			 $ram = $row["ram"];
			 $processor = $row["processor"];
			 $office_version = $row["office_version"];
			 $office_serial = $row["office_serial"];
			 $additional_software = $row["additional_software"];
			 $user = $row["user"];
			 
	
	?>
    
    <h1 class="h1">Client Machines - Edit Information</h1>
        <form name="form1" action="http://bu2003:83/php/systems/editInfo.php" method="post"><br />

    <table width="90%" border="0" cellspacing="6">
      <tr>
        <td width="22%">Client_Name:</td>
        <td width="78%"><label>
          <input type="text" name="client_name" id="client_name" style="width:50%;" value="<?php echo $client_name; ?>" />
        </label></td>
      </tr>
      <tr>
        <td>Supplier:</td>
        <td><label>
          <input type="text" name="supplier" id="supplier" style="width:50%;" value="<?php echo $supplier; ?>" />
        </label></td>
      </tr>
      <tr>
        <td>Purchased Date:</td>
        <td><label>
          <input type="text" name="purchased_date" id="purchased_date" style="width:50%;" value="<?php echo $purchased_date; ?>" />
        </label></td>
      </tr>
      <tr>
        <td>Warranty Expires:</td>
        <td><label>
          <input type="text" name="warranty_expires" id="warranty_expires" style="width:50%;" value="<?php echo $warranty_expires; ?>" />
        </label></td>
      </tr>
      <tr>
        <td>Company:</td>
        <td><label>
          <select name="company" id="company" <?php echo $company; ?>>
            <option>Hayward Baker</option>
            <option>Victory Legal</option>
          </select>
        </label></td>
      </tr>
      <tr>
        <td>Department:</td>
        <td width="50%"><label>
          <input type="text" name="department" id="department" style="width:50%;" value="<?php echo $department; ?>" />
        </label></td>
      </tr>
      <tr>
        <td>Operating System:</td>
        <td><label>
          <select name="os" id="os"> 
            <option>Vista</option>
            <option>XP</option>
            <option>Windows 7</option>
          </select>
        </label></td>
      </tr>
      <tr>
        <td>Operating System Serial No:</td>
        <td><label>
          <input type="text" name="os_serial" id="os_serial" style="width:50%;" value="<?php echo $os_serial; ?>" />
        </label></td>
      </tr>
      <tr>
        <td>RAM:</td>
        <td><label>
          <input type="text" name="ram" id="ram" style="width:50%;" value="<?php echo $ram; ?>"  />
        </label></td>
      </tr>
      <tr>
        <td>Processor:</td>
        <td><label>
          <input type="text" name="processor" id="processor" style="width:50%;" value="<?php echo $processor; ?>" />
        </label></td>
      </tr>
      <tr>
        <td>Office Version</td>
        <td><label>
          <select name="office_version" id="office_version" <?php echo $office_version; ?> >
            <option>2003</option>
            <option>2007</option>
          </select>
        </label></td>
      </tr>
      <tr>
        <td>Office Serial</td>
        <td><label>
          <input type="text" name="office_serial" id="office_serial" style="width:50%;" value="<?php echo $office_serial; ?>" />
        </label></td>
      </tr>
      <tr>
        <td>Additional Software</td>
        <td><label>
          <input type="text" name="additional_software" id="additional_software" style="width:50%;" value="<?php echo $additional_software; ?>" />
        </label></td>
      </tr>
      <tr>
        <td>User</td>
        <td><label>
          <input type="text" name="user" id="user" style="width:50%;" value="<?php echo $user; ?>" />
        </label></td>
      </tr>
    </table>
    <input type="text" name="id" style="width:0; visibility:hidden;" value="<?php echo $id; ?>" />
  <input type="submit" value="Save Changes" style="width:140px;" />
  </form>
    <p>&nbsp;</p>
    
	</div>

Open in new window


Here is "editinfo."
<?php

include_once("conn.php");


			 
	$id = mysql_real_escape_string($_POST['id']);
    $client_name = mysql_real_escape_string($_POST['client_name']);
	$supplier = mysql_real_escape_string($_POST['supplier']);
	$purchased_date = mysql_real_escape_string($_POST['purchased_date']);
	$warranty_expires = mysql_real_escape_string($_POST['warranty_expires']);
	$company = mysql_real_escape_string($_POST['company']);
	 $department = mysql_real_escape_string($_POST['department']);
    $os = mysql_real_escape_string($_POST['os']);
	$os_serial = mysql_real_escape_string($_POST['os_serial']);
	$ram = mysql_real_escape_string($_POST['ram']);
	$processor = mysql_real_escape_string($_POST['processor']);
	$office_version = mysql_real_escape_string($_POST['office_version']);
	 $office_serial = mysql_real_escape_string($_POST['office_serial']);
    $additional_software = mysql_real_escape_string($_POST['additional_software']);
	$user = mysql_real_escape_string($_POST['user']);
	

	
	

	//Generate SQL Insert Query
	$sql = mysql_query("UPDATE it.system SET client_name='$client_name', supplier='$supplier', purchased_date='$purchased_date', warranty_expires='$warranty_expires', company='$company' department='$department', os='$os', os_serial='$os_serial', ram='$ram', processor='$processor' office_version='$office_version', office_serial='$office_serial', additional_software='$additional_software', user='$user', WHERE id='$id'");

	
	if (!mysql_query($sql,$conn))
  	{
  		die('Error: ' . mysql_error());
  	}
	echo "1 record ameneded";
	
	
?>

Open in new window


You might enjoy this little book.  It is not going to make anyone a professional, but it will help you get some foundation in PHP and MySQL, and will make some of the things like this question much easier for you.
http://www.sitepoint.com/books/phpmysql4/

You might also like this from the PHP web site about how to use HTML forms in PHP.
http://php.net/manual/en/tutorial.forms.php

Best of luck with your project, ~Ray
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.