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)
Viewing 15 replies - 1 through 15 (of 15 total)
- The topic ‘php code works but not in wordpress’ is closed to new replies.