Jump to content

underknown

Members
  • Posts

    22
  • Joined

  • Last visited

    Never

Everything posted by underknown

  1. Alright, I am programming a PHP/HTML forum and we need an IM/chatroom application that can be embedded into forum threads. The only thing is, we need to be able to make a new chat / room everytime it's used, so if people post the chatroom in several different threads, it all needs to be different chats/rooms. Does anyone know of an application that can pull this off?
  2. Frig...yeah you're right....I dunno how I missed that. Thank you!
  3. I tried entering the values from dbvars.php into functions.php directly in the connect statement, which works fine. I'm not sure what's wrong though, given the fact that I'm sure they're exactly the same.
  4. I did that already, the errors are the same. functions.php: <html> <body> <?php require_once('includes/dbvars.php'); function displayVideos($dbc){ $dbc = mysqli_connect('DB_HOST', 'DB_USER', 'DB_PW', 'DB_NAME'); //Query $query = "SELECT * FROM videos"; //Execute $result = mysqli_query($dbc, $query) or die ("Error querying database."); While ($row = mysqli_fetch_assoc($result)) { echo '<h2>' . $row['Title'] . '</h2>'; echo '<b>Director</b>:' . $row['Director'] . '<br />'; echo '<b>Description</b>:<br />' . $row['Description']; echo '<hr>'; } mysqli_close($dbc); } ?> </body> </html> dbvars.php: <html> <body> <?php require_once('includes/dbvars.php'); function displayVideos($dbc){ $dbc = mysqli_connect('DB_HOST', 'DB_USER', 'DB_PW', 'DB_NAME'); //Query $query = "SELECT * FROM videos"; //Execute $result = mysqli_query($dbc, $query) or die ("Error querying database."); While ($row = mysqli_fetch_assoc($result)) { echo '<h2>' . $row['Title'] . '</h2>'; echo '<b>Director</b>:' . $row['Director'] . '<br />'; echo '<b>Description</b>:<br />' . $row['Description']; echo '<hr>'; } mysqli_close($dbc); } ?> </body> </html> Still not sure of what the issue is. Same error message.
  5. Well here's the dbvars.php code, but I can't see any mistakes with the host. <html> <body> <?php //Defines Vars define('DB_HOST', 'localhost'); define('DB_USER', 'root'); define('DB_PW', 'root'); define('DB_NAME', 'functions'); ?> </body> </html>
  6. Yeah, it must've gotten removed when I undid something; new error message: Warning: mysqli_connect() [function.mysqli-connect]: (HY000/2005): Unknown MySQL server host 'DB_HOST' (11001) in Z:\www\cms\includes\functions.php on line 9 Warning: mysqli_query() expects parameter 1 to be mysqli, boolean given in Z:\www\cms\includes\functions.php on line 15 Error querying database.
  7. Alright, I changed it, but now it's back to: Parse error: syntax error, unexpected '}' in Z:\www\cms\includes\functions.php on line 25
  8. New error message now at least: Warning: mysqli_query() expects parameter 1 to be mysqli, null given in Z:\www\cms\includes\functions.php on line 13 Error querying database.
  9. That is functions.php; the unexpected '}' seems to be the one that closes the function statement, but I can't see why that would be unexpected, and if I take it out I get an unexpected end from the </html> tag at the bottom...
  10. I'm gonna be perfectly honest, I have no idea what's wrong with this code, I'm not even entirely sure what it all means, I just need to make it work. -.- I get this error: Parse error: syntax error, unexpected '}' in Z:\www\cms\includes\functions.php on line 25 From this code: <html> <body> <?php include('includes/dbvars.php'); function displayVideos($dbc){ mysqli_connect('DB_HOST', 'DB_USER', 'DB_PW', 'DB_NAME'); //Query $query = "SELECT * FROM videos"; //Execute $result = mysqli_query($dbc, $query) or die ("Error querying database."); While ($row = mysqli_fetch_assoc($result)) { echo '<h2>' . $row['Title'] . '</h2>'; echo '<b>Director</b>:' . $row['Director'] . '<br />'; echo '<b>Description</b>:<br />' . $row['Description']; echo '<hr>'; } mysqli_close($dbc) } ?> </body> </html> Any help very much appreciated
  11. Ah, missing space. Got it, thanks for your help!
  12. The exact result: Search word: charles SELECT * FROM customersWHERE customers.given_name='charles'You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '.given_name='charles'' at line 1
  13. Sorry, I've never been familiarized with that die code before. Here's the error. "Warning: mysqli_error() expects exactly 1 parameter, 0 given in Z:\www\website\search_get.php on line 20" The Query: "SELECT * FROM customersWHERE customers.given_name='charles'"
  14. I'm having some trouble with a GET search code; everything works until the stringresult but then it dies to Error Querying Database <html> <body> <?php //Get sort setting and search terms from URL with GET $usersearch = $_GET['usersearch']; echo 'Search word: ' . $usersearch; echo '<br>'; require_once("dbvars.php"); //Connect to Database $dbc = mysqli_connect (DB_HOST, DB_USER, DB_PW, DB_NAME) or die ("Error connecting to database."); //Build the Query $query = "SELECT * FROM customers" . 'WHERE customers.given_name=\'' . $usersearch . '\''; echo $query; //Execute the Query $result = mysqli_query($dbc, $query) or die ("Error querying database."); //Create the Table Headings echo '<table border="1"><tr>'; echo '<td><b>First Name</b></td>'; echo '<td><b>Last Name</b></td>'; echo '<td><b>Address</b></td>'; echo '<td><b>City</b></td>'; echo '<td><b>Province</b></td>'; echo '<td><b>Postal Code</b></td>'; echo '<td><b>Phone Number</b></td>'; echo '</tr>'; //Display Results through Array Loop While ($row = mysqli_fetch_array($result)) { echo '<tr><td>' . $row['given_name'] . '</td>'; echo '<td>' . $row['surname'] . '</td>'; echo '<td>' . $row['address'] . '</td>'; echo '<td>' . $row['city'] . '</td>'; echo '<td>' . $row['province'] . '</td>'; echo '<td>' . $row['postal_code'] . '</td>'; echo '<td>' . $row['phone_number'] . '</td></tr>'; } '</table>'; // Close the database connection mysqli_close($dbc); ?> <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="get"> <input name="usersearch" type="text" size="30" /> <input name="submit" type="submit" value="go" /> </form> </body> </html>
  15. Nevermind, I found the issue.
  16. Alright, I'm supposed to be creating a search bar, but I keep running into errors, and I'm sure there must be something wrong here that I'm missing. I don't know whether it's the PHP or the HTML that's messing up, so I apologize for that, but given the nature of the errors, I'd assume the former. Here's the code: <?php include("header.php"); ?> <?php include("topmenu.php"); ?> <?php include("menu.php"); ?> <?php include("news.php"); ?> <?php include("links.php"); ?> <?php include("info.php"); ?> <!-- **** php include news.php, links.php and info.php here to return side menu --> <div id="column2"> <h1>introduction</h1> <!-- **** INSERT PAGE CONTENT HERE **** --> <div id="content"> <li><a id="various3" href="http://localhost/website/center.php">Add Customers</a></li> </ul> </div> <br /> <?php echo "Customer Results from Database"; require_once("dbvars.php"); //Search if (isset($_POST['search'])) { $name = $_POST['name']; $name_trimmed = trim($name); $dbc = mysqli_connect(DB_HOST, DB_USER, DB_PW, DB_NAME) or die('Error connecting to database.'); $query = "SELECT * FROM customers WHERE name LIKE '%$name_trimmed%'"; $result = mysqli_query($dbc, $query) or die('Error querying database.'); mysqli_close($dbc); echo '<h1>Search Results</h1>'; echo '<table border="0\"><tr>'; echo '<td><b>First Name</b></td>'; echo '<td><b>Last Name</b></td>'; echo '<td><b>Address</b></td>'; echo '<td><b>City</b></td>'; echo '<td><b>Province</b></td>'; echo '<td><b>Postal Code</b></td>'; echo '<td><b>Phone Number</b></td>'; While ($row = mysqli_fetch_array($result)) { echo '<tr><td>' . $row['given_name'] . '</td>'; echo '<td>' . $row['surname'] . '</td>'; echo '<td>' . $row['address'] . '</td>'; echo '<td>' . $row['city'] . '</td>'; echo '<td>' . $row['province'] . '</td>'; echo '<td>' . $row['postal_code'] . '</td>'; echo '<td>' . $row['phone_number'] . '</td>'; } } // Connect to the database $dbc = mysqli_connect(DB_HOST, DB_USER, DB_PW, DB_NAME) or die('Error connecting to MySQL server.'); // Build the query $query = "SELECT * FROM customers"; $result = mysqli_query($dbc, $query) or die('Error querying database.'); //Table Headers echo '<table border="1\"><tr>'; echo '<td><b>First Name</b></td>'; echo '<td><b>Last Name</b></td>'; echo '<td><b>Address</b></td>'; echo '<td><b>City</b></td>'; echo '<td><b>Province</b></td>'; echo '<td><b>Postal Code</b></td>'; echo '<td><b>Phone Number</b></td>'; //Display Results through Array Loop While ($row = mysqli_fetch_array($result)) { echo '<tr><td>' . $row['given_name'] . '</td>'; echo '<td>' . $row['surname'] . '</td>'; echo '<td>' . $row['address'] . '</td>'; echo '<td>' . $row['city'] . '</td>'; echo '<td>' . $row['province'] . '</td>'; echo '<td>' . $row['postal_code'] . '</td>'; echo '<td>' . $row['phone_number'] . '</td>'; } '</table>'; // Close the database connection mysqli_close($dbc); ?> <!-- Search Form --> <div class="form" /> <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post" /> <input name="name" id="name" type="text" value="enter name" size="30" maxlength="50" /> <div class="button"> <input name="search" type="submit" value="go" /> </div> </form> </div> <div style="clear:both"> </div> </body> </html>
  17. Parse error: syntax error, unexpected T_VARIABLE in Z:\www\website\center.php on line 35 This error is coming up when attempting to run the following code. line 35 is the one containing the $query statement. :/ <?php include("header.php"); ?> <?php include("topmenu.php"); ?> <?php include("menu.php"); ?> <?php include("news.php"); ?> <?php include("links.php"); ?> <?php include("info.php"); ?> <div id="column2"> <h1>introduction</h1> <!-- **** INSERT PAGE CONTENT HERE **** --> <p> This page can be used to insert new customers. </p> <?php //Check Form Submission if (isset($_POST['Create'])) { //Extract Values $surname = $_POST['surname']; $givenname = $_POST['given_name']; $address = $_POST['address']; $city = $_POST['city']; $province = $_POST['province']; $postalcode = $_POST['postal_code']; $phonenumber = $_POST['phone_number']; //Connect to Database $dbc = mysqli_connect(DB_HOST, DB_USER, DB_PW, DB_NAME) //Insert Query $query = "INSERT INTO customers (surname, given_name, address, city, province, postal_code, phone_number) VALUES ('$surname', '$givenname', '$address', '$city', '$province', '$postalcode', '$phonenumber') "; //Execute Query mysqli_query($dbc, $query) or die ("Error inserting data."); //Close Connection mysqli_close($dbc) //Confirm echo 'Customer Added.<br />'; } ?> <!-- Create the Form to Add Users --> <form method = "post" action = "<?php echo $_SERVER['PHP_SELF']; ?>"> <label for="surname">Surname:</label><input type="text" id="surname" name="surname"><br /> <label for="given_name">First Name:</label><input type="text" id="given_name" name="given_name"><br /> <label for="address">Address:</label><input type="text" id="address" name="address"><br /> <label for="city">City:</label><input type="text" id="city" name="city"><br /> <label for="province">Province:</label><input type="text" id="province" name="province"><br /> <label for="postal_code">Postal Code:</label><input type="text" id="postal_code" name="postal_code"><br /> <label for="phone_number">Phone Number:</label><input type="text" id="phone_number" name="phone_number"><br /> <input type = "submit" name = "Create" value = "Create" /> </form> </div> </div> </div> </body> </html>
  18. I'm using this code with a free template, after having separated the header, footer, menues etc. into different php files, but the table currently echoes into the sidebar. Any idea on how to fix this? I can send the code for the main page or other parts of the page if needed. Template is here: http://www.2dwebdesign.com/templates/121.html Code here for page: <?php include("header.php"); ?> <?php include("topmenu.php"); ?> <?php include("menu.php"); ?> <?php include("news.php"); ?> <!-- **** php include news.php, links.php and info.php here to return side menu --> <div id="column2"> <h1>introduction</h1> <!-- **** INSERT PAGE CONTENT HERE **** --> <p> <?php echo "Customer Results from Database"; require_once("dbvars.php"); // Connect to the database $dbc = mysqli_connect(DB_HOST, DB_USER, DB_PW, DB_NAME) or die('Error connecting to MySQL server.'); // Build the query $query = "SELECT * FROM customers"; $result = mysqli_query($dbc, $query) or die('Error querying database.'); //Table Headers echo '<table border="1\"><tr>'; echo '<td><b>First Name</b></td>'; echo '<td><b>Last Name</b></td>'; echo '<td><b>Address</b></td>'; echo '<td><b>City</b></td>'; echo '<td><b>Province</b></td>'; echo '<td><b>Postal Code</b></td>'; echo '<td><b>Phone Number</b></td>'; echo '<td><b>Email</b></td>'; //Display Results through Array Loop While ($row = mysqli_fetch_array($result)) { echo '<tr><td>' . $row['given_name'] . '</td>'; echo '<td>' . $row['surname'] . '</td>'; echo '<td>' . $row['address'] . '</td>'; echo '<td>' . $row['city'] . '</td>'; echo '<td>' . $row['province'] . '</td>'; echo '<td>' . $row['postal_code'] . '</td>'; echo '<td>' . $row['phone_number'] . '</td>'; echo '<td>' . $row['email'] . '</td>'; } '</table>'; // Close the database connection mysqli_close($dbc); ?> </body> </html>
  19. Basically wondering how to format the individual lines of data, so each entry is displayed on its own line with spaces between?
  20. THANK YOU so much. If I could bother someone for a bit of additional assistance, how would I make those display in the same rows that they're in in the database? Do I just need a break after all the echoes?
  21. Alright, so I've been building code in my computer science class (no prior PHP experience before approx. this past week). We're just importing the first array from a MySQL database, and it's not working for me. Our teacher included a broken-linked image that apparently tells us how to close the connection, but being unable to see it....I can't. I'm not sure exactly what's not working, but here's my current code: <html> <body> <?php echo "<h1>This is a test. Does this script insert values?</h1>"; // Connect to the database $dbc = mysqli_connect('localhost', 'root', 'root', 'myrent-a-movie-final') or die('Error connecting to MySQL server.'); // Build the query $query = "SELECT * FROM customers"; $result = mysqli_query($dbc, $query) or die('Error querying database.'); //Display Results through Array Loop While ($row = mysqli_fetch_array($result)) { echo $row['surname']; echo $row['given_name']; echo $row['address']; echo $row['city']; echo $row['province']; echo $row['postal_code']; echo $row['phone_number']; echo $row['email']; // Close the database connection mysqli_close($dbc); ?> </body> </html> And here is my accompanying error message: "Parse error: syntax error, unexpected $end in Z:\www\mysql_basics\view_data.php on line 32"
×
×
  • 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.