XAMPP PHP/MySQL/APACHE Question v1.8.1

Problems with the Windows version of XAMPP, questions, comments, and anything related.

XAMPP PHP/MySQL/APACHE Question v1.8.1

Postby cover » 29. December 2012 07:51

I downloaded and successfully installed XAMPP 1.8.1 on my Windows 7 64bit machine recently. My question is that 'occasionally', I seem to write to the MySQL database but upon running a query, the entry isn't there. It only happens now and then and usually, after I've already successfully written something to the database as in, on the second or third attempt.

Here's some of my PHP code:

mysql_connect($DBhost,$DBuser,$DBpass) or die("Unable to connect to database");
mysql_select_db($DBname) or die("Unable to select database $DBname");
if (mysqli_connect_errno())
{
echo 'Error: Could not connect to database.';
exit;
}
$sqlquery = "INSERT INTO $table VALUES('$id', '$event', '$date', '$name', '$year')";
$results = mysql_query($sqlquery);
mysql_close();

Oddly, no errors and the write always appears successful.

Some specifics on how I have the MySQL db table set up:
input text fields with a varchar type (except ID which is int). ID is primary key and default is 'latin1' with 'latin1_swedish_ci' collation. In matching another XP WAMP system that has worked flawlessly, I set the engine to MyISAM

Any ideas as to why it would only write to the database occasionally anyone?

TIA
cover
 
Posts: 19
Joined: 24. December 2012 14:15
Operating System: Windows 7 64bit

Re: XAMPP PHP/MySQL/APACHE Question v1.8.1

Postby cover » 29. December 2012 15:35

I'm inclined to think that my PHP code is okay so am wondering if my database setup configuration isn't to blame for the fact that it's a 'part-timer'.

I changed the engine to InnoDB, character set to UTF8, and collation to utf8_general_ci and it's doing the same thing. Appearing to have written just fine but upon a query, data isn't there. Other times it's fine.
cover
 
Posts: 19
Joined: 24. December 2012 14:15
Operating System: Windows 7 64bit

Re: XAMPP PHP/MySQL/APACHE Question v1.8.1

Postby JJ_Tagy » 29. December 2012 16:09

Without your full code, I'm not inclinded to think so. How do you get your variables? Are they always valued? Have you put debug code in to show each entry (or entry attempt)?
JJ_Tagy
 
Posts: 788
Joined: 30. January 2012 13:44
XAMPP version: 5.5.15
Operating System: Windows 10 Pro x64

Re: XAMPP PHP/MySQL/APACHE Question v1.8.1

Postby cover » 29. December 2012 16:16

variables pass from one page to the next (entry form to insert form which shows what was entered into the database). On the WAMP installation, the PHP and MySQL are dated but I can't recall what version. On the XAMPP, both are more recent which caused me to wonder if my PHP connect, select, etc etc might be keeping it from working 100% of the time. Odd thing is it shows as the write being successful.

Currently using:
<?php
require_once('generic_connect.php');
$DBname = "events";
$table = "events_tbl";

$id = $_POST['id'];
$event = $_POST['event'];
$date = $_POST['date'];
$name = $_POST['name'];
$year = $_POST['year'];
mysql_connect($DBhost,$DBuser,$DBpass) or die("Unable to connect to database");
mysql_select_db($DBname) or die("Unable to select database $DBname");

$sqlquery = "INSERT INTO $table VALUES('$id', '$event', '$date', '$name', '$year')";
$results = mysql_query($sqlquery);
mysql_close();
cover
 
Posts: 19
Joined: 24. December 2012 14:15
Operating System: Windows 7 64bit

Re: XAMPP PHP/MySQL/APACHE Question v1.8.1

Postby hackattack142 » 29. December 2012 16:51

You could try adding something like
Code: Select all
$results = mysql_query($sqlquery);
if (mysql_errno())
echo "MySQL error ".mysql_errno().": ".mysql_error()."\n<br>When executing:<br>\n$sqlquery\n<br>";
to see if any errors are coming as a result of the query

You could also try using the mysqli extension
XAMPP Control Panel Developer
Latest CP: viewtopic.php?f=16&t=48932
hackattack142
 
Posts: 701
Joined: 20. May 2011 23:29
Operating System: Windows 7 Ultimate SP1 64-Bit

Re: XAMPP PHP/MySQL/APACHE Question v1.8.1

Postby cover » 30. December 2012 22:45

Thanks for the ideas. I'll have to do some digging too, to see if there's a more modern way to write the code I posted (with the newer PHP and My SQL).
cover
 
Posts: 19
Joined: 24. December 2012 14:15
Operating System: Windows 7 64bit

Re: XAMPP PHP/MySQL/APACHE Question v1.8.1

Postby Altrea » 31. December 2012 04:06

cover wrote:if there's a more modern way to write the code I posted

Sure, there are :D
Take some looks into MySQLi or my favorite PDO.

There are even more advanced techniques like ORM and ActiveRecord Pattern, like in Idiorm and Paris, Propel or the very famous Doctrine.

best wishes,
Altrea
We don't provide any support via personal channels like PM, email, Skype, TeamViewer!

It's like porn for programmers 8)
User avatar
Altrea
AF Moderator
 
Posts: 11926
Joined: 17. August 2009 13:05
XAMPP version: several
Operating System: Windows 10 Pro x64


Return to XAMPP for Windows

Who is online

Users browsing this forum: No registered users and 150 guests