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 7 of 7

Thread: Update query?

  1. #1
    Regular Coder westmatrix99's Avatar
    Join Date
    Dec 2006
    Location
    South Africa
    Posts
    307
    Thanks
    12
    Thanked 0 Times in 0 Posts

    Question Update query?

    Please tell what I am doing wrong?
    I am using this form to post this page back to itself to unsubscribe users by changing a value from "Y" to "N" based on the email address posted.
    PHP Code:
    <form action="<?php $_SERVER['PHP_SELF']; ?>" method="get" name="modeloform">
    <table width="100%" border="0" cellpadding="2" cellspacing="0" class="table1">
    <tr><td width="9%" valign="top" class="normaltext">Email:</td>
    <td width="32%" valign="top"><input name="email" type="text" size="32"></td>
    <td width="59%" valign="top" class="normaltext">Required field.</td>
    </tr><tr><td>
    <input name="active" type="hidden" id="active" value="N" size="1" checked>
    <input name="StuID" type="hidden" id="StuID" value="<?php echo $_GET['id']; ?>" size="1" checked></td>
    <td colspan=2>
    <input type="submit" value="Submit" ></td></tr></table>
    </form>
    I get errors, when I post this below any idea why?

    PHP Code:
    <?php
    $unsub 
    $_POST['active']
    $mail $_POST['email']
    ?>
    This is the error:
    Parse error: parse error, unexpected T_VARIABLE in c:\Inetpub\wwwroot\stu2stuphp\unsubscribe2.php on line 4
    On line 4:
    $mail = $_POST['email']

    Cheers
    West
    Last edited by westmatrix99; 03-15-2007 at 02:29 PM.
    Thanks for you support!

  • #2
    Senior Coder timgolding's Avatar
    Join Date
    Aug 2006
    Location
    Southampton
    Posts
    1,517
    Thanks
    114
    Thanked 110 Times in 109 Posts
    If your using the get method when you submit the form then you need to use the $_GET variable to recive the data. You are trying to use $_POST when the form used $_GET
    You can not say you know how to do something, until you can teach it to someone else.

  • #3
    Regular Coder westmatrix99's Avatar
    Join Date
    Dec 2006
    Location
    South Africa
    Posts
    307
    Thanks
    12
    Thanked 0 Times in 0 Posts
    Just got it, How !@#$%^^#@@# was that question!!!

    Add a semi-colon like this:

    [Quote];[Quote]

    PHP Code:
    <?php
    $unsub 
    $_POST['active'];
    $mail $_POST['email'];
    ?>
    Thanks for you support!

  • #4
    Regular Coder westmatrix99's Avatar
    Join Date
    Dec 2006
    Location
    South Africa
    Posts
    307
    Thanks
    12
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by timgolding View Post
    If your using the get method when you submit the form then you need to use the $_GET variable to recive the data. You are trying to use $_POST when the form used $_GET
    The reason I use $_GET is I want to see the text I want to get in the URL.
    If I don't want to see then I use $_POST.

    Cool hey.

    Cheers
    West
    Thanks for you support!

  • #5
    Regular Coder westmatrix99's Avatar
    Join Date
    Dec 2006
    Location
    South Africa
    Posts
    307
    Thanks
    12
    Thanked 0 Times in 0 Posts
    Cool now that the error is fixed I still need an update query to connect to my database to update it:

    If the user's active is set to "Y" then it must be set to "N" where the email = the variable.

    Any ideas?

    Cheers
    West
    Thanks for you support!

  • #6
    Regular Coder westmatrix99's Avatar
    Join Date
    Dec 2006
    Location
    South Africa
    Posts
    307
    Thanks
    12
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by westmatrix99 View Post
    Cool now that the error is fixed I still need an update query to connect to my database to update it:
    If the user's active is set to "Y" then it must be set to "N" where the email = the variable.
    Any ideas?
    Cheers
    West
    This is what I got:
    This is what I got but not working!!!
    PHP Code:
    <?php
    //$unsub = $_POST['active'];
    $mail $_POST['email'];
    $colname_rsmail "-1";
    if (isset(
    $_GET['email'])) {
      
    $colname_rsmail = (get_magic_quotes_gpc()) ? $_GET['email'] : addslashes($_GET['email']);
    }
    mysql_select_db($database_cnstu2stu$cnstu2stu);
    $query_rsmail sprintf("SELECT * FROM stulogin WHERE StuEmail = '%s'"$colname_rsmail);
    $rsmail mysql_query($query_rsmail$cnstu2stu) or die(mysql_error());
    $row_rsmail mysql_fetch_assoc($rsmail);
    $totalRows_rsmail mysql_num_rows($rsmail);
    //the update or at least try
    $query "UPDATE stulogin WHERE StuEmail=$mail";
    $r mysql_query ($query);
    if(
    mysql_affected_rows()==1){
    echo 
    'Done';
    } else {
    'Not done';
    }
    mysql_close();
    ?>
    I don't get any message or anyhthing I must have something wrong here.
    Any ideas?
    Cheers
    West
    Thanks for you support!

  • #7
    Regular Coder westmatrix99's Avatar
    Join Date
    Dec 2006
    Location
    South Africa
    Posts
    307
    Thanks
    12
    Thanked 0 Times in 0 Posts
    OK WORKING!!! STUPID GET INSTEAD OF POST!!!
    PHP Code:
    <?php
    $colname_rsmail 
    "-1";
    if (isset(
    $_GET['email'])) {
      
    $colname_rsmail = (get_magic_quotes_gpc()) ? $_GET['email'] : addslashes($_GET['email']);
    }
    mysql_select_db($database_cnstu2stu$cnstu2stu);
    $query_rsmail sprintf("SELECT * FROM stulogin WHERE StuEmail = '%s'"$colname_rsmail);
    $rsmail mysql_query($query_rsmail$cnstu2stu) or die(mysql_error());
    $row_rsmail mysql_fetch_assoc($rsmail);
    $totalRows_rsmail mysql_num_rows($rsmail);
    $query "UPDATE stulogin set Active = 'N' WHERE Active = 'Y' AND StuEmail = '".$_GET['email']."' "
    $r mysql_query ($query);
    /*
    if(mysql_affected_rows()==1){
    echo 'Done';
    } else {
    echo 'Not done';
    }
    */
    mysql_close();
    ?>
    Change to $_GET['email'] from $_POST['email']
    Thank you so much for you help there guys and gals.
    Thanks for you support!


  •  

    Posting Permissions

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