Hi everyone. the professor has given us an assignment that is due on friday.

We are Using XAMPP for Apache and PHPMyAdmin, Visual Studio Code for the programming and my database professor has us using Workbench

he wants the database, an online form, a login screen, and the use of bootstrap. we are free to build it however we want as long as the project has all of these in it. we also have to make up our own fake company. in my case i choose a Custom PC Building Company which has a total of 15 tables which i already have finished with the use of MYSQL Workbench.

my plan is to use bootstrap just for the login screen, and the online form to input the database. Don't know if this is hard, easy or medium difficulty is there another way that can be easier perhaps. for the bootstrap he basically told us "go on the site and just copy and paste the code for whatever you are doing cuz i want you guys to focus more on the other coding".

i have begun to code the database to make sure i have that working properly but from what i am seeing and judging by my notes from class i will soon run into errors when i attempt to code after the first table so i figured i make this thread now so that you guys can perhaps help me before i get to that issue as he only showed us in class with one table and here i have 15 tables so i'm guessing i will need to make either a class, loop, public function, or something else to get past the first table but i'm not sure which one.

as soon as i get some coding complete i will post it here and if i run into some other trouble i'll post here. i will constantly be on here since i will be putting alot of hours into this project from here till friday so i should respond quickly.

    bd.php

    <?php
    
    
    
    class BD
    { // start
    
    private $mysql;
    	function __construct($server, $username, $password, $database)
    	{ //  start function
    	$this -> mysql = new mysqli($server, $username, $password, $database);
    
    	if ($this -> mysql --> connect_errno)
    	{ // start if
    	echo "Failed to Connect to MySQL: (" . $this -> mysqli -> connect_errno . ")" . $this-> mysqli -> connect_error;
    	} // end if
    } // end function
    
    
    
    	public function get_clients()
    	{ //  start function
    
    	$clients = array();
    	$resultclient = $this -> mysqli -> query("Select * from clients");
    
    	while ($row = $resultclients -> fetch_asssoc())
    	{ // start while
    	$clients[] = array ($row ['ClientIDNumber'], $row['ClientFirstName'], $row['ClientLastName'], $row['ClientPhoneNumber'], $row['ClientCompanyName'], $row['ClientType']);
    	} // end while
    
    	return $clients;
    	} //  end function
    
    
    
    public function insertclients ($ClientIDNumber, $ClientFirstName, $ClientLastName, $ClientPhoneNumber, $ClientCompanyName, $ClientType)
    { // start function
    $result = $this -> mysqli -> query ("Insert Into clients (ClientIDNumber, $ClientFirstName, $ClientLastName, $ClientCompanyName) values ('".$ClientIDNumber."', '".$ClientFirstName."', '".$ClientLastName."', '".$ClientCompanyName."')");
    return $resultclient;
    } // end function
    
    
    } // end
    ?>

    end of bd.php

    start of data.php

    <?php
    
    
    
    $ClientIDNumber=$_POST["ClientIDNumber"];
    echo "<br>"; echo $ClientIDNumber;
    
    $ClientFirstName=$_POST["ClientFirstName"];
    echo "<br>"; echo $ClientFirstName;
    
    $ClientLastName=$_POST["ClientLastName"];
    echo "<br>"; echo $ClientLastName;
    
    $ClientPhoneNumber=$_POST["ClientPhoneNumber"];
    echo "<br>"; echo $ClientPhoneNumber;
    
    $ClientCompanyName=$_POST["ClientCompanyName"];
    echo "<br>"; echo $ClientCompanyName;
    
    $ClientType=$_POST["ClientType"];
    echo "<br>"; echo $ClientType;
    
    
    
    
    ?>
    
    
    

    end of data.php

    start of index.php

    <html>
    	<head>
    		<title>Forms</title>
    		</head>
    		<body>
    
    
    		<form action="data.php" method="post">
    			<p>Client ID Number: <input type="text" name="Client ID Number" /></p>
    			<p>Client First Name: <input type="text" name="Client First Name" /></p>
    			<p>Client Last Name: <input type="text" name="Client Last Name" /></p>
    			<p>Client Phone Number: <input type="text" name="Client Phone Number" /></p>
    			<p>Client Company Name: <input type="text" name="Client Company Name" /></p>
    			<p>Client Type: <input type="text" name="Client Type" /></p>
    			<p><input type="submit" /></p>
    			</form>
    			</body>
    			</html>
    
    <?php
    	include "bd.php";
    
    
    
    $tableclients = new BD('localhost', 'root', '', 'Assignment');
    $clients = $bd -> get_clients();
    
    
    
    foreach($clients as $clients)
    {
    echo $clients. '<br>';	
    }
    ?>

    end of index.php

    start of insertclient.php

    <?php
    
    include "bd.php";
    include "data.php";
    
    $tableclients = new BD('localhost', 'root', '', 'assignment');
    $tableclients -> insertclients ("1", "John", "Smith", "555-555-5555", "", "Customer");
    
    if ($result==true)
    { // start if
    echo "Data Correctly Entered";
    } // end if
    	else
    	{ // start else
    	echo "Error";
    	} // end else
    
    
    
    ?>

    end of insert client

    this is all i got and i was given the following error codes:

    [ATTACH]5233[/ATTACH]

    what am i doing wrong and how can i fix these errors. i still got 14 more to go 🙁

    error.png

      I could be wrong, but it looks to me like you're mixing mysql and mysqli:

      <?php

      class BD
      { // start

      private $mysql;
      function __construct($server, $username, $password, $database)
      { // start function
      $this -> mysql = new mysqli($server, $username, $password, $database);

          if ($this -> [B]mysql[/B] --> connect_errno)
          { // start if
          echo "Failed to Connect to MySQL: (" . $this -> [B]mysqli[/B] -> connect_errno . ")" . $this-> [B]mysqli[/B] -> connect_error;
          } // end if
      } // end function [/quote]
        schwim;11050137 wrote:

        I could be wrong, but it looks to me like you're mixing mysql and mysqli:

        that was the code the professor showed us in class and i copied it exactly as how he had it.

          wilmer007 wrote:

          that was the code the professor showed us in class and i copied it exactly as how he had it.

          In that case your professor made some typo errors that you should, or perhaps are even expected to, fix.

          Note that while schwim bolded mysqli on this line:

          $this -> mysql = new mysqli($server, $username, $password, $database);

          That is actually not a problem: one can validly name a reference variable pointing to a mysqli object mysql and hence assign to $this->mysql. The problem comes when $this->mysqli is used instead of $this->mysql, resuling in the "undefined property" notice and other related warnings/errors. Additionally, there is also the typo error where --> was used instead of ->

          By the way, why is the class named BD rather than DB?

            alright i was able to get rid of all the errors now except for one:

            Fatal error: Call to undefined method mysqli_result::fetch_asssoc() in D:\xampp\htdocs\assignment\db.php on line 28[/QUOTE]

            line 28 is:

            while ($row = $resultclient -> fetch_asssoc())

            how can i fix this last error?

              An error message that says "Call to undefined method" means that the method has not been defined, e.g., because you did not define it. In this case the method belongs to a class from a well known database extension, so it is likely to have been defined, except that you made a mistake. The most likely possibilities is that you tried to call a method that is from a different class, or you simply misspelled the method name. As it turns out, you made the latter mistake: fetch_asssoc should have been fetch_assoc.

                wow i can't believe i did not see that extra s. lol thanks for helping me find that mistake.

                this is what i got so far:

                [ATTACH]5235[/ATTACH]
                [ATTACH]5237[/ATTACH]

                now the question is how do i make the create, insert, edit tables in the database management to function. he only showed us how to insert he didn't show us how to create and edit tables or how to do the queries.

                i also have to get a working registration and login form

                index.png site.png
                  5 days later

                  ok so i have completed the entire project but now i'm stuck with trying to update the database. can someone look this code over and see what is going on. the error code i am getting is

                  Failed to run query: SQLSTATE[HY093]: Invalid parameter number: number of bound variables does not match number of tokens

                  <?php 
                  
                  //connects to database
                      require("config.php");
                  ?>
                  
                  
                  
                  <!doctype html>
                  <html lang="en">
                  <head>
                      <meta charset="utf-8">
                      <title>Assignment</title>
                      <meta name="description" content="Assignment">
                      <meta name="author" content="Untame.net">
                  
                  <script src="http://ajax.googleapis.com/ajax/libs/jquery/2.0.0/jquery.min.js"></script>
                  <script src="assets/bootstrap.min.js"></script>
                  <link href="assets/bootstrap.min.css" rel="stylesheet" media="screen">
                  <style type="text/css">
                      body { background: url(assets/bglight.png); }
                      .hero-unit { background-color: #fff; }
                      .center { display: block; margin: 0 auto; }
                  </style>
                  </head>
                  
                  <body>
                  
                  <div class="navbar navbar-fixed-top navbar-inverse">
                    <div class="navbar-inner">
                      <div class="container">
                        <a class="btn btn-navbar" data-toggle="collapse" data-target=".nav-collapse">
                          <span class="icon-bar"></span>
                          <span class="icon-bar"></span>
                          <span class="icon-bar"></span>
                        </a>
                        <a class="brand">Assignment</a>
                        <div class="nav-collapse">
                          <ul class="nav pull-right">
                            <li><a href="secret.php">Return To Main Menu</a></li>
                          </ul>
                        </div>
                      </div>
                    </div>
                  </div>
                  
                  <div class="container hero-unit">
                      <h1>Update</h1> <br /><br />
                      <form action="update.php" method="post"> 
                          <label>ID:</label> 
                          <input type="text" name="id" value="" /> 
                          <label>Lot: <strong style="color:darkred;">*</strong></label> 
                          <input type="text" name="lot" value="" /> 
                          <label>Model:</label> 
                          <input type="text" name="model" value="" /> <br /><br />
                          <input type="submit" class="btn btn-info" value="Update" /> 
                      </form>
                  </div>
                  
                  </body>
                  </html>
                  
                  
                  
                  <?php 
                      if(!empty($_POST)) 
                      { 
                          // Ensure that the user fills out fields 
                          if(empty($_POST['id'])) 
                          { die("Please enter an id."); } 
                          if(empty($_POST['model'])) 
                          { die("Please enter a model."); } 
                           if(empty($_POST['lot'])) 
                          { die("Please enter a lot."); } 
                  
                  
                  
                  
                  
                  
                      // Update 
                      $query = " 
                          UPDATE products
                          SET model=model,lot=lot,...
                          WHERE id = :id
                      "; 
                  
                       $model = $_POST['model']; 
                       $query_params = array( 
                  
                          ':id' => $_POST['id'], 
                          ':model' => $model, 
                          ':lot' => $_POST['lot'] 
                      ); 
                  
                      try {  
                          $stmt = $db->prepare($query);
                          $result = $stmt->execute($query_params); 
                      } 
                      catch(PDOException $ex){ die("Failed to run query: " . $ex->getMessage()); } 
                      header("Location: secret.php"); 
                      die("Redirecting to secret.php"); 
                  } 
                  ?>

                  this is the last thing i need to get working to turn in the project this afternoon.

                            // Update 
                            $query = " 
                                UPDATE products
                                SET model=model,lot=lot,...
                                WHERE id = :id
                            "; 
                    
                         $model = $_POST['model']; 
                         $query_params = array( 
                    
                            ':id' => $_POST['id'], 
                            ':model' => $model, 
                            ':lot' => $_POST['lot'] 
                        ); 
                         

                    Look at how you're using (and, more importantly, not using) colons here.

                      Weedpacket;11050281 wrote:

                      Look at how you're using (and, more importantly, not using) colons here.

                       
                                  ':id' => $_POST['id'],  
                      ':model' => $_POST['model'],
                      ':lot' => $_POST['lot']

                      just fixed it and i still get the same error. i was able to get the update working with a different code but i would rather fix this one since this HTML looks alot better.

                        someone wanna help me please i got two hours left before i have to leave and present. he also told me i have to program to show the insert and update and i don't know if ill have time to finish all this in 2 hours.

                          Write a Reply...