Jump to content

sonnieboy

Members
  • Posts

    154
  • Joined

  • Last visited

Profile Information

  • Gender
    Not Telling

sonnieboy's Achievements

Regular Member

Regular Member (3/5)

0

Reputation

  1. Thanks Barand; you helped me understand the point @requinix was trying to make. Thank you both very much for your great assistance.
  2. Thanks so much for your response. The page said edit.html and it has the task_lead, task_title and a few more. I just shortened it for emphasis. The code I posted comes from edit.php I also see parameters like these: $rowId = (int) $_GET[ 'rowId' ]; $taskId = $row['Id']; Not sure which one of those is passed through URL. The edit.html doesn't have Id either coming from it or passed to it.
  3. Greetings mates, I have not been here for years. I have been thrust into an app written by someone else. The requirement is to amend, not edit, an existing record. In other words, rather than edit an existing record, management would like an empty new text box to enter amended data and save to another table so that when queried, would display existing record and the newly amended record. Below is an ID of an existing record: $sql = "SELECT * FROM DBO.existingTable where year_created = 2019 Order by Id"; echo '<table id="results-table"> <thead> <tr> <th>ID</th> <th>Edit</th> <th>View PDF</th> <th>Task Lead</th> <th>Task Title</th> <th>Division</th> </tr> </thead>'; while ( $row = sqlsrv_fetch_array( $stmt, SQLSRV_FETCH_BOTH ) ) { $div = ($row['division'] == "1" ? "Divname" : ($row['division'] == "2" ? "Highway" : "NULL")); $taskType = ($row['task_type'] == 0 ? "Annual" : ($row['task_type'] == 1 ? "Carryover" : ($row['task_type'] == 2 ? "New" : "NULL"))); if($row['year_created'] == 2019){ echo '<tr id="taskId"> <td>'.$row['Id'].'</td> <td><a href="project_edit.html?id='.$row['Id'].'" target="_blank">Edit</a></td> <td><input type="button" onclick="getReport('.$row['Id'].')" value="View PDF"></td> <td>'.$row['task_lead'].'</td> <td>'.$row['task_title'].'</td> <td>'.$div.'</td> </tr> } } echo '</table>' The above code isa snippet of code in edit.php. What I would like to do is grab the ID which is '.$row['Id'].' from this edit page and use it when inserting the amended code which is in insert,php file: //The ID from edit.php code should go here $task_lead = (empty($_POST['task_lead'])) ? "''" : "'" . str_ireplace( "'", "", $_POST[ 'task_lead' ] ) . "'"; $task_title = (empty($_POST['task_title'])) ? "''" : "'" . str_ireplace( "'", "''", $_POST[ 'task_title' ] ). "'"; $division = (empty($_POST['division'])) ? "''" : "'" . str_ireplace( "'", "", $_POST[ 'division' ] ) . "'"; //Then my insert statement should be something like this: $sql = "INSERT INTO DBO.Amended_Records ({id from table with existing record}, amended_taskActivities, amended_taskProducts,amendscope_dev_fhwa, amendconsultant_procurement, amendcontract_negotiations, amendconsultant_notice, amendtotal_duration, year_created) VALUES ({$rowId - that I need to get from edit.php}, $amendproposed_activities, $amendanticipated_products,$amendscope_dev_fhwa,$amendconsultant_procurement,$amendcontract_negotiations,$amendconsultant_notice,$amendtotal_duration, 2021)"; When I insert this record into the DB, the id from edit.php is getting inserted as null. Can you please advise how I can resolve this?
  4. After managing to incorporate your latest changes,, the errors are gone and record is getting inserted again but once again, just one only instead of more than one rows I created.
  5. Man, as much as I truly, truly appreciate your help and time, I am officially fully confused now. Do I get rid the following right after INSERT(..) VALUES(..) and replace $sourcestmt=$databaseonnection(...)? And do I replace the line that begins with mysqli_stmt_bind_param(...$sth,'sssssss'... with your latest foreach? I cant thank you enough for your help if( $sth = mysqli_prepare($conn,$sql) ) { mysqli_stmt_bind_param($sth, 'sssssss',
  6. Notice: Undefined offset: 0 in C:\xampp\htdocs\losures\forms\final.php on line 47 array(6) { ["sourcename"]=> string(14) "Penny Hardaway" ["sourceaddress"]=> string(16) "21 Martin Street" ["income"]=> string(5) "71000" ["spousename"]=> string(14) "Andrew Jackson" ["spouseAddress"]=> string(17) "1 Presidents Road" ["spouseIncome"]=> string(6) "201000" } Error: Column 'sourcename' cannot be null I do have var_dump(...) on that code but you are right; what good is if I don't use it. Even after fixing sourcename, I am still getting the error that sourcename cannot be blank. I don't understand this. I mean I know what the error means but I don't understand why. This is what var_dum($sname) shows. One thing that stands out is that I entered two sourcenames, two source addresses, two incomes, two spousenames, two spouseAddresses and two spouseIncomes but only one of each is showing up. My gosh!
  7. Great helpers, Just to be sure that I followed your instructions correctly, Here is the markup: <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; ?>"> <input type="hidden" name="sname[<?=$id?>][sourcename" value="<?php echo $_POST['sourcename']; ?>"> <input type="hidden" name="sname[<?=$id?>][sourceaddress]" value="<?php echo $_POST['sourceaddress']; ?>"> <input type="hidden" name="sname[<?=$id?>][income]" value="<?php echo $_POST['income']; ?>"> <input type="hidden" name="sname[<?=$id?>][spousename]" value="<?php echo $_POST['spousename']; ?>"> <input type="hidden" name="sname[<?=$id?>][spouseAddress]" value="<?php echo $_POST['spouseAddress']; ?>"> <input type="hidden" name="sname[<?=$id?>][spouseIncome]" value="<?php echo $_POST['spouseIncome']; ?>"> Then the processing page: $sql = 'INSERT INTO `myDB`.`wp_myTable` ( `employeeID`' . ', `sourcename`, `sourceaddress`, `income`,`spousename`,`spouseAddress`,`spouseIncome` )' . ' VALUES ( ? , ? , ? , ? , ? , ? , ? )'; if( $sth = mysqli_prepare($conn,$sql) ) { mysqli_stmt_bind_param($sth, 'sssssss', $lastID, $sourcename, $sourceaddress, $income, $spousename, $spouseAddress, $spouseIncome); foreach($_POST['sname'] as $sname) { list($sourcename, $sourceaddress, $income, $spousename, $spouseAddress, $spouseIncom) = $sname; } But I am getting: Notice: Undefined offset: 1 in C:\xampp\htdocs\closures\forms\final.php on line 47
  8. Sorry, that was a failed attempt at recreating the reason for the one character record insert. I just put the foreach at wrong place. My sincere apology for that. But going back to Psycho's code snippet, when I apply it to my part of the code that is an array as shown again, does his code replace this version? Sorry but I am trying to understand how it replaces my version: Anything that reduces confusion on my part only helps me to get this working finally. Thanks all for ($i=0; $i<count($_POST['sourcename']); $i++) { $sourcename = $_POST['sourcename'][$i]; $sourceaddress = $_POST['sourceaddress'][$i]; $income = $_POST['income'][$i]; $spousename = $_POST['spousename'][$i]; $spouseAddress = $_POST['spouseAddress'][$i]; $spouseIncome = $_POST['spouseIncome'][$i]; }
  9. Hi Psycho, Thank sir. Just an fyi, employeename, ttitle and email are not array. These are displayed just once. That's why they don't have the [] thing on them. Do I still need to do them as you suggested. I am so desperate to get working so I can catch up on sleep for just one night.
  10. hmm, excellent point. This is the markup on previous page where the FOR loop is based on. Based on the point you just made, I revisited this page and notice that I had this: <form action='final.php' method = 'POST'> <?phpforeach ($rowIDs as $id) { ?> <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? } ?> <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]; ?>"> <?phpforeach ($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? } ?> <input type="submit" value="submit" /> </form> I removed them and now have each as this: <input type="hidden" name="sourcename[]" value="<?php echo $_POST['sourcename']; ?>"> with their various hidden form names of course. Now, the names are displaying in full but I still have the issue of one row instead of two or more. This is the only issue that I have now. Between the hidden form fields and the FOR loop, something is causing this immense grief. I am hopeful you gurus can help me ride this out. Thanks to you guys here for the continued assistance.
  11. <?php // Database connection $conn = mysqli_connect("localhost","myuser","mypass","myDB"); if(!$conn) { die('Problem in database connection: ' . mysql_error()); } // Data insertion into database $query = 'INSERT INTO `myDB`.`employees` ( `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)); } $lastID = mysqli_insert_id($conn); //Insert this primary key from employees table to the myTable $sql = 'INSERT INTO `myDB`.`myTable` ( `employeeID`' . ', `sourcename`, `sourceaddress`, `income`,`spousename`,`spouseAddress`,`spouseincome` )' . ' VALUES ( ? , ? , ? , ? , ? , ? , ? )'; if( $sth = mysqli_prepare($conn,$sql) ) { mysqli_stmt_bind_param($sth, 'sssssss', $lastID, $sourcename, $sourceaddress, $income, $spousename, $spouseAddress, $spouseIncome); for ($i=0; $i<count($_POST['sourcename']); $i++) { $sourcename = $_POST['sourcename'][$i]; $sourceaddress = $_POST['sourceaddress'][$i]; $income = $_POST['income'][$i]; $spousename = $_POST['spousename'][$i]; $spouseAddress = $_POST['spouseAddress'][$i]; $spouseIncome = $_POST['spouseIncome'][$i]; } var_dump($_POST); if( mysqli_stmt_execute($sth) ) { echo '<h1>Success!</h1><br>Your record successfully submitted <br><br>");'; } else { printf("Error: %s\n",mysqli_stmt_error($sth)); } } else { printf("Error: %s\n",mysqli_connect_error($conn)); } ?> Greetings again. I have made some good strides with this project I am very close to the finish line. Right now, all my errors are gone and code is inserting data into the database. However, I still have two problems. One, when create for instance three records expecting all three to be inserted into the database, only one record gets inserted instead of three. Second, of the record that got inserted, only the first character of each value gets inserted. Others are cut off. I tried var_dump() but no truncation. Can you please assist again if possible? Thank you.
  12. Thank you (again) very much. I really appreciate your help. I could dump all the code I have here but they won't help much. So, let me try and hopefully, I can make some sense. On the first page called order.php, we have several rows separated by divs. The idea of this app is to get employees to declare their sources of income other than their regular pay. So, the database is designed, I think to have normalized data. We have employee table that stores employee info. Then the main table. So, an emp can have one or more rows of data associated with his or her name. So if I for instance, have 3 income sources as a result of my wife's dealings with different entities, I would enter spousename, spouseaddress and spouseincome. Since there is more information related to my spouse income source, I would click a button to give me more rows to provide more information about my wife's income source. So employee name, title, email can only be provided once. honoria can only be provided once. And the rest can be provided once or more than once. Then the next page called preview.php where you have a couple of foreach loops and hidden form fields, is used by user to preview entries. On this page, you can see the array works great as it captures however many rows or entries an employee enters regarding his/her income sources. The biggest challenge now is to capture all the values coming from the hidden form fields and insert them into the database. I am not able to do that on the INSERT. For instance, using the example you just showed, I have this: $_POST['sourcename'] which is on the final.php page with the INSERT statement, if I need to capture the array of $_POST['sourcename'] and use that on the insert statement, how do I do it? That's where I am struggling mightily. Thanks so much for your help.
  13. Thanks very much for your response. To respond to this: The reason some of them are not arrays is because they require one response only. For instance, an employee (employeename) can provide his/her name once. His or her title once and his or her email once. however, when dealing with income source (sourcename, sourceaddress, income), those could come from multiple sources. That's why a user is given an option to click to add more sources of income. If you could be kind enough to give me just one example of how to check if an array and what to do if it is, I would really appreciate. Thank you again
  14. Greetings again, I have tried everything and everywhere but I just can't find the solution to this latest issue. This is the last piece of my project. I will appreciate your highly valued expert help on this. We have an order.php page. User inputs data into a row. User might click to add another row and input data into that row as well. When done, user clicks the submit button which takes him or her to preview.php. The code below is on preview.php: <?php error_reporting(E_ALL); echo "DEBUG POST DATA: <pre>".print_r($_POST, 1)."</pre>"; if(isset($_POST['employeename'])) $employeename = $_POST['employeename']; if(isset($_POST['email'])) $email = $_POST['email']; if(isset($_POST['ttitle'])) $ttitle = $_POST['ttitle']; $rowIDs = $_POST['rowIDs']; $row2IDs = $_POST['row2IDs']; echo $employeename .'<br>'; echo $ttitle .'<br> <hr width=400 align=left>'; $rowIDs = $_POST['rowIDs']; foreach ($rowIDs as $id) { $sourcename = $_POST['sourcename' . $id]; $sourceaddress = $_POST['sourceaddress' . $id]; $income = $_POST['income' . $id]; echo 'Name: '. $sourcename . '<br />'; echo 'Address: '. $sourceaddress . '<br />'; echo 'Income: '. $income . '<br /><br>'; } foreach ($row2IDs as $id) { $spousename = $_POST['spousename' . $id]; $spouseAddress = $_POST['spouseAddress' . $id]; $spouseIncome = $_POST['spouseIncome' . $id]; echo 'Name: '. $spousename . '<br />'; echo 'Address: '. $spouseAddress . '<br />'; echo 'spouseIncome: '. $spouseIncome . '<br /><br>'; echo 'Your email: '. $email . '<br /><br>'; } ?> <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="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]; ?>"> <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]; ?>"> <a href="javascript:history.go(-1)">Return to correct changes</a> <input type="submit" value="submit" /> </form> </body> If everything looks goo to the user on this page, the user clicks Submit and final.php processes the submit request and inserts the records into the database if everything is ok. When only one row of data is submitted, the record is processed and submitted successfully into the database. However, when more than one row is processed, it fails with the following error: Notice: Array to String Conversion error in C:\httpdocs\xampp\myfolder\final.php I believe the reason I am getting that error in final.php page is because most of those values are being processed as strings when they should be processed as arrays. Can one of you experts point me in the right direction of modify the code below: This place is my last hope to get this working. Thank you for your assistance. $sql = 'INSERT INTO `mydb`.`wp_mytable` ( `employeeID`' . ', `sourcename`, `sourceaddress`, `income`,`spousename`,`spouseAddress`,`spouseincome` )' . ' VALUES ( ? , ? , ? , ? , ? , ? , ? )'; if( $sth = mysqli_prepare($conn,$sql) ) { mysqli_stmt_bind_param($sth,'sssssss' ,$last_id ,$_POST["sourcename"] ,$_POST["sourceaddress"] ,$_POST["income"] ,$_POST["spousename"] ,$_POST["spouseAddress"] ,$_POST["spouseIncome"] );
  15. You see that input tag line EXACTLY as you typed it here with the little boxes and the unnecessary quotes at the end? As you know, sometimes when you look at your screen for extended period of time, you can no longer see anything beyond what you have been seeing. Sometimes, when we post, we do so because we need coding help. Sometimes, it is to get a new set of eyes to look at things. Anyway, it is resolved now. Thanks to everyone who responded. I didn't need to copy those few lines. I must have inadvertently typed in something that created the problem that bugged me down for days.
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.