PDA

View Full Version : vBulletin 4.2.5 Nightmare: MySQLi destroyed Sidebar Custom Code.


MacroPhotoPro
11-16-2017, 11:11 PM
My brother is designed MySQL code for the sidebar to our site.

All was wonderful, for many years ...

Then, we 'upgraded' from vBulletin 4.2.2 (which ran the MySQL code we put together)
... but now the vBulletin 4.2.5. (and our new webhost) runs MySQLi ... and we have no idea how to get our side carts functional again. Here is our (failed) attempt to re-do the code:

$local_dev = FALSE;
if ($local_dev) { echo "<link rel='stylesheet' type='text/css' href='styles/additional.css' />"; }
if ($local_dev==TRUE) {

// Establish a Local MySQL connection
$host = 'localhost:3306';
$user = 'xxxxxxx';
$pass = 'xxxxxxx';
$con = mysqli_connect($host,$user,$pass,TRUE);
$con_user = mysqli_connect($host,$user,$pass,TRUE);
$con_tol = mysqli_connect($host,$user,$pass,TRUE);

// User Identity Variables
$user_id = 2;
$usergroupid = 5;
$security_token = 0;

// Website configurations
$baseurl = "localhost/macrophoto/";

} else {

// database connection: macrophoto
$host = 'localhost';
$user = 'xxxxxxx';
$pass = 'xxxxxxx';
$con = mysqli_connect($host,$user,$pass,TRUE);

// database connection: Forum database
$host = 'localhost';
$user = 'xxxxxxx';
$pass = 'xxxxxxx';
$con_user = mysqli_connect($host,$user,$pass,TRUE);

// database connection: treeoflife
$host = 'localhost';
$user = 'xxxxxxx';
$pass = 'xxxxxxx';
$con_tol = mysqli_connect($host,$user,$pass,TRUE);

// Website configurations
$baseurl = "www.thenaturephotographer.club";
}
$SQL_QRY = "
SELECT
pic_id, pic_user_id, pic_folder, pic_title, pic_subtitle
FROM
xxxxxxx.xxxxxxx
WHERE
pic_folder>1
ORDER BY pic_uploaded DESC
LIMIT 0,5
";
$result = mysqli_query($SQL_QRY, $con);
$cart = "<table style='margin-top:10px;' width='100%' >";
$i = 0;
while ($row=mysqli_fetch_array($result)){

$i++;

// grab the data
$pic_id = $row["pic_id"];
$user_id = $row["pic_user_id"];
$folder_id = $row["pic_folder"];
$title = $row["pic_title"];
$subtitle = $row["pic_subtitle"];
if (!empty($subtitle)) { $title = "$title ($subtitle)"; }

$size = "tiny";
$url_mosaic = "http://$baseurl"."image_mosaic.php";

// Get the images
$field = "pic_path";
$path = "'thumbnails/', pic_user_id, '/', ";
$SQL_QRY = "SELECT concat($path"."pic_user_id, '_thumb_', LPAD(pic_id, 10, '0'), '_$size.', pic_ext ) as '$field' FROM macrophoto.pics WHERE pic_id=$pic_id";
$result2 = mysql_query($SQL_QRY, $con);
$row = mysqli_fetch_array($result2);
$img_path = $row[$field];
$size = getimagesize($img_path);
$width = $size[0];
$height = $size[1];

// Username
$field = "username";
$SQL_QRY = "SELECT $field FROM natureforum.vbuser WHERE userid=$user_id";
$value_result = mysqli_query($SQL_QRY, $con_user);
if ($value_result != NULL ) {
$row = mysqli_fetch_array($value_result);
$user_name = $row[$field];
} else {
$user_name = "";
}

// Avatar
$field = "avatarrevision";
$SQL_QRY = "SELECT $field FROM natureforum.vbuser WHERE userid='$user_id'";
$result3 = mysqli_query($SQL_QRY, $con_user);
$row = mysqli_fetch_array($result3);
$av_idx = $row[$field];
$avatar_path = "./customavatars/thumbs/avatar$user_id"."_$av_idx.gif";
if (!file_exists($avatar_path)) { $avatar_path = "./images/misc/unknown.gif"; }
$avatar = "<img style='width=100%;max-width:30px;' src='$avatar_path'>";
$profile_url = "member.php?$user_id";
$avatar = "<a href='$profile_url' target='profile' title='$user_name'>$avatar</a>";

// Get a Link to the View page
if ($local_dev) {
$view_path = "$baseurl"."image_view.php?username=$user_name&folder_id=$folder_id&pic_id=$pic_id&thumb_size=$size";
} else {
$view_path = "$user_name/$folder_id/$pic_id";
}

if ($width>$height) { $measure="width"; } else { $measure="height"; }
$img = "<img style='$measure:100%;min-$measure:200px;max-$measure:210px;box-shadow: 5px 5px 5px #1c1d1f;margin-bottom:15px;margin-left:10px;' src='$img_path' title='$title'>";
$link = "<a href='$view_path' target='view'>$img</a>";
$user = "<font size='-1'><a href='$url_mosaic?user_id=$user_id' target='user'>$user_name</a></font>";

if ($i==5) {$px = "0px";} else { $px="1px"; }

$cart .= "<tr' ><td style='padding-top:5px;border-bottom:$px dotted;' align='left' valign='top' width='10%' >$avatar</td><td style='padding-top:5px;border-bottom:$px dotted;' valign='middle' align='center' >$link</td></tr>";

}
$cart .= "</table>";
return $cart;




Can anyone please point out our coding errors?

Would be very grateful!

Dave
11-17-2017, 12:38 AM
Take a look at https://www.phpclasses.org/blog/package/9199/post/3-Smoothly-Migrate-your-PHP-Code-using-the-Old-MySQL-extension-to-MySQLi.html

MacroPhotoPro
11-17-2017, 01:27 PM
Thanks, Dave, I will try!

Dead Eddie
11-17-2017, 08:12 PM
I noticed this:

$result2 = mysql_query($SQL_QRY, $con);

;)

MacroPhotoPro
11-17-2017, 08:31 PM
Thanks :)