...

View Full Version : Update query?



westmatrix99
03-15-2007, 12:12 PM
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.

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

timgolding
03-15-2007, 02:34 PM
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

westmatrix99
03-15-2007, 02:39 PM
Just got it, How !@#$%^^#@@# was that question!!!

Add a semi-colon like this:

[Quote];[Quote]



<?php
$unsub = $_POST['active'];
$mail = $_POST['email'];
?>

westmatrix99
03-15-2007, 02:42 PM
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

westmatrix99
03-15-2007, 02:46 PM
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

westmatrix99
03-15-2007, 03:45 PM
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
//$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

westmatrix99
03-15-2007, 04:25 PM
OK WORKING!!! STUPID GET INSTEAD OF POST!!!


<?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.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum