lyleb Posted October 27, 2011 Share Posted October 27, 2011 I've been trying to get php working with a mysql database. I've created a database and have no trouble adding records, etc., using mysql, but I can't seem to update records with php. I created the following page, uploaded to my server and opened it and it returns nothing. The tab reads "templates" and I get the spinning wheel. <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" lang="en"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>templates</title> <meta name="author" content="lyleb" /> <!-- Date: 2011-10-27 --> </head> <body> <?php phpinfo (); ?> </body> </html> Link to comment Share on other sites More sharing options...
lyleb Posted October 27, 2011 Author Share Posted October 27, 2011 Silly me. I now see why the tab reads "templates." That's what I called it. However, I still don't get why this page returns nothing. Link to comment Share on other sites More sharing options...
Jonathon Posted October 27, 2011 Share Posted October 27, 2011 are you using a php extension? ie "templates.php" - what does the page return and what does the view source code return? Link to comment Share on other sites More sharing options...
lyleb Posted October 27, 2011 Author Share Posted October 27, 2011 are you using a php extension? ie "templates.php" - what does the page return and what does the view source code return? Yes, I'm using a .php extension. The file is called test.php. The source code that is returned is as follows: <! DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> < html xmlns="http://www.w3.org/1999/xhtml" lang="en"> < head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>templates</title> <meta name="author" content="lyleb" /> <!-- Date: 2011-10-27 --> </ head> < body> <! DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "DTD/xhtml1-transitional.dtd"> < html><head> < style type="text/css"> body {background-color: #ffffff; color: #000000;} body , td, th, h1, h2 {font-family: sans-serif;} pre {margin: 0px; font-family: monospace;} a:link {color: #000099; text-decoration: none; background-color: #ffffff;} a:hover {text-decoration: underline;} table {border-collapse: collapse;} .center {text-align: center;} .center table { margin-left: auto; margin-right: auto; text-align: left;} .center th { text-align: center !important; } td , th { border: 1px solid #000000; font-size: 75%; vertical-align: baseline;} h1 {font-size: 150%;} h2 {font-size: 125%;} .p {text-align: left;} .e {background-color: #ccccff; font-weight: bold; color: #000000;} .h {background-color: #9999cc; font-weight: bold; col Link to comment Share on other sites More sharing options...
lyleb Posted October 27, 2011 Author Share Posted October 27, 2011 By the way, the source code is more compact than is shown in the previous post (30 lines), but it does get cut off half way through the word "color" at the end. Link to comment Share on other sites More sharing options...
lyleb Posted October 27, 2011 Author Share Posted October 27, 2011 By the way, the source code is more compact than is shown in the previous post (30 lines), but it does get cut off half way through the word "color" at the end. The source code actually looks like this? <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" lang="en"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>templates</title> <meta name="author" content="lyleb" /> <!-- Date: 2011-10-27 --> </head> <body> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "DTD/xhtml1-transitional.dtd"> <html><head> <style type="text/css"> body {background-color: #ffffff; color: #000000;} body, td, th, h1, h2 {font-family: sans-serif;} pre {margin: 0px; font-family: monospace;} a:link {color: #000099; text-decoration: none; background-color: #ffffff;} a:hover {text-decoration: underline;} table {border-collapse: collapse;} .center {text-align: center;} .center table { margin-left: auto; margin-right: auto; text-align: left;} .center th { text-align: center !important; } td, th { border: 1px solid #000000; font-size: 75%; vertical-align: baseline;} h1 {font-size: 150%;} h2 {font-size: 125%;} .p {text-align: left;} .e {background-color: #ccccff; font-weight: bold; color: #000000;} .h {background-color: #9999cc; font-weight: bold; col Link to comment Share on other sites More sharing options...
Jonathon Posted October 27, 2011 Share Posted October 27, 2011 Have you called phpinfo () with a space before the parenthesis?also are you actually declaring 2 doctypes? Link to comment Share on other sites More sharing options...
lyleb Posted October 29, 2011 Author Share Posted October 29, 2011 Have you called phpinfo () with a space before the parenthesis?also are you actually declaring 2 doctypes? There is no space before the "()". As far as declaring two document types, I don't think so. Link to comment Share on other sites More sharing options...
Larry Posted October 29, 2011 Share Posted October 29, 2011 You can try just using this script: <?php phpinfo(); ?> and nothing more. Also, can you provide a URL of this phpinfo() script in action? Link to comment Share on other sites More sharing options...
lyleb Posted November 8, 2011 Author Share Posted November 8, 2011 You can try just using this script: <?php phpinfo(); ?> and nothing more. Also, can you provide a URL of this phpinfo() script in action? Tried it. I reduced the file to the above line and nothing esle. Still doesn't work. The URL is: http://rezman.com/council/test.php Link to comment Share on other sites More sharing options...
Jonathon Posted November 8, 2011 Share Posted November 8, 2011 This page doesn't load for me. Link to comment Share on other sites More sharing options...
Larry Posted November 9, 2011 Share Posted November 9, 2011 Not loading for me either. What application are you using to create this script? And what application are you using to put it onto the server? Link to comment Share on other sites More sharing options...
lyleb Posted November 11, 2011 Author Share Posted November 11, 2011 Not loading for me either. What application are you using to create this script? And what application are you using to put it onto the server? Aptana Studio 3, but I've also tried creating the script in the service providers file management system. I'm using FTP Voyager to upload the file I create locally. Link to comment Share on other sites More sharing options...
Larry Posted November 11, 2011 Share Posted November 11, 2011 Still not loading for me. Are you successfully able to create any page on your home computer and upload it to the server and get it to load in the Web browser? Link to comment Share on other sites More sharing options...
lyleb Posted November 11, 2011 Author Share Posted November 11, 2011 Still not loading for me. Are you successfully able to create any page on your home computer and upload it to the server and get it to load in the Web browser? Yes, I have been using both apps for creating and uploading html files and they work fine. I modified the html page as follows: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" lang="en"> <head> <meta http-equiv="content-type" content="text/html; charset=utf-8" /> <title>PHP Configuration</title> </head> <body> <?php error_reporting(E_ALL); echo 'PHP Version: ' . phpversion(); phpinfo(); ?> </body> </html> Now I get the PHP Version number, but I don't get any PHP configuration information. When I try and load the page (http://www.rezman.com/council/test.php), I get the following source code (and no error message): <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" lang="en"> <head> <meta http-equiv="content-type" content="text/html; charset=utf-8" /> <title>PHP Configuration</title> </head> <body> PHP Version: 5.2.8<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "DTD/xhtml1-transitional.dtd"> <html><head> <style type="text/css"> body {background-color: #ffffff; color: #000000;} body, td, th, h1, h2 {font-family: sans-serif;} pre {margin: 0px; font-family: monospace;} a:link {color: #000099; text-decoration: none; background-color: #ffffff;} a:hover {text-decoration: underline;} table {border-collapse: collapse;} .center {text-align: center;} .center table { margin-left: auto; margin-right: auto; text-align: left;} .center th { text-align: center !important; } td, th { border: 1px solid #000000; font-size: 75%; vertical-align: baseline;} h1 {font-size: 150%;} h2 {font-size: 125%;} .p {text-align: left;} .e {background-color: #ccccff; font-weight: bold; color: #000000;} .h {background-color: #9999cc; font-weight: bold; color: #00 Link to comment Share on other sites More sharing options...
lyleb Posted November 11, 2011 Author Share Posted November 11, 2011 Another bit of info, the mysql select version() function returns 5.0.67-community. My service provider is fastwebserver.com. Link to comment Share on other sites More sharing options...
Larry Posted November 11, 2011 Share Posted November 11, 2011 And that test.php script is only: <?php phpinfo(); ?> ? It's strange that it's outputting two doctypes. Have you confirmed with your Web host that PHP is supported? Link to comment Share on other sites More sharing options...
lyleb Posted November 12, 2011 Author Share Posted November 12, 2011 I contacted Fastwebserver about phpinfo() and about the mysqli extension and here is what they said: "As you said phpinfo() has been disabled. This is a production server and the system admins decided to lock it down to protect the users. If you need to know specific PHP config details please let m kenow and I will send you the information. Mysqli extensions are not enabled. You can use the standard mysql functions instead." Link to comment Share on other sites More sharing options...
lyleb Posted November 12, 2011 Author Share Posted November 12, 2011 And that test.php script is only: <?php phpinfo(); ?> ? It's strange that it's outputting two doctypes. Have you confirmed with your Web host that PHP is supported? See my last post. Link to comment Share on other sites More sharing options...
lyleb Posted November 12, 2011 Author Share Posted November 12, 2011 My real problem is that I've created a database called rezman_com_events that has the following table called council_terms: Field Type Null Key Default Extra council_term_id smallint(5) unsigned NO PRI NULL auto_increment council_term_start date NO UNI NULL council_term_end date NO UNI NULL council_term_voters smallint(5) unsigned YES NULL council_term_chiefvotes smallint(5) unsigned YES NULL council_term_councilvotes smallint(5) unsigned YES NULL To add records to it, I've created a page called add_council_term.php which is as follows: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" lang="en"> <head> <meta http-equiv="content-type" content="text/html; charset=iso-8859-1" /> <title>Add A Council Term</title> </head> <body> <?php // Turn on error reporting error_reporting(E_ALL); // ***** add_council_term.php ***** // This page displays and handles a form // for inserting records into the council_terms table in the rezman_com_events database. // Include the MySQL information: require_once '/home/rezman43/connection.php'; if (isset($_POST['submitted'])) { // If the form has been submitted, handle it. // Check the required form fields: if (isset($_POST['council_term_start']) AND (!empty($_POST['council_term_end'])) AND (!empty($_POST['council_term_voters'])) AND (!empty($_POST['council_term_chiefvotes'])) AND (!empty($_POST['council_term_councilvotes'])) ) { // Create the query: $q = "INSERT INTO council_terms VALUES (NULL, {$_POST['council_term_start']}, '" . addslashes($_POST['council_term_end']) . "', '" . addslashes($_POST['council_term_voters']) . "', '" . addslashes($_POST['council_term_chiefvotes']) . "', '" . addslashes($_POST['council_term_councilvotes']) . "')"; // Execute the query: $r = mysql_query ($dbc, $q); // Print a message indicating success or not: if (mysql_affected_rows($dbc) == 1) { echo '<b><font color="green">The Council term has been added!</font></b>'; } else { echo '<b><font color="red">The Council term was not entered into the table!</font></b>'; } } else { // Print a message if they failed to enter a required field: echo '<b><font color="red">You missed a required field!</font></b>'; } } else { // If the form has not been submitted, display it. // Close out of the PHP for ease of coding. ?> Add a new record in the Council Terms table:<br /><br /> <form action="add_council_term.php" method="post"> <p>Term Start Date: <input type="text" name="council_term_start" /> Enter in this format: yyyy-mm-dd.</p> <p>Term End Date: <input type="text" name="council_term_end" /> Enter in this format: yyyy-mm-dd.</p> <p>Eligible Voters: <input type="text" name="council_term_voters" /></p> <p>Ballots Cast For Chief: <input type="text" name="council_term_chiefvotes" /></p> <p>Ballots Cast For Council: <input type="text" name="council_term_councilvotes" /></p> <input type="hidden" name="submitted" value="true" /> <input type="submit" name="submit" value="Submit!" /> </form> <?php } // Finish the main "submit" conditional. // Close the database connection: mysql_close($dbc); ?> </body> </html> I've placed the connection file in the directory above the web root. The URL for the form is at http://www.rezman.com/council/add_council_term.php. The form loads, however, when I click on the submitt button, it returns the message "The Council term was not entered into the table!" I've based this form on script_07_03.php (add_expense.php) from your MySQL VQS Second Edition. Link to comment Share on other sites More sharing options...
Jonathon Posted November 12, 2011 Share Posted November 12, 2011 So the query is failing. Do you have access to the mysql client or phpmyadmin? Try the queries in there. See what error is returned or the script itself. Link to comment Share on other sites More sharing options...
lyleb Posted November 12, 2011 Author Share Posted November 12, 2011 I'm using phpmyadmin. If I run the following query, it inserts a record just fine: INSERT INTO`council_terms` VALUES (NULL,'2001-02-13','2003-02-12',800,400,400); If I click on "Create PHP Code," it gives me this: $sql = 'INSERT INTO`council_terms` VALUES (NULL,\'2001-02-13\',\'2003-02-12\',800,400,400);'; How do I replace the values in $sql above with the values from the form? That's where I seem to be having difficulty. Link to comment Share on other sites More sharing options...
Jonathon Posted November 12, 2011 Share Posted November 12, 2011 Implement debugging into the script to see why the script fails. mysql_error(). Then it should tell you why it's failing exactly Link to comment Share on other sites More sharing options...
Jonathon Posted November 12, 2011 Share Posted November 12, 2011 I have a feeling that the mysql_query() Only needs to takes 1 parameter, it can take a resource secondly as an optional argument, so try just mysql_query($q); But also write mysql_error() into your code to pull up why it fails still. Link to comment Share on other sites More sharing options...
Antonio Conte Posted December 6, 2011 Share Posted December 6, 2011 Try this instead for $q: $q = 'INSERT INTO council_terms VALUES (NULL, '.$_POST['council_term_start'].', '.$_POST['council_term_end'].', '.$_POST['council_term_voters'].', '.$_POST['council_term_chiefvotes'].', '.$_POST['council_term_councilvotes'].')'; I'm not sure, but I'm guessing the backslashes and the characters " and ' could be causing this. You should even escape this before using the $_POST-globsl in your SQL: $term_start = mysql_real_escape_string($dbc, $_POST['council_term_start']); $q = 'INSERT INTO council_terms VALUES (NULL, '.$term_start'.... And so on. Link to comment Share on other sites More sharing options...
Recommended Posts