Jump to content


Photo

Submitting data gets no result; submitting blanks works!


  • Please log in to reply
3 replies to this topic

#1 wardweb

wardweb
  • New Members
  • Pip
  • Newbie
  • 2 posts

Posted 02 June 2006 - 06:50 PM

I have a simple form to submit data to a local MySQL database. It uses the "post" method to call an acknowledgment page, which uses PHP to connect to the DB and update fields in a table.

When I fill in either/both form fields and click Submit, nothing happens; no page change, no change to the DB. But if I leave the form fields blank and click Submit, the DB is updated and the acknowledgment page appears as it should.

The DB table is "URLs".

I've checked the syntax many times, but I suspect the problem may lay in my SQL query code. Here's a snippet of it:

//Set the variables for the DB queries:
$queryOverallProductionStatus = "UPDATE URLs SET stable_url = '{$_POST['OverallProductionStatus']}' WHERE document = 'Overall Production Status'";
$rOPS = mysql_query ($queryOverallProductionStatus);

//Print error message if query not successful.
echo mysql_error();

$query747ProductionStatus = "UPDATE URLs SET stable_url = '{$_POST['747ProductionStatus']}' WHERE document = '747 Production Status'";
$r7PS = mysql_query ($query747ProductionStatus);

//Print error message if query not successful.
echo mysql_error();


#2 AndyB

AndyB
  • Staff Alumni
  • Advanced Member
  • 5,465 posts
  • LocationToronto

Posted 02 June 2006 - 07:50 PM

Serious stupid questions:

#1 - you do have the same code under test on a server as you think you do, right?
#2 - you have not turned off all error reporting, right?

When in doubt, echo some stuff to see what's really happening (which isn't necessarily what you think ought to happen). Change your code typically to something like this for each query:

$queryOverallProductionStatus = "UPDATE URLs SET stable_url = '{$_POST['OverallProductionStatus']}' WHERE document = 'Overall Production Status'";
echo $$queryOverallProductionStatus. "<br>"; // see what we tried

$rOPS = mysql_query ($queryOverallProductionStatus) or die("Error: ". mysql_error());

//Print error message if query not successful.
// echo mysql_error();

Tell us what happened with that type of change.
Legend has it that reading the manual never killed anyone.
My site

#3 wardweb

wardweb
  • New Members
  • Pip
  • Newbie
  • 2 posts

Posted 02 June 2006 - 09:43 PM

[!--quoteo(post=379454:date=Jun 2 2006, 02:50 PM:name=AndyB)--][div class=\'quotetop\']QUOTE(AndyB @ Jun 2 2006, 02:50 PM) View Post[/div][div class=\'quotemain\'][!--quotec--]
Serious stupid questions:

#1 - you do have the same code under test on a server as you think you do, right?
#2 - you have not turned off all error reporting, right?

When in doubt, echo some stuff to see what's really happening (which isn't necessarily what you think ought to happen). Change your code typically to something like this for each query:

$queryOverallProductionStatus = "UPDATE URLs SET stable_url = '{$_POST['OverallProductionStatus']}' WHERE document = 'Overall Production Status'";
echo $$queryOverallProductionStatus. "<br>"; // see what we tried

$rOPS = mysql_query ($queryOverallProductionStatus) or die("Error: ". mysql_error());

//Print error message if query not successful.
// echo mysql_error();

Tell us what happened with that type of change.
[/quote]

Thanks for your quick reply, Andy.

In the "file" fields I had been typing random strings to test the code, instead of using the Browse button to select a file. I tried using the Browse buttons and suddenly all is well; the database is updated and the acknowledgement page appears as it should.

I've used "file" fields before successfully, but I didn't know they fail unless the correct syntax is used in them. Experimenting, it looks as if the string needs to begin with a letter and a colon, or \, or \\.


#4 AndyB

AndyB
  • Staff Alumni
  • Advanced Member
  • 5,465 posts
  • LocationToronto

Posted 02 June 2006 - 10:06 PM

Oh, good. I was slightly baffled as to why what looked like perfectly functional code wasn't working. One good thing is that now you know the script needs to include error trapping for blank or phoney file field data so that it doesn't write to the database in those circumstance.
Legend has it that reading the manual never killed anyone.
My site




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users