Hey... nice to see I'm not bugging you enough for you to avoid my post.....

Anyway (since your here and all), I am having trouble getting my MySql function to update.... (most likely its a typo that I am blind to)... So here goes:

<EditCompany.php>

<?php
$modify = $_GET['id'];
?>
<form method="POST" action="EditCompany2.php">
<input type="hidden" name="ModifyID" Value="<?php
echo $modify;
?>">
 <table cellspacing="0" cellpadding="2" border="1">
    <tr>
        <td>Company Name</td>
    </tr>

<?php
include '../includes/Connect.php';
mysql_select_db("$dbDatabase", $db) or die ("Couldn't select the database.");
$result = mysql_query("SELECT * FROM company WHERE Company_id = '$modify'");
if (!$result) {
   echo 'Could not run query: ' . mysql_error();
   exit;
}
$row = mysql_fetch_row($result);



echo '<tr>
        <td><input type="text" name="ModifyCompany" size="20" value="';
echo $row[1];
echo '"></td>';
echo '"></tr>';
?>
</table>
<input type="submit" value="Modify" />

<EditCompany2.php>

<?php
include 'includes/Header.php';
//Get Post Information
$ModifyID = $_POST['ModifyID'];
$ModifyCompany = $_POST['ModifyCompany'];

//Connect to Database
include '../includes/connect.php';
mysql_select_db("$dbDatabase", $db) or die ("Couldn't select the database.");

$Query =mysql_query("UPDATE company SET company_name='$ModifyCompany' WHERE user_id='$ModifyID'");
header( "Location: ValidURL" );
?>

    I dont really see an error, unless it is the space here:

    $result = mysql_query("SELECT * FROM company WHERE Company_id = '$modify'"); 
    
    //should be
    
    $result = mysql_query("SELECT * FROM company WHERE Company_i ='".$modify."'"); 

    If you are getting blank inserts, it's probably becuase the variables aren't being read due to the double quotes.

    Should be:

    $Query = mysql_query("UPDATE company SET company_name='".$ModifyCompany."' WHERE user_id='".$ModifyID."'");

    edit
    $modify could also be empty, check that like this:

    if(!empty($_GET['id'])){ 
    $modify = $_GET['id']; 
    } else {
    echo 'Could not get ID.'; exit;
    }

      Okay, I forgot to mention that it must be somewhere in EditCompany2.php because EditCompany populates the fields properly, but once it submits the database doesn't recieve any changes... 🙁

      I quickly tried your changes to EditCompany2 to no avail... (I am at work now, will get back at er tomorrow)..

      Thanks!

        Try this:

        <?php
        include ('includes/Header.php');
        //Get Post Information
        $modify_ID = $_POST['ModifyID'];
        $modify_company = $_POST['ModifyCompany'];
        
        if((empty($modify_id)) || (empty($modify_company))){
        	echo 'There was an errer receiving the posted information.';
        	exit;
        }
        
        //Connect to Database
        include '../includes/connect.php';
        mysql_select_db($dbDatabase, $db) or die ("Couldn't select the database.");
        
        if((mysql_query("UPDATE company SET company_name='".$modify_company."' WHERE user_id='".$modify_ID."'")) !== FALSE){
        	header( "Location: ValidURL" );
        } else {
        	echo 'There wasn an error updating the database.';
        	exit;
        }
        ?>  

          Like a charm... Thanks 🙂

          I was just being very stupid, I have a similar script that updates a different table and i forgot to change the "where user_id=", but what you gave me allowed more debugging... I threw mysql_error (); in there and bada-bing-badda-boom I knew where i was going wrong

          Cheers,
          Thanks again!
          (I did fix the if empty string.... (the variable changed from upper case to lowercase)

            Write a Reply...