Jump to content

[SOLVED] Update MySQL with PHP errors out with strings of numbers and letters


woocha

Recommended Posts

HAPPY NEW YEAR GUYS !!

I am having a hard time understanding why this little script only works when the variable $item_numb is a string of numbers, not when it is letters and numbers.  Here is my code, I hope you guys can tell me what I am not seeing or somethins I have done wrong.  The information comes from a form that a user would fill out.  

 

  if ( $action == "update" )
  {
  $merchadmin = $_POST['merchadmin'];
  $item_numb = $_POST['item_numb'];
  $merchdir = $_POST['merchdir'];
      
  require  ("db_connect.php");
  	$query = "update catalog set ";
   $query .= " meta_item_title=\"$meta_item_title\", ";
   $query .= " meta_item_key=\"$meta_item_key\", ";
   $query .= " meta_item_dec=\"$meta_item_dec\", ";
	$query .= " file_modified = now()";
	$query .= " where merchant=$merchadmin and item_numb=$item_numb";
         $result = mysql_query( $query);
}
       echo mysql_error();

 

the SQL error I am getting is this:

Unknown column 'LDUTTS0011' in 'where clause'

LDUTTS0011 equals my test item number.

 

Thanks for the help :)

Link to comment
Share on other sites

What data type is item_numb in the database?

 

If it is anything other than int, then you need to have single quotes around your variable:

 

$query .= " where merchant=$merchadmin and item_numb='$item_numb'";

 

If it is an int, then you shouldn't be letting the user submit alphanumeric values.

Link to comment
Share on other sites

Unless you have a VERY good reason for using text as the data type for an item identifier change it to a VARCHAR that is acceptably long.  Using TEXT will kill performance as the table gets larger and use increases.  Not to mention if you have an index on that field (and you probably should since you are using it in your where clause and it's a product identifier) the index for a TEXT field will be huge.

Link to comment
Share on other sites

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.