Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 11 of 11
  1. #1
    New Coder
    Join Date
    Aug 2011
    Posts
    52
    Thanks
    0
    Thanked 0 Times in 0 Posts

    MYQSL UPDATE not working

    Can you guys please tell me why this is not updating the database?

    PHP Code:
    <?php 
                
    if(isset($_POST['agent'])){
                    
                    
    $buy_sales_agent $_POST['buyers'];
                    
    $seller_sales_agent $_POST['sellers'];
                    
    $sales_agent $_POST['sales_agent'];
                    
                    
    $query12 " UPDATE lead_partners_pages  "
                               
    " SET buy_sales_agent = $sales_agent, seller_sales_agent = $sales_agent "
                               
    " WHERE partner_id_buyer = $buy_sales_agent, afid_seller_name = $seller_sales_agent ";

               
                    
    mysql_query($query12);
                    
                    
                }else
                {
                    echo 
    "Something went wrong!! you broke the script!<br/>";
                }
    ?>

  • #2
    Senior Coder djm0219's Avatar
    Join Date
    Aug 2003
    Location
    Wake Forest, North Carolina
    Posts
    1,303
    Thanks
    4
    Thanked 204 Times in 201 Posts
    You aren't checking for a failure of the MYSql query so you don't know what's going wrong with it. Your WHERE statement is also not correct. If you want both of those values to be tested to be equal you need to use AND between them not a ,

    Code:
    WHERE partner_id_buyer = $buy_sales_agent AND afid_seller_name = $seller_sales_agent
    Try changing your call to mysql_query to

    PHP Code:
    mysql_query($query12) or die(mysql_error()); 
    Last edited by djm0219; 11-29-2011 at 06:05 PM.
    Dave .... HostMonster for all of your hosting needs

  • #3
    New Coder
    Join Date
    Aug 2011
    Posts
    52
    Thanks
    0
    Thanked 0 Times in 0 Posts
    still not working here is the complete code this is stumping me

    PHP Code:
    <div id="sign_up">
                <div id="hidden_agent" style="font-family:Tahoma, Geneva, sans-serif; font-size:12px;">
                <h1 style="font-size:15px"><strong>Assign Sales Agent to Company</strong></h1>
                <p><strong style="color:#990000;">NOTICE:</strong> you can only assiagn the agent to one buyer or seller company at a time!</p>
                <?php 
                
    if(isset($_POST['agent'])){
                    
                    
    $buy_sales_agent $_POST['buyers'];
                    
    $seller_sales_agent $_POST['sellers'];
                    
    $sales_agent $_POST['sales_agent'];
                    
                    
    $query121 " UPDATE lead_partners_pages  "
                               
    " SET buy_sales_agent = '$sales_agent', seller_sales_agent = '$sales_agent' "
                               
    " WHERE partner_id_buyer = '$buy_sales_agent' AND afid_seller_name = '$seller_sales_agent' ";

               
                    
    $addagent mysql_query($query121) or die(mysql_error()); 
                    
                    if(
    $addagent)
                    {
                        echo
    "<span style=\"color:#11d728;\">It worked!</span<p></p>";
                    }
                    
                    else
                    {
                        echo 
    "<span style=\"color:#11d728;\">Something went wrong!! you broke the script!</span><p></p>";
                    }
                    
                }else
                {
                    echo 
    "<span style=\"color:#11d728;\">Please fill out the info and hit submit.</span><p></p>";
                }
                
    ?>
                <form  method="post" action="">
                    <select name="buyers">
                    <option selected="selected">Select Buying Company</option>
                    <option>CIQFY</option>
                    <?php foreach($PartnerClients as $Partnerclientname): ?>
                    <?php ?>
                            <?php echo "<option>" $Partnerclientname['partner_id_buyer'] . "</option>";?>
                    <?php ?>
                    <?php endforeach; ?>
                    </select>
                    
                    <select name="sellers">
                        <option selected="selected"> Select Selling Company </option>
                        <option>CIQFY</option>
                        <?php foreach($afid_sellerClients as $afid_sellerclientname): ?>
                        <?php ?>
                            <?php echo "<option>" $afid_sellerclientname['afid_seller_name'] . "</option>";  ?>
                        <?php ?>
                        <?php endforeach; ?>
                    </select>
                    <hr/>
                    <label>Sales Agent Name:</label><br/>
                    <input type="text" name="sales_agent"/><br/>
                    <input style="width: 93px; height: 31px; font-size:14px; margin-top:7px" type="submit" name="agent" value="Submit"/>
                </form>
            </div>
            </div>

  • #4
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,933
    Thanks
    79
    Thanked 4,424 Times in 4,389 Posts
    But the *FIRST* thing to do is DEBUG DEBUG DEBUG.

    Why does it seem to me that PHP programmers don't do this automatically??

    Code:
          $query12 = " UPDATE lead_partners_pages  "
                       . " SET buy_sales_agent = $sales_agent, seller_sales_agent = $sales_agent "
                      . " WHERE partner_id_buyer = $buy_sales_agent, afid_seller_name = $seller_sales_agent ";
    
          echo "<hr/>DEBUG SQL: " . $query12 . "<hr/>\n";
    
           ...
    Aside from the missing AND that DJM noted, I would bet that there are also at least some, if not many, missing apostrophes. I would bet that if a field is named afid_seller_name then indeed you are storing a name there. And that would mean you need apostrophes around $seller_sales_agent.

    If you would put in the DEBUG code and show us the results of that, we could tell you for sure. (You also have zero protection against SQL Injection Attacks there, but that's another issue.)
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • #5
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,933
    Thanks
    79
    Thanked 4,424 Times in 4,389 Posts
    Talk about posting at nearly the same time! LOL!

    Okay, so *did* the query die with an error message?

    If not, then show the output of the debug I asked for.
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • #6
    New Coder
    Join Date
    Aug 2011
    Posts
    52
    Thanks
    0
    Thanked 0 Times in 0 Posts
    it did not die it exacted this like of the code

    PHP Code:
    {
    echo
    "<span style=\"color:#11d728;\">It worked!</span<p></p>";


    but once i check the database i don't see anything updated
    Last edited by Atrhick; 11-29-2011 at 07:40 PM.

  • #7
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,933
    Thanks
    79
    Thanked 4,424 Times in 4,389 Posts
    Once again, ADD IN THE DEBUG CODE and show us what it shows you.
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • #8
    New Coder
    Join Date
    Aug 2011
    Posts
    52
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Here is the report I dont see any problems with it

    PHP Code:
    <hr/>DEBUG SQL:  UPDATE lead_partners_pages   SET buy_sales_agent 'Atrhick'seller_sales_agent 'Atrhick'  WHERE partner_id_buyer 'CompareInsuranceQ' AND afid_seller_name 'DataTree' <hr/> 

  • #9
    New Coder
    Join Date
    Aug 2011
    Posts
    52
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I got it to work. I have to make another query and run it in tandem

    PHP Code:
    <?php 
                
    if(isset($_POST['agent'])){
                    
                    
    $buy_sales_agent $_POST['buyers'];
                    
    $seller_sales_agent $_POST['sellers'];
                    
    $sales_agent $_POST['sales_agent'];
                    
                    
    $query121 " UPDATE lead_partners_pages  "
                               
    " SET buy_sales_agent = '$sales_agent' "
                               
    " WHERE partner_id_buyer = '$buy_sales_agent' ";
                               
                    
    $query122 " UPDATE lead_partners_pages  "
                               
    " SET seller_sales_agent = '$sales_agent' "
                               
    " WHERE afid_seller_name = '$seller_sales_agent' ";

               
                    
    $addagent1 mysql_query($query121) or die(mysql_error()); 
                    
    $addagent2 mysql_query($query122) or die(mysql_error()); 
                    
                    if(
    $addagent1 && $addagent2)
                    {
                        echo 
    "<span style=\"color:#11d728;\">The recoed has been updated!</span><p></p>";
                    }
                    
                    else
                    {
                        echo 
    "<span style=\"color:#11d728;\">Something went wrong!! you broke the script!</span><p></p>";
                    }
                    
                }else
                {
                    echo 
    "<span style=\"color:#11d728;\">Please fill out the info and hit submit.</span><p></p>";
                }
                
    ?>

  • #10
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,933
    Thanks
    79
    Thanked 4,424 Times in 4,389 Posts
    AHHH! Yes, UPDATE affects *ALL* records in the same way.

    So if you didn't have any *one* record that met both of the ANDed conditions, then of course no records would be affected.
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • #11
    New Coder
    Join Date
    Aug 2011
    Posts
    52
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I guess I am getting better with MYSQL, in August when i joined here i was not good at all with MySQL now I am getting it

    I just have to get my head around relational databases now.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •