Jump to content


Photo

Somehow the insert from form is failing w/out error message...?


  • Please log in to reply
12 replies to this topic

#1 yshua

yshua

    Advanced Member

  • Members
  • PipPipPip
  • 119 posts

Posted 07 November 2013 - 09:39 AM

Dear PHP and MySQL people:

 

         Am  using Apache2.2.17, PHP5.3.8, MySQL5.1.65, phpmyadmin3.5.3, Win7 with the following code:

<?php
session_start();
include("includes/db.php");
$submitform = 0;
if(!empty($_POST)){
	$submitform = 1;
   
   $query = "INSERT INTO usrtable (firstname,lastname,phone,emailid,howhear) 
           VALUES 
          ('".$_REQUEST['firstname']."',
           '".$_REQUEST['lastname']."',
           '".$_REQUEST['phone']."',
           '".$_REQUEST['emailid']."',
           '".mysql_real_escape_string($_REQUEST['howhear'])."')";

 	
  if (mysql_query($query) === TRUE) {
   	 $_SESSION['seqno'] = mysql_insert_id();
       $_SESSION['user'] = $_POST['firstname'];
       $_SESSION['emailid'] = $_REQUEST['emailid'];
   }else{
	header('Location: form.php?errormsg=Insert Error.'.mysql_error());
      #die("Error! Insert failed.Please try again");	
   }

 mysql_close($mysql);

}
if($submitform == 1) {
?>
<html>
<body onLoad="document.myform.submit();">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<form action="https://www.paypal.com/cgi-bin/webscr" method="post">
<table width="843" height="102" align="center" bgcolor="#F7F7F7">   
<tr> <td width="573" height="104"><img src="images/mysite.bmp" border="0">
</td>   </tr>
     <tr>     <td height="53" valign="center">
<table width="799" height="185" align="center"></td>   </tr>
    <tr><td height="179" valign="top"><h2 align="center">                     
<h2><strong>My Site Heading!!</strong></h2>
</td>   </tr>
<input type="hidden" name="cmd" value="_s-xclick">
<input type="hidden" name="hosted_button_id" value="1111111111111">
<input type="image" src="https://www.paypalobjects.com/en_US/i/btn/btn_buynowCC_LG.gif" border="0" name="submit" alt="PayPal - The safer, easier way to pay online!">
<img alt="" border="0" src="https://www.paypalobjects.com/en_US/i/scr/pixel.gif" 
width="800" height="1" valign="center">
</table>
<input type="hidden" name="charset" value="UTF-8">
<input type="hidden" name="return" value="https://www.mysite.com/finish.php"> 
<input type="hidden" name="rm" value="1">
<input type="hidden" name="cancel_return" value="https://www.mysite.com/thisscreen/unhook.php">
</form>

</body>
</html>
<?php
}
else{
  header('Location: form.php');	
}

?>

            Can anyone see what might prevent the line insert which had been working before...?

 

Completely at a loss,

Yshua



#2 dalecosp

dalecosp

    Advanced Member

  • Members
  • PipPipPip
  • 287 posts
  • LocationJoplin, MO

Posted 07 November 2013 - 03:31 PM

Not really.  Perhaps corrupt/unexpected input?  That's often why something that has been working quits (if you haven't made changes) --- because you forgot to account for some edge case/funky character input.


"God doesn't play dice" --- Albert Einstein
"Perl is hardly a paragon of beautiful syntax." --- Weedpacket

#3 yshua

yshua

    Advanced Member

  • Members
  • PipPipPip
  • 119 posts

Posted 07 November 2013 - 05:10 PM

Thanks, Dale,

 

          Am sorry about the lack of clarity,  some typo MAY have been inserted in the php code of other code files.  Will reverify your theory, but so far, in this testing phase, the input has also all been pristine and expected!  Repeatedly, as in 10 attempts by myself, it fails to insert....   But perhaps some little script warning has caused this.

 

Still looking,

Yshua


Edited by yshua, 07 November 2013 - 05:22 PM.


#4 mac_gyver

mac_gyver

    Advanced Member

  • Moderators
  • 1,909 posts

Posted 07 November 2013 - 05:33 PM

what exact execution path or symptom are you getting?

 

do you have php's error_reporting set to E_ALL and either display_errors set to ON or log_errors set to ON so that any php detected errors will be reported?

 

do you have output_buffering turned OFF in your php.ini so that things you or php might display on a page aren't discarded when you do a header() redirect?

 

edit: do you know for a fact that the code where your query is at is even being executed?


Edited by mac_gyver, 07 November 2013 - 05:36 PM.

multi-purpose programming fool and resident naysayer [We try not be negative in replies, but telling someone what they're doing wrong, while staying politically correct, isn't always going to happen.]

#5 yshua

yshua

    Advanced Member

  • Members
  • PipPipPip
  • 119 posts

Posted 12 November 2013 - 11:51 AM

Dear Mac_gyver:

Please forgive how late this reply arrived. Have been fighting home front only somewhat successfully. The error reporting is THE most disappointing function of my PHP at this time! Good that you brought that up. The most infuriating is that the old "access.log" and "error.log" has somehow been bypassed with a new "sitename.com-access.log" and "sitename.com-error.log," both of which have these bulky dumps interspersed, taking up a huge amount of space, and making the logs practically impossible to read/decipher....

