WAMP vs XAMPP Question

Alles, was PHP betrifft, kann hier besprochen werden.

WAMP vs XAMPP Question

Postby cover » 09. January 2013 03:51

I have a question that I can't figure out and I'm wondering if it might not be because my last success was on WAMP and now I'm having trouble with XAMPP 'or' perhaps just that WAMP was on Windows XP whereas my XAMPP install is on a 64 bit machine of Windows 7. My tried and true code that follows has never let me down on the XP WAMP machine but for some reason, sometimes doesn't actually write to my MySQL database table even though I don't get an error message and it appears from my PHP code that it was a successful data entry.

My data entry is passed from a text field form on one page to the next where upon successful write, displays a message as to what has just successfully written to the db.

The PHP code:
Code: Select all
<?php
require_once(connect.php');   // user & password
$DBname = "history";
$table = "history_tbl";

$id = $_POST['id'];
$event = $_POST['event'];
$date = $_POST['date'];
$name = $_POST['name'];

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')";
if ($results = mysql_query($sqlquery)) {
    $event = stripslashes($event);
}

mysql_close();

print "<center><table border=\"0\"
width=\"500\"><tr><td>";
print "<p><font face=\"verdana\" size=\"+0\"> <center>You
Just Entered This Information <p><blockquote>";
print "Event: $event<p>Date: $date<p> Name: $name</blockquote></td></tr></table>
</CENTER>
</body>
</html>";
?>


PHP is version 5.47

DB/Table structure:
id = int, auto-increment, primary key
event = varchar 250
date = date
name = varchar 20

Engine InnoDB
Collation utf8_general-ci w/UTF-8 Unicode character set

Anyone have any ideas what might be causing this occasional failure to write? Usually writes fine but occasionally the data isn't in the table even though the entry screen indicates a successful write. Again, not sure if it's WAMP/XAMPP or something to do with 64 bit buffers, etc.

Thanks for any ideas,
cov
cover
 
Posts: 19
Joined: 24. December 2012 14:15
Operating System: Windows 7 64bit

Re: WAMP vs XAMPP Question

Postby Nobbie » 12. January 2013 15:33

id is a primary key and automatic increment - therefore it is a very bad idea to pass a value to the id and try to INSERT into a table, because it may collide with an existing id.

Do not apply an id (pass empty value instead), it is given automatically by MySQL. You also do not render any message, if the sql-Statement fails. You should change your code and output a proper message if mysql_query() returns FALSE. Use mysql_error() for a proper error message.
Nobbie
 
Posts: 13170
Joined: 09. March 2008 13:04

Re: WAMP vs XAMPP Question

Postby cover » 12. January 2013 23:48

Thanks. What really strikes me as odd is that the queries NEVER fail and this input *seems* to never fail although when I look at the table contents later, the entry didn't make it in. I'm starting to think it's more either XAMPP config related OR something to do with how windows 7 machines buffer data. Sure is frustrating.
cover
 
Posts: 19
Joined: 24. December 2012 14:15
Operating System: Windows 7 64bit

Re: WAMP vs XAMPP Question

Postby cover » 13. January 2013 00:29

Y'all have any thoughts on uninstalling my XAMPP 32 and reinstalling a 64 bit version??? This 'phantom' problem is so weird. Connecting to the db and table never fails on a query and when inputting the data through a form, it never seems to fail on a write to the table (for all appearances) and then you check the table and nothing's there.
cover
 
Posts: 19
Joined: 24. December 2012 14:15
Operating System: Windows 7 64bit

Re: WAMP vs XAMPP Question

Postby Nobbie » 13. January 2013 14:24

cover wrote:Thanks. What really strikes me as odd is that the queries NEVER fail and this input *seems* to never fail


What makes you sure about that? There is no error handling in your script and even if the SQL fails, you wont receive any error message. So how can you be sure, that the query never fails? I am pretty sure that it fails! But you cannot recognize it.

Thats what i mentioned above, you have to implement an error handling and output an error message (i.e. mysql_error()), otherwhise you will never know, if your SQL failed or not!

cover wrote:Y'all have any thoughts on uninstalling my XAMPP 32 and reinstalling a 64 bit version???


There is no 64 bit Xampp Version, so it's useless even to think about...
Nobbie
 
Posts: 13170
Joined: 09. March 2008 13:04

Re: WAMP vs XAMPP Question

Postby cover » 14. January 2013 04:02

Using the following error handling and nothing is showing up. INSERT INTO seems to have been successful until you check the table contents and I'm using an echo to see the contents from the first input to the insert page. I've not had a query fail as I query this table for data in a number of ways. Oddly, I've dropped the characters going to the varchar(250) by 100 as a test and the write was successful. I'm inclined to think that something else with configuration is going on.
cover
 
Posts: 19
Joined: 24. December 2012 14:15
Operating System: Windows 7 64bit

Re: WAMP vs XAMPP Question

Postby Nobbie » 14. January 2013 23:44

cover wrote:Using the following error handling and nothing is showing up.


Sorry, i cant see anything, Which error handling do you mean?
Nobbie
 
Posts: 13170
Joined: 09. March 2008 13:04

Re: WAMP vs XAMPP Question

Postby cover » 15. January 2013 04:28

Code: Select all
$con = mysql_connect($DBhost,$DBuser,$DBpass);
if (!$con)
    {
    die("Connect Fail:" . mysql_error());
    }
$db_select = mysql_select_db($DBname, $con);
if (!$db_select)
    {
    die ("DB Select fail:" . mysql_error());
    }

$sqlquery = "INSERT INTO $table VALUES('', '$event', '$date', '$name', '$year')";
if ($results = mysql_query($sqlquery)) {
$event = stripslashes($event);
}
echo "<hr>$sqlquery<hr>";


yet nothing out of the ordinary shows up - looks like it went in okay but upon checking the table, nada
cover
 
Posts: 19
Joined: 24. December 2012 14:15
Operating System: Windows 7 64bit

Re: WAMP vs XAMPP Question

Postby Altrea » 15. January 2013 06:09

Hi cover,

I added code-BBTags covering your code. Please use that BBCode functionality (there is a Code-Button right above the text field) if you want to post code.
That makes it much more readable because of intending and scrolling functionality.

However, i don't see any error handling for your INSERT mysql_query() function. Without handling errors, nobody knows what is going on there, so please use mysql_error()

Another very helpful function would be mysql_affected_rows() which should output 1 if your query was successful.

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 11 Pro x64

Re: WAMP vs XAMPP Question

Postby cover » 15. January 2013 15:04

Can someone please show me what error handling you think I should have, now that you've seen the code for that page (and particularly, the INSERT INTO portion) ?
cover
 
Posts: 19
Joined: 24. December 2012 14:15
Operating System: Windows 7 64bit

Re: WAMP vs XAMPP Question

Postby Altrea » 15. January 2013 16:19

cover wrote:Can someone please show me what error handling you think I should have, now that you've seen the code for that page (and particularly, the INSERT INTO portion) ?

Of course :) . Okay, let's see, just a basic example. You can do something like that:

