1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Other rewrite of a 36 line script to work with mysqli/php 7

Discussion in 'Custom Service/Development Requests' started by Carla Birch, Jan 31, 2016.

  1. Carla Birch

    Carla Birch Well-Known Member

    Hi, i have a very old 5 star rating script that is a core part of some of my sites systems, the problem is it's that old the code is all for mysql, so it could do with a rewrite to work with mysqli and php 7 as i wish to update my servers php to the latest version, but this script breaking is stopping me.

    here is the code for the script.

    mysql_connect($db_server$db_username$db_password) or die(mysql_error());
    mysql_select_db($db_database) or die(mysql_error());

    $div_id $_GET['id'];
    $rating $_GET['rating'];

    //Check that this person hasn't already left a rating
    $result mysql_query("SELECT id FROM ratings WHERE div_id = '" $div_id "' AND ip = '" $_SERVER['REMOTE_ADDR'] . "'") or die(mysql_error()); 
    $row mysql_fetch_array$result );
    $result mysql_query("INSERT INTO ratings (rating,div_id,ip) VALUES('" $rating "','" $div_id "','" $_SERVER['REMOTE_ADDR'] . "')") or die(mysql_error());      if($result){ $report "<span style=\"color: green;\"> You rated this: $rating</span>"; }
    } else {
    $report "<span style=\"color: red;\"> You have already rated this.</span>";

    mysql_query("SELECT avg(rating), COUNT(*) FROM ratings WHERE div_id = '" $div_id "'") or die(mysql_error()); 
    $row mysql_fetch_array$result );

    $stars .= "<li><a onClick=\"javascript:addRating('$div_id','$x');\" class=\"star$x\">$x</a></li>";

    <ul class='star-rating'>
    <li class="current-rating" id="current-rating" style="width: <?php echo round($row[0],1) * 20?>%;"></li>
    <? echo $stars; ?>
    <div><small><?php echo "<span style=\"color: grey;\">Rating: " round($row[0],1) . "/5 (" $row[1] . " Ratings)</span> " $report?></small></div>
    If anyone is willing to rewrite it that will be a great help even if a small fee is needed for your time.

Share This Page