0

This is one of my school project. So it should show mobile devices <= customers budget. and if budget smaller than<3090 (which is the lowest value) it should show a sorry message. Now the problem is it's work fine on my pc while I run it using xampp. but when I upload it. It show me a blank table. (the number ofrows are the same as it needed to show)

enter image description here

update: Here are the errors:

Notice: Undefined index: brand_model in /home/710/283710/public_html/index.php on line 129
Notice: Undefined index: price in /home/710/283710/public_html/index.php on line 130
Notice: Undefined index: price in /home/710/283710/public_html/index.php on line 131
Notice: Undefined index: brand_model in /home/710/283710/public_html/index.php on line 135
Notice: Undefined index: price in /home/710/283710/public_html/index.php on line 136
Notice: Undefined index: offer_availability in /home/710/283710/public_html/index.php on line 144
Notice: Undefined index: brand_model in /home/710/283710/public_html/index.php on line 129
Notice: Undefined index: price in /home/710/283710/public_html/index.php on line 130
Notice: Undefined index: price in /home/710/283710/public_html/index.php on line 131
Notice: Undefined index: brand_model in /home/710/283710/public_html/index.php on line 135
Notice: Undefined index: price in /home/710/283710/public_html/index.php on line 136
Notice: Undefined index: offer_availability in /home/710/283710/public_html/index.php on line 144
Notice: Undefined index: brand_model in /home/710/283710/public_html/index.php on line 129
Notice: Undefined index: price in /home/710/283710/public_html/index.php on line 130
Notice: Undefined index: price in /home/710/283710/public_html/index.php on line 131
Notice: Undefined index: brand_model in /home/710/283710/public_html/index.php on line 135
Notice: Undefined index: price in /home/710/283710/public_html/index.php on line 136
Notice: Undefined index: offer_availability in /home/710/283710/public_html/index.php on line 144
Notice: Undefined index: brand_model in /home/710/283710/public_html/index.php on line 129
Notice: Undefined index: price in /home/710/283710/public_html/index.php on line 130
Notice: Undefined index: price in /home/710/283710/public_html/index.php on line 131
Notice: Undefined index: brand_model in /home/710/283710/public_html/index.php on line 135
Notice: Undefined index: price in /home/710/283710/public_html/index.php on line 136
Notice: Undefined index: offer_availability in /home/710/283710/public_html/index.php on line 144

Error messages works fine. So I guess there is some thing wrong with linking with Database.

Server: 000webhost.com (my lecturer told me to use this for assignment as it is free.)

<html>

<?php
$dbhost = 'localhost';
$dbname = 'id283710_mis410';
$dbuser = 'id283710_ahmedhojaief';
$dbpass = 'root123';
//$dbuser = 'root';
//$dbpass = '';
try {
    $db = new PDO("mysql:host={$dbhost};dbname={$dbname}",$dbuser,$dbpass);
    $db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
}

catch(PDOException $e) {
    echo "Connection error: ".$e->getMessage();
}
?>
<head>
    <title>Mis-410 | Assignment</title>
    <link rel="stylesheet" type="text/css" href="style.css" />

</head>
<body>
<form name="assignment" action="<?php $_PHP_SELF ?>" method="post" enctype="multipart/form-data">

