• I wrote a php code do do some sql stuff it works fine outside of wordpress. I made a wordpress page and put the php code inside the page.php and it does not work.
    Also if add
    <?php require_once(‘/wordpress/wp-blog-header.php’); ?>
    to the top of just the code page and load it by its self it will not work.
    Any Ideas.

    <?php
    
    // login to server
    
    $username="";
    $password="";
    $database="challenges";
    mysql_connect(localhost,$username,$password);
    @mysql_select_db($database) or die( "Unable to select database");
    //get info for user guest
    $query="SELECT * FROM members WHERE username='Guest'";
    $result=mysql_query($query);
    $num=mysql_numrows($result);
    mysql_close();
    
    $i=0;
    while ($i < $num) {
    // asign var for fields in guest
    $user=mysql_result($result,$i,"username");
    $pass=mysql_result($result,$i,"password");
    $Basic1=mysql_result($result,$i,"Basic1");
    $points=mysql_result($result,$i,"points");
    
    $i++;
    }
    
    // if password is correct
    if ($pass2 == "password"){
    	// if basic1 field == yes
    
    	if ($Basic1=="Yes"){
    //	echo $Basic1;//check status of basic1 remove this line when done
    	echo "You already beat this challenge.";}
    	// if basic field does not == yes make it equal yes and add points
    	else {
    $com="Yes";
    $newpoints=$points+20;
    mysql_connect(localhost,$username,$password);
    @mysql_select_db($database) or die( "Unable to select database");
    $query = "UPDATE members SET " . "Points='$newpoints', " ."Basic1='$com'"."WHERE id=1";
    
    mysql_query($query);
    
    mysql_close();
    
    echo "You have received 20 points.";
    echo "You new total points is $newpoints";
    }
    }
    elseif ($pass2 != ""){ // if they got the pass wrong
    echo "You fail.";
    }
    else{
    echo '<form action="" method="post">';
    echo '<input type="password" name="pass2" />';
    echo '<input type="submit" value="Login" />';
    }
    
    ?>

Viewing 15 replies - 1 through 15 (of 15 total)
  • you dont put php code inside pages unless youre using exec-php or similar.

    AND you dont need that include either based on what I see above. Not to mention that it will error since thats already ‘included’

    Thread Starter override

    (@override)

    i put the php code inside and actual page ie page.php
    and the include statment i tryed in side just a regualr page outside of wordpress to see if wordpress was what was causing the error, and the code works great outside of wordpress as long as you leave out the include. But inside wordpress or ouside wordpress with the include header it does not work.

    Thread Starter override

    (@override)

    Let me try and explain a little better im confusing my self.
    Put the code above in a blank php page out side of wordpress and it works great.
    Add
    <?php require_once(‘/wordpress/wp-blog-header.php’); ?>
    to the top of the page and the code will stop working

    You might want to try renaming some of your variables. Names like $username and $password are pretty common…

    Thread Starter override

    (@override)

    thanks esmi yeah i shold have mentioned that i tryed renaming all veriables to of the wall stuff like $username33333 and $password333333
    and it still does not work.
    That was my first thought as well though

    ok, so you say it doesnt work. what specifically doesnt work?

    does it make a mysql connection?

    Thread Starter override

    (@override)

    with <?php require_once(‘/wordpress/wp-blog-header.php’); ?>
    it does not make the mysql connection and it does not echo any of the results.
    All that is displayed is the form and when click submit it just reffreshes the form.

    ok, well thats more than likely because you are not using the new_link parameter.

    https://us.php.net/function.mysql-connect

    Thread Starter override

    (@override)

    But it works great outside of wordpress?

    are you for help or chat?

    ok, well thats more than likely because you are not using the new_link parameter.

    https://us.php.net/function.mysql-connect

    Read the page behind the link, and you will understand why you need to use that if you want to integrate it into wordpress.

    Thread Starter override

    (@override)

    Ok sorry i skimmed over it and didnt see anything ill take a closer look. Thank you

    new_link

    Thread Starter override

    (@override)

    tryed
    mysql_connect(localhost,$username,$password, new_link );
    and same thing works outside wordpress
    does not work inside wordpress

    Thread Starter override

    (@override)

    its almost as if whatever text is input into the form is not being passed to the php code

    Thread Starter override

    (@override)

    input any text into the box you will get a “you fail ” if the script is working.
    with out header
    https://securityoverride.com/Challenges/1/overidepoints.php

    with header <?php require_once(‘/wordpress/wp-blog-header.php’); ?>
    https://securityoverride.com/Challenges/1/overidepointswithwpheader.php
    no “you fail” script does not work

Viewing 15 replies - 1 through 15 (of 15 total)
  • The topic ‘php code works but not in wordpress’ is closed to new replies.