Jump to content

sonnieboy

Members
  • Posts

    154
  • Joined

  • Last visited

Everything posted by sonnieboy

  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.
  16. Thanks for your responses. I did F12 to see what's going on and this is what I see: <input�type='text'�name='custname'�value="John Doe"=""> This is why the screen is showing blank. Do you know why that is happening and how to resolve it? I have never seen anything like this before.
  17. Great point indeed. I changed to text to see the values but I could not. Nothing on screen as though they were still hidden. That's why I had to do a VIEW SOURCE to see if I see any values. Now, your point leads me to a very important question which may lead us to the solution and that question is if I can see the values when I do VIEW SOURCE, what does it mean when I can't see the values when I change the text type from hidden to text? This is really baffling. I one of you great minds can help me. My manager is losing confidence that I can get this done and I have been looking at this for a long while now.
  18. Barand, Yes, the names are the same. The action is to be processed by process.php. I changed it to text so I can see the values. That should be no brainer even for someone like me. That's why I said I am confused because every example I looked up followed same convention as the one I am following, That's also why I am wondering if the fact that I am trying to insert into a WordPress DB might have something to do with it, I have never done something like this in WordPress before.
  19. ?php error_reporting(E_ALL); echo "DEBUG POST DATA: <pre>".print_r($_POST, 1)."</pre>"; if(isset($_POST['custname'])) $custname = $_POST['custname']; if(isset($_POST['zip'])) $zip = $_POST['zip']; if(isset($_POST['city'])) $city = $_POST['city']; if(isset($_POST['email'])) $email = $_POST['email']; $address = $_POST['address']; $rowIDs = $_POST['rowIDs']; $row2IDs = $_POST['row2IDs']; echo $custname .'<br>'; echo $zip .'<br> <hr width=400 align=left>'; $rowIDs = $_POST['rowIDs']; foreach ($rowIDs as $id) { $agentname = $_POST['agentname' . $id]; $agentaddress = $_POST['agentaddress' . $id]; $agentincome = $_POST['agentincome' . $id]; echo 'Name: '. $agentname . '<br />'; echo 'Address: '. $agentaddress . '<br />'; echo 'agentincome: '. $agentincome . '<br /><br>'; } ?> <body> <form action='process.php' method = 'POST'> <input type='text' name='custname' value="<?php echo $custname; ?>"> <input type='text' name='address' value="<?php echo $address; ?>"> <input type='text' name=email value="<?php echo $email; ?>"> <input type='text' name=city value="<?php echo $city; ?>"> <input type='text' name='zip' value="<?php echo $zip; ?>"> <input type='hidden' name='agentname' value="<?php echo $agentname; ?>"> <input type='hidden' name='agentaddress' value="<?php echo $agentaddress; ?>"> <input type='hidden' name='agentincome' value="<?php echo $agentincome; ?>"> <input type="action" type="button" value="Return to data" onclick="history.go(-1);" /> | <input type="submit" value="Submit your form" /> </form> </body> My sincere apology. Unnecessary pressure from powers to be Here it is: I will eventually add agent info. Those are arrays
  20. ginerjm, sorry I had hit the post before I saw your post. The code that produced the error is above on my original post. You will see the code below. printf("Error: %s\n",mysqli_stmt_error($sth)); My error always says: Errror: custname cannot be null. No, it is the casing is correct. If I am sure that if I remove that field, the error goes to next field. Let me ask this, is possible that I am having this problem because I am attempting to insert this record in WordPress db?
  21. No, that's not what I said. Sorry if I confused you. I have a page called review.php. When a customer places an order from the order.php, s/he clicks the Review button and is taken to review.php page. On this page, I have the hidden form fields I posted above. I don't want to risk reposting. After reviewing his or her order on review.php page and if everything is ok, s/he clicks to submit his or her order. This is where we are having issues. I expect those values from the hidden form fields to be passed to the process.php. So, what I am saying is that when I VIEW SOURCE in review.php for those hidden form fields, I see the values. However, when I do the var_dump(...), they show up as null and I can't figure out why.
  22. Yes, I tried that and the value coming out is NULL which is what is confusing me. In my original thread, I indicated that when I VIEW SOURCE on that page that passed the hidden form values to this process.php, I see the values. So, I guess my confusion is why is process.php page not recognizing those values? Every example I have looked at so far, suggests that I am doing it correctly but why it showing NULL value?
  23. Hi Thanks for helping me again. There were a total of 9 fieldnames. I removed 4 before posting but forgot to reduce that number. Sorry about that. The error is on the first fieldname, custname and I am sure that if I remove that, the error goes to the next line. I am sure the issue is with the hidden field values not recognized by process.php for some reason.
  24. <?php global $wpdb; // Database connection $conn = mysqli_connect("localhost","myuser","mypwd","myDB"); if(!$conn) { die('Problem in database connection: ' . mysql_error()); } // Data insertion into database $sql = 'INSERT INTO `myDB`.`myTable` ( `custname`' . ', `address`, `city`, `zip`, `email` )' . ' VALUES ( ? , ? , ? , ? , ? , ? , ? , ? , ? )'; if( $sth = mysqli_prepare($conn,$sql) ) { mysqli_stmt_bind_param($sth,'sssss' ,$_POST["custname"] ,$_POST["address"] ,$_POST["city"] ,$_POST["zip"] ,$_POST["email"] ); if( mysqli_stmt_execute($sth) ) { echo '<h1>Thank you</h1> <br> Go back to the main page <a href="index.php");'; } else { printf("Error: %s\n",mysqli_stmt_error($sth)); } } else { printf("Error: %s\n",mysqli_connect_error($conn)); } ?> <form action='process.php' method = 'POST'> <input type='hidden' name='custname' value="<?php echo $custname; ?>"> <input type='hidden' name='address' value="<?php echo $address; ?>"> <input type='hidden' name='city' value="<?php echo $city; ?>"> <input type='hidden' name='zip' value="<?php echo zip; ?>"> <input type='hidden' name='email' value="<?php echo $email; ?>"> Greetings gurus, I hope you guys can forgive me for asking this because this is more of confusion than ignorance. I have some form fields as hidden shown above. When I right-click on my PC to VIEW SOURCE, I see the values passed to them. However, when I tried submitting the values from these hidden forms, I am getting an error that "Custname cannot be null". This tells me that this page is passing null values to process.php page. Every browsing I have done so far, suggests that I am doing it correctly and I have spend more than three hours searching for answers. Does anyone know what could be wrong? Your help in pointing me to the right direction is greatly appreciated. Here is process.php
  25. I do value your time very much and I do sincerely appreciate your help. I do spend a lot of time researching the problems before posting, sometimes, I spend more than a day believe it or not as is the case with this issue but sometimes, it so happens that as I keep researching, I see something that leads me to the solution. I will handle things differently next time. Your point is well taken and thank you very much.
×
×
  • 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.