DonationCoder.com forum
 
Read-only archive. This is a static copy of the DonationCoder.com forum. Reading and searching work as before; logging in, posting and private messages do not.
Archive of 2026-10-21 · About this archive · Main site

Author Topic: Data not being written to MySQL DB  (Read 17,839 times)

kyrathaba

  • N.A.N.Y. Organizer
  • Honorary Member
  • Joined in 2006
  • **
  • Posts: 3,200
    • Participated in NANY Challenge Eight Times
    • Programming School - Deluxe Bonus Medal
    • Programming School - Stage 1 Medal
    • Coding Snacks
    • Military Service Badge - US Army
    • Writer
Data not being written to MySQL DB
« on: July 21, 2014, 08:33 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
Win 10 Pro running on a 3.2 GHz CPU and 12 Gb RAM
__________________________________________

Proofreading Service: http://williammillerservices.com/proofreading

« Last Edit: July 21, 2014, 10:11 PM by kyrathaba »

rgdot

  • Supporting Member
  • Joined in 2009
  • **
  • Posts: 2,197
Re: Data not being written to MySQL DB
« Reply #1 on: July 21, 2014, 08:52 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,200
    • Participated in NANY Challenge Eight Times
    • Programming School - Deluxe Bonus Medal
    • Programming School - Stage 1 Medal
    • Coding Snacks
    • Military Service Badge - US Army
    • Writer
Re: Data not being written to MySQL DB
« Reply #2 on: July 21, 2014, 09:22 PM »
Dunno that I have access. This is on a gamera host. I have filed a support ticket.
Win 10 Pro running on a 3.2 GHz CPU and 12 Gb RAM
__________________________________________

Proofreading Service: http://williammillerservices.com/proofreading

Stoic Joker

  • Honorary Member
  • Joined in 2008
  • **
  • Posts: 6,652
    • Cody Award
    • Participated in NANY Challenge Five Times
Re: Data not being written to MySQL DB
« Reply #3 on: July 21, 2014, 09:54 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,200
    • Participated in NANY Challenge Eight Times
    • Programming School - Deluxe Bonus Medal
    • Programming School - Stage 1 Medal
    • Coding Snacks
    • Military Service Badge - US Army
    • Writer
Re: Data not being written to MySQL DB
« Reply #4 on: July 21, 2014, 10:15 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.
Win 10 Pro running on a 3.2 GHz CPU and 12 Gb RAM
__________________________________________

Proofreading Service: http://williammillerservices.com/proofreading

kyrathaba

  • N.A.N.Y. Organizer
  • Honorary Member
  • Joined in 2006
  • **
  • Posts: 3,200
    • Participated in NANY Challenge Eight Times
    • Programming School - Deluxe Bonus Medal
    • Programming School - Stage 1 Medal
    • Coding Snacks
    • Military Service Badge - US Army
    • Writer
Re: Data not being written to MySQL DB
« Reply #5 on: July 21, 2014, 10:17 PM »
Note: the following line of code never gets executed:

Quote
echo "Your data was successfully added to the database.";
Win 10 Pro running on a 3.2 GHz CPU and 12 Gb RAM
__________________________________________

Proofreading Service: http://williammillerservices.com/proofreading

rgdot

  • Supporting Member
  • Joined in 2009
  • **
  • Posts: 2,197
Re: Data not being written to MySQL DB
« Reply #6 on: July 22, 2014, 12:16 AM »
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: 11,205
    • Participated in NANY Challenge Fourteen Times
    • Coding Snacks
    • Writer
    • Hardware Hacker
Re: Data not being written to MySQL DB
« Reply #7 on: July 22, 2014, 12:52 AM »
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,200
    • Participated in NANY Challenge Eight Times
    • Programming School - Deluxe Bonus Medal
    • Programming School - Stage 1 Medal
    • Coding Snacks
    • Military Service Badge - US Army
    • Writer
