Click here to Skip to main content
15,889,651 members
Home / Discussions / JavaScript
   

JavaScript

 
AnswerRe: Setting URL Pin
ZurdoDev7-Mar-17 9:21
professionalZurdoDev7-Mar-17 9:21 
GeneralRe: Setting URL Pin
Kevin Marois7-Mar-17 10:47
professionalKevin Marois7-Mar-17 10:47 
AnswerRe: Page appearing way to wide. Pin
Richard MacCutchan3-Mar-17 21:14
mveRichard MacCutchan3-Mar-17 21:14 
AnswerRe: Page appearing way to wide. Pin
ZurdoDev7-Mar-17 9:23
professionalZurdoDev7-Mar-17 9:23 
QuestionSetting SignalR URL in JQuery Pin
Kevin Marois2-Mar-17 12:21
professionalKevin Marois2-Mar-17 12:21 
AnswerRe: Setting SignalR URL in JQuery Pin
Nathan Minier3-Mar-17 1:26
professionalNathan Minier3-Mar-17 1:26 
QuestionJavaScript Error - Internet Explorer - Object doesn't support property or method 'indexOf' Pin
Kevin Marois2-Mar-17 10:54
professionalKevin Marois2-Mar-17 10:54 
Question(SOLVED) Call to Member function execute() on null... Pin
samflex25-Feb-17 11:36
samflex25-Feb-17 11:36 
Even though this forum got me to where I am now on this project due largely the generous help of Richard Deeming, I have tried hard to avoid coming back here but I am having so much difficulty getting to the finish line which is this last bit.

First, on the screen that we use to preview data, I have this:

PHP
<body>
<form action='final.php' method = 'POST'>
<input type="hidden" name="employeename" value="<?php echo $employeename; ?>">
<input type="hidden" name="ttitle" value="<?php echo $ttitle; ?>">
<input type="hidden" name="email" value="<?php echo $email; ?>">
<?php foreach ($rowIDs as $id) { ?>
<input type="hidden" name="sourcename" value="<?php echo $_POST['sourcename' . $id]; ?>">
<input type="hidden" name="sourceaddress" value="<?php echo $_POST['sourceaddress' . $id]; ?>">
<input type="hidden" name="income" value="<?php echo $_POST['income' . $id]; ?>">
<?php }?>
<?php foreach ($row2IDs as $id) { ?>
<input type="hidden" name="spousename" value="<?php echo $_POST['spousename' . $id]; ?>">
<input type="hidden" name="spouseAddress" value="<?php echo $_POST['spouseAddress' . $id]; ?>">
<input type="hidden" name="spouseIncome" value="<?php echo $_POST['spouseIncome' . $id]; ?>">
<?php } ?>
<a href="javascript:history.go(-1)" data-icon="back" data-role="button" data-theme="b">Return to make changes</a>
<input type="submit" value="submit" />
</form>


There is more but I thought this is relevant part.

Then on the next page (final.php) after user clicks the submit button, I have this:

PHP
<?php

// Database connection
$conn = mysqli_connect("localhost","myusername","mypass","myDB");
if(!$conn) {
die('Problem in database connection: ' . mysql_error());
}

// Data insertion into database

$query = 'INSERT INTO `mydb`.`wp_mytable` ( `employeename`, `ttitle`, `email` )'
     . ' VALUES ( ? , ? , ? )';
if( $sth = mysqli_prepare($conn,$query) ) {
   mysqli_stmt_bind_param($sth,'sss'
      ,$_POST["employeename"]
      ,$_POST["ttitle"]
      ,$_POST["email"]
   );
   if( mysqli_stmt_execute($sth) ) {
     echo 'Successfully created employee record;';
   } else {
      printf("Error: %s\n",mysqli_stmt_error($sth));
   }
} else {
   printf("Error: %s\n",mysqli_connect_error($conn));
}
$last_id = mysqli_insert_id($conn);


$sql = 'INSERT INTO `myDB`.`wp_myTable` ( `employeeID`'
     . ', `sourcename`, `sourceaddress`, `income`,`spousename`,`spouseAddress`,`spouseincome` )'
     . ' VALUES ( ? , ? , ? , ? , ? , ? , ? )';

