Jump to content
Killersites Community

falkencreative

Administrators
  • Content Count

    4,419
  • Joined

  • Last visited

  • Days Won

    26

Everything posted by falkencreative

  1. Check out our new Interactive Web Developer course (created in 2016) that covers this, and much more: shop.killervideostore.com This is a revised version of my previous tutorial (http://www.killersites.com/community/index.php?/topic/1969-basic-php-system-vieweditdeleteadd-records/) which uses MySQLi rather than regular MySQL to connect to the database. MySQLi, often called MySQL Improved, has several advantages over regular MySQL, including support for prepared statements (which helps prevent SQL injection, a common security issue) and object-oriented code. I've also provided a modified view.php file that shows one way to do basic pagination. I have also recorded a 8 part video tutorial (a bit over an an hour worth of video) showing how to build this system and explaining it as I go. It's available in the KillerSites University (http://www.webmentor.org - subscription required) under PHP > PHP CRUD Videos. --- (Anyone with PHP knowledge is welcome to comment on the code. If there are issues I haven't noticed, please let me know. Do realize that it is intended for beginners, so I didn't want to do anything too advanced that might lead to confusion. Yes, I realize I could use OOP, or could separate some of these out into methods, etc. etc.) OK... Here's some code for you to play with. It's a basic system that allows you to: -- view existing records -- edit existing records -- delete existing records -- add new records Online demo: http://www.falkencreative.com/forum/records-mysqli/view.php Basically, just imagine that you are in charge of a sports team, and you want to keep a list of all your player's contact information. The code I've created could be a starting point for that (it only includes fields for their first name/last name, but could obviously could be expanded to use more fields). This is just a basic starting point for projects that require view/edit/delete functionality. I know it may seem a lot to understand at first, but read all the comments in the code -- I try to explain what I am doing step by step. I'm also happy to help with any questions (please post questions in a new topic.) How to create a system that allows a user to add/edit/remove data in a database seems to be a commonly asked topic, so I may adapt this into an actual tutorial at some point in the future. DATABASE: -- You'll need to create a database (I named mine 'records' but it can be changed) using PHPMyAdmin -- Save the included sql file on your desktop as a .txt file -- Once you've created the database, make sure the database is selected, then click the "import" tab -- Select the .txt file on your desktop, and import it into your database. PHPMyAdmin will create all of the necessary tables/import some test data for you to play with SQL file: -- -- Table structure for table `players` -- CREATE TABLE `players` ( `id` int(11) NOT NULL auto_increment, `firstname` varchar(32) NOT NULL, `lastname` varchar(32) NOT NULL, PRIMARY KEY (`id`) ) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=5 ; -- -- Dumping data for table `players` -- INSERT INTO `players` VALUES(1, 'Bob', 'Baker'); INSERT INTO `players` VALUES(2, 'Tim', 'Thomas'); INSERT INTO `players` VALUES(3, 'Rachel', 'Roberts'); INSERT INTO `players` VALUES(4, 'Sam', 'Smith'); Save these php files all in the same folder in a place where you can run them using your server (I'm assuming you are using something like WAMP for the server? I'm not sure if Dreamweaver includes something like that by default.) connect-db.php <?php // server info $server = 'localhost'; $user = 'root'; $pass = 'root'; $db = 'records2'; // connect to the database $mysqli = new mysqli($server, $user, $pass, $db); // show errors (remove this line if on a live site) mysqli_report(MYSQLI_REPORT_ERROR); ?> view.php (non-paginated -- will just display one long list of members) <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> <html> <head> <title>View Records</title> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/> </head> <body> <h1>View Records</h1> <p><b>View All</b> | <a href="view-paginated.php">View Paginated</a></p> <?php // connect to the database include('connect-db.php'); // get the records from the database if ($result = $mysqli->query("SELECT * FROM players ORDER BY id")) { // display records if there are records to display if ($result->num_rows > 0) { // display records in a table echo "<table border='1' cellpadding='10'>"; // set table headers echo "<tr><th>ID</th><th>First Name</th><th>Last Name</th><th></th><th></th></tr>"; while ($row = $result->fetch_object()) { // set up a row for each record echo "<tr>"; echo "<td>" . $row->id . "</td>"; echo "<td>" . $row->firstname . "</td>"; echo "<td>" . $row->lastname . "</td>"; echo "<td><a href='records.php?id=" . $row->id . "'>Edit</a></td>"; echo "<td><a href='delete.php?id=" . $row->id . "'>Delete</a></td>"; echo "</tr>"; } echo "</table>"; } // if there are no records in the database, display an alert message else { echo "No results to display!"; } } // show an error if there is an issue with the database query else { echo "Error: " . $mysqli->error; } // close database connection $mysqli->close(); ?> <a href="records.php">Add New Record</a> </body> </html> view-paginated.php <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> <html> <head> <title>View Records</title> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/> </head> <body> <h1>View Records</h1> <?php // connect to the database include('connect-db.php'); // number of results to show per page $per_page = 3; // figure out the total pages in the database if ($result = $mysqli->query("SELECT * FROM players ORDER BY id")) { if ($result->num_rows != 0) { $total_results = $result->num_rows; // ceil() returns the next highest integer value by rounding up value if necessary $total_pages = ceil($total_results / $per_page); // check if the 'page' variable is set in the URL (ex: view-paginated.php?page=1) if (isset($_GET['page']) && is_numeric($_GET['page'])) { $show_page = $_GET['page']; // make sure the $show_page value is valid if ($show_page > 0 && $show_page <= $total_pages) { $start = ($show_page -1) * $per_page; $end = $start + $per_page; } else { // error - show first set of results $start = 0; $end = $per_page; } } else { // if page isn't set, show first set of results $start = 0; $end = $per_page; } // display pagination echo "<p><a href='view.php'>View All</a> | <b>View Page:</b> "; for ($i = 1; $i <= $total_pages; $i++) { if (isset($_GET['page']) && $_GET['page'] == $i) { echo $i . " "; } else { echo "<a href='view-paginated.php?page=$i'>$i</a> "; } } echo "</p>"; // display data in table echo "<table border='1' cellpadding='10'>"; echo "<tr> <th>ID</th> <th>First Name</th> <th>Last Name</th> <th></th> <th></th></tr>"; // loop through results of database query, displaying them in the table for ($i = $start; $i < $end; $i++) { // make sure that PHP doesn't try to show results that don't exist if ($i == $total_results) { break; } // find specific row $result->data_seek($i); $row = $result->fetch_row(); // echo out the contents of each row into a table echo "<tr>"; echo '<td>' . $row[0] . '</td>'; echo '<td>' . $row[1] . '</td>'; echo '<td>' . $row[2] . '</td>'; echo '<td><a href="records.php?id=' . $row[0] . '">Edit</a></td>'; echo '<td><a href="delete.php?id=' . $row[0] . '">Delete</a></td>'; echo "</tr>"; } // close table> echo "</table>"; } else { echo "No results to display!"; } } // error with the query else { echo "Error: " . $mysqli->error; } // close database connection $mysqli->close(); ?> <a href="records.php">Add New Record</a> </body> </html> </html> records.php (create a new record/edit existing records) <?php /* Allows the user to both create new records and edit existing records */ // connect to the database include("connect-db.php"); // creates the new/edit record form // since this form is used multiple times in this file, I have made it a function that is easily reusable function renderForm($first = '', $last ='', $error = '', $id = '') { ?> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> <html> <head> <title> <?php if ($id != '') { echo "Edit Record"; } else { echo "New Record"; } ?> </title> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/> </head> <body> <h1><?php if ($id != '') { echo "Edit Record"; } else { echo "New Record"; } ?></h1> <?php if ($error != '') { echo "<div style='padding:4px; border:1px solid red; color:red'>" . $error . "</div>"; } ?> <form action="" method="post"> <div> <?php if ($id != '') { ?> <input type="hidden" name="id" value="<?php echo $id; ?>" /> <p>ID: <?php echo $id; ?></p> <?php } ?> <strong>First Name: *</strong> <input type="text" name="firstname" value="<?php echo $first; ?>"/><br/> <strong>Last Name: *</strong> <input type="text" name="lastname" value="<?php echo $last; ?>"/> <p>* required</p> <input type="submit" name="submit" value="Submit" /> </div> </form> </body> </html> <?php } /* EDIT RECORD */ // if the 'id' variable is set in the URL, we know that we need to edit a record if (isset($_GET['id'])) { // if the form's submit button is clicked, we need to process the form if (isset($_POST['submit'])) { // make sure the 'id' in the URL is valid if (is_numeric($_POST['id'])) { // get variables from the URL/form $id = $_POST['id']; $firstname = htmlentities($_POST['firstname'], ENT_QUOTES); $lastname = htmlentities($_POST['lastname'], ENT_QUOTES); // check that firstname and lastname are both not empty if ($firstname == '' || $lastname == '') { // if they are empty, show an error message and display the form $error = 'ERROR: Please fill in all required fields!'; renderForm($firstname, $lastname, $error, $id); } else { // if everything is fine, update the record in the database if ($stmt = $mysqli->prepare("UPDATE players SET firstname = ?, lastname = ? WHERE id=?")) { $stmt->bind_param("ssi", $firstname, $lastname, $id); $stmt->execute(); $stmt->close(); } // show an error message if the query has an error else { echo "ERROR: could not prepare SQL statement."; } // redirect the user once the form is updated header("Location: view.php"); } } // if the 'id' variable is not valid, show an error message else { echo "Error!"; } } // if the form hasn't been submitted yet, get the info from the database and show the form else { // make sure the 'id' value is valid if (is_numeric($_GET['id']) && $_GET['id'] > 0) { // get 'id' from URL $id = $_GET['id']; // get the recod from the database if($stmt = $mysqli->prepare("SELECT * FROM players WHERE id=?")) { $stmt->bind_param("i", $id); $stmt->execute(); $stmt->bind_result($id, $firstname, $lastname); $stmt->fetch(); // show the form renderForm($firstname, $lastname, NULL, $id); $stmt->close(); } // show an error if the query has an error else { echo "Error: could not prepare SQL statement"; } } // if the 'id' value is not valid, redirect the user back to the view.php page else { header("Location: view.php"); } } } /* NEW RECORD */ // if the 'id' variable is not set in the URL, we must be creating a new record else { // if the form's submit button is clicked, we need to process the form if (isset($_POST['submit'])) { // get the form data $firstname = htmlentities($_POST['firstname'], ENT_QUOTES); $lastname = htmlentities($_POST['lastname'], ENT_QUOTES); // check that firstname and lastname are both not empty if ($firstname == '' || $lastname == '') { // if they are empty, show an error message and display the form $error = 'ERROR: Please fill in all required fields!'; renderForm($firstname, $lastname, $error); } else { // insert the new record into the database if ($stmt = $mysqli->prepare("INSERT players (firstname, lastname) VALUES (?, ?)")) { $stmt->bind_param("ss", $firstname, $lastname); $stmt->execute(); $stmt->close(); } // show an error if the query has an error else { echo "ERROR: Could not prepare SQL statement."; } // redirec the user header("Location: view.php"); } } // if the form hasn't been submitted yet, show the form else { renderForm(); } } // close the mysqli connection $mysqli->close(); ?> delete.php <?php // connect to the database include('connect-db.php'); // confirm that the 'id' variable has been set if (isset($_GET['id']) && is_numeric($_GET['id'])) { // get the 'id' variable from the URL $id = $_GET['id']; // delete record from database if ($stmt = $mysqli->prepare("DELETE FROM players WHERE id = ? LIMIT 1")) { $stmt->bind_param("i",$id); $stmt->execute(); $stmt->close(); } else { echo "ERROR: could not prepare SQL statement."; } $mysqli->close(); // redirect user after delete is successful header("Location: view.php"); } else // if the 'id' variable isn't set, redirect the user { header("Location: view.php"); } ?>
  2. This is a summary of the topic 'Starting a web design business', originally posted on July 23, 2008. Original thread: http://killersites.com/mvnforum/mvnforum/viewthread?thread=11509 ------------------------------------------------------------------------------
  3. falkencreative

    Divi elementor beaver

    I've built sites using Divi and other such builders, and it is possible to customize sites built on those platforms. Depending on your needs, you'll likely find that you will need to make styling or layout adjustments. No site builder is perfect and you likely won't find something that matches 100% with what you want to do. Most site builders have specific APIs or expectations for how changes are made. At least in my experience, even if you use a site builder plugin, it's rare that you won't have to code anything at all. The downside with site builders is that they often try to do too much -- they try to be the solution to every possible problem, and it results in sites that are over-engineered and slow to download. You'll potentially wind up with a site that only uses 20% of the theme builder's functionality, but 100% of all the downsides. I generally prefer to custom build my sites, using the Advanced Custom Fields plugin to provide the editing interface for the various content blocks that make up the site. In general, you won't be able to export out the code that these Wordpress-based site builders generate -- they rely on Wordpress and Wordpress' editing interface in order to work. I suppose you could manually download each page as HTML and piece the file structure together, but that's a significant amount of work and you'll lose the ability to easily edit the content or change functionality.
  4. falkencreative

    Basic Php System: View/edit/delete/add Records

    Check out our new Interactive Web Developer course (created in 2016) that covers this, and much more: shop.killervideostore.com (Anyone with PHP knowledge is welcome to comment on the code. If there are issues I haven't noticed, please let me know. Do realize that it is intended for beginners, so I didn't want to do anything too advanced that might lead to confusion. Yes, I realize I could use OOP, or could separate some of these out into methods, etc. etc.) OK... Here's some code for you to play with. It's a basic system that allows you to: -- view existing records -- edit existing records -- delete existing records -- add new records Online demo: http://www.falkencre...ecords/view.php Basically, just imagine that you are in charge of a sports team, and you want to keep a list of all your player's contact information. The code I've created could be a starting point for that (it only includes fields for their first name/last name, but could obviously could be expanded to use more fields). This is just a basic starting point for projects that require view/edit/delete functionality. I know it may seem a lot to understand at first, but read all the comments in the code -- I try to explain what I am doing step by step. I'm also happy to help with any questions (please post questions in a new topic.) How to create a system that allows a user to add/edit/remove data in a database seems to be a commonly asked topic, so I may adapt this into an actual tutorial at some point in the future. DATABASE: -- You'll need to create a database (I named mine 'records' but it can be changed) using PHPMyAdmin -- Save the included sql file on your desktop as a .txt file -- Once you've created the database, make sure the database is selected, then click the "import" tab -- Select the .txt file on your desktop, and import it into your database. PHPMyAdmin will create all of the necessary tables/import some test data for you to play with SQL file: -- -- Table structure for table `players` -- CREATE TABLE `players` ( `id` int(11) NOT NULL auto_increment, `firstname` varchar(32) NOT NULL, `lastname` varchar(32) NOT NULL, PRIMARY KEY (`id`) ) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=5 ; -- -- Dumping data for table `players` -- INSERT INTO `players` VALUES(1, 'Bob', 'Baker'); INSERT INTO `players` VALUES(2, 'Tim', 'Thomas'); INSERT INTO `players` VALUES(3, 'Rachel', 'Roberts'); INSERT INTO `players` VALUES(4, 'Sam', 'Smith'); Save these php files all in the same folder in a place where you can run them using your server (I'm assuming you are using something like WAMP for the server? I'm not sure if Dreamweaver includes something like that by default.) connect-db.php <?php /* CONNECT-DB.PHP Allows PHP to connect to your database */ // Database Variables (edit with your own server information) $server = 'localhost'; $user = 'root'; $pass = 'root'; $db = 'records'; // Connect to Database $connection = mysql_connect($server, $user, $pass) or die ("Could not connect to server ... \n" . mysql_error ()); mysql_select_db($db) or die ("Could not connect to database ... \n" . mysql_error ()); ?> view.php <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> <html> <head> <title>View Records</title> </head> <body> <?php /* VIEW.PHP Displays all data from 'players' table */ // connect to the database include('connect-db.php'); // get results from database $result = mysql_query("SELECT * FROM players") or die(mysql_error()); // display data in table echo "<p><b>View All</b> | <a href='view-paginated.php?page=1'>View Paginated</a></p>"; echo "<table border='1' cellpadding='10'>"; echo "<tr> <th>ID</th> <th>First Name</th> <th>Last Name</th> <th></th> <th></th></tr>"; // loop through results of database query, displaying them in the table while($row = mysql_fetch_array( $result )) { // echo out the contents of each row into a table echo "<tr>"; echo '<td>' . $row['id'] . '</td>'; echo '<td>' . $row['firstname'] . '</td>'; echo '<td>' . $row['lastname'] . '</td>'; echo '<td><a href="edit.php?id=' . $row['id'] . '">Edit</a></td>'; echo '<td><a href="delete.php?id=' . $row['id'] . '">Delete</a></td>'; echo "</tr>"; } // close table> echo "</table>"; ?> <p><a href="new.php">Add a new record</a></p> </body> </html> view-paginated.php Same as view.php above, except that results are split up into separate pages <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> <html> <head> <title>View Records</title> </head> <body> <?php /* VIEW-PAGINATED.PHP Displays all data from 'players' table This is a modified version of view.php that includes pagination */ // connect to the database include('connect-db.php'); // number of results to show per page $per_page = 3; // figure out the total pages in the database $result = mysql_query("SELECT * FROM players"); $total_results = mysql_num_rows($result); $total_pages = ceil($total_results / $per_page); // check if the 'page' variable is set in the URL (ex: view-paginated.php?page=1) if (isset($_GET['page']) && is_numeric($_GET['page'])) { $show_page = $_GET['page']; // make sure the $show_page value is valid if ($show_page > 0 && $show_page <= $total_pages) { $start = ($show_page -1) * $per_page; $end = $start + $per_page; } else { // error - show first set of results $start = 0; $end = $per_page; } } else { // if page isn't set, show first set of results $start = 0; $end = $per_page; } // display pagination echo "<p><a href='view.php'>View All</a> | <b>View Page:</b> "; for ($i = 1; $i <= $total_pages; $i++) { echo "<a href='view-paginated.php?page=$i'>$i</a> "; } echo "</p>"; // display data in table echo "<table border='1' cellpadding='10'>"; echo "<tr> <th>ID</th> <th>First Name</th> <th>Last Name</th> <th></th> <th></th></tr>"; // loop through results of database query, displaying them in the table for ($i = $start; $i < $end; $i++) { // make sure that PHP doesn't try to show results that don't exist if ($i == $total_results) { break; } // echo out the contents of each row into a table echo "<tr>"; echo '<td>' . mysql_result($result, $i, 'id') . '</td>'; echo '<td>' . mysql_result($result, $i, 'firstname') . '</td>'; echo '<td>' . mysql_result($result, $i, 'lastname') . '</td>'; echo '<td><a href="edit.php?id=' . mysql_result($result, $i, 'id') . '">Edit</a></td>'; echo '<td><a href="delete.php?id=' . mysql_result($result, $i, 'id') . '">Delete</a></td>'; echo "</tr>"; } // close table> echo "</table>"; // pagination ?> <p><a href="new.php">Add a new record</a></p> </body> </html> new.php <?php /* NEW.PHP Allows user to create a new entry in the database */ // creates the new record form // since this form is used multiple times in this file, I have made it a function that is easily reusable function renderForm($first, $last, $error) { ?> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> <html> <head> <title>New Record</title> </head> <body> <?php // if there are any errors, display them if ($error != '') { echo '<div style="padding:4px; border:1px solid red; color:red;">'.$error.'</div>'; } ?> <form action="" method="post"> <div> <strong>First Name: *</strong> <input type="text" name="firstname" value="<?php echo $first; ?>" /><br/> <strong>Last Name: *</strong> <input type="text" name="lastname" value="<?php echo $last; ?>" /><br/> <p>* required</p> <input type="submit" name="submit" value="Submit"> </div> </form> </body> </html> <?php } // connect to the database include('connect-db.php'); // check if the form has been submitted. If it has, start to process the form and save it to the database if (isset($_POST['submit'])) { // get form data, making sure it is valid $firstname = mysql_real_escape_string(htmlspecialchars($_POST['firstname'])); $lastname = mysql_real_escape_string(htmlspecialchars($_POST['lastname'])); // check to make sure both fields are entered if ($firstname == '' || $lastname == '') { // generate error message $error = 'ERROR: Please fill in all required fields!'; // if either field is blank, display the form again renderForm($firstname, $lastname, $error); } else { // save the data to the database mysql_query("INSERT players SET firstname='$firstname', lastname='$lastname'") or die(mysql_error()); // once saved, redirect back to the view page header("Location: view.php"); } } else // if the form hasn't been submitted, display the form { renderForm('','',''); } ?> edit.php <?php /* EDIT.PHP Allows user to edit specific entry in database */ // creates the edit record form // since this form is used multiple times in this file, I have made it a function that is easily reusable function renderForm($id, $firstname, $lastname, $error) { ?> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> <html> <head> <title>Edit Record</title> </head> <body> <?php // if there are any errors, display them if ($error != '') { echo '<div style="padding:4px; border:1px solid red; color:red;">'.$error.'</div>'; } ?> <form action="" method="post"> <input type="hidden" name="id" value="<?php echo $id; ?>"/> <div> <p><strong>ID:</strong> <?php echo $id; ?></p> <strong>First Name: *</strong> <input type="text" name="firstname" value="<?php echo $firstname; ?>"/><br/> <strong>Last Name: *</strong> <input type="text" name="lastname" value="<?php echo $lastname; ?>"/><br/> <p>* Required</p> <input type="submit" name="submit" value="Submit"> </div> </form> </body> </html> <?php } // connect to the database include('connect-db.php'); // check if the form has been submitted. If it has, process the form and save it to the database if (isset($_POST['submit'])) { // confirm that the 'id' value is a valid integer before getting the form data if (is_numeric($_POST['id'])) { // get form data, making sure it is valid $id = $_POST['id']; $firstname = mysql_real_escape_string(htmlspecialchars($_POST['firstname'])); $lastname = mysql_real_escape_string(htmlspecialchars($_POST['lastname'])); // check that firstname/lastname fields are both filled in if ($firstname == '' || $lastname == '') { // generate error message $error = 'ERROR: Please fill in all required fields!'; //error, display form renderForm($id, $firstname, $lastname, $error); } else { // save the data to the database mysql_query("UPDATE players SET firstname='$firstname', lastname='$lastname' WHERE id='$id'") or die(mysql_error()); // once saved, redirect back to the view page header("Location: view.php"); } } else { // if the 'id' isn't valid, display an error echo 'Error!'; } } else // if the form hasn't been submitted, get the data from the db and display the form { // get the 'id' value from the URL (if it exists), making sure that it is valid (checing that it is numeric/larger than 0) if (isset($_GET['id']) && is_numeric($_GET['id']) && $_GET['id'] > 0) { // query db $id = $_GET['id']; $result = mysql_query("SELECT * FROM players WHERE id=$id") or die(mysql_error()); $row = mysql_fetch_array($result); // check that the 'id' matches up with a row in the databse if($row) { // get data from db $firstname = $row['firstname']; $lastname = $row['lastname']; // show form renderForm($id, $firstname, $lastname, ''); } else // if no match, display result { echo "No results!"; } } else // if the 'id' in the URL isn't valid, or if there is no 'id' value, display an error { echo 'Error!'; } } ?> delete.php <?php /* DELETE.PHP Deletes a specific entry from the 'players' table */ // connect to the database include('connect-db.php'); // check if the 'id' variable is set in URL, and check that it is valid if (isset($_GET['id']) && is_numeric($_GET['id'])) { // get id value $id = $_GET['id']; // delete the entry $result = mysql_query("DELETE FROM players WHERE id=$id") or die(mysql_error()); // redirect back to the view page header("Location: view.php"); } else // if id isn't set, or isn't valid, redirect back to view page { header("Location: view.php"); } ?>
  5. falkencreative

    Bootstrap Question

    Looks like the issue is primarily due to the fixed height on .header. The set height doesn't allow that section to re-flow into multiple lines. Removing the fixed height would be the first step to fixing it, though you'll need to do some styling adjustments on the header as well, such as removing the left margin on the .header h2. Personally, I'd consider restyling the .header section completely, removing the background image, removing the fixed header height, and making it a normal <img> element with floated text. The background image and the left margin on the header text is the primary issue that is preventing proper mobile display.
  6. falkencreative

    Bootstrap Question

    What is currently happening, and what do you want to happen?
  7. falkencreative

    Responsive Design With Bootstrap

    If all the data you are displaying is the same for both desktop and mobile devices, I would focus on using both the built in Bootstrap options and potentially custom media queries to adjust the layout to fit the device and hide/show elements as necessary. If the data needs to be different for different devices, sounds like the only way would be to build the PHP differently to avoid those errors. That particular error means that you have two functions that are named the same, so either you need to rename it, or if it's common functionality shared by both includes, you can keep one and you don't need the duplicate. Duplicated variables won't necessarily cause errors -- depends on the variable scope. For quick and dirty mobile testing, assuming of course that you are using media queries, you should be able to simply resize your browser to get a feel for how the layout changes at different device widths. It's not perfect -- ideally, you'd have a smart phone to test on -- but it isn't like you are completely without options for testing.
  8. falkencreative

    Responsive Design With Bootstrap

    You won't be able to switch an include based on the screen resolution. You can include multiple sizes all at once when the page is first loaded, and then use media queries to hide/show the correct content at different sizes. You can also assign a column multiple widths at different screen sizes. For example, since the grid is 12 columns, you could have a section that is 2 columns wide on large devices (".col-lrg-2") but 4 columns on medium devices (".col-md-4"). So that would look like this: <div class="col-lg-2 col-md-4">Column content...</div>
  9. falkencreative

    Responsive Web Design (I Think!)

    Media queries are pieces of code you put in your CSS file that tell the browser which CSS to use for which screen sizes.
  10. falkencreative

    Hacked?

    I had to deal with a couple sites like this recently. Start by uploading fresh, safe Wordpress files, overwriting anything that's there (just the core Wordpress files though, and don't overwrite your wp-content directory). After, double check for suspicious code in all your theme files or in the wp-config file. It will be PHP, but it will most likely look like a block of gibberish (so you can't easily search for the text). Then, download/install https://wordpress.org/plugins/exploit-scanner/and the free version of https://wordpress.org/plugins/sucuri-scanner/, run their scans, and see if you catch anything else. In many cases, an exploit will randomly duplicate itself within your wp-content directory, those files need to be looked at too.
  11. falkencreative

    Responsive Web Design (I Think!)

    Yes, that is responsive web design. You can see Google's comments on that topic here: http://searchengineland.com/google-finally-takes-a-clear-stance-on-mobile-seo-practices-123543. They don't explicitly say yes/no whether RWD will boost your rankings, but they do say that it helps make it easier for your users and makes it easier for Google to properly index your content (versus different versions of your site for different devices, for example.) The primary tool for RWD is media queries -- they allow you to specify different CSS for different screen sizes. The underlying HTML will stay the same, but you can use media queries to adjust the layout and sizing of the elements, or hide/show elements as appropriate.
  12. falkencreative

    How Do I Style This?

    See http://www.w3schools.com/css/css_table.asp http://css-tricks.com/complete-guide-table-element/
  13. falkencreative

    Teaxtarea Wiped Out After Form Submission

    When the user submits the form, you'd want to store the data from the textarea, and then insert it back into the textarea when you re-show the form with the error message. Take a look at this tutorial: http://www.w3schools.com/php/php_forms.asp, clicking right through the chapters on making form fields required and validating the data. Specifically look at the "Keep the values in the form" section of http://www.w3schools.com/php/php_form_complete.asp.
  14. falkencreative

    Question About Check Boxes

    Well, the code you posted above only works for using integers, not "yes" or "no". What does your code that doesn't work look like? What doesn't work about it? What error(s) are you getting?
  15. falkencreative

    Is This Possible With Php And Mysql

    Sure, I suppose you could do that, but it seems very inefficient to me. I'd create tables by grouping related data, so perhaps it makes sense to split the data if the content has different purposes, but if it's all contact information about a person, I think that belongs in the same table. I wouldn't worry about too many rows on a table (rows are horizontal, each representing a record in the database), but I would worry about a huge table with a large number of unrelated columns (vertical) I wouldn't worry too much about security on information like names, addresses and phone numbers -- that information is likely publicly available anyway if someone were to search for it. If someone gets access to the database, splitting up that data into multiple tables won't really be any other than a minor annoyance.
  16. falkencreative

    Textarea Filling With Blank Spaces

    What does the code for your textarea look like? Do you have spaces between <textarea> and the closing </textarea> ?
  17. falkencreative

    Question About Check Boxes

    See http://www.html-form-guide.com/php-form/php-form-checkbox.html. If you want to use "yes" and "no" instead, you'll need to use "yes" for the value of the checkbox, check that $Active is "yes" rather than 1, and not convert the post data to an int (by removing the "(int)" in your code).
  18. falkencreative

    Return Total Number Of Records Found

    Take a look at the first example here: http://php.net/manual/en/mysqli-result.num-rows.php
  19. falkencreative

    My New Book Is On Amazon!

    Congrats!
  20. falkencreative

    Pdo Conditional Select Statement

    I don't have a huge amount of experience with PDO... but the place to start with is checking your work against the documentation: http://php.net/manual/en/pdostatement.bindvalue.php You should also check http://php.net/manual/en/pdostatement.rowcount.php: "For most databases, PDOStatement::rowCount() does not return the number of rows affected by a SELECT statement. Instead, use PDO::query() to issue a SELECT COUNT(*) statement with the same predicates as your intended SELECT statement, then use PDOStatement::fetchColumn() to retrieve the number of rows that will be returned. Your application can then perform the correct action." See example #2 in the link for a sample. I would also suggest that you be checking for exact matches, not "like", because you might accidentally match something that shouldn't be matched. For example, if someone enters "password" as their password, you don't want the query to also match for "password1" and "1password2" (which I believe currently happens, due to the "%" before and after your variables. You'd what to use "=" instead.
  21. falkencreative

    Hijacked Site - Imageshack

    Just a quick response... looking at the source code of the page, down in the bottom in the script is this line: bobexample.setStatus('<img src="http://img242.imageshack.us/img242/5553/opencq8.png" /> ', '<img src="http://img167.imageshack.us/img167/7718/closedy2.png" /> ') That's the line that adds the image. Personally, I don't think this is a hack or a hijacked site at all... I think this is more likely a link to some sort of arrow image, which (due to the age of the script -- looks like it's from 2007 or so) is no longer available. Rather than displaying some sort of 404 message, ImageShack is replacing that missing image with its own image, as a way of promoting itself. The fix for this is likely either to remove the line above, or to change the src's to your own open/closed images.
  22. falkencreative

    Transfering Select Value From Drop Down Box

    The easiest solution would be to show the dropdown -- same as you would in the "create new" page -- but have the default selected state be whatever that field is set to. That's pretty straight-forward. You'd want to create the dropdown in the same way that you created the dropdown on the create new page, but for every option you create in your dropdown, you check to see if the value of that option matches the selected option, and if so, give that the "selected" attribute. http://www.w3schools.com/tags/att_option_selected.asp So, something like this... <select name="selectname"> <option value="optionvalue" <?php if($selectedname == 'optionvalue') { echo 'selected'; } ?>>Option Name</option> </select> So in this case, you'd need to change the "selectname" to whatever you've named the select, and any values/names as appropriate. $selectedname is whatever value the user had selected for that field when they originally created the record.
  23. falkencreative

    Php Link

    What data does "$row[5]" contain? One way or another, you need a link that opens up a new tab: <a href="your-link.html" target="_blank">Link Text</a> If $row[5] contains a website URL, for example, "http://google.com", you would do something like this: echo '<td><a href="' . $row[5] . '" target="_blank">' . $row[5] . '</a></td>'; which would result in: <a href="http://google.com" target="_blank">http://google.com</a>
  24. falkencreative

    Transfering Select Value From Drop Down Box

    Assuming I'm understanding you correctly... So you have a single dropdown field that the user can select from. And you want to save their selected value in the database? In that case, you'd name the dropdown using the name attribute (which in your code above you named "dropdown"), you'd have the user submit the form, you'd retrieve the dropdown value using $_POST['dropdown'], and you'd use that value when creating an SQL query that would save it in the database using an SQL insert statement. I guess I'm just not sure what part of that process you are confused about? It works exactly the same way as using a regular text input and saving that value to a database. If your existing PHP script which processes the form and saves the values to the database is expecting to get that data from a field named msdstype, you'd just want to name your select "msdstype" rather than "dropdown", and everything else should work fine.
  25. falkencreative

    Transfering Select Value From Drop Down Box

    So, just so I understand the process... You have two fields -- one dropdown, and one text field? And when a user selects from the dropdown, you want the value from the dropdown to automatically be added to the text field? I'm assuming you need that text field because the user may be editing the content? You'd need to do that with Javascript. -- In pure Javascript, you'd want to use the onChange event (http://www.w3schools.com/jsref/event_onchange.asp), which would get the value from the dropdown (http://www.w3schools.com/jsref/met_doc_getelementbyid.asp) and set the value of the text field (http://stackoverflow.com/questions/4541855/how-do-i-set-value-of-a-textbox-using-javascript) -- If you're using jQuery, it would be similar, using change() (http://api.jquery.com/change/) to check when the value of the dropdown changes, find the value (http://learn.jquery.com/using-jquery-core/faq/how-do-i-get-the-text-value-of-a-selected-option/) and set the value of the text field (also using val() http://api.jquery.com/val/)
×