:: Forum >> Version 2 >>

updateSingleCell.php issue

I realize that this may not be the right place for PHP questions, but since many of you may have already implemented a "updateSingleCell.php" or something similar, I thought you may have had a similar issue.

<?php

    
// Full db user info ...
    
$hostname_connAdmin "localhost";
    
$database_connAdmin "db";
    
$username_connAdmin "db_admin";
    
$password_connAdmin "password";
    
$connAdmin mysql_pconnect($hostname_connAdmin$username_connAdmin$password_connAdmin) or trigger_error(mysql_error(),E_USER_ERROR);
/*
    // Data from $_POST ...
    $Contact_ID = intval($_POST['Contact_ID']);
    $column = $_POST['column'];
    $text = $_POST['text'];
*/    
    // Same data used to troubleshoot, get same error ...
    
$Contact_ID 2;
    
$column "3";
    
$text "Brougham";
    
    
$contactFields = array('Contact_ID','Title','First_Name','Middle_Name','Last_Name','Suffix','Friend_Of','Street','City','State','Zip','Phone','Email');
    
$columnName $contactFields[$column];

    
// Set up query ...
    
$updateSQL "UPDATE contacts_jmsavoy SET `$columnName`=`$text` WHERE Contact_ID=`$Contact_ID`";

    
// Run query ...
    
mysql_select_db($database_connAdmin$connAdmin);
    
$Result1 mysql_query($updateSQL$connAdmin) or die(mysql_error());

?>
 
The error I get is always the same:
Unknown column '2' in 'where clause'  Where '2' is actually the Contact_ID of the contact in the table (see the code please).

Contact_ID does indeed exist in my table as an int(10). I just don't understand ... the column should be "Contact_ID" per my where clause and the value is "2", not a column named "2" -- what am I missing here?

thanks!
Jeremy Savoy
Monday, January 21, 2008
Just to clarify -- in this code example, I am trying to set a contact's middle name to "Brougham". This contact's Contact_ID is 2. Contact_ID is my primary key.
Jeremy Savoy
Monday, January 21, 2008
I guess the problem is because you are using the wrong type of quote character here (`) instead of " or '. The ` char indicates that this is a column name and not a string value.
Alex (ActiveWidgets)
Monday, January 21, 2008
Yes, you are correct Alex - when I surrounded the column values with ' instead of `, things worked properly - THANKS!

// Set up query ...
    
$updateSQL "UPDATE contacts_jmsavoy SET `$columnName`='$text' WHERE `Contact_ID`='$Contact_ID'";
 
Now, the only issue remaining here is that after the php code updates the database, a dialog box pops up with the title: "The page at http://localhost/ says" and then just an empty dialog box.
Jeremy Savoy
Monday, January 21, 2008
And I found that problem as well -- in my javascript function I was issuing alert() with the results from the PHP code .... simple mistake ...
Jeremy Savoy
Monday, January 21, 2008



This topic is archived.

Back to support forum

Forum search