But you have given me much to go on! Am hoping and praying for quick insights.

Yshua

#6 dalecosp

dalecosp

    Advanced Member

  • Members
  • PipPipPip
  • 287 posts
  • LocationJoplin, MO

Posted 12 November 2013 - 06:23 PM

If you have access to php.ini, you can set something like:

 

error_log = /some/path/you/can/read/php_error_log

 

and get only PHP errors written here.


"God doesn't play dice" --- Albert Einstein
"Perl is hardly a paragon of beautiful syntax." --- Weedpacket

#7 yshua

yshua

    Advanced Member

  • Members
  • PipPipPip
  • 119 posts

Posted 12 November 2013 - 08:29 PM

OK, fellow PHP'ers:

Got error log coming out again by resetting the buffer reporting "On" in php.ini and also setting the error_reporting to E-ALL! Brilliant, Mac-gyver, because you made this very worthwhile even without a solution yet. Access.log still is without updates....

Regarding the execution path or symptom, am still researching.... Although the insert fails, the following PHP MySQL queries in followup.php does fine with updates of other lines of data. Does that help?

Yshua

Edited by yshua, 12 November 2013 - 08:38 PM.


#8 dalecosp

dalecosp

    Advanced Member

  • Members
  • PipPipPip
  • 287 posts
  • LocationJoplin, MO

Posted 13 November 2013 - 11:09 AM

When an insert fails, I always log, mail, or print the SQL query --- it's the best way to debug it (assuming, of course, you speak SQL, and you should, if you intend to program it).


"God doesn't play dice" --- Albert Einstein
"Perl is hardly a paragon of beautiful syntax." --- Weedpacket

#9 yshua

yshua

    Advanced Member

  • Members
  • PipPipPip
  • 119 posts

Posted 14 November 2013 - 12:04 PM

Dear Dalecosp:

Only WISH to log, mail, or print SQL, but my access.log is still avoiding logging, and am unfamiliar how to do the other (mail or print). Meanwhile, the seqno is auto increment, and could this have something to do with why the insert fails? Zero attempt is made to fill in the seqno, if you notice.

Also, a bit of hindsight, does this belong in MySQL installation forum?

Yshua

Edited by yshua, 14 November 2013 - 12:05 PM.


#10 Ch0cu3r

Ch0cu3r

    Advanced Member

  • Moderators
  • 1,716 posts

Posted 14 November 2013 - 12:13 PM

 

Only WISH to log, mail, or print SQL, but my access.log is still avoiding logging,

access.log as in Apaches access log? It only logs (http) requests not (server) errors. You need to check Apaches error.log for (server) errors.



#11 dalecosp

dalecosp

    Advanced Member

  • Members
  • PipPipPip
  • 287 posts
  • LocationJoplin, MO

Posted 14 November 2013 - 01:02 PM

Let's take a look at these lines:

if (mysql_query($query) === TRUE) {
$_SESSION['seqno'] = mysql_insert_id();
$_SESSION['user'] = $_POST['firstname'];
$_SESSION['emailid'] = $_REQUEST['emailid'];
}else{
header('Location: form.php?errormsg=Insert Error.'.mysql_error());
#die("Error! Insert failed.Please try again");
}


You actually had, at some point, the ability to print planned ... but you're redirecting first.

Try something like this for debug purposes *only*:

if (mysql_query($query) === TRUE) {
$_SESSION['seqno'] = mysql_insert_id();
$_SESSION['user'] = $_POST['firstname'];
$_SESSION['emailid'] = $_REQUEST['emailid'];
}else{
//header('Location: form.php?errormsg=Insert Error.'.mysql_error());
die("Error! Insert failed. The SQL was $query <br><br> MySQL said: ".mysql_error());
}

Edited by dalecosp, 14 November 2013 - 01:05 PM.

"God doesn't play dice" --- Albert Einstein
"Perl is hardly a paragon of beautiful syntax." --- Weedpacket

#12 yshua

yshua

    Advanced Member

  • Members
  • PipPipPip
  • 119 posts

Posted 15 November 2013 - 08:42 AM

Dear Dalecosp:

Definitely with all the error message checking now in effect, the insert correctly takes off from the insert.php file without failing! Perhaps warnings/errors in the Javascript as recorded in the Firefox Web Developer Error Console are actually interfering with the insert in Paypal shopping cart protocol, or the unspecified 'seqno' which is specified in Phpmyadmin as "auto_increment" is somehow needing to be specified...? Either way, one or another of these explanations must be the issue!

Yshua

#13 dalecosp

dalecosp

    Advanced Member

  • Members
  • PipPipPip
  • 287 posts
  • LocationJoplin, MO

Posted 15 November 2013 - 11:25 AM

Well, sounds like we're making progress :)

JS errors are not good either, of course; my goal is to eliminate all errors (I'm apparently a tyrannical dictator! :D )

At any rate, I hope you can get it sorted, and I'll be checking back here periodically...
"God doesn't play dice" --- Albert Einstein
"Perl is hardly a paragon of beautiful syntax." --- Weedpacket




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

Cheap Linux VPS from $5
SSD Storage, 30 day Guarantee
1 TB of BW, 100% Network Uptime

AlphaBit.com