Jump to content

[SOLVED] php4 to php5


stelthius

Recommended Posts

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

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

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

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

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.