<div id="div_resposive">
    <div id="div_top_header">
        Mobile Shop Management

        </br><marquee>WELCOME TO MY ASSIGNMENT</marquee>
    </div>
    <div id="div_middle">
        <!--div id="div_middle_left"></div-->

        <div id="div_middle_right">
            <div id="div_middle_right_top">         
                    <table id="entry_table" border="">
                        <tr>
                            <td id="order_sn"></td>                         
                            <td id="order_description">Customer Name</td>
                            <td id="order_semi"><b>:</b></td>   
                            <td id="order_text">
                                <input placeholder="Customer Name" type="text" name="n1" id="text_filed"  style="background-color:#EDEDED;"   title="Customer Name" value="<?php echo (isset($_POST['n1'])?$_POST['n1']:''); ?>" />
                            </td>
                        </tr>

                        <tr>
                            <td id="order_sn"></td>                         
                            <td id="order_description">Type your Budget</td>
                            <td id="order_semi"><b>:</b></td>   
                            <td id="order_text">
                                <input placeholder="Type your Budget" type="text" name="n2" id="text_filed"  style="background-color:#EDEDED;"   title="Type your Budget" value="<?php echo (isset($_POST['n2'])?$_POST['n2']:''); ?>" />
                            </td>
                        </tr>

                        <tr>
                            <td id="order_sn" colspan="4" style="height:50px;">
                                Hello mr./ms. <?php echo($_POST['n1']);?> Your Quarry is Places
                            </td>   
                        </tr>

                        <tr>
                            <td id="order_sn" colspan="4">
                                <a style="text-decoration:none; color:#880E4F;" href=""><button name="submit_button" type="submit" value="Submit" id="submit_button_style" title="SUBMIT">SUBMIT</button></a>
                                <a style="text-decoration:none; color:#880E4F;" href=""><button name="reset" type="reset" value="submit" id="submit_button_style" title="RESET">RESET</button></a>
                            </td>   
                        </tr>
                    </table>            
            </div>
            <div id="div_middle_right_down">

                    <?php
                            if(isset($_POST['n1']))
                            {
                                $x=$_POST['n1'];
                            }
                            if(isset($_POST['n2']))
                            {
                                $y=$_POST['n2'];
                            }



                            if(empty($_POST['n1']) && empty($_POST['n2'])) 
                            {   $message = "Sorry!! Customer Name & Budget is Empty..!";
                                echo "<script type='text/javascript'>alert('$message');</script>";
                            }
                            elseif(empty($_POST['n1'])) 
                            {   $message = "Sorry!! Customer Name is Empty..!";
                                echo "<script type='text/javascript'>alert('$message');</script>";
                            }

                            elseif(empty($_POST['n2'])) 
                            {   $message = "Sorry!! Budget is Empty..!";
                                echo "<script type='text/javascript'>alert('$message');</script>";
                            }

                            elseif($y<3090) 
                            {   $message = 'Hello Mr./Ms.&nbsp'.$x .'&nbspCurrently we do not have any mobile devices within your budget.';
                                echo "<script type='text/javascript'>alert('$message');</script>";
                                echo('</br></br>'.$message);
                            }

                            elseif (!empty($_POST['n1']) || !empty($_POST['n2'])) 
                            {

                                $x=$_POST['n1'];
                                $y=$_POST['n2'];


                                    $i=1;

                                    echo "Hello mr./ms. $x <br> Here is a list of available devices within your Budget : ";
                                    echo "<table border='1' id='price_list_table'>
                                        <th>Serial</th>
                                        <th>Name & Brand of Mobile </th>
                                        <th>Price</th>
                                        <th>Discount%</th>
                                        <th>Discounted Price</th>"; 

                                        $i=1;                                               
                                        $statement = $db->prepare("SELECT * FROM mobile_shop WHERE price <='$y' ORDER BY price DESC");
                                        $statement->execute();
                                        $result = $statement->fetchAll(PDO::FETCH_ASSOC);
                                        foreach($result as $row) {
                                            $mobile_shop_sn = $row['mobile_shop_sn'];
                                            $brand_model = $row['brand_model'];
                                            $price = $row['price'];
                                            $my_price = $row['price'];

                                            echo "<tr>";
                                            echo "<td id='price_list_table_sn'>".$i."</td>";
                                            echo "<td id='price_list_table_model'>".$row['brand_model']."</td>";
                                            echo "<td id='price_list_table_price'>".$row['price']."</td>";


                                                $mobile_shop_sn = $row['mobile_shop_sn'];
                                                $statement1 = $db->prepare("SELECT * from discount_offer where discount_offer_sn='$mobile_shop_sn'");
                                                $statement1->execute();
                                                $result1 = $statement1->fetchAll(PDO::FETCH_ASSOC);
                                                foreach($result1 as $row1) {
                                                    $discount_percent = $row1['offer_availability'];
                                                    echo "<td id='price_list_table_discount'>".$discount_percent."</td>";                                                   
                                                }                                               

                                            $my_discount = ($my_price * $discount_percent);
                                            $my_price_new = $my_price - $my_discount;
                                            echo "<td id='price_list_table_final_price'>".$my_price_new."</td>";

                                            echo"</tr>";                                            

                                            $i++;
                                        }

                                    echo "</table>";



                                //mysql_close($c);
                            }
                    ?> 



            </div>

        </div>
    </div>


</form>
</body>
</html>
bansi
  • 55,591
  • 6
  • 41
  • 52
ahmed
  • 1
  • 2
  • Well, I hope that your assignment isn't for OOP because the whole of this code is procedural & very messy. Have you turned on error reporting? Do that and tell us if you receive any errors. – Jaquarh Dec 17 '16 at 12:37
  • it shows something like API problem – ahmed Dec 17 '16 at 12:44
  • Can you update your question with this error? So we can see – Jaquarh Dec 17 '16 at 12:46
  • put these 2 lines `error_reporting(-1); ini_set('display_errors', 'On');` on the top of your code and post the exact full error message you get – bansi Dec 17 '16 at 12:47
  • I have updated it, I want to cry. I have to submit it tomorrow. – ahmed Dec 17 '16 at 12:54
  • try `foreach($result as $key => $row) {` instead of `foreach($result as $row) {` you should also change the other foreach also. try `print_r($row);` and see what is in `$row` first. you may then understand the error. – bansi Dec 17 '16 at 13:46

0 Answers0