Zara Posted December 28, 2012 Share Posted December 28, 2012 (edited) Hello i am new to this forum, but after spendning hours on internet looking for an answer i joined here. What i want to do is basic and maybe i am doing it totaly wrong. My commandline looks like this in my php file SELECT meta_value FROM `wp_usermeta` WHERE user_id=1 and meta_key='rcp_status' I have a mysql database called blogg and i have a table called wp_usermeta in this table i have allot of rows with data in them. I have been in phpadmin and tryed the commando SELECT meta_value FROM wp_usermeta WHERE user_id=1 and meta_key='rcp_status' and it gives me correct answer "active" is the text but when i do it in php its emty and i get no errors so what could be wrong? My logg.txt file only show results for $sms_kod and $sms_id and the row where $results should be is emty. Hole script: <?php $sms_id = $_POST["userid"]; $sms_kod = $_POST["koden"]; $link = mysql_connect("localhost", "$username","$password"); mysql_select_db("blogg",$link); $result = mysql_query("SELECT meta_value FROM wp_usermeta WHERE user_id=1 and meta_key='rcp_status'"); echo mysql_error(); //For debugging $myFile = "logg.txt"; $fh = fopen($myFile, 'w') or die("can't open file"); fwrite($fh, $sms_kod); $stringData = "\n"; fwrite($fh, $stringData); fwrite($fh, $sms_id); $stringData = "\n"; fwrite($fh, $stringData); $stringData = "\n"; fwrite($fh, $stringData); fwrite($fh, $result); fclose($fh); ?> //Zara Edited December 28, 2012 by Zara Quote Link to comment Share on other sites More sharing options...
Barand Posted December 29, 2012 Share Posted December 29, 2012 After the query you need to fetch the returned data $result = mysql_query("SELECT meta_value FROM wp_usermeta WHERE user_id=1 and meta_key='rcp_status'"); $row = mysql_fetch_assoc($result); $meta_value = $row['meta_value']; Quote Link to comment Share on other sites More sharing options...
sowna Posted December 29, 2012 Share Posted December 29, 2012 simply you can use like this, $result = mysql_query("SELECT meta_value FROM wp_usermeta WHERE user_id=1 and meta_key='rcp_status'"); $meta_value = mysql_result($result,0); Quote Link to comment Share on other sites More sharing options...
Christian F. Posted December 29, 2012 Share Posted December 29, 2012 Do note that mysql_result () should be used only when you're fetching one field, and only one field, from the DB. Otherwise the mysql_fetch_* () functions are recommended, due to efficiency. PS: You should also consider moving on to PDO or MySQLI, as the mysql-library is old, outdated and no longer being developed. All of which means that it'll become deprecated soon, and then removed from PHP. Better get a head start, after all. Quote Link to comment Share on other sites More sharing options...
Zara Posted December 29, 2012 Author Share Posted December 29, 2012 Thanks guys! Now it works i went with " $result = mysql_query("SELECT meta_value FROM wp_usermeta WHERE user_id=1 and meta_key='rcp_status'"); $meta_value = mysql_result($result,0); " Now i am done with my php file, ofcourse it dosent work and i dont get any errors as well. Is there a good way of debugging php files? When i run it in my webbrowser the page is white. My ide was to inplant echos but that ide dident really work. Is there some kind of editor i can use that will show that i have done right on all the "(" ")" and stuff like that? Here is my code if anyone se any errors please help me correct them. Or point me to a good editor or similar that would help me find my errors. CODE: <?php $sms_id = $_POST["userid"]; $sms_kod = $_POST["koden"]; $datev = date('Y-m-d', strtotime("+1 week")); $datev1 = "$datev 23:59:59"; $datem = date('Y-m-d', strtotime("+1 month")); $datem1 = "$datem 23:59:59"; $link = mysql_connect("localhost", "$username","$password"); mysql_select_db("blogg",$link); //kolla om kodefinns eller ar anvand. check if the code is used or not $result1 = mysql_query("SELECT used FROM wp_sms_nummer WHERE kod='$sms_kod'"); $used_value = mysql_result($result1,0); //not used do this if ($used_value = "1") { echo "Koden ar redan anvand" }; elseif ($used_value = "0") { $result5 = mysql_query("SELECT typ FROM wp_sms_nummer WHERE kod='$sms_kod'"); $typ_value = mysql_result($result5,0); if ($typ_value == "vecka") ( $dateex = "$datev1"); elseif ($typ_value == "manad") ( $dateex = "$datem1"); $myFile = "logg.txt"; $fh = fopen($myFile, 'w') or die("can't open file"); fwrite($fh, $dateex); $stringData = "\n"; fwrite($fh, $stringData); fclose($fh); //is there an useraccount? $result = mysql_query("SELECT meta_value FROM wp_usermeta WHERE user_id='$sms_id' and meta_key='rcp_status'"); $meta_value = mysql_result($result,0); if ($meta_value = active) { echo "Kontot ar redan aktivt" }; elseif ($meta_value == "pending" || $$meta_value == "expired" || $meta_value == "cancelled") { //this will set user active $result2 = mysql_query("update wp_usermeta set meta_value='active' WHERE user_id='$sms_id' and meta_key='rcp_status'"); $result3 = mysql_query("update wp_usermeta set meta_value='$dateex' WHERE user_id='$sms_id' and meta_key='rcp_expiration'"); $result3 = mysql_query("update wp_usermeta set meta_value='1' WHERE user_id='$sms_id' and meta_key='rcp_subscription_level'"); $result53 = mysql_query("update wp_sms_nummer set used='1' WHERE kod='$sms_kod' and used='0'"); echo "aktiverat user"; }; //there is no account need to make one else { $query11 = "INSERT INTO `wp_usermeta`(`umeta_id`, `user_id`, `meta_key`, `meta_value`) VALUES (null,'$sms_id','rcp_subscription_key','d6f65269dc03eefabb6faa330a72b01b')"; mysql_query($query11, $link); $query12 = "INSERT INTO `wp_usermeta`(`umeta_id`, `user_id`, `meta_key`, `meta_value`) VALUES (null,'$sms_id','rcp_subscription_level','1')"; mysql_query($query12, $link); $query13 = "INSERT INTO `wp_usermeta`(`umeta_id`, `user_id`, `meta_key`, `meta_value`) VALUES (null,'$sms_id','rcp_status','active')"; mysql_query($query13, $link); $query14 = "INSERT INTO `wp_usermeta`(`umeta_id`, `user_id`, `meta_key`, `meta_value`) VALUES (null,'$sms_id','rcp_expiration','$dateex')"; mysql_query($query14, $link); $result55 = mysql_query("update wp_sms_nummer set used='1' WHERE kod='$sms_kod' and used='0'"); echo "fick skapa en ny user"; }; }; echo mysql_error(); $myFile = "logg.txt"; $fh = fopen($myFile, 'w') or die("can't open file"); fwrite($fh, $sms_kod); $stringData = "\n"; fwrite($fh, $stringData); fwrite($fh, $sms_id); $stringData = "\n"; fwrite($fh, $stringData); $stringData = "\n"; fwrite($fh, $stringData); fwrite($fh, $meta_value); $stringData = "\n"; fwrite($fh, $stringData); fwrite($fh, $used_value); fclose($fh); ?> Quote Link to comment Share on other sites More sharing options...
Zara Posted December 29, 2012 Author Share Posted December 29, 2012 (edited) <p> How to past the code into a code block here? Edited December 29, 2012 by Zara Quote Link to comment Share on other sites More sharing options...
Pikachu2000 Posted December 29, 2012 Share Posted December 29, 2012 You almost had it . . . Use either . . . or . . . tags, or you can highlight the code in the editor box and click the <> button above. Quote Link to comment Share on other sites More sharing options...
Zara Posted December 29, 2012 Author Share Posted December 29, 2012 (edited) I hope i dont spam to much but seems that i cant edit my another post. Now i am done with my php file, ofcourse it dosent work and i dont get any errors as well. Is there a good way of debugging php files? When i run it in my webbrowser the page is white i expected it do make the tabels /update tabels and also print my echos on screen nothing happend. My ide was to inplant echos but that ide dident really work. Is there some kind of editor i can use that will show that i have done right on all the "(" ")" and stuff like that? Here is my code if anyone se any errors please help me correct them. Or point me to a good editor or similar that would help me find my errors. <?php $sms_id = $_POST["userid"]; $sms_kod = $_POST["koden"]; $datev = date('Y-m-d', strtotime("+1 week")); $datev1 = "$datev 23:59:59"; $datem = date('Y-m-d', strtotime("+1 month")); $datem1 = "$datem 23:59:59"; $link = mysql_connect("localhost", "$username","$password"); mysql_select_db("blogg",$link); //kolla om kodefinns eller ar anvand. check if the code is used or not $result1 = mysql_query("SELECT used FROM wp_sms_nummer WHERE kod='$sms_kod'"); $used_value = mysql_result($result1,0); //not used do this if ($used_value = "1") { echo "Koden ar redan anvand" }; elseif ($used_value = "0") { $result5 = mysql_query("SELECT typ FROM wp_sms_nummer WHERE kod='$sms_kod'"); $typ_value = mysql_result($result5,0); if ($typ_value == "vecka") ( $dateex = "$datev1"); elseif ($typ_value == "manad") ( $dateex = "$datem1"); $myFile = "logg.txt"; $fh = fopen($myFile, 'w') or die("can't open file"); fwrite($fh, $dateex); $stringData = "\n"; fwrite($fh, $stringData); fclose($fh); //is there an useraccount? $result = mysql_query("SELECT meta_value FROM wp_usermeta WHERE user_id='$sms_id' and meta_key='rcp_status'"); $meta_value = mysql_result($result,0); if ($meta_value = active) { echo "Kontot ar redan aktivt" }; elseif ($meta_value == "pending" || $$meta_value == "expired" || $meta_value == "cancelled") { //this will set user active $result2 = mysql_query("update wp_usermeta set meta_value='active' WHERE user_id='$sms_id' and meta_key='rcp_status'"); $result3 = mysql_query("update wp_usermeta set meta_value='$dateex' WHERE user_id='$sms_id' and meta_key='rcp_expiration'"); $result3 = mysql_query("update wp_usermeta set meta_value='1' WHERE user_id='$sms_id' and meta_key='rcp_subscription_level'"); $result53 = mysql_query("update wp_sms_nummer set used='1' WHERE kod='$sms_kod' and used='0'"); echo "aktiverat user"; }; //there is no account need to make one else { $query11 = "INSERT INTO `wp_usermeta`(`umeta_id`, `user_id`, `meta_key`, `meta_value`) VALUES (null,'$sms_id','rcp_subscription_key','d6f65269dc03eefabb6faa330a72b01b')"; mysql_query($query11, $link); $query12 = "INSERT INTO `wp_usermeta`(`umeta_id`, `user_id`, `meta_key`, `meta_value`) VALUES (null,'$sms_id','rcp_subscription_level','1')"; mysql_query($query12, $link); $query13 = "INSERT INTO `wp_usermeta`(`umeta_id`, `user_id`, `meta_key`, `meta_value`) VALUES (null,'$sms_id','rcp_status','active')"; mysql_query($query13, $link); $query14 = "INSERT INTO `wp_usermeta`(`umeta_id`, `user_id`, `meta_key`, `meta_value`) VALUES (null,'$sms_id','rcp_expiration','$dateex')"; mysql_query($query14, $link); $result55 = mysql_query("update wp_sms_nummer set used='1' WHERE kod='$sms_kod' and used='0'"); echo "fick skapa en ny user"; }; }; echo mysql_error(); $myFile = "logg.txt"; $fh = fopen($myFile, 'w') or die("can't open file"); fwrite($fh, $sms_kod); $stringData = "\n"; fwrite($fh, $stringData); fwrite($fh, $sms_id); $stringData = "\n"; fwrite($fh, $stringData); $stringData = "\n"; fwrite($fh, $stringData); fwrite($fh, $meta_value); $stringData = "\n"; fwrite($fh, $stringData); fwrite($fh, $used_value); fclose($fh); ?> Edited December 29, 2012 by Zara Quote Link to comment Share on other sites More sharing options...
Jessica Posted December 29, 2012 Share Posted December 29, 2012 You need to turn on error reporting. There are several good links in my signature for you. Quote Link to comment Share on other sites More sharing options...
Jessica Posted December 29, 2012 Share Posted December 29, 2012 Also look in your log file. Quote Link to comment Share on other sites More sharing options...
Barand Posted December 29, 2012 Share Posted December 29, 2012 (edited) Do you have any error reporting turned on. That code does not even parse corrrectly - you have a misplaced ; on line 27 (move it before the } ) also line 52 and remove the ; on line 63 Edited December 29, 2012 by Barand Quote Link to comment 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.