Re: Data not being written to MySQL DB
« Reply #8 on: July 22, 2014, 01:15 AM »
Charles Little, one of the support staff, is helping me sort it. I'll post back the solution we arrive at.
Win 10 Pro running on a 3.2 GHz CPU and 12 Gb RAM
__________________________________________

Proofreading Service: http://williammillerservices.com/proofreading

Stoic Joker

  • Honorary Member
  • Joined in 2008
  • **
  • Posts: 6,652
    • Cody Award
    • Participated in NANY Challenge Five Times
Re: Data not being written to MySQL DB
« Reply #9 on: July 22, 2014, 02:30 AM »
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,200
    • Participated in NANY Challenge Eight Times
    • Programming School - Deluxe Bonus Medal
    • Programming School - Stage 1 Medal
    • Coding Snacks
    • Military Service Badge - US Army
    • Writer
Re: Data not being written to MySQL DB
« Reply #10 on: July 22, 2014, 02:34 AM »
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.
Win 10 Pro running on a 3.2 GHz CPU and 12 Gb RAM
__________________________________________

Proofreading Service: http://williammillerservices.com/proofreading

kyrathaba

  • N.A.N.Y. Organizer
  • Honorary Member
  • Joined in 2006
  • **
  • Posts: 3,200
    • Participated in NANY Challenge Eight Times
    • Programming School - Deluxe Bonus Medal
    • Programming School - Stage 1 Medal
    • Coding Snacks
    • Military Service Badge - US Army
    • Writer
Re: Data not being written to MySQL DB
« Reply #11 on: July 22, 2014, 02:35 AM »
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
Win 10 Pro running on a 3.2 GHz CPU and 12 Gb RAM
__________________________________________

Proofreading Service: http://williammillerservices.com/proofreading

Stoic Joker

  • Honorary Member
  • Joined in 2008
  • **
  • Posts: 6,652
    • Cody Award
    • Participated in NANY Challenge Five Times
Re: Data not being written to MySQL DB
« Reply #12 on: July 22, 2014, 03:07 AM »
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: 2,197
Re: Data not being written to MySQL DB
« Reply #13 on: July 22, 2014, 03:09 AM »
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,200
    • Participated in NANY Challenge Eight Times
    • Programming School - Deluxe Bonus Medal
    • Programming School - Stage 1 Medal
    • Coding Snacks
    • Military Service Badge - US Army
    • Writer
Re: Data not being written to MySQL DB
« Reply #14 on: July 22, 2014, 03:15 AM »
@Stoic gotcha. I derived my code from sample code in a php/mysql Head First book.
Win 10 Pro running on a 3.2 GHz CPU and 12 Gb RAM
__________________________________________

Proofreading Service: http://williammillerservices.com/proofreading

kyrathaba

  • N.A.N.Y. Organizer
  • Honorary Member
  • Joined in 2006
  • **
  • Posts: 3,200
    • Participated in NANY Challenge Eight Times
    • Programming School - Deluxe Bonus Medal
    • Programming School - Stage 1 Medal
    • Coding Snacks
    • Military Service Badge - US Army
    • Writer
Re: Data not being written to MySQL DB
« Reply #15 on: July 26, 2014, 10:25 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)
<center><a href="index.html">Return to proofreading page</a></center>