if( $sth = mysqli_prepare($conn,$sql) ) {
for($i=0; $i<count($_POST['sourcename']); $i++)
{
$stmt->execute(array($last_id,
$_POST['sourcename'][$i],
$_POST['sourceaddress'][$i],
$_POST['income'][$i]),
$_POST['spousename'][$i],
$_POST['spouseAddress'][$i],
$_POST['spouseIncome'][$i]));
 }

   if( mysqli_stmt_execute($sth) ) {
     echo '<h1>Success!</h1><br>Your record successfully submitted <br><br><h1>Thank You!</h1';
   } else {
      printf("Error: %s\n",mysqli_stmt_error($sth));
   }
} else {
   printf("Error: %s\n",mysqli_connect_error($conn));
}
?>


If I can get records to submit correctly, I am done with this project.

However, I am stuck here with the following error messages:

Notice: Undefined variable: stmt in C:\xampp\htdocs\closures\forms\final.php on line 37

Fatal error: Call to a member function execute() on null in C:\xampp\htdocs\closures\forms\final.php on line 37

This error starts on this line:

$stmt->execute(array($last_id,...

I have spent my entire weekend on this without any progress. I will be truly grateful once again for solution.

Thanks

modified 28-Feb-17 11:38am.

AnswerRe: Call to Member function execute() on null... Pin
Richard MacCutchan25-Feb-17 20:47
mveRichard MacCutchan25-Feb-17 20:47 
GeneralRe: Call to Member function execute() on null... Pin
samflex25-Feb-17 21:25
samflex25-Feb-17 21:25 
GeneralRe: Call to Member function execute() on null... Pin
Richard MacCutchan25-Feb-17 21:29
mveRichard MacCutchan25-Feb-17 21:29 
GeneralRe: Call to Member function execute() on null... Pin
samflex25-Feb-17 21:37
samflex25-Feb-17 21:37 
GeneralRe: Call to Member function execute() on null... Pin
Richard MacCutchan25-Feb-17 21:42
mveRichard MacCutchan25-Feb-17 21:42 
GeneralRe: Call to Member function execute() on null... Pin
samflex25-Feb-17 21:47
samflex25-Feb-17 21:47 
GeneralRe: Call to Member function execute() on null... Pin
Richard MacCutchan26-Feb-17 21:06
mveRichard MacCutchan26-Feb-17 21:06 
GeneralRe: Call to Member function execute() on null... Pin
samflex27-Feb-17 0:34
samflex27-Feb-17 0:34 
GeneralRe: Call to Member function execute() on null... Pin
Richard MacCutchan27-Feb-17 0:42
mveRichard MacCutchan27-Feb-17 0:42 
GeneralRe: Call to Member function execute() on null... Pin
samflex27-Feb-17 3:22
samflex27-Feb-17 3:22 
GeneralRe: Call to Member function execute() on null... Pin
Richard MacCutchan27-Feb-17 3:33
mveRichard MacCutchan27-Feb-17 3:33 
GeneralRe: Call to Member function execute() on null... Pin
samflex27-Feb-17 4:04
samflex27-Feb-17 4:04 
GeneralRe: Call to Member function execute() on null... Pin
Richard MacCutchan27-Feb-17 4:21
mveRichard MacCutchan27-Feb-17 4:21 
GeneralRe: Call to Member function execute() on null... Pin
samflex27-Feb-17 4:31
samflex27-Feb-17 4:31 
GeneralRe: Call to Member function execute() on null... Pin
Richard MacCutchan27-Feb-17 4:38
mveRichard MacCutchan27-Feb-17 4:38 
GeneralRe: Call to Member function execute() on null... Pin
samflex27-Feb-17 5:35
samflex27-Feb-17 5:35 
GeneralRe: Call to Member function execute() on null... Pin
Richard MacCutchan27-Feb-17 6:49
mveRichard MacCutchan27-Feb-17 6:49 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.