stelthius Posted January 21, 2009 Share Posted January 21, 2009 Hello, I'm curious is there a easy way to convert a scipt written for php4 to php5 as i ugraded my php version and some small parts of my script fail to work now.. Regards Rick Link to comment https://forums.phpfreaks.com/topic/141759-solved-php4-to-php5/ Share on other sites More sharing options...
kenrbnsn Posted January 21, 2009 Share Posted January 21, 2009 If you post the parts of the script that fail, we could help you. Ken Link to comment https://forums.phpfreaks.com/topic/141759-solved-php4-to-php5/#findComment-742074 Share on other sites More sharing options...
stelthius Posted January 21, 2009 Author Share Posted January 21, 2009 Hello, Thanks for the reply, im not 100% sure which parts it is but i have a general idea, Im positive its this part of my script, this is basicly accepts or declines the friend request, when i hit accept it doesnt input the data into the database, this is my theory it maybe wrong tho lol, it did work on php4 tho, Keep in mind im still learning so my coding isnt as clean as i'd like it to be lol <? include("include/session.php"); ?> <table width="922" height="31" border="2"> <tr> <td height="23" bordercolor="#FFFFFF" bgcolor="#FFFFFF"> <p align="center"><span class="logotext">Friend Requests </span></p> <p> <? /* Requested Username error checking */ $req_user = trim($_GET['user']); if ($session->logged_in) { //checks user is logged in switch ($_GET[friends]) { //allows multiple pages default: $get = mysql_query( "SELECT * FROM `friend_requests` WHERE `username` = '$session->username' "); //gets requests while ($reqs = mysql_fetch_array($get)) { echo ( "<center><b>Friend Requests</b></center><br> $reqs[by] wants to be friends with you.<br> <a href='newfriends.php?friends=accept&user=$reqs[by]'>Accept</a><br/> <a href='newfriends.php?friends=delete&user=$reqs[by]'>Delete</a><br><br>" ); //displays requests and shows accept delete links } break; case 'accept': //accept page if ($session->logged_in) { //get username $add = mysql_query( "INSERT INTO `friends` (`friendname` , `username`) VALUES ('$req_user' , '$session->username') "); // add to your friends list $delete = mysql_query( "DELETE FROM `friend_requests` WHERE `by` = '$_GET[user]' "); // deletes friend request echo ( "$req_user has been added as a friend and the request has been deleted" ); // echos the completion } break; //ends accept page case 'delete': // delete page if ($req_user) { //gets username $delete = mysql_query( "DELETE FROM `friend_requests` WHERE `by` = '$req_user' "); // deletes friend request echo ( "$req_user's request has been deleted" ); // echos completion } break; //ends delete page } // ends switch } else { echo ( "You need to be logged in" ); // not logged in } ?> Link to comment https://forums.phpfreaks.com/topic/141759-solved-php4-to-php5/#findComment-742117 Share on other sites More sharing options...
PFMaBiSmAd Posted January 21, 2009 Share Posted January 21, 2009 Except for a very few minor and obscure differences, php4 code will work as is under php5, given the same php.ini configuration - http://www.php.net/manual/en/migration5.incompatible.php Most problems are due to configuration differences and code that is using depreciated and removed features (such as register_globals that were turned of almost seven freaking years ago) that are not present in the current recommend php.ini settings. Link to comment https://forums.phpfreaks.com/topic/141759-solved-php4-to-php5/#findComment-742121 Share on other sites More sharing options...
stelthius Posted January 21, 2009 Author Share Posted January 21, 2009 Everything is still pretty much the same i have done alot of googling and reading but i can still not get my head around it.. i know there are some pretty good coders on here thus being the reason i asked on here thanks rick Link to comment https://forums.phpfreaks.com/topic/141759-solved-php4-to-php5/#findComment-742124 Share on other sites More sharing options...
PFMaBiSmAd Posted January 21, 2009 Share Posted January 21, 2009 Does the code execute the query to delete the request: DELETE FROM `friend_requests` WHERE `by` = '$_GET[user]' and echo the message: $req_user has been added as a friend and the request has been deleted? Link to comment https://forums.phpfreaks.com/topic/141759-solved-php4-to-php5/#findComment-742138 Share on other sites More sharing options...
stelthius Posted January 21, 2009 Author Share Posted January 21, 2009 Yes it does but it doesnt save the person requesting to be a friend in the database this is why i dont understand the problem as it worked perferctly before i changed versions Link to comment https://forums.phpfreaks.com/topic/141759-solved-php4-to-php5/#findComment-742144 Share on other sites More sharing options...
PFMaBiSmAd Posted January 21, 2009 Share Posted January 21, 2009 It's either a problem with your database, your table, your query, or the data in your query. Change the following line - $add = mysql_query( "INSERT INTO `friends` (`friendname` , `username`) VALUES ('$req_user' , '$session->username') "); // add to your friends list to this (to get some error checking and error reporting, which your code should have anyway) - $query = "INSERT INTO `friends` (`friendname` , `username`) VALUES ('$req_user' , '$session->username')"; // add to your friends list mysql_query($query) or die("Query failed: $query<br /> Mysql error: " . mysql_error()); Link to comment https://forums.phpfreaks.com/topic/141759-solved-php4-to-php5/#findComment-742157 Share on other sites More sharing options...
stelthius Posted January 21, 2009 Author Share Posted January 21, 2009 It says that the Query failed because it was empty ? how can i have come across this error if it was working fine before, its lost me lol, Error report below :- Query failed: Mysql error: Query was empty Link to comment https://forums.phpfreaks.com/topic/141759-solved-php4-to-php5/#findComment-742167 Share on other sites More sharing options...
stelthius Posted January 21, 2009 Author Share Posted January 21, 2009 Ok i have got it to stroe the sent request inthe database but it still refuses to actaully add that person as a friend when you click accept Link to comment https://forums.phpfreaks.com/topic/141759-solved-php4-to-php5/#findComment-742171 Share on other sites More sharing options...
stelthius Posted January 21, 2009 Author Share Posted January 21, 2009 Ok i have now solved both of them issues, but it isnt showing the information from the database to the user this code shows (or is supposed to show the friends list) <? $getfriends = mysql_query( "SELECT * FROM `users` WHERE `active_users` = '1'" ); while ($friends = mysql_fetch_array($getfriends)) { echo "<a href='userinfo.php?user=$friends[friendname]'>$friends[friendname]</a> <br>"; } ?> Sorry if this seems a little stupid but im learning as i said im just not sure why things are so difficult if there arnt many changes in versions :S Link to comment https://forums.phpfreaks.com/topic/141759-solved-php4-to-php5/#findComment-742176 Share on other sites More sharing options...
stelthius Posted January 21, 2009 Author Share Posted January 21, 2009 Fixed i replaced my code with $getfriends = mysql_query( "SELECT * FROM `friends` WHERE `username` = '$session->username'" ); while ($friends = mysql_fetch_array($getfriends)) { echo "<a href='userinfo.php?user=$friends[friendname]'>$friends[friendname]</a> <br>"; } Now all is working well Thank you PFMaBiSmAd for the shove in the right direction Link to comment https://forums.phpfreaks.com/topic/141759-solved-php4-to-php5/#findComment-742182 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.