PHP echo problem

Community Forums/General Help/PHP echo problem

Yahfree(Posted 2010) [#1]
Hey! So when I run this code(process.php) off a jquery form, it puts the information from the form into the database correctly, but the echo statement doesn't work (echo "test";)??




BUT! when i comment out the database accessing stuff (below) the echo statement works. it spits "test." on the page as expected.



What's going on here? am i going insane?


GfK(Posted 2010) [#2]
I think your comment lines are all to cock. Its probably the //******* lines that are arsing things up.

Use /* and */ to begin/end comment blocks (multi line comments), or // for single line comments.


Yahfree(Posted 2010) [#3]
I just threw those in as i posted this. It's not the comments. It's so frustrating.

Let me explain what I'm doing more, I think I was a bit vague.


I'm writing a form (think a contact form) in PHP, HTML, and Jquery.

When I submit the form, jquery POSTS the information to process.php (which is the file above) and then that file inserts the form data into the database, AND idealy, outputs an error message or a successful message.


I have a special div back on the main file called "results" which recieves any output from this process.php.

When the database accessing code is present in the file, it adds the data to the database, but there is no visible output from the echo statement. BUT when I remove the database accessing code, and just leave the echo statements, it adds the output to the div#results as expected.

Why does the database code make the echo statements not work??

Last edited 2010


GfK(Posted 2010) [#4]
Do you get ANY output?

Is either of the Die() statements kicking in? Does $result actually contain anything?


Yahfree(Posted 2010) [#5]
I tried commenting out the die statements, etc..

still doesn't work as long as the database accessing stuff is present (msql_connect)

I even tried putting an echo statement ABOVE everything, still no output :(

BUT! I know the files working cause there's a bunch of new entries in the database haha.

Last edited 2010


GfK(Posted 2010) [#6]
Stumped, tbh.

Probably won't make any diff but have you tried closing the database connection *before* calling Echo?


Yahfree(Posted 2010) [#7]
nope. no difference.

I'm going to call it on the main page, and see if that works. If it does, then it's something to do with all this jquery stuff, which I have little knowledge about :(

Maybe I can pass a variable back to the main page and echo there :)


Yahfree(Posted 2010) [#8]
Here's a tutorial that kinda explains what I'm doing(using the same methods)

http://www.askaboutphp.com/213/php-and-jquery-submit-a-form-without-refreshing-the-page.html

So weird that the database calls make a difference!


TaskMaster(Posted 2010) [#9]
Did you look at the actual page source after it processes? Just to make sure the word test wasn't just get written to a spot in the web page that wasn't getting printed to the screen? Like in a comment, or within a code section or something like the wrong section of a table that doesn't show on the screen...


Perturbatio(Posted 2010) [#10]
Put the following after your mysql_query statement:

	echo '<pre>', print_r($result, true), '<pre>';
	echo '<pre>', print_r(mysql_error(), true), '<pre>';


Does anything display?


Perturbatio(Posted 2010) [#11]
On a separate issue, if you're storing your date as a mysql datetime value, you need to use the format "Y-m-d H:i:s".

And you really should escape the values passed in via the form ( use mysql_real_escape_string AFTER you've established your connection)


Yahfree(Posted 2010) [#12]
Nothing displays. @Preturbatio, I'll be sure to escape the values after everythings working :)

So my code is:
index.php


process.php (the mysql login stuff has been removed)



What's going on? still no output!!

On a side note, I ran this in IE, and it says theres an error on the page at:

line 19
char 6
unexpected string or number

I don't see this anywhere.

I think I'm going insane. :o


Perturbatio(Posted 2010) [#13]
The IE issue is the commas in your objects before closing them

					rules: {
						name: "required",
					},


The other issue would appear to be a probable server config issue or your database details are incorrect. It works on my local dev server.

try putting
error_reporting(1);

at the top of your code


Yahfree(Posted 2010) [#14]
I use wamp, and I just noticed the apache http server is crashing when I click submit.

Here's what I found in the error logs:
[Sun Nov 21 12:35:30 2010] [notice] Parent: child process exited with status 255 -- Restarting.
[Sun Nov 21 12:35:30 2010] [notice] Apache/2.2.11 (Win32) PHP/5.3.0 configured -- resuming normal operations
[Sun Nov 21 12:35:30 2010] [notice] Server built: Dec 10 2008 00:10:06
[Sun Nov 21 12:35:30 2010] [notice] Parent: Created child process 9752
[Sun Nov 21 12:35:31 2010] [notice] Child 9752: Child process is running
[Sun Nov 21 12:35:31 2010] [notice] Child 9752: Acquired the start mutex.
[Sun Nov 21 12:35:31 2010] [notice] Child 9752: Starting 64 worker threads.
[Sun Nov 21 12:35:31 2010] [notice] Child 9752: Starting thread to listen on port 80.



Perturbatio(Posted 2010) [#15]
This might help you then:

http://www.apachefriends.org/f/viewtopic.php?f=16&t=32617

*EDIT*
I use an ubuntu install personally after a little bit of experimentation, I set it up myself and can now test using virtual hosts very easily (so i can host multiple test domains on the same server).

Last edited 2010


Yahfree(Posted 2010) [#16]
i was just looking at that. The download link is broken -.-


Perturbatio(Posted 2010) [#17]
If you can't find the DLLs, a long shot would be to try setting compatibility settings on apache, PHP and others to WinXP.

Alternatively, download Virtual Box (free) and install winXP on it if you have a spare copy and want to use wamp, or install ubuntu and then just install the apache, mysql and php packages.


Perturbatio(Posted 2010) [#18]
or you could download from here: http://windows.php.net/download/


Yahfree(Posted 2010) [#19]
I'm wondering if it's just a windows vista thing. I'll try it on my Windows XP desktop later today.

What setup (wamp, xamp, etc?) are you running that allows my code to work correctly?

Thank you for all your help by the way. I'd be completely lost right now for a few days if it wasn't for you.

Last edited 2010


Perturbatio(Posted 2010) [#20]
I posted above, I'm using a LAMP server (running ubuntu desktop edition).


Yahfree(Posted 2010) [#21]
Awesome. Thanks for the help! (You too GfK)

I'll report back later