Jump to content

Recommended Posts

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 by Zara
Link to comment
https://forums.phpfreaks.com/topic/272460-use-select-newbi-question/
Share on other sites

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'];

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. ;)

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);

 

?>

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 by Zara

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 by Barand
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.