law Posted January 19, 2008 Share Posted January 19, 2008 ok *disclaimer* I am literally reading "php bible" and trying to teach myself php.. i have no friends who know php and its the first real "language" im learning (html doesnt count im sure).. so please don't assume i know ANYTHING im 99% sure i won't.. thanks i did a search but i don't know what would be a good string to get the results that would give me my answer hope this hasn't been covered before! Here is my problem 1) i need a mysql_query to pull an user ID out of a table using a USER NAME 2) once i have the user ID i need to change an already existing value in that row Notes about my site When a user logs into the site that i have made i use their username as their session id.. so i can pull that up from any where (is this a good idea? or are there security issues with this? im not using cookies and im not _POSTing anything.) i am familiar with includes so don't worry i have all of the connections to the database and ect... working My code SO FAR $tmp = _session id = user's nickname when they login <?php include_once("./dbconfig.php"); //echo "$tmp"; $result = mysql_query("SELECT id FROM members WHERE nickname = '$tmp'"); $num=mysql_num_rows($result); //echo "$result"; if ($num >0){ $insert = mysql_query("INSERT INTO $tbl_members WHERE nickname = '$tmp' (payment) VALUE('1')"); // NO IDEA WHAT THIS QUERY SHOULD BE TO MODIFY THE PAYMENT FIELDS VALUE echo "$insert"; }else { echo "An error has occured. My coding has a flaw in it."; } ?> Link to comment https://forums.phpfreaks.com/topic/86724-php-mysql-query-to-select-a-row/ Share on other sites More sharing options...
revraz Posted January 19, 2008 Share Posted January 19, 2008 Not a bad start First I'm going to assume this is all your code. So with that, you need to define $tmp and $tbl_members Next, once you find the row id, you want to do a UPDATE sql command on it, not a INSERT. Link to comment https://forums.phpfreaks.com/topic/86724-php-mysql-query-to-select-a-row/#findComment-443195 Share on other sites More sharing options...
darkfreaks Posted January 19, 2008 Share Posted January 19, 2008 <?php $insert = mysql_query ("UPDATE $tbl_members SET nickname = '$tmp' WHERE nickname = '$tmp' (payment) VALUE('1')";?> Link to comment https://forums.phpfreaks.com/topic/86724-php-mysql-query-to-select-a-row/#findComment-443203 Share on other sites More sharing options...
revraz Posted January 19, 2008 Share Posted January 19, 2008 I think it would be more along the lines UPDATE $tbl_members SET payment = 1 WHERE nickname = '$tmp'; Link to comment https://forums.phpfreaks.com/topic/86724-php-mysql-query-to-select-a-row/#findComment-443206 Share on other sites More sharing options...
law Posted January 19, 2008 Author Share Posted January 19, 2008 I think it would be more along the lines UPDATE $tbl_members SET payment = 1 WHERE nickname = '$tmp'; Great! Thanks! The initial problem is solved now! Sorry I forgot to mention that the file that i am showing is an include.. every $variable is defined somewhere! Thank you for the quick help.. New problem.. Now I am getting greedy! I would like for the page to assess if the user has made a payment. If they have gone through the paypal payment process the page should change their database entry to a "1".. once the admin has verified the payment has been received he will change the users payment value to "2" ill cover the admin function on another page.. but now i am having an issue getting the page to check for the payment value? i think im going this right but my page is turning up completely blank.. my assumption is that my problem is somewhere withing the IF syntax.. but i am not familiar with it enough to know whats wrong.. thank you! in advance <?php include_once("./dbconfig.php"); //echo "$tmp"; //---------------------HERE IS MY NEW PROBLEM----------------------------------------- $paid = mysql_query("SELECT * FROM members WHERE nickname ='$tmp' AND payment = '2'"); $paidrows = mysql_num_rows($paid); if ($paidrows==1){ echo "Your Payment Has Allready Been Accepted Thank You!"; echo "$paidrows"; } $paid2 = mysql_query("SELECT * FROM members WHERE nickname ='$tmp' AND payment = '1'"); $paidrows2 = mysql_num_rows($paid2); if ($paidrows2==1){ echo "Your payment is being processed. Please check back to make sure that it clears!"; } //-------------------------------------------------------------- if ($paid=0){ if ($_GET['payed'] == 1){ echo '<font color=red>Payment being processed. Thank you! Goodluck! </font><p>'; $result = mysql_query("SELECT id FROM members WHERE nickname = '$tmp'"); $num=mysql_num_rows($result); //echo "$result"; if ($num >0){ $insert = mysql_query("UPDATE $tbl_members SET payment = 1 WHERE nickname = '$tmp'"); //echo "$insert"; }else { echo "An error has occured. My coding has a flaw in it."; } } else { echo '<form action="https://www.paypal.com/cgi-bin/webscr" method="post"> <input type="hidden" name="cmd" value="_xclick"> <input type="hidden" name="business" value="[email protected]"> <input type="hidden" name="item_name" value="Subscription to xxxxxxxxxxxxx"> <input type="hidden" name="amount" value="8.00"> <input type="hidden" name="shipping" value="0.00"> <input type="hidden" name="no_shipping" value="1"> <input type="hidden" name="return" value="http://localhost/xxxxxx/payment.php?payed=1"> <input type="hidden" name="cancel_return" value="http://localhost/xxxxxx/payment.php?=canceled1"> <input type="hidden" name="no_note" value="1"> <input type="hidden" name="currency_code" value="USD"> <input type="hidden" name="tax" value="0.00"> <input type="hidden" name="lc" value="US"> <input type="hidden" name="bn" value="PP-BuyNowBF"> <input type="image" src="./css/images/paybutton.png" border="0" name="submit" alt="https://www.paypal.com/en_US/i/btn/btn_paynowCC_LG.gif"> <img alt="Image Failed to load" border="0" src="https://www.paypal.com/en_US/i/scr/pixel.gif" width="1" height="1"> </form>';}} ?> Link to comment https://forums.phpfreaks.com/topic/86724-php-mysql-query-to-select-a-row/#findComment-443261 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.