Home | Blog | Software | Reviews and Features | Forum | Help | Donate | About us
topbanner_forum
  *

avatar image

Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
  • December 06, 2016, 02:23:16 AM
  • Proudly celebrating 10 years online.
  • Donate now to become a lifetime supporting member of the site and get a non-expiring license key for all of our programs.
  • donate

Author Topic: Data not being written to MySQL DB  (Read 7944 times)

kyrathaba

  • N.A.N.Y. Organizer
  • Honorary Member
  • Joined in 2006
  • **
  • Posts: 3,120
    • View Profile
    • Donate to Member
Data not being written to MySQL DB
« on: July 21, 2014, 03:33:21 PM »
I have a very simple web form that collects firstname, lastname, and email address from someone visiting my Proofreading Services page and wanting to contact me regarding me doing some proofreading work for them.

I'm quite sure that my username, database, password, and host are set correctly, and my attempt to write to the database doesn't trigger a die(), and yet...

No data gets written to the MySQL database table. Furthermore, I get the following error-log info:

Quote
[21-Jul-2014 16:24:38 America/New_York] PHP Warning:  PHP Startup: Unable to load dynamic library '/usr/local/lib/php/extensions/no-debug-non-zts-20100525/php_xslt.dll' - /usr/local/lib/php/extensions/no-debug-non-zts-20100525/php_xslt.dll: cannot open shared object file: No such file or directory in Unknown on line 0
[21-Jul-2014 16:28:38 America/New_York] PHP Warning:  PHP Startup: Unable to load dynamic library '/usr/local/lib/php/extensions/no-debug-non-zts-20100525/php_xslt.dll' - /usr/local/lib/php/extensions/no-debug-non-zts-20100525/php_xslt.dll: cannot open shared object file: No such file or directory in Unknown on line 0
« Last Edit: July 21, 2014, 05:11:59 PM by kyrathaba »

rgdot

  • Supporting Member
  • Joined in 2009
  • **
  • Posts: 1,879
    • View Profile
    • Donate to Member
Re: Data not being written to MySQL DB
« Reply #1 on: July 21, 2014, 03:52:41 PM »
Probably need to look in the php.ini and make sure phpxslt.dll exists or is referenced at all. Also the path to it exists.

kyrathaba

  • N.A.N.Y. Organizer
  • Honorary Member
  • Joined in 2006
  • **
  • Posts: 3,120
    • View Profile
    • Donate to Member
Re: Data not being written to MySQL DB
« Reply #2 on: July 21, 2014, 04:22:34 PM »
Dunno that I have access. This is on a gamera host. I have filed a support ticket.

Stoic Joker

  • Honorary Member
  • Joined in 2008
  • **
  • Posts: 6,294
    • View Profile
    • www.StoicJoker.com
    • Donate to Member
Re: Data not being written to MySQL DB
« Reply #3 on: July 21, 2014, 04:54:11 PM »
php_xslt.dll has nothing to do with MySQL that I know of. One Quick-N-Dirty trick I've used a few times is to have a page echo the MySQL query to the page (and then stop) so I can then either just see what's happening (/missing at run time), or then paste it into a PHPMyAdmin prompt to see if I can get an error or successful result set of 0.

It's saved me much anguish over stupid (leading spaces in values etc.) mistakes.

kyrathaba

  • N.A.N.Y. Organizer
  • Honorary Member
  • Joined in 2006
  • **
  • Posts: 3,120
    • View Profile
    • Donate to Member
