Title: php code works but not in wordpress
Last modified: August 19, 2016

---

# php code works but not in wordpress

 *  [override](https://wordpress.org/support/users/override/)
 * (@override)
 * [16 years, 9 months ago](https://wordpress.org/support/topic/php-code-works-but-not-in-wordpress/)
 * 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)

 *  [whooami](https://wordpress.org/support/users/whooami/)
 * (@whooami)
 * [16 years, 9 months ago](https://wordpress.org/support/topic/php-code-works-but-not-in-wordpress/#post-1173309)
 * 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](https://wordpress.org/support/users/override/)
 * (@override)
 * [16 years, 9 months ago](https://wordpress.org/support/topic/php-code-works-but-not-in-wordpress/#post-1173328)
 * 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](https://wordpress.org/support/users/override/)
 * (@override)
 * [16 years, 9 months ago](https://wordpress.org/support/topic/php-code-works-but-not-in-wordpress/#post-1173349)
 * 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
 *  [esmi](https://wordpress.org/support/users/esmi/)
 * (@esmi)
 * [16 years, 9 months ago](https://wordpress.org/support/topic/php-code-works-but-not-in-wordpress/#post-1173352)
 * You might want to try renaming some of your variables. Names like $username and
   $password are pretty common…
 *  Thread Starter [override](https://wordpress.org/support/users/override/)
 * (@override)
 * [16 years, 9 months ago](https://wordpress.org/support/topic/php-code-works-but-not-in-wordpress/#post-1173356)
 * 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
 *  [whooami](https://wordpress.org/support/users/whooami/)
 * (@whooami)
 * [16 years, 9 months ago](https://wordpress.org/support/topic/php-code-works-but-not-in-wordpress/#post-1173365)
 * ok, so you say it doesnt work. what specifically doesnt work?
 * does it make a mysql connection?
 *  Thread Starter [override](https://wordpress.org/support/users/override/)
 * (@override)
 * [16 years, 9 months ago](https://wordpress.org/support/topic/php-code-works-but-not-in-wordpress/#post-1173367)
 * 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.
 *  [whooami](https://wordpress.org/support/users/whooami/)
 * (@whooami)
 * [16 years, 9 months ago](https://wordpress.org/support/topic/php-code-works-but-not-in-wordpress/#post-1173369)
 * ok, well thats more than likely because you are not using the new_link parameter.
 * [http://us.php.net/function.mysql-connect](http://us.php.net/function.mysql-connect)
 *  Thread Starter [override](https://wordpress.org/support/users/override/)
 * (@override)
 * [16 years, 9 months ago](https://wordpress.org/support/topic/php-code-works-but-not-in-wordpress/#post-1173370)
 * But it works great outside of wordpress?
 *  [whooami](https://wordpress.org/support/users/whooami/)
 * (@whooami)
 * [16 years, 9 months ago](https://wordpress.org/support/topic/php-code-works-but-not-in-wordpress/#post-1173371)
 * are you for help or chat?
 * >  ok, well thats more than likely because you are not using the new_link parameter.
   > [http://us.php.net/function.mysql-connect](http://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](https://wordpress.org/support/users/override/)
 * (@override)
 * [16 years, 9 months ago](https://wordpress.org/support/topic/php-code-works-but-not-in-wordpress/#post-1173373)
 * Ok sorry i skimmed over it and didnt see anything ill take a closer look. Thank
   you
 *  [whooami](https://wordpress.org/support/users/whooami/)
 * (@whooami)
 * [16 years, 9 months ago](https://wordpress.org/support/topic/php-code-works-but-not-in-wordpress/#post-1173375)
 * **new_link **
 *  Thread Starter [override](https://wordpress.org/support/users/override/)
 * (@override)
 * [16 years, 9 months ago](https://wordpress.org/support/topic/php-code-works-but-not-in-wordpress/#post-1173378)
 * tryed
    `mysql_connect(localhost,$username,$password, new_link );` and same thing
   works outside wordpress does not work inside wordpress
 *  Thread Starter [override](https://wordpress.org/support/users/override/)
 * (@override)
 * [16 years, 9 months ago](https://wordpress.org/support/topic/php-code-works-but-not-in-wordpress/#post-1173379)
 * its almost as if whatever text is input into the form is not being passed to 
   the php code
 *  Thread Starter [override](https://wordpress.org/support/users/override/)
 * (@override)
 * [16 years, 9 months ago](https://wordpress.org/support/topic/php-code-works-but-not-in-wordpress/#post-1173382)
 * input any text into the box you will get a “you fail ” if the script is working.
   
   with out header [http://securityoverride.com/Challenges/1/overidepoints.php](http://securityoverride.com/Challenges/1/overidepoints.php)
 * with header <?php require_once(‘/wordpress/wp-blog-header.php’); ?>
    [http://securityoverride.com/Challenges/1/overidepointswithwpheader.php](http://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.

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 15 replies
 * 3 participants
 * Last reply from: [override](https://wordpress.org/support/users/override/)
 * Last activity: [16 years, 9 months ago](https://wordpress.org/support/topic/php-code-works-but-not-in-wordpress/#post-1173382)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
