Jump to content

[SOLVED] why doesnt one field update into table??! all others do...


mac007

Recommended Posts

Hello, All:

 

I have this script that SELECTS all correct fields to update into a form and then UPDATES afterwards as well. All works well, thru month of Nov., but when I add to also update the month of Dec. (in update statement: Dec='$Dec'), then it gives an error cause it doesnt update any of them!  If I take if off, then it updates all other months just fine!..

 

Here's the script:

 

<CODE>

 

<table width="30%" border="0" align="center" cellpadding="0" cellspacing="0">

  <tr>

    <td align="center"><h2><strong>UPDATE ACCOUNT:</strong></h2></td>

  </tr>

  <tr>

    <td align="center" valign="top"><?php

 

if (isset($_GET['budgetrecord']))

{

$accountid = $_GET['budgetrecord'];

$selectAccount = mysql_query("SELECT * FROM MEMBERS, ACCOUNTS, BUDGETS WHERE accountid = recordnameid AND id = accountmemberid AND accountmemberid = recordcustid AND email = '$username' AND recordyear = '$year' AND recordid = '$accountid'");

$row_selectAccount = mysql_fetch_array($selectAccount);

if (isset($_POST['updateAccount']))

{

$Jan = $_POST['Jan'];

$Feb = $_POST['Feb'];

$Mar = $_POST['Mar'];

$Apr = $_POST['Apr'];

$May = $_POST['May'];

$Jun = $_POST['Jun'];

$Jul = $_POST['Jul'];

$Aug = $_POST['Aug'];

$Sep = $_POST['Sep'];

$Oct = $_POST['Oct'];

$Nov = $_POST['Nov'];

$Dec = $_POST['Dec'];

$updateQuery = mysql_query("UPDATE BUDGETS SET Jan='$Jan', Feb='$Feb', Mar='$Mar', Apr='$Apr', May='$May', Jun='$Jun', Jul='$Jul', Aug='$Aug', Sep='$Sep', Oct='$Oct', Nov='$Nov', Dec='$Dec' WHERE recordid = '$accountid'");

header("Location: update-testing-VER2.php");

}

?>

 

<form action="#" method="post">

<strong>Account Name:</strong>  <?php echo $row_selectAccount['accountname']; ?>

        <br />

        <strong>Account Year:</strong> <?php echo $row_selectAccount['recordyear']; ?><br />

        <strong>Due Date</strong>: <?php echo $row_selectAccount['accountdue']; ?><br />

        <br />

       

        <table width="75%" border="0" cellspacing="0" cellpadding="0">

  <tr>

    <td align="center">Jan<br />

      <input name="Jan" type="text" value="<?php echo $row_selectAccount['Jan']; ?>" size="6"/></td>

    <td align="center">Feb<br />

        <input name="Feb" type="text" value="<?php echo $row_selectAccount['Feb']; ?>" size="6"/></td>

    <td align="center">Mar<br />

        <input name="Mar" type="text" value="<?php echo $row_selectAccount['Mar']; ?>" size="6"/></td>

    <td align="center">Apr<br />

        <input name="Apr" type="text" value="<?php echo $row_selectAccount['Apr']; ?>" size="6"/></td>

    <td align="center">May<br />

        <input name="May" type="text" value="<?php echo $row_selectAccount['May']; ?>" size="6"/></td>

    <td align="center">Jun<br />

        <input name="Jun" type="text" value="<?php echo $row_selectAccount['Jun']; ?>" size="6"/></td>

    <td align="center">Jul<br />

        <input name="Jul" type="text" value="<?php echo $row_selectAccount['Jul']; ?>" size="6"/></td>

    <td align="center">Aug<br />

        <input name="Aug" type="text" value="<?php echo $row_selectAccount['Aug']; ?>" size="6"/></td>

    <td align="center">Sep<br />

        <input name="Sep" type="text" value="<?php echo $row_selectAccount['Sep']; ?>" size="6"/></td>

    <td align="center">Oct<br />

        <input name="Oct" type="text" value="<?php echo $row_selectAccount['Oct']; ?>" size="6"/></td>

    <td align="center">Nov<br />

        <input name="Nov" type="text" value="<?php echo $row_selectAccount['Nov']; ?>" size="6"/></td>

    <td align="center">Dec<br />

        <input name="Dec" type="text" value="<?php echo $row_selectAccount['Dec']; ?>" size="6"/></td>

  </tr>

</table>

       

        <br />

<input name="updateAccount" type="submit" value="Update Account"/>

</form> <?php

}

?></td>

</tr>

</table>

   

   

</CODE>

 

Appreciate the help...

 

 

Thanks Mchl:

 

I see what you mean... I guess it's cause mysql is reading the "Dec" as "Decimal" and not as referring to my db-field?  how should I call the field in that instance then? put in within single quotes??  like:  'Dec'='$Dec'

 

Thanks...

WOW... that did it; been breaking my head!!  I dont think I have ever used the backticks.. and whenever I saw then I always thougth it was a browser-display thing,  thinking all along they were single-quotes. Woudl that be one of the few times you would use backticks at all??  or is it good habits to always use backticks to refer to db fields??

 

Thanks appreciate the help!!

I guess most important rule is to be consistent. Either use them everywhere, or avoid them everywhere.

 

Backticks are MySQL specific, so if you use them, your code will not be easily portable to other database systems.

 

And of course avoid reserved words. Why not use Dcmb or Dc instead of Dec?

yeah, I guess better to use a different field-name; I was trying to be consistent in my month-naming conventions.. but thanks for pointing out that these backticks are mysql specific, that's important to keep in mind...

 

Thanks again!

Ya use a different column name, back-tics are so overused today, in fact the SQL 2003 standard states back-tic(s) should only be used as a temporary development fix, never in a production environment! Read the "The Relational Model for Database Management" it's a great read. The original Relational Database designer Ted Codd wrote it.

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.