Jump to content

Stephie22

Members
  • Posts

    13
  • Joined

  • Last visited

Stephie22's Achievements

Member

Member (2/5)

1

Reputation

  1. Hi Guys, what is the best way or links to read up on how to create an automatic image slider with the arrows on the side on the bubbles on the bottom so that the slide can move on its on, and when you click on the arrows, that you can manually change the slide.
  2. Thanx for the answers. We actually use the Active setting for reports. Where they dont want any data if a dealer is not active irrespective whether it has a cloaed date or not. In some cases they dont even provide a close date which makes it so difficult. Which editor would be best to use with PDO that is free? I am using notepad++ but it seems that it doesnt have the auto complete attributes for PDO. I have to type out everything.
  3. And the active column can only be Active and Not Active. Active is when a dealer is still open and selling cars. Not active is when they closed down the dealership
  4. Ok si basicallt im trying to create a web page where we as Nissan can go and keep our deal information up to datem currently they using an ezcel sheet which they enter duplicate data and duplicate dealercodes. Hence my primary key on row id and dealer code. So now im revamping this and making a project out of it. So as Nissan we sell Nissan and Datsun Vehicles.
  5. Ok if i would say just by looking at it. Put the dealer id. Dealer code. Dealer name. Dealer brand in one table. Then add the dealer id as a key in the second table with the rest of the columns. This was just a wild guess
  6. Thanx you requinix. That link helped me alot. Thanx for the help @benanamen thanx for advice. I will go learn that. If you can change the dealers table. How will you do it?
  7. i went and enhanced it now so that it can create a user as well. <?php $servername = "localhost"; $db_user = "root"; $db_password = ""; $db = "bdealers"; $username = "dealers"; $password = "dealers123"; $user = $username.'@'.$servername; $dsn = "mysql:host=$servername"; $opt = [PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION, PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC, PDO::ATTR_EMULATE_PREPARES => false]; try{ $pdo = new PDO($dsn, $db_user, $db_password, $opt); $sql = "CREATE DATABASE IF NOT EXISTS $db"; $pdo->exec($sql); $pdo->exec("CREATE USER $user IDENTIFIED WITH $password; GRANT ALL PRIVILEGES *.* TO $user; GRANT SELECT, INSERT, UPDATE, DELETE ON $db TO $user; FLUSH PRIVILEGES;"); $sql = "use $db"; $pdo->exec($sql); $sql = "CREATE TABLE IF NOT EXISTS dealers( dealer_id INTEGER UNSIGNED NOT NULL AUTO_INCREMENT, dealer_code VARCHAR(7) NOT NULL, dealer_name VARCHAR(20) NOT NULL, dealer_brand CHAR(1) NOT NULL, active CHAR(1) NOT NULL, registered_name VARCHAR(100) NOT NULL, date_opened VARCHAR( NOT NULL, date_closed VARCHAR( NOT NULL, year_registered INTEGER UNSIGNED NOT NULL, PRIMARY KEY(dealer_id, dealer_code) )"; $pdo->exec($sql); echo 'The database and table has successfully been created!'; }catch(PDOException $e){ echo $e->getMessage(); } ?> but now i get the following error: SQLSTATE[HY000]: General error: 1524 Plugin 'dealers123' is not loaded
  8. thank you so much.. i never thought that would be such a deal breaker, so used to use '' with mysql. thank you for the help. i worked.
  9. i might be misreading that, but i don't see anything wrong accept that it might be ambiguous? or is there something else missing in the string?
  10. Good Day Guys, I need some help. Took advice and started to learn PDO, and this is what i have done: <?php $host = '127.0.0.1'; $username = 'dealers'; $password = 'dealers123'; $dsn = 'mysql:host=$host'; $opt = [PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION, PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC, PDO::ATTR_EMULATE_PREPARES => false]; try{ $pdo = new PDO($dsn, $username, $password, $opt); $sql = 'CREATE DATABASE IF NOT EXISTS bdealers'; $pdo->exec($sql); $sql = 'use bdealers'; $pdo->exec($sql); $sql = 'CREATE TABLE IF NOT EXISTS dealers( dealer_id INTEGER UNSIGNED NOT NULL AUTO_INCREMENT, dealer_code VARCHAR(7) NOT NULL, dealer_name VARCHAR(20) NOT NULL, dealer_brand CHAR(1) NOT NULL, active CHAR(1) NOT NULL, registered_name VARCHAR(100) NOT NULL, date_opened VARCHAR( NOT NULL, date_closed VARCHAR( NOT NULL, year_registered INTEGER UNSIGNED NOT NULL, PRIMARY KEY(dealer_id, dealer_code) )'; $pdo->exec($sql); echo 'The database and table has successfully been created!'; }catch(PDOException $e){ echo $e->getMessage(); } ?> When i try to run it, i get the following error: SQLSTATE[HY000] [2002] php_network_getaddresses: getaddrinfo failed: No such host is known. Am i doing something wrong, as the localhost does exist?
  11. thank you for the response. any tutorials where i can go and learn the PDO side?
  12. Good Day Guys, I am busy creating a simple interactive website using php and i need some help. I have two forms. One that acts with all my actions like Add, Delete, Edit etc. My forms looks like this: Dealer_transaction.php: <!DOCTYPE HTML> <?php require 'db_connect.php'; //connect to mySQL $db = mysql_connect(MYSQL_HOST, MYSQL_USER, MYSQL_PASSWORD) or die('Unable to connect. Please check connection parameters!'); //make sure that the correct database is chosen mysql_select_db(MYSQL_DB, $db) or die(mysql_error($db)); switch($_POST['action']){ case 'Add Dealer': //escape incoming values to protect the db $dealer_code = mysql_real_escape_string($_POST['dealer_code'], $db); $dealer_name = mysql_real_escape_string($_POST['dealer_name'], $db); $dealer_brand = mysql_real_escape_string($_POST['dealer_brand'], $db); $active = mysql_real_escape_string($_POST['active'], $db); $registered_name = mysql_real_escape_string($_POST['registered_name'], $db); $date_opened = mysql_real_escape_string($_POST['date_opened'], $db); $date_closed = mysql_real_escape_string($_POST['date_closed'], $db); $year_registered = mysql_real_escape_string($_POST['year_registered'], $db); //add dealer information into the tables $query = 'INSERT IGNORE INTO dealers(dealer_code, dealer_name, dealer_brand, active, registered_name, date_opened, date_closed, year_registered) VALUES("'.$dealer_code.'", "'.$dealer_name.'", "'.$dealer_brand.'", "'.$active.'", "'.$registered_name.'", "'.$date_opened.'", "'.$date_closed.'", "'.$year_registered.'")'; mysql_query($query, $db) or die(mysql_error($db)); $redirect = '../index.php'; break; case 'Delete Dealer': //delete the dealer from the db $query = 'DELETE FROM dealers'; mysql_query($query, $db) or die(mysql_error($db)); $redirect = '../index.php'; break; default: $redirect = '../index.php'; break; } header('Location: ' . $redirect); ?> Delete.php: <!DOCTYPE HTML> <?php require 'db_connect.php'; //connect to mySQL $db = mysql_connect(MYSQL_HOST, MYSQL_USER, MYSQL_PASSWORD) or die('Unable to connect. Please check connection parameters!'); //make sure that the correct database is chosen mysql_select_db(MYSQL_DB, $db) or die(mysql_error($db)); ?> <html lang="en"> <head> <meta charset="UTF-8"> <title>Nissan Dealer Editing</title> <link rel="shortcut icon" href="../images/Group_of_Africa.ico"> <link rel="stylesheet" href="../Styles/add_delete_dealer.css"> <script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script> <script src="https://code.jquery.com/jquery-3.1.1.js"></script> <script src="js/dealer.js"></script> </head> <body> <header> <a href="../index.php"><img src="../images/Group_of_Africa_Logo.jpg" alt="Nissan Logo" height="80"></a> <hgroup> <h1>NISSAN</h1> <h2>Innovation that excites</h2> </hgroup> </header> <nav id="dealer_nav"> <ul> <li><a href="../index.php">Home</a></li> <li><a href="../php/add_dealer.php">Add Dealer</a></li> <li><a href="../php/delete_dealer.php" class="current">Delete Dealer</a></li> <li><a href="../php/about_us.php">About Us</a></li> <li><a href="../php/contact_us.php">Contact Us</a></li> </ul> </nav> <section> <form action="dealer_transactions.php" method="post"> <h2>Deleting A Dealer:</h2> <hr> <figure> <figcaption><h2 id="dealers_heading"><span style="color: red">NISSAN </span> <span style="color: #003F65">DATSUN </span><span style="color: silver">INFINITI </span>Dealerships</h2></figcaption> </figure> <fieldset> <legend>Dealer Information:</legend> <table> <?php //select the information from the database that you will be deleting $query = 'SELECT * from dealers'; $result = mysql_query($query, $db) or die(mysql_error($db)); $total_dealers = mysql_num_rows($result); $odd = true; if(mysql_num_rows($result) > 0){ while($row = mysql_fetch_assoc($result)){ echo ($odd == true) ? '<tr class="odd_row">' : '<tr class="even_row">'; $odd = !$odd; echo '<td style="width: 100%">'; echo $row['dealer_name']; echo '</td><td>'; echo '<input type="submit" class="button" name="action" value="Delete Dealer">'; echo '</td></tr>'; } echo '<tfoot>'; echo '<th colspan="9"></p>Total Dealers:'.$total_dealers.'</p></th>'; echo '</tfoot>'; echo '</table>'; }else{ echo '<table>'; echo '<hr>'; echo '<p><strong>No Dealers Has Been Added Yet...</strong></p>'; echo '<hr>'; echo '<tfoot>'; echo '<th colspan="9"><p>Total Dealers:'.$total_dealers.'</p></th>'; echo '</tfoot>'; echo '</table>'; } ?> </table> </fieldset> </form> </section> <footer> <p>© 2017 Accolade Consulting, Partners with Nissan</p> </footer> </body> what i am currently struggling with is the following. When i click on delete now, it will delete every record as per code ive written. But when i try to delete only a specific record. it does not want to work. I know i am suppose to pass the id to delete_transaction.php in order for it to delete the record, but i am only a novice for now. Can any1 help me to pass the id to the form that will action the delete query?
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.