Re: Data not being written to MySQL DB
« Reply #4 on: July 21, 2014, 05:15:20 PM »
I'm attaching my PHP script. The only thing I've changed is that I substituted the pound symbol (#) in place of the actual characters used in my db password, username, etc.

That, and the attached file ends in .txt instead of .php. Now, be gentle, I've never written PHP code before, so it's probably not well-formed. But see if anything is a deal-breaker
in the code. I'm not triggering the die( ) function in my code.

kyrathaba

  • N.A.N.Y. Organizer
  • Honorary Member
  • Joined in 2006
  • **
  • Posts: 3,120
    • View Profile
    • Donate to Member
Re: Data not being written to MySQL DB
« Reply #5 on: July 21, 2014, 05:17:09 PM »
Note: the following line of code never gets executed:

Quote
echo "Your data was successfully added to the database.";

rgdot

  • Supporting Member
  • Joined in 2009
  • **
  • Posts: 1,879
    • View Profile
    • Donate to Member
Re: Data not being written to MySQL DB
« Reply #6 on: July 21, 2014, 07:16:57 PM »
Pretty sure it's just the path to the dll that's not /usr/local/lib/php/extensions/no-debug-non-zts-20100525/php_xslt.dll

wraith808

  • Supporting Member
  • Joined in 2006
  • **
  • Posts: 8,406
  • "In my dreams, I always do it right."
    • View Profile
    • Donate to Member
Re: Data not being written to MySQL DB
« Reply #7 on: July 21, 2014, 07:52:11 PM »
I removed the php_xslt.dll from the php config as I don't use it in any case.  Not sure why you happened across this error as I'm using php with database access all across the server, but try again.

kyrathaba

  • N.A.N.Y. Organizer
  • Honorary Member
  • Joined in 2006
  • **
  • Posts: 3,120
    • View Profile
    • Donate to Member
Re: Data not being written to MySQL DB
« Reply #8 on: July 21, 2014, 08:15:43 PM »
Charles Little, one of the support staff, is helping me sort it. I'll post back the solution we arrive at.

Stoic Joker

  • Honorary Member
  • Joined in 2008
  • **
  • Posts: 6,294
    • View Profile
    • www.StoicJoker.com
    • Donate to Member
Re: Data not being written to MySQL DB
« Reply #9 on: July 21, 2014, 09:30:16 PM »
Its been awhile since I've done any PHP, but shouldn't:
$query = "INSERT INTO proofreading_sought (firstname, lastname, email) " .
      "VALUES ($first, $last, $theMail)";

Be:
$query = "INSERT INTO proofreading_sought (firstname, lastname, email) ";
$query.= "VALUES ($first, $last, $theMail)";

other thing that looked odd was:
$dbc = @mysqli_connect($mysql_host,$mysql_user,$mysql_password,$mysql_database)
      or die("Failed to connect to the database...");

or should be || as in:
$dbc = @mysqli_connect($mysql_host,$mysql_user,$mysql_password,$mysql_database)
      || die("Failed to connect to the database...");

kyrathaba

  • N.A.N.Y. Organizer
  • Honorary Member
  • Joined in 2006
  • **
  • Posts: 3,120
    • View Profile
    • Donate to Member
Re: Data not being written to MySQL DB
« Reply #10 on: July 21, 2014, 09:34:29 PM »
Both lines of the $query are needed. The "VALUES..." needs to be concatenated with the dot operator to the previous line, because you must match values to the number of column parameters passed into the table.

kyrathaba

  • N.A.N.Y. Organizer
  • Honorary Member
  • Joined in 2006
  • **
  • Posts: 3,120
    • View Profile
    • Donate to Member
Re: Data not being written to MySQL DB
« Reply #11 on: July 21, 2014, 09:35:47 PM »
The help guy disabled the module that was causing the error message I showed earlier. But now I'm getting this error_log:

Quote
[21-Jul-2014 22:30:42 America/New_York] PHP Warning:  PHP Startup: Unable to load dynamic library '/usr/local/lib/php/extensions/no-debug-non-zts-20100525/' - /usr/local/lib/php/extensions/no-debug-non-zts-20100525/: cannot read file data: Is a directory in Unknown on line 0

Stoic Joker

  • Honorary Member
  • Joined in 2008
  • **
  • Posts: 6,294
    • View Profile
    • www.StoicJoker.com
    • Donate to Member
Re: Data not being written to MySQL DB
« Reply #12 on: July 21, 2014, 10:07:03 PM »
Both lines of the $query are needed. The "VALUES..." needs to be concatenated with the dot operator to the previous line, because you must match values to the number of column parameters passed into the table.

Yes, knew that part (familiar with SQL). I'm just not sure it's syntactically correct, as I've only seen a plain '.' used with echo direct to page...never for a query string build.

rgdot

  • Supporting Member
  • Joined in 2009
  • **
  • Posts: 1,879
    • View Profile
    • Donate to Member
Re: Data not being written to MySQL DB
« Reply #13 on: July 21, 2014, 10:09:55 PM »
The help guy disabled the module that was causing the error message I showed earlier. But now I'm getting this error_log:

Quote
[21-Jul-2014 22:30:42 America/New_York] PHP Warning:  PHP Startup: Unable to load dynamic library '/usr/local/lib/php/extensions/no-debug-non-zts-20100525/' - /usr/local/lib/php/extensions/no-debug-non-zts-20100525/: cannot read file data: Is a directory in Unknown on line 0

Same error without the specific dll? perhaps (another) line in php.ini needs to be commented out.

kyrathaba

  • N.A.N.Y. Organizer
  • Honorary Member
  • Joined in 2006
  • **
  • Posts: 3,120
    • View Profile
    • Donate to Member
Re: Data not being written to MySQL DB
« Reply #14 on: July 21, 2014, 10:15:41 PM »
@Stoic gotcha. I derived my code from sample code in a php/mysql Head First book.

kyrathaba

  • N.A.N.Y. Organizer
  • Honorary Member
  • Joined in 2006
  • **
  • Posts: 3,120
    • View Profile
    • Donate to Member
Re: Data not being written to MySQL DB
« Reply #15 on: July 26, 2014, 05:25:42 PM »
At this point, I can connect to my server, AND correctly select the desired database. My code even creates the needed table if it's not existent. But there's some little problem that prevents my code from inserting a record. To see the results, go to the following URL and enter a fake first name, last name, and email address and click the submit button:

http://williambryanmiller.com/proofreading/index.html

Below is my PHP Script. The only thing I've altered is to replace the actual database name and password with an asterisk, but we already know my code connects and selects the database.

Code: PHP [Select]
  1. <center><a href="index.html">Return to proofreading page</a></center>
  2.  
  3. <?php
  4.        
  5.        
  6.         $tablename = 'proofreading_sought';
  7.         $echo_on = true;
  8.         $user="kyrathab";
  9.         $password="*";
  10.         $database="*";
  11.         $mysql_host = "localhost";
  12.        
  13.         if($_POST['firstname']=='')
  14.         {              
  15.                 ?>
  16.                 You should <a href="index.html">return</a> to my proofreading page, because
  17.                 <?php
  18.                         die(" you failed to enter data for your first name!");
  19.         }
  20.         if($_POST['lastname']=='')
  21.         {
  22.                 ?>
  23.                 You should <a href="index.html">return</a> to my proofreading page, because
  24.                 <?php
  25.                         die(" you failed to enter data for your last name!");
  26.         }
  27.        
  28.         if($_POST['email']=='')
  29.         {
  30.                 ?>
  31.                 You should <a href="index.html">return</a> to my proofreading page, because
  32.                 <?php
  33.                         die(" you failed to enter an email address!");
  34.         }
  35.        
  36.         echo 'Hello, ' . $_POST['firstname'] . ' ' . $_POST['lastname'] . '!<p>';
  37.         echo 'You specified the following email address: ' . $_POST['email'] . '.';
  38.         echo '<p>';
  39.         echo "Your information was submitted. Thank you! You should hear back from the proofreader within the next 48 hours. ";
  40.         echo "The proofreader will attempt to contact you at the following email address: " . $theMail . '<p>';
  41.        
  42.        
  43.         mail("kyrathasoft@gmail.com","Interested in obtaining proofreading", $msg, 'From:' . $_POST['email']);
  44.        
  45.         $link = mysql_connect($mysql_host, $user, $password);
  46.         if (!$link) {
  47.                 die('Could not connect to host: ' . mysql_error());
  48.         }
  49.         echo 'Connected to host...<p>';
  50.        
  51.         $db_selected = mysql_select_db($database, $link) or die('Connected to host but could not select database: '     . mysql_error());
  52.         echo 'Connected successfully to the database...<p>';
  53.        
  54.         if (!blnTableNameFoundInDatabase($database,$tablename)){        
  55.         //Let's create the table...
  56.         if($echo_on){ echo "Creating table $tablename"; }
  57.         $query = "CREATE TABLE $tablename
  58.         ( ID int unsigned not null auto_increment primary key,
  59.         FirstName char(45) not null, LastName char(45) not null,
  60.         Email char(50) not null)";
  61.         @mysql_query($query) or Die('Failed to create table $tablename, script dies...' . mysql_error());      
  62.         $blnJustCreatedTable = True;
  63.         }
  64.        
  65.         $query = "INSERT INTO $tablename (FirstName, LastName, Email)
  66.                 VALUES ($first, $last, $theMail)";
  67.         mysql_query($query) or die('Insertion failed!' . mysql_error() . '<p>');
  68.  
  69.        
  70.         $file = 'proofread_seekers.txt';
  71.         // The new person to add to the file
  72.         $person = $name . '|' . $theMail . '|' . date("Y-m-d H:i:s") . "\n";
  73.         // Write the contents to the file,
  74.         // using the FILE_APPEND flag to append the content to the end of the file
  75.         // and the LOCK_EX flag to prevent anyone else writing to the file at the same time
  76.         file_put_contents($file, $person, FILE_APPEND | LOCK_EX);
  77.        
  78.         function blnTableNameFoundInDatabase($the_database, $the_tablename){
  79.                 $res = mysql_query("SHOW TABLES FROM $the_database");  
  80.                 $bln = False;
  81.                 while($row = mysql_fetch_array($res, MYSQL_NUM)){
  82.                         if($row[0] == $the_tablename){ $bln = True; }
  83.                 }
  84.         return $bln;
  85. }
  86.                
  87.  
  88. ?>

If anyone can test the web form and take a gander at my PHP and figure out why it's producing the error, I'd be much obliged.
« Last Edit: July 26, 2014, 05:34:40 PM by kyrathaba »

Ath

  • Supporting Member
  • Joined in 2006
  • **
  • Posts: 2,779
    • View Profile
    • Donate to Member
Re: Data not being written to MySQL DB
« Reply #16 on: July 27, 2014, 05:55:58 AM »
I'm unable to find the spot in your code where you assign values to $first, $last and $theMail variables. That could IMHO explain the failure to store, as the columns have the 'not null' attribute...

kyrathaba

  • N.A.N.Y. Organizer
  • Honorary Member
  • Joined in 2006
  • **
  • Posts: 3,120
    • View Profile
    • Donate to Member
Re: Data not being written to MySQL DB
« Reply #17 on: July 27, 2014, 08:16:44 AM »
Thanks, Ath. That may be what the problem was. I found an online example and worked backward from it, and got it working:

http://williambryanmiller.com/proofreading/needProofreading.php