Code: Select all
$con = mysql_connect($DBhost,$DBuser,$DBpass);
if (!$con)
    {
    die("Connect Fail:" . mysql_error());
    }
$db_select = mysql_select_db($DBname, $con);
if (!$db_select)
    {
    die ("DB Select fail:" . mysql_error());
    }

$sqlquery = "INSERT INTO $table VALUES('', '$event', '$date', '$name', '$year')";
if ($results = mysql_query($sqlquery)) {
    $numrows = mysql_affected_rows();
    echo 'affected rows: ' .$numrows;
    $event = stripslashes($event);
} else {
    echo 'MySQL Error (' .mysql_errno(). '): ' .mysql_error();
}
echo "<hr>$sqlquery<hr>";


best wishes,
Altrea

P.S.: just an inside to the future: The mysql functions will be marked as deprecated in PHP 5.5 and removed in PHP 5.6 or PHP 6.
To get future proof you should start to take a look to the mysql classes and function mysqli and PDO
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 11 Pro x64

Re: WAMP vs XAMPP Question

Postby cover » 16. January 2013 03:39

Thank you, Altrea - appreciate very much your help...
cover
 
Posts: 19
Joined: 24. December 2012 14:15
Operating System: Windows 7 64bit

Re: WAMP vs XAMPP Question

Postby Altrea » 16. January 2013 04:58

You're welcome :)
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 11 Pro x64

Re: WAMP vs XAMPP Question

Postby cover » 16. January 2013 05:42

Hey to close this out, with the help of your code I could pick up on an error (mysql error 1064: SQL Syntax) that I was chasing and it repeatedly referred to an InnoDB engine. I changed the table to MyISAM and it works every time now. I've read where InnoDB is preferred but couldn't get the consistency as my INSERT INTO continued to error out so... After reading through my MySQL error log, I saw references to the InnoDB too and went to the my.ini file to UNcomment the recommended lines for InnoDB but couldn't get Apache to fire back up so undid that and changed my DB table engine to MyISAM.


Thanks again for your help and to others who replied too. :D

Here was that my.ini code:
Code: Select all
# Uncomment the following if you are using InnoDB tables
#innodb_data_home_dir = C:\mysql\data/
#innodb_data_file_path = ibdata1:10M:autoextend
#innodb_log_group_home_dir = C:\mysql\data/
#innodb_log_arch_dir = C:\mysql\data/
# You can set .._buffer_pool_size up to 50 - 80 %
# of RAM but beware of setting memory usage too high
#innodb_buffer_pool_size = 16M
#innodb_additional_mem_pool_size = 2M
# Set .._log_file_size to 25 % of buffer pool size
#innodb_log_file_size = 5M
#innodb_log_buffer_size = 8M
#innodb_flush_log_at_trx_commit = 1
#innodb_lock_wait_timeout = 50
cover
 
Posts: 19
Joined: 24. December 2012 14:15
Operating System: Windows 7 64bit

Re: WAMP vs XAMPP Question

Postby Altrea » 16. January 2013 06:05

What was the full error message you get?
Your code contains just a simple INSERT query, so i can't believe this is a InnoDB issue (exept you are getting constraint integrety messages, which is at the end not the fault of InnoDB but of your way to insert data into it - changing to MyISAM instead just destroys the integrety).
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 11 Pro x64

Next

Return to PHP

Who is online

Users browsing this forum: No registered users and 15 guests