calmchess Posted January 9, 2010 Share Posted January 9, 2010 I'm trying to use a $_POST variable in a mysql update statement but i can't use it for some unknown reason i can echo the variable and it outputs the correct value but i cannot use that variable in anyway in the mysql update statement here is the whole page.Thankyou for your time. <?php session_start(); ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <title>Model login</title> <META name="keywords" content="webcam, webcams, cam, cams, live, girls, free, video, women, lesbians, porn, porno, teen, teens, men, guys, nude, private, pussy, sexy, webcam, camgirls, home cams, video chat, free video, teen, sex, xxx, adult, age ,naked"> <META name="robots" content="index,follow"> <META name="revisit-after" content="10"> <META name="robots" content="all"> <meta name="author" content="root"> <META name="page-topic" content="live sexy web cams and chat"> <META name="copyright" content="privatechatnow.com,2009"> <META name="distribution" content="global"> <META name="ABSTRACT" CONTENT="Privatechatnow.com - Live video cam and chat"> <META name="rating" content="Mature"> <?php include("../secure_php/admin_database.php"); //exchange 3 with 1 //$oldnum =3; //$newnum =1; if(isset($_POST['exchange'])){ $oldnum =$_POST['oldnum']; $newnum =$_POST['newnum']; $current1 = Array(); $currsel1 = mysql_query("select id from page0.page0 where refnum ='$oldnum' AND username!='admin'") or die(mysql_error()); while($currrow1 = mysql_fetch_array($currsel1)){ array_push($current1,$currrow1['id']); } print_r($current1); $test = $current1[0]; $upref11= mysql_query("update page0.page0 SET refnum='$oldnum' where id='$test'") or die(mysql_error()); } ?> </head> <body > <form action="" method="POST"> <table align="left" border="0" cellspacing="0" cellpadding="3"> <?php $_SESSION['refnum0'] = $_POST['oldnum']; $_SESSION['refnum1'] = $_POST['newnum']; ?> <tr><td>Old RefNum:</td><td><input type="text" name="oldnum" maxlength="4" width= "30"value ="<?php if(isset ($_SESSION['refnum0'])){echo $_SESSION['refnum0'];}?>"> </td></tr> <tr><td>New RefNum:</td><td><input type="text" name="newnum" maxlength="4"value ="<?php if(isset ($_SESSION['refnum1'])){ echo $_SESSION['refnum1'];}?>"></td></tr> <tr><td colspan="2" align="right"><input type="submit" name="exchange" value="Change"></td></tr> </table> </form> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/187855-_post-variable-un-useable/ Share on other sites More sharing options...
wildteen88 Posted January 9, 2010 Share Posted January 9, 2010 Are they any errors? _POST variables are treated the same as any other variable. Quote Link to comment https://forums.phpfreaks.com/topic/187855-_post-variable-un-useable/#findComment-991845 Share on other sites More sharing options...
calmchess Posted January 9, 2010 Author Share Posted January 9, 2010 no errors and if i assign the post variable to a session variable then use the session in the update statement everything works fine??????? Quote Link to comment https://forums.phpfreaks.com/topic/187855-_post-variable-un-useable/#findComment-991849 Share on other sites More sharing options...
wildteen88 Posted January 9, 2010 Share Posted January 9, 2010 So what is the problem? How do you know you cant use your post variable in mysql update? Quote Link to comment https://forums.phpfreaks.com/topic/187855-_post-variable-un-useable/#findComment-991880 Share on other sites More sharing options...
jl5501 Posted January 10, 2010 Share Posted January 10, 2010 It looks to me like a problem in your quoting try something like this $currsel1 = mysql_query("select id from page0.page0 where refnum =\'".$oldnum."\' AND username!='admin'") Quote Link to comment https://forums.phpfreaks.com/topic/187855-_post-variable-un-useable/#findComment-992284 Share on other sites More sharing options...
mattal999 Posted January 10, 2010 Share Posted January 10, 2010 It looks to me like a problem in your quoting try something like this $currsel1 = mysql_query("select id from page0.page0 where refnum =\'".$oldnum."\' AND username!='admin'") Actually that won't work. That would output: select id from page0.page0 where refnum=\'123\' AND username!='admin' It should be: $currsel1 = mysql_query("SELECT id FROM page0.page0 WHERE refnum='".$oldnum."' AND username!='admin'"); Quote Link to comment https://forums.phpfreaks.com/topic/187855-_post-variable-un-useable/#findComment-992285 Share on other sites More sharing options...
calmchess Posted January 10, 2010 Author Share Posted January 10, 2010 Mattal999 you are the winner thankyou so much .......weird that select statements work my way but the update staments wouldn't ??? go figure. Quote Link to comment https://forums.phpfreaks.com/topic/187855-_post-variable-un-useable/#findComment-992289 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.