dcsimg
Results 1 to 3 of 3

Thread: convert to mysqli

  1. #1

    Thread Starter
    New Member
    Join Date
    Aug 2016
    Posts
    9

    convert to mysqli

    hello,

    can anyone help me transfer this code from mysql to mysqli please?

    PHP Code:
    // We include out connect to database file.
    include('scripts/connect.php');
    // now we check to see if the button has been pressed.
    if ($_SERVER['REQUEST_METHOD'] == 'POST'){
    // retrieving the input from the user, also securing from SQL injection and
    // making the password md5 encryption.    
        
    $username mysql_real_escape_string($_POST['username']);
        
    $password mysql_real_escape_string(md5($_POST['password']));
    // now to make sure the fields are not empty.
        
    if(!empty($_POST['username']) && !empty($_POST['password'])){
              
    $query mysql_query("SELECT * FROM users WHERE username='$username'");
              
    $rows mysql_num_rows($query);
              
              if(
    $rows 0){
                 echo (
    "You have entered a username that already exists!. $form");
              }
              else {
                
    $user_input mysql_query("INSERT INTO users (username, password) VALUES('$username' , '$password')");
                echo (
    "You have been successfully added to the database!.");   
              }
                
        }
        else 
            echo(
    "You need to enter a valid username and password!. $form");
    }
    else
        echo 
    $form;

    ?> 

  2. #2
    PowerPoster Arnoutdv's Avatar
    Join Date
    Oct 2013
    Posts
    3,247

    Re: convert to mysqli

    Never used PHP, never heard of mysqli, but a quick search revealed this page:
    https://www.w3schools.com/php/php_ref_mysqli.asp

    Based on the mySQLi functions you just have to replace mysql_* with mysqli_*

    My 2 cents...

  3. #3

    Thread Starter
    New Member
    Join Date
    Aug 2016
    Posts
    9

    Re: convert to mysqli

    I cant seem to get the code in read to work in mysli can anyone help please
    i still need to change some to mysli but thats the line i have the problem with?

    Code:
    <?php include('styles/top.php'); ?>
    
    
        
         <div id="full">
        
            <div id="view_box">
                <ul>
                    <li><img src="images/1.png" /></li>
                    <!-- <li><img src="pics/2.jpg" /></li> -->
                    <!-- <li><img src="pics/3.jpg" /></li> -->
                </ul>
            </div>
            
            <div id="button">
                <ul>
                    <!-- <li><button class="button" scroll_value="0">*</button></li> -- >
                    <!-- <li><button class="button" scroll_value="600">*</button></li> -->
                    <!-- <li><button class="button" scroll_value="1200">*</button></li> -->
                </ul>
            </div>
            <hr /><br />
            
           <?php
            
            if (($user_level !=1) && ($user_level !=2)){
                echo "No Access Allowed";
            } else {
            
            $per_page = 8;
            $pages_query = mysqli_query($link,"SELECT COUNT(`id`) FROM(`orders`) WHERE OrderBy = '$username'");
            $pages = ceil(mysql_result($pages_query,0)/$per_page);
            
            if (!isset($_GET['page']))
            {
                echo "<meta http-equiv='refresh' content='0;url=view.php?page=1'>";
            }
            else
            {
                $page = $_GET['page'];
            }
            
            $start = (($page - 1)*$per_page);
            
            
            ?>
            
            <h3>View Orders</h3>
            
            		<table border=1">
    				<tr>
    					<th>FULL NAME </th>
                        <th>DATE GOT </th>
    					<th>PAY DATE</th>
    					<th>MONEY DUE</th>
                        <th>UPDATE ORDER STATUS</th>
    				</tr>
                    
                    <tr>
    						<td>&nbsp;</td>
    						<td></td>
    						<td></td>
                            <td></td>
                            <td></td>
    					</tr>
                    
                    <?php
                    
                    error_reporting(0);
                    $result = mysql_query("SELECT * FROM orders WHERE OrderBy = '$username' AND Status = 'Layon' LIMIT $start,$per_page");
                
                    
                    $totmoney = 0;
                    $strmoney = "";
                    
                    while ($myrow = mysql_fetch_array($result))
                    {
                        $strmoney = $myrow["Money"];
                        $strmoney = str_replace(',','',$strmoney);
                        
                        if(is_numeric($strmoney))
                        {
                            settype($strmoney, "float");
                            $strmoney = number_format($strmoney, 2);
                        }
                        echo "<TR><TD><a href=\"_view.php?id=".$myrow['id']."\">".$myrow["FullName"]."</A>&nbsp;</TD><TD>".$myrow["GotDate"]."&nbsp;</TD><TD>".$myrow["PayDate"]."&nbsp;</TD><TD>&pound;".$strmoney."&nbsp;</TD>";
        				echo "<TD><center><a href=\"update_order.php?id=".$myrow['id']."\"><img class=\"displayed\" alt=\"View\" src=\"images/edit.png\" width=\"175\" height=\"25\" /></a></center></TD>";
                        echo "</TR>";
                        
                        $totmoney = $totmoney + (int)$myrow["Money"];
                    }
                    
                    
                    ?>
                    
                    
                       <tr>
    						<td>&nbsp;</td>
    						<td></td>
    						<td></td>
                            <td></td>
                            <td></td>
    					</tr>
                    
                    <tr>
    						<td>&nbsp;</td>
    						<td>TOTAL DUE</td>
    						<td>&pound;<?=number_format($totmoney, 2);?>&nbsp;</td>
                            <td></td>
                            <td></td>
    					</tr>
                  			
    			</table>
                
                
                <br />  
           
           <?php
           echo "<center>";
           for ($number=1;$number<=$pages;$number++)
            {
                echo '<a href="?page='.$number.'">'.$number.'</a> | ';
            }
                echo "<br/><br/><font color='white'>Current Page: $page</font>";
           echo "</center></br>";
           
           ?>
                   
            <?php
            }
            ?>
            
            
           
        </div>
    
    <?php include('styles/bottom.php'); ?>

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Featured


Click Here to Expand Forum to Full Width