<?php
	
	
	$tablename = 'proofreading_sought';
	$echo_on = true;
	$user="kyrathab";
	$password="*";
	$database="*";
	$mysql_host = "localhost";
	
	if($_POST['firstname']=='')
	{		
		?>
		You should <a href="index.html">return</a> to my proofreading page, because
		<?php
			die(" you failed to enter data for your first name!");
	}
	if($_POST['lastname']=='')
	{
		?>
		You should <a href="index.html">return</a> to my proofreading page, because
		<?php
			die(" you failed to enter data for your last name!");
	}
	
	if($_POST['email']=='')
	{
		?>
		You should <a href="index.html">return</a> to my proofreading page, because
		<?php
			die(" you failed to enter an email address!");
	}
	
	echo 'Hello, ' . $_POST['firstname'] . ' ' . $_POST['lastname'] . '!<p>';
	echo 'You specified the following email address: ' . $_POST['email'] . '.';
	echo '<p>';
	echo "Your information was submitted. Thank you! You should hear back from the proofreader within the next 48 hours. ";
	echo "The proofreader will attempt to contact you at the following email address: " . $theMail . '<p>';
	
	
	mail("kyrathasoft@gmail.com","Interested in obtaining proofreading", $msg, 'From:' . $_POST['email']);
	
	$link = mysql_connect($mysql_host, $user, $password);
	if (!$link) {
		die('Could not connect to host: ' . mysql_error());
	}
	echo 'Connected to host...<p>';
	
	$db_selected = mysql_select_db($database, $link) or die('Connected to host but could not select database: '	. mysql_error());
	echo 'Connected successfully to the database...<p>';
	
	if (!blnTableNameFoundInDatabase($database,$tablename)){ 	
	//Let's create the table...
	if($echo_on){ echo "Creating table $tablename"; }
	$query = "CREATE TABLE $tablename
	( ID int unsigned not null auto_increment primary key,
	FirstName char(45) not null, LastName char(45) not null,
	Email char(50) not null)";
	@mysql_query($query) or Die('Failed to create table $tablename, script dies...' . mysql_error());	
	$blnJustCreatedTable = True;
	}
	
	$query = "INSERT INTO $tablename (FirstName, LastName, Email) 
		VALUES ($first, $last, $theMail)";
	mysql_query($query) or die('Insertion failed!' . mysql_error() . '<p>');

	
	$file = 'proofread_seekers.txt';
	// The new person to add to the file
	$person = $name . '|' . $theMail . '|' . date("Y-m-d H:i:s") . "\n";
	// Write the contents to the file, 
	// using the FILE_APPEND flag to append the content to the end of the file
	// and the LOCK_EX flag to prevent anyone else writing to the file at the same time
	file_put_contents($file, $person, FILE_APPEND | LOCK_EX);
	
	function blnTableNameFoundInDatabase($the_database, $the_tablename){
		$res = mysql_query("SHOW TABLES FROM $the_database");	
		$bln = False;
		while($row = mysql_fetch_array($res, MYSQL_NUM)){
			if($row[0] == $the_tablename){ $bln = True; }
		}
	return $bln;
}
		

?>

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.
Win 10 Pro running on a 3.2 GHz CPU and 12 Gb RAM
__________________________________________

Proofreading Service: http://williammillerservices.com/proofreading

« Last Edit: July 26, 2014, 10:34 PM by kyrathaba »

Ath

  • Supporting Member
  • Joined in 2006
  • **
  • Posts: 3,649
    • Participated in NANY Challenge Eleven Times
    • Coding Snacks
    • Linux User
    • Hardware Hacker
Re: Data not being written to MySQL DB
« Reply #16 on: July 27, 2014, 10:55 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...
/Ton
Ath's software collection, Quote: "A problem well stated is a problem half-solved." (Charles Kettering)

kyrathaba

  • N.A.N.Y. Organizer
  • Honorary Member
  • Joined in 2006
  • **
  • Posts: 3,200
    • Participated in NANY Challenge Eight Times
    • Programming School - Deluxe Bonus Medal
    • Programming School - Stage 1 Medal
    • Coding Snacks
    • Military Service Badge - US Army
    • Writer
Re: Data not being written to MySQL DB
« Reply #17 on: July 27, 2014, 01:16 PM »
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
Win 10 Pro running on a 3.2 GHz CPU and 12 Gb RAM
__________________________________________

Proofreading Service: http://williammillerservices.com/proofreading

Original address: https://www.donationcoder.com/forum/index.php?topic=38490.0