PHP - How To Retain Attributes Ina Class
I am making a project by designing my own MVC model. In this the user accesses controller class which further calls model class which accesses the database by $dbh attiribute defined public. My View is a script which calls different pages. In the constructor of model I'm establishing connection with the database. Firstly I construct the model object when the user accesses i.e. in the controller class to check in the databse then if the username is not present in the dtaabse I want to insert his info in the database for that I again calla model class but this time I again have to establish connection. Is the $dbh firstly constructed is lost like dangling pointers in C++. Do I have to worry about it. If yes how can I solve this problem.
Similar TutorialsHow do I retain a password as a user navigates from page to page without having to ask him for it again. I do not need it to protect the page, I need it to execute whatever selection he makes. enter_psw.html // this is a form verify_psw.php // I have the password here menu1.html // I don't have the password here and need it display_records add_record.php change_record.php delete_record_php hi there, I have a chained combo boxes. I manage to get the values for the sub process using onchange event.My problem here is how can I retain the values in the sub process combo box after the page is loaded? main.php Code: [Select] <?php require_once 'connectDB.php'; $sub_id = $_GET['sub_id']; $id = $_SESSION['process_id']; $sql = " SELECT * FROM tb_process ORDER BY pro_id ASC"; $result = mysql_query($sql) or die(mysql_error()); $sql = "SELECT tb_record.rec_tpcd, tb_record.rec_part, tb_record.rec_code, tb_record.rec_vendor, tb_record.rec_location, tb_record.rec_remark, tb_sub_process.sub_name, tb_process.pro_name FROM tb_record LEFT JOIN tb_sub_process ON tb_record.sub_id=tb_sub_process.sub_id LEFT JOIN tb_process ON tb_sub_process.pro_id=tb_process.pro_id WHERE tb_sub_process.sub_id = '$sub_id'"; $result2 = mysql_query($sql); $row = mysql_fetch_assoc($result2); $pro_name = $row['pro_name']; $sub_name = $row['sub_name']; ?> <html> <head> <script type="text/javascript" src="js/ajax.js"></script> <script type="text/javascript" src="js/jquery-1.2.3.min.js"></script> <script type="text/javascript"> $(document).ready(function() { $("#selectProcess").change(function() { var processID = $(this).val(); if(processID > 0) { $("#txtID").val(processID); $("#selectSubProcess").load('getSub.php?processID='+processID); } }); $("#selectSubProcess").change(function() { var subProcessID = $(this).val(); if(subProcessID > 0) { window.location = 'main.php?sub_id='+subProcessID; } }); }); </script> </head> <body> <form action="" method="post"> <table> <tr> <td>Process: </td> <td> <select id="selectProcess" name="selectProcess"> <option value="0" selected="selected">---SELECT PROCESS---</option> <?php while ($row = mysql_fetch_array($result)) { $process_id = $row['pro_id']; $process_name = $row['pro_name']; $select = ($id == $process_id) ? 'selected="selected"' : NULL; echo "<option value='$process_id' $select>$process_name</option>"; } ?> </select> </td> </tr> <tr> <td>Sub Process: </td> <td> <select id="selectSubProcess" name="selectSubProcess" > <option>SELECT PROCESS FIRST</option> </select> </td> </tr> </table> </form> <table border=1> <?php while($row = mysql_fetch_assoc($result2)) { extract($row); $imageDir1="images/".$rec_tpcd.".jpg"; $info = @getimagesize($imageDir1); if((bool)$info) { $imageDir="images/".$rec_tpcd.".jpg"; } else { $imageDir="images/NoPhoto.jpg"; } if ($col == 0) { $display .= "<tr>"; } $col++; if ($col == 1) { $col = 0; $display .= "</td>"; } echo "<tr> <td> <img src=$imageDir width='220' height='170' onClick=\"window.open('$imageDir', 'popup','height=500,width=800,scrollbars=yes,resizeable=yes status=yes'); return false\" target=\"_blank\"> </td> <td> <table style='overflow:auto; width:325px;'> <tr> <td width='80' valign='top'>Name</td> <td valign='top'>:</td> <td valign='top' colspan='2'>$rec_part</td> </tr> <tr> <td valign='top'>Code</td> <td valign='top'>:</td> <td valign='top' colspan='2'>$rec_code</td> </tr> <tr> <td>TPCD</td> <td>:</td> <td colspan='2'>$rec_tpcd</td> </tr> <tr class='style15'> <td>Vendor</td> <td>:</td> <td colspan='2'>$rec_vendor</td> </tr> <tr> <td>Location</td> <td>:</td> <td colspan='2'>$rec_location</td> </tr> <tr> <td>Remarks</td> <td>:</td> <td>$rec_remark</td> <td align='right'> <input type='image' name='change[$rec_tpcd]' src='library/cart add.png' width='20' height='20' value='Add To Order List >'/> </td> </tr> </table> </td> </tr>"; } ?> </table> </body> </html> getSub.php Code: [Select] <?php require_once 'connectDB.php'; if(isset($_GET['processID'])) { $process_id = $_GET['processID']; $sql = " SELECT * FROM tb_sub_process WHERE pro_id = '$process_id' ORDER BY sub_id ASC"; $result = mysql_query($sql) or die(mysql_error()); $_SESSION['process_id'] = $process_id; echo "<option>---------------------SELECTION--------------------</option>"; while($row = mysql_fetch_assoc($result)) { $sub_process_id = strtoupper($row['sub_id']); $sub_process_name = strtoupper($row['sub_name']); echo "<option value='$sub_process_id'>$sub_process_name</option>"; } } ?> I have several drop down boxes. When submit is clicked it execute query on another page. Problem is when submit is clicked selected values are return to defaults. Is it possible for the values to be remembered after submitting them? Part of the drop down code: Code: [Select] <?php $result = mysql_query("SELECT * FROM product GROUP BY Rim"); ?> <select id="Rim" name="Rim" selected="selected" style="width:158px;position:static;z-index:-1;"> <option value="rim" selected="selected"><?php echo "Rim"; ?></option> <?php while ($row = mysql_fetch_array($result)) { echo "<option>" . $row['Rim'] . "</option>"; echo "<br />"; } ?> </select> Hi all, I have a listbox on a form that gets it's data from a MySQL query, all of which is working fine. I make a selection in my listbox and then submit the form which is reloading itself. However on the reload I would like the listbox to display the selection made by the user, instead it reverts to the first item in the list. I have included the code, if someone could point me in the right direction that would be great. I have searched these forums and tried a few things that are suggested but I still can't get it to work. Code: [Select] <?php include("dbconn.php"); $query = "SELECT location.location_name, printer.model_number, location_printer.serial_number" . " FROM location, printer, location_printer" . " WHERE location.location_id = location_printer.location_id" . " AND printer.printer_id = location_printer.printer_id"; $result = mysql_query($query); echo "<table>"; echo "<th>Location</th>"; echo "<th>Printer</th>"; echo "<th>Serial No</th>"; while(($row = mysql_fetch_array($result))) { echo "<tr>"; echo "<td>".$row['location_name']."</td>"; echo "<td>".$row['model_number']."</td>"; echo "<td>".$row['serial_number']."</td>"; echo "</tr>"; } echo "</table>"; if(isset($_POST['location'])) { $loc = $_POST['location']; echo "<p>Location = <b> $loc </b>"; } ?> <html> <head> <title>Loop Results</title> </head> <body> <form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>" > <table> <tr> <td> <?php $query = "SELECT * FROM location ORDER BY location_name"; $result = mysql_query($query); $default = $_POST['location']; echo "<p>Location: "; echo "<select name='location'>"; while(($row = mysql_fetch_array($result))) { echo "<option value='{$row['location_id']}"; //Selected value if($row['location_id'] == $default) echo " selected "; echo "'>{$row['location_name']}</option>\n"; } echo "</select>"; ?> </td> </tr> <tr> <td> <input type="submit" /> </td> </tr> </table> </form> </body> </html> Hi all,
I am trying to validate all required fields in my contact form using php. However I am unable to retain what was selected in my country dropdown list after it is selected and submitted if the form had errror while validating. I want the form to retain the value that was selected by the user to stay in the form so that users can make necessary changes and resubmit the form all other values stay in the form except the country dropdown. Please help Below is the code. <!DOCTYPE HTML> <html> <head> <style> .error {color: #FF0000;} </style> </head> <body> <?php // define variables and set to empty values $nameErr = $emailErr = $genderErr = $websiteErr = $countryErr = ""; $name = $email = $gender = $comment = $website = ""; $country =""; if ($_SERVER["REQUEST_METHOD"] == "POST") { if (empty($_POST["name"])) { $nameErr = "Name is required"; } else { $name = test_input($_POST["name"]); // check if name only contains letters and whitespace if (!preg_match("/^[a-zA-Z ]*$/",$name)) { $nameErr = "Only letters and white space allowed"; } } if (empty($_POST["email"])) { $emailErr = "Email is required"; } else { $email = test_input($_POST["email"]); // check if e-mail address syntax is valid if (!preg_match("/([\w\-]+\@[\w\-]+\.[\w\-]+)/",$email)) { $emailErr = "Invalid email format"; } } if (empty($_POST["website"])) { $website = ""; } else { $website = test_input($_POST["website"]); // check if URL address syntax is valid (this regular expression also allows dashes in the URL) if (!preg_match("/\b(?:(?:https?|ftp):\/\/|www\.)[-a-z0-9+&@#\/%?=~_|!:,.;]*[-a-z0-9+&@#\/%=~_|]/i",$website)) { $websiteErr = "Invalid URL"; } } if (empty($_POST["comment"])) { $comment = ""; } else { $comment = test_input($_POST["comment"]); } if (empty($_POST["gender"])) { $genderErr = "Gender is required"; } else { $gender = test_input($_POST["gender"]); } $country = $_POST['country']; if (!in_array($country, array("AF", "AX", "AL", "DZ", "AS", "AD", "AO", "AI", "AQ", "AG", "AR", "AM", "AW", "AU", "AT", "AZ", "BS", "BH", "BD", "BB", "BY", "BE", "BZ", "BJ", "BM", "BT", "BO", "BA", "BW", "BV", "BR", "IO", "BN", "BG", "BF", "BI", "KH", "CM", "CA", "CV", "KY", "CF", "TD", "CL", "CN", "CX", "CC", "CO", "KM", "CG", "CD", "CK", "CR", "CI", "HR", "CU", "CY", "CZ", "DK", "DJ", "DM", "DO", "EC", "EG", "SV", "GQ", "ER", "EE", "ET", "FK", "FO", "FJ", "FI", "FR", "GF", "PF", "TF", "GA", "GM", "GE", "DE", "GH", "GI", "GR", "GL", "GD", "GP", "GU", "GT", "Gg", "GN", "GW", "GY", "HT", "HM", "VA", "HN", "HK", "HU", "IS", "IN", "ID", "IR", "IQ", "IE", "IM", "IL", "IT", "JM", "JP", "JE", "JO", "KZ", "KE", "KI", "KP", "KR", "KW", "KG", "LA", "LV", "LB", "LS", "LR", "LY", "LI", "LT", "LU", "MO", "MK", "MG", "MW", "MY", "MV", "ML", "MT", "MH", "MQ", "MR", "MU", "YT", "MX", "FM", "MD", "MC", "MN", "MS", "MA", "MZ", "MM", "NA", "NR", "NP", "NL", "AN", "NC", "NZ", "NI", "NE", "NG", "NU", "NF", "MP", "NO", "OM", "PK", "PW", "PS", "PA", "PG", "PY", "PE", "PH", "PN", "PL", "PT", "PR", "QA", "RE", "RO", "RU", "RW", "SH", "KN", "LC", "PM", "VC", "WS", "SM", "ST", "SA", "SN", "CS", "SC", "SL", "SG", "SK", "SI", "SB", "SO", "ZA", "GS", "ES", "LK", "SD", "SR", "SJ", "SZ", "SE", "CH", "SY", "TW", "TJ", "TZ", "TH", "TL", "TG", "TK", "TO", "TT", "TN", "TR", "TM", "TC", "TV", "UG", "UA", "AE", "GB", "US", "UM", "UY", "UZ", "VU", "VE", "VN", "VG", "VI", "WF", "EH", "YE", "ZM", "ZW" ))) { $country1 = "Please select your country";} } function test_input($data) { $data = trim($data); $data = stripslashes($data); $data = htmlspecialchars($data); return $data; } ?> <h2>contact us</h2> <p><span class="error">* required field.</span></p> <form method="post" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>"> Name: <input type="text" name="name" value="<?php echo $name;?>"> <span class="error">* <?php echo $nameErr;?></span> <br><br> E-mail: <input type="text" name="email" value="<?php echo $email;?>"> <span class="error">* <?php echo $emailErr;?></span> <br><br> <legend>Country:</legend> <select name="country"> <option value="NULL">select</option> <option value="AF">Afghanistan</option> <option value="AX">Ã…Land Islands</option> <option value="AL">Albania</option> <option value="DZ">Algeria</option> <option value="AS">American Samoa</option> <option value="AD">Andorra</option> <option value="AO">Angola</option> <option value="AI">Anguilla</option> <option value="AQ">Antarctica</option> <option value="AG">Antigua And Barbuda</option> <option value="AR">Argentina</option> <option value="AM">Armenia</option> <option value="AW">Aruba</option> <option value="AU">Australia</option> <option value="AT">Austria</option> <option value="AZ">Azerbaijan</option> <option value="BS">Bahamas</option> <option value="BH">Bahrain</option> <option value="BD">Bangladesh</option> <option value="BB">Barbados</option> <option value="BY">Belarus</option> <option value="BE">Belgium</option> <option value="BZ">Belize</option> <option value="BJ">Benin</option> <option value="BM">Bermuda</option> <option value="BT">Bhutan</option> <option value="BO">Bolivia</option> <option value="BA">Bosnia And Herzegovina</option> <option value="BW">Botswana</option> <option value="BV">Bouvet Island</option> <option value="BR">Brazil</option> <option value="IO">British Indian Ocean Territory</option> <option value="BN">Brunei Darussalam</option> <option value="BG">Bulgaria</option> <option value="BF">Burkina Faso</option> <option value="BI">Burundi</option> <option value="KH">Cambodia</option> <option value="CM">Cameroon</option> <option value="CA">Canada</option> <option value="CV">Cape Verde</option> <option value="KY">Cayman Islands</option> <option value="CF">Central African Republic</option> <option value="TD">Chad</option> <option value="CL">Chile</option> <option value="CN">China</option> <option value="CX">Christmas Island</option> <option value="CC">Cocos (Keeling) Islands</option> <option value="CO">Colombia</option> <option value="KM">Comoros</option> <option value="CG">Congo</option> <option value="CD">Congo, The Democratic Republic Of The</option> <option value="CK">Cook Islands</option> <option value="CR">Costa Rica</option> <option value="CI">Cote D'Ivoire</option> <option value="HR">Croatia</option> <option value="CU">Cuba</option> <option value="CY">Cyprus</option> <option value="CZ">Czech Republic</option> <option value="DK">Denmark</option> <option value="DJ">Djibouti</option> <option value="DM">Dominica</option> <option value="DO">Dominican Republic</option> <option value="EC">Ecuador</option> <option value="EG">Egypt</option> <option value="SV">El Salvador</option> <option value="GQ">Equatorial Guinea</option> <option value="ER">Eritrea</option> <option value="EE">Estonia</option> <option value="ET">Ethiopia</option> <option value="FK">Falkland Islands (Malvinas)</option> <option value="FO">Faroe Islands</option> <option value="FJ">Fiji</option> <option value="FI">Finland</option> <option value="FR">France</option> <option value="GF">French Guiana</option> <option value="PF">French Polynesia</option> <option value="TF">French Southern Territories</option> <option value="GA">Gabon</option> <option value="GM">Gambia</option> <option value="GE">Georgia</option> <option value="DE">Germany</option> <option value="GH">Ghana</option> <option value="GI">Gibraltar</option> <option value="GR">Greece</option> <option value="GL">Greenland</option> <option value="GD">Grenada</option> <option value="GP">Guadeloupe</option> <option value="GU">Guam</option> <option value="GT">Guatemala</option> <option value="Gg">Guernsey</option> <option value="GN">Guinea</option> <option value="GW">Guinea-Bissau</option> <option value="GY">Guyana</option> <option value="HT">Haiti</option> <option value="HM">Heard Island And Mcdonald Islands</option> <option value="VA">Holy See (Vatican City State)</option> <option value="HN">Honduras</option> <option value="HK">Hong Kong</option> <option value="HU">Hungary</option> <option value="IS">Iceland</option> <option value="IN">India</option> <option value="ID">Indonesia</option> <option value="IR">Iran, Islamic Republic Of</option> <option value="IQ">Iraq</option> <option value="IE">Ireland</option> <option value="IM">Isle Of Man</option> <option value="IL">Israel</option> <option value="IT">Italy</option> <option value="JM">Jamaica</option> <option value="JP">Japan</option> <option value="JE">Jersey</option> <option value="JO">Jordan</option> <option value="KZ">Kazakhstan</option> <option value="KE">Kenya</option> <option value="KI">Kiribati</option> <option value="KP">Korea, Democratic People'S Republic Of</option> <option value="KR">Korea, Republic Of</option> <option value="KW">Kuwait</option> <option value="KG">Kyrgyzstan</option> <option value="LA">Lao People'S Democratic Republic</option> <option value="LV">Latvia</option> <option value="LB">Lebanon</option> <option value="LS">Lesotho</option> <option value="LR">Liberia</option> <option value="LY">Libyan Arab Jamahiriya</option> <option value="LI">Liechtenstein</option> <option value="LT">Lithuania</option> <option value="LU">Luxembourg</option> <option value="MO">Macao</option> <option value="MK">Macedonia, The Former Yugoslav Republic Of</option> <option value="MG">Madagascar</option> <option value="MW">Malawi</option> <option value="MY">Malaysia</option> <option value="MV">Maldives</option> <option value="ML">Mali</option> <option value="MT">Malta</option> <option value="MH">Marshall Islands</option> <option value="MQ">Martinique</option> <option value="MR">Mauritania</option> <option value="MU">Mauritius</option> <option value="YT">Mayotte</option> <option value="MX">Mexico</option> <option value="FM">Micronesia, Federated States Of</option> <option value="MD">Moldova, Republic Of</option> <option value="MC">Monaco</option> <option value="MN">Mongolia</option> <option value="MS">Montserrat</option> <option value="MA">Morocco</option> <option value="MZ">Mozambique</option> <option value="MM">Myanmar</option> <option value="NA">Namibia</option> <option value="NR">Nauru</option> <option value="NP">Nepal</option> <option value="NL">Netherlands</option> <option value="AN">Netherlands Antilles</option> <option value="NC">New Caledonia</option> <option value="NZ">New Zealand</option> <option value="NI">Nicaragua</option> <option value="NE">Niger</option> <option value="NG">Nigeria</option> <option value="NU">Niue</option> <option value="NF">Norfolk Island</option> <option value="MP">Northern Mariana Islands</option> <option value="NO">Norway</option> <option value="OM">Oman</option> <option value="PK">Pakistan</option> <option value="PW">Palau</option> <option value="PS">Palestinian Territory, Occupied</option> <option value="PA">Panama</option> <option value="PG">Papua New Guinea</option> <option value="PY">Paraguay</option> <option value="PE">Peru</option> <option value="PH">Philippines</option> <option value="PN">Pitcairn</option> <option value="PL">Poland</option> <option value="PT">Portugal</option> <option value="PR">Puerto Rico</option> <option value="QA">Qatar</option> <option value="RE">Reunion</option> <option value="RO">Romania</option> <option value="RU">Russian Federation</option> <option value="RW">Rwanda</option> <option value="SH">Saint Helena</option> <option value="KN">Saint Kitts And Nevis</option> <option value="LC">Saint Lucia</option> <option value="PM">Saint Pierre And Miquelon</option> <option value="VC">Saint Vincent And The Grenadines</option> <option value="WS">Samoa</option> <option value="SM">San Marino</option> <option value="ST">Sao Tome And Principe</option> <option value="SA">Saudi Arabia</option> <option value="SN">Senegal</option> <option value="CS">Serbia And Montenegro</option> <option value="SC">Seychelles</option> <option value="SL">Sierra Leone</option> <option value="SG">Singapore</option> <option value="SK">Slovakia</option> <option value="SI">Slovenia</option> <option value="SB">Solomon Islands</option> <option value="SO">Somalia</option> <option value="ZA">South Africa</option> <option value="GS">South Georgia And The South Sandwich Islands</option> <option value="ES">Spain</option> <option value="LK">Sri Lanka</option> <option value="SD">Sudan</option> <option value="SR">Suriname</option> <option value="SJ">Svalbard And Jan Mayen</option> <option value="SZ">Swaziland</option> <option value="SE">Sweden</option> <option value="CH">Switzerland</option> <option value="SY">Syrian Arab Republic</option> <option value="TW">Taiwan, Province Of China</option> <option value="TJ">Tajikistan</option> <option value="TZ">Tanzania, United Republic Of</option> <option value="TH">Thailand</option> <option value="TL">Timor-Leste</option> <option value="TG">Togo</option> <option value="TK">Tokelau</option> <option value="TO">Tonga</option> <option value="TT">Trinidad And Tobago</option> <option value="TN">Tunisia</option> <option value="TR">Turkey</option> <option value="TM">Turkmenistan</option> <option value="TC">Turks And Caicos Islands</option> <option value="TV">Tuvalu</option> <option value="UG">Uganda</option> <option value="UA">Ukraine</option> <option value="AE">United Arab Emirates</option> <option value="GB">United Kingdom</option> <option value="US">United States</option> <option value="UM">United States Minor Outlying Islands</option> <option value="UY">Uruguay</option> <option value="UZ">Uzbekistan</option> <option value="VU">Vanuatu</option> <option value="VE">Venezuela</option> <option value="VN">Viet Nam</option> <option value="VG">Virgin Islands, British</option> <option value="VI">Virgin Islands, U.S.</option> <option value="WF">Wallis And Futuna</option> <option value="EH">Western Sahara</option> <option value="YE">Yemen</option> <option value="ZM">Zambia</option> <option value="ZW">Zimbabwe</option> </select> <span class="error">*<?php echo $country1;?></span> <br><br> Website: <input type="text" name="website" value="<?php echo $website;?>"> <span class="error"><?php echo $websiteErr;?></span> <br><br> Gender: <input type="radio" name="gender" <?php if (isset($gender) && $gender=="female") echo "checked";?> value="female">Female <input type="radio" name="gender" <?php if (isset($gender) && $gender=="male") echo "checked";?> value="male">Male <span class="error">* <?php echo $genderErr;?></span> <br><br> Comment: <textarea name="comment" rows="5" cols="40"><?php echo $comment;?></textarea> <br><br> <input type="submit" name="submit" value="Submit"> </form> </body> </html> Edited by Ch0cu3r, 15 July 2014 - 03:37 PM. Reformatted post Hi there, I am having a PHP form with simple combo box. Here is the code: <form name="form1" method="get" action=""> <select name="select" onChange="form1.submit()"> <option value='value1'>My Value1</option> <option value='value2'>My Value2</option> <option value='value3'>My Value3</option> </select> </form> Now the form is successfully being submitted upon 'onChange' event. The only thing I am trying to do is to retain the value of the new option. As every time I select the value from the combo, it goes back and displays the 'value 1' even when I select value 3 or 2. How do I make the combo box retain the value as 3 (when I select option 3) after the form is submitted. Please reply. Thank you! Hi, I have set up 2 php pages page 1 - add_entry2.php In this page I have a invoice table created where I can dynamically add/delete rows. This has a View Bill button which takes me to page 2- add_entry3.php In this page it shows up the rows added in page 1 in read only format, so if the user wants to modify the data that he/she entered then he must Click on <back> that i have provided in the page 2 which will direct him to page 1 Now the problem starts here on click of Back the dynamically added rows dissappear..which is frustrating..I know its something to do with my code..but can anyone help me fix it. One more thing is that i dont want to store the data into DB till the finalise button is clicked on page 2 so that means till page 2 is submitted nothing goes to DB from Page 1. here is the code(I have removed the java script functionalities to reduce length of the post) add_entry2.php Code: [Select] <html> <head> <title>Page Title</title> </head> <body leftmargin="0" topmargin="0"> <!--- forms are good when you wanna actually do stuff ---> <form action="add_entry3.php" name="eval_edit" method="post" format="html"> <table align="center" width = "75%"> <tr> <td align = "center"> Invoice </td> </tr> <tr> <td align = "center"> <!--- very imporant to give the table an id ---> <!--- otherwise it won't know where to edit ---> <table border="1" id="mySampleTable"> <tr> <th>Item No</th> <th>Item Name</th> <th>Item code</th> <th>Description</th> <th>Unit Cost</th> <th>Quantity</th> <th>Price</th> <th>Cancel ?</th> </tr> <tr> <td>1</td> <td><input type="text" name="itemname[]" size="40" maxsize="100"/></td> <td><input type="text" name="itemcode[]" size="20" maxsize="100" /></td> <td><input type="text" name="description[]" size="20" maxsize="100" /></td> <td><input type="text" name="unitcost[]" size="10" maxsize="100" /></td> <td><input type="text" name="quantity[]" size="4" maxsize="100" /></td> <td><input type="text" name="price[]" size="10" maxsize="100" /></td> <td><input type="CHECKBOX" name="cancel[]"/></td> </tr> </table> <table id="totaltbl"> <tr> <th>Total</th> <th>Vat%</th> </tr> <tr> <td><input type="text" name="total" size="20" maxsize="100" /></td> <td><input type="text" name="total" size="3" maxsize="3" /></td> </tr> </table> <!--- our buttons call our javascript functions when clicked ---> <p> <input type="button" value="Add Row" onclick="addRow();" /> <input type="button" value="Calculate Total Amount" onclick="Totalcal();" /> <input type="hidden" name="count" value=""/> <!--<input type="submit" name="submit" onclick="countRow();" value="Insert into Invoice!" />--> <input type="submit" name="submit" value="View Bill" /> <input type="hidden" name="submitted" value="true" /> </p> </td> </tr> </table> </form> </body> </html> ****************************************************8888 This is add_entry3.php Code: [Select] <?php $num=count($_POST['itemcode']); $itemname= $_POST['itemname']; $itemcode = $_POST['itemcode']; $unitcost = $_POST['unitcost']; $description = $_POST['description']; $unitcost = $_POST['unitcost']; $quantity = $_POST['quantity']; $price = $_POST['price']; $problem = FALSE; ?> <h1 align ="center"><b><u>Invoice Details</b></u></h1> <table align="center" width = "75%"> <tr> <td align = "center"> <table border="1" id="mySampleTableheader"> <tr> <td width="75"><b>Item No</b></td> <td width="275"><b>Item Name</b></td> <td width="155"><b>Item code</b></td> <td width="155"><b>Description</b></td> <td width="95"><b>Unit Cost</b></td> <td width="60"><b>Quantity</b></td> <td width="95"><b>Price</b></td> </tr> </table> <?php $i=0; while ($i < $num) { ?> <!--- forms are good when you wanna actually do stuff ---> <form action="save_entry.php" name="eval_edit" method="post" format="html"> <table border="1" id="mySampleTable"> <tr> <td width="75"><?php echo $i+1; ?></td> <td><input type="text" name="itemname[]" value = "" size="40" maxsize="100" readonly/></td> <td><input type="text" name="itemcode[]" value ="<?php echo $itemcode[$i]; ?>" size="20" maxsize="100" readonly/></td> <td><input type="text" name="description[]" value ="<?php echo $description[$i]; ?>" size="20" maxsize="100" readonly/></td> <td><input type="text" name="unitcost[]" value ="<?php echo $unitcost[$i]; ?>" size="10" maxsize="100" readonly/></td> <td><input type="text" name="quantity[]" value = "<?php echo $quantity[$i]; ?>" size="4" maxsize="100" readonly/></td> <td><input type="text" name="price[]" value = "<?php echo $price[$i]; ?>" size="10" maxsize="100" readonly/></td> </tr> </table> <?php $i++;} ?> <!--- our buttons call our javascript functions when clicked ---> </td> </tr> </table> <p> <table id="totaltbl"> <tr> <th>Total</th> </tr> <tr> <td><input type="text" name="total" size="20" maxsize="100" /></td> </tr> </table> <input type="button" value="Add Row" onclick="addRow();" /> <input type="button" value="Row count" onclick="countRow();" /> <input type="hidden" name="count" value=""/> <!--<input type="hidden" name="count" value=""/> <input type="submit" name="submit" onclick="countRow();" value="Insert into Invoice!" />--> <input type="button" value="Back" onClick="history.go(-1);return true;"> <input type="submit" name="submit" value="Finalise" /> <input type="hidden" name="submitted" value="true" /> </p> </form> </body> </html> Hello JS experts,
I'm new to JS coding (self-learning) and I have just one (potenitally) simple request to ask of you wonderful folks here.
Oh BTW, I've tried searching through this forum (and the WWW as well) but couldn't seem to easily find something that fits my request, or was easy for me to understand and apply to my situation.
So what I have/want is: a Data-Entry form which (for the first record/entry for a given date) allows the user to select a date from a "Calendar Date Picker". Upon subsequent records/entries (for the same date), the date field should no longer be accessible, but the (previously entered/selected) value should be both displayed (greyed-out) and certainly carried over to the DB/Table.
I know this might be a very simple piece of code, but being that I'm a newbie, I'm not sure how to achieve this.
Would appreciate any and all help to get this done (preferably the necessary code).
If it helps, here's some of my existing code that's related to the field names:
Form field details:
<div class="control-group"> <label class='control-label'>Select Flyer Start Date:</label> <input type="text" name="datepicker" id="datepicker"> </div>DB (table) field details: $flyerDateStart = isset($_POST["datepicker"]) ? $_POST["datepicker"] : "";Thanks much. I have a site that allows members to create pages. These pages consist of small sections some of which HTML can be entered. To keep visitors from straying away from the site, any outside urls are brought up in a modal window. Using inline attributes, a class has to be created (or added to), and the title tag requires some special characters. I can probably get around this by inserting an onclick or something, but there must be a way to replace attributes, and I am at a loss. The text segments are stored in a database. What I want to do is change the <a> tag attributes as the page is created. So I have a segment of text "$TheText" and I want to change or replace the attribute values. For instance, If $TheText contains an 'a' tag that looks like this: Code: [Select] <a class="MyClass" title="Godzilla" href="http://www.godzillaslair.com">Godzilla</a>I would want to change it to Code: [Select] <a class="MyClass Lightview" title="Godzilla :: {Lightview's parameters}">Godzilla</a>Or even just replace the attributes entirely, so it would look like Code: [Select] <a class="Lightview" title="{Inserted Title} :: {Lightview's parameters}">Godzilla</a> In other words, just replacing the attribute values. Of course, I need to see if the attributes exist. I know how to do that and how to get their values. But all that tells me is that I have an 'a' tag in the text with those values for those attributes. I cannot, for example, then do a str_replace in the first example, because there may be another tag in the text with the "MyClass" class. I can iterate character by character between <a and </a> but there must be a better way. I'm no good at regex, so I haven't even attempted that. Any suggestions would certainly be appreciated. $_POST['select'] permits me access to the selected value of my combo box named 'select'. are any other attributes of the box accessible? in particular, index # ... etc.? thanks in advance for any light you might shed on the topic. I cant get my head around this. I m trying to add product attributes into this script. I have products tables and product_extras product.id and product_extras.id are same. How can I add this to cart. Is there any easy way to do this. Any help would be much appreciated! Quote cart.php Code: [Select] <?php // Include MySQL class require_once('inc/mysql.class.php'); // Include database connection require_once('inc/global.inc.php'); // Include functions require_once('inc/functions.inc.php'); // Start the session session_start(); // Process actions $cart = $_SESSION['cart']; $action = $_GET['action']; switch ($action) { case 'add': if ($cart) { $cart .= ','.$_GET['id']; } else { $cart = $_GET['id']; } break; case 'delete': if ($cart) { $items = explode(',',$cart); $newcart = ''; foreach ($items as $item) { if ($_GET['id'] != $item) { if ($newcart != '') { $newcart .= ','.$item; } else { $newcart = $item; } } } $cart = $newcart; } break; case 'update': if ($cart) { $newcart = ''; foreach ($_POST as $key=>$value) { if (stristr($key,'qty')) { $id = str_replace('qty','',$key); $items = ($newcart != '') ? explode(',',$newcart) : explode(',',$cart); $newcart = ''; foreach ($items as $item) { if ($id != $item) { if ($newcart != '') { $newcart .= ','.$item; } else { $newcart = $item; } } } for ($i=1;$i<=$value;$i++) { if ($newcart != '') { $newcart .= ','.$id; } else { $newcart = $id; } } } } } $cart = $newcart; break; } $_SESSION['cart'] = $cart; ?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head> <title>products</title> <link rel="stylesheet" href="css/styles.css" /> </head> <body> <div id="shoppingcart"> <h1>Your Shopping Cart</h1> <?php echo writeShoppingCart(); ?> </div> <div id="contents"> <h1>Please check quantities...</h1> <?php echo showCart(); ?> <p><a href="index.php">Back to products...</a></p> </div> </body> </html> Quote functions.php Code: [Select] <?php function writeShoppingCart() { $cart = $_SESSION['cart']; if (!$cart) { return '<p>You have no items in your shopping cart</p>'; } else { // Parse the cart session variable $items = explode(',',$cart); $s = (count($items) > 1) ? 's':''; return '<p>You have <a href="cart.php">'.count($items).' item'.$s.' in your shopping cart</a></p>'; } } function showCart() { global $db; $cart = $_SESSION['cart']; if ($cart) { $items = explode(',',$cart); $contents = array(); foreach ($items as $item) { $contents[$item] = (isset($contents[$item])) ? $contents[$item] + 1 : 1; } $output[] = '<form action="cart.php?action=update" method="post" id="cart">'; $output[] = '<table>'; foreach ($contents as $id=>$qty) { $sql = 'SELECT * FROM products WHERE id = '.$id; $result = $db->query($sql); $row = $result->fetch(); extract($row); $output[] = '<tr>'; $output[] = '<td><a href="cart.php?action=delete&id='.$id.'" class="r">Remove</a></td>'; $output[] = '<td>'.$title.'</td>'; $output[] = '<td>£'.$price.'</td>'; $output[] = '<td><input type="text" name="qty'.$id.'" value="'.$qty.'" size="3" maxlength="3" /></td>'; $output[] = '<td>£'.($price * $qty).'</td>'; $total += $price * $qty; $output[] = '</tr>'; } $output[] = '</table>'; $output[] = '<p>Grand total: <strong>£'.$total.'</strong></p>'; $output[] = '<div><button type="submit">Update cart</button></div>'; $output[] = '</form>'; } else { $output[] = '<p>You shopping cart is empty.</p>'; } return join('',$output); } ?> Context. Class AbstractTenantEntity's purpose is to restrict access to data to the tenant (i.e. account, owner, etc) that owns the data. Any entity which extends it will have the TenantId added when created and the TenantId in the WHERE clause for all other requests. Tenant typically does not have collections of the various entities which extend AbstractTenantEntity, but does for a few of them do. When using annotation, I handled it by applying Doctrine's AssociationOverride annotation to the extended classes which should have a collection in Tenant. use Doctrine\ORM\Mapping as ORM; /** * @ORM\Entity() */ class Tenant { /** * @ORM\OneToMany(targetEntity=Asset::class, mappedBy="tenant") */ private $assets; // Other properties and typical getters and setters }
use Doctrine\ORM\Mapping as ORM; abstract class AbstractTenantEntity implements TenantInterface { /** * inversedBy performed in child where required * @ORM\ManyToOne(targetEntity=Tenant::class) * @ORM\JoinColumn(nullable=false) */ protected ?Tenant $tenant = null; // Typical getters and setters }
use Doctrine\ORM\Mapping as ORM; /** * @ORM\Entity() * @ORM\AssociationOverrides({ * @ORM\AssociationOverride(name="tenant", inversedBy="assets") * }) */ class Asset extends PublicIdTenantEntity { // Various properties and typical getters and setters }
So, now I am changing from annotations to attributes, and modified AbstractTenantEntity as follows: use Doctrine\ORM\Mapping\ManyToOne; use Doctrine\ORM\Mapping\JoinColumn; abstract class AbstractTenantEntity implements TenantInterface { /** * inversedBy performed in child where required */ #[ManyToOne(targetEntity: Tenant::class)] #[JoinColumn(nullable: false)] protected ?Tenant $tenant = null; // Typical getters and setters } Next I went to modify Asset and realized that there didn't appear to be an attribute for AssociationOverride. I found a little discussion on the topic on github but couldn't find any resolution. Question Can inheritance be used with PHP 8 attributes where the property is defined in the parent class and the attribute is applied in the child class? Googling php 8 attributes inheritance didn't provide anything and thus I expect the answer is no but thought I'd ask. Thanks
EDIT. Maybe Doctrine does have an attribute version: https://github.com/doctrine/orm/blob/2.9.x/lib/Doctrine/ORM/Mapping/AttributeOverride.php EDIT2. Actually don't think so Edited July 30 by NotionCommotionHi, I have set up 2 php pages page 1 - add_entry2.php In this page I have a invoice table created where I can dynamically add/delete rows. This has a View Bill button which takes me to page 2- add_entry3.php In this page it shows up the rows added in page 1 in read only format, so if the user wants to modify the data that he/she entered then he must Click on <back> that i have provided in the page 2 which will direct him to page 1 Now the problem starts here on click of Back the dynamically added rows dissappear..which is frustrating..I know its something to do with my code..but can anyone help me fix it. One more thing is that i dont want to store the data into DB till the finalise button is clicked on page 2 so that means till page 2 is submitted nothing goes to DB from Page 1. I am able to retain values if I use the code Code: [Select] <form action="add_entry2.php" name="eval_edit" method="post" format="html"> i,e if I submit back to the same page and retrieve values form $_POST but If I use the code Code: [Select] <input type="button" value="Back" onClick="history.go(-1);return true;">to get back to add_entry2.ph it looses all the values. Is there any other way to code the BACK link retaining my $_POST values(Do you think $_SESSION would work in this case?) I have mysqli object in Database class base: [color=]database class:[/color] class Database { private $dbLink = null; public function __construct() { if (is_null($this->dbLink)) { // load db information to connect $init_array = parse_ini_file("../init.ini.inc", true); $this->dbLink = new mysqli($init_array['database']['host'], $init_array['database']['usr'], $init_array['database']['pwd'], $init_array['database']['db']); if (mysqli_connect_errno()) { $this->dbLink = null; } } } public function __destruct() { $this->dbLink->close(); } } Class derived is Articles where I use object dBLink in base (or parent) class and I can't access to mysqli methods (dbLink member of base class): Articles class: require_once ('./includes/db.inc'); class Articles extends Database{ private $id, .... .... $visible = null; public function __construct() { // Set date as 2009-07-08 07:35:00 $this->lastUpdDate = date('Y-m-d H:i:s'); $this->creationDate = date('Y-m-d H:i:s'); } // Setter .... .... // Getter .... .... public function getArticlesByPosition($numArticles) { if ($result = $this->dbLink->query('SELECT * FROM articles ORDER BY position LIMIT '.$numArticles)) { $i = 0; while ($ret = $result->fetch_array(MYSQLI_ASSOC)) { $arts[$i] = $ret; } $result->close(); return $arts; } } } In my front page php I use article class: include_once('./includes/articles.inc'); $articlesObj = new articles(); $articles = $articlesObj->getArticlesByPosition(1); var_dump($articles); [color=]Error that go out is follow[/color] Notice: Undefined property: Articles::$dbLink in articles.inc on line 89 Fatal error: Call to a member function query() on a non-object in articles.inc on line 89 If I remove constructor on derived class Articles result don't change Please help me Hi, Im trying to grab some data from a XML generated by an external server. I know how to grab from XML without attributes, but I cant seem to wrap my head around the structure of this file. What would be easiest way to get the value of the "dbnr" field? Part of the XML file: Code: [Select] <data> <location> <field name="id" format="Long">xxxxxx</field> <field name="dbnr" format="Long">xxxxxx</field> <field name="jobnr" format="Long">xxxxxx</field> <field name="job_type" format="String" maxlen="50">xxxxxx</field> <field name="job_category" format="String" maxlen="50">xxxxxx</field> </location> </data> Hi all, I'm sure I'm making this far more difficult than I need to... I've got an xml document... <library id="1"> <lname>Lib1</name> <book id="1"> <title>book 1</title> <author>Author 1</author> </book> <book id="2"> <title>book 2</title> <author>Author 2</author> </book> </library> I can access the nested elements using xpath like : $result = $xml->xpath('//book'); foreach($result as $books) { echo $books->title; } How would I do this for the attributes? If I specify I want the attributes in the xpath query I can't get at the elements... I'm trying to turn this xml file into a simple relational database... A library table and a book table. So I need the library id (attribute) and the name(nested element) for one insert query - and the book id, title, author and the library id for the other. Anyone got any idea? Cheers John How can I print the attributes of a child node? I have been trying and looking and cant get it. I need the attributes of subfield printed after datafield so a line would look like datafield plus attributes plus subfield attributes plus subfield =906 __$a0$bcbc$corignew etc... <?php //child nodes http://www.w3schools.com/php/php_xml_dom.asp //http://books.google.com/books?id=ygQRKDEsLecC&pg=PA196&lpg=PA196&dq=print+php+xml+child+node+attributes&source=bl&ots=TCAhH4kpCt&sig=yJUPXesIkRUrNXdNE9Yr5ul7Wdw&hl=en&ei=U51kTeKQKsL48AbN4MDTBg&sa=X&oi=book_result&ct=result&resnum=10&ved=0CF4Q6AEwCQ#v=onepage&q=print%20php%20xml%20child%20node%20attributes&f=false //http://stackoverflow.com/questions/4598409/printing-content-of-a-xml-file-using-xml-dom $doc = new DOMDocument(); $doc->preserveWhiteSpace = FALSE; $doc->load( 'loc.xml' ); $root = $doc->documentElement; $type = $root->nodeType; //print $doc->nodeName."\n"; //print $root->nodeName."\n"; //print $doc->nodeValue."\n"; //print $root->nodeValue."\n"; $librecords = $doc->getElementsByTagName( "record" ); foreach( $librecords as $record ){ $leader = $record->getElementsByTagName( "leader" ); $controlfields = $record->getElementsByTagName( "controlfield" ); $datafields = $record->getElementsByTagName( "datafield" ); $subfields = $record->getElementsByTagName( "subfield" ); $leader = $leader->item(0)->nodeValue; echo '=LDR '.$leader.'<BR>'; foreach( $controlfields as $controlfield ){ $tag = $controlfield->getAttribute('tag'); $cf_value = $controlfield->firstChild->nodeValue; echo "=".$tag." ".$cf_value.'<BR>'; } foreach( $datafields as $datafield ){ $tag = $datafield->getAttribute('tag'); $ind1 = $datafield->getAttribute('ind1'); $ind2 = $datafield->getAttribute('ind2'); if ($ind1 ==" ") {$ind1 = "_";} if ($ind2 ==" ") {$ind2 = "_";} echo "=".$tag." ".$ind1.$ind2; //if($datafield->hasChildNodes()){echo 'This node has children!<br />';} foreach ($datafield->childNodes AS $item) { // $arr = $item->attributes; print $arr; print 'nodeName '.$item->nodeName . " = " . $item->nodeValue." | " ;} //. "<br />"; } // foreach ($datafield->children() as $node) { // $arr = $node->attributes(); // returns an array // print ("code=".$arr["code"]); // get the value of this attribute // print (" Company=".$node->subfield); // print ("<p><hr>"); //} // foreach( $subfields as $subfield){ // foreach($subfield->attributes as $attr){ // $attributes = $subfield->attributes; // print $attr->nodeName; // print $attr->nodeValue; // //print $attributes->nodeName; //print $attributes->nodeValue; // print $subfield->nodeName; // print $subfield->nodeValue; //}} // print $item->nodeValue ; // print $item->attributes("code"); // $valueID = $item->getAttribute('code'); // print $item->nodeName->attributes("code"); // echo $item->nodeValue.getAttribute("code"); // print $item->getAttribute('code') //http://www.devshed.com/c/a/PHP/Accessing-Attributes-and-Cloning-Nodes-with-the-DOM-XML-Extension-in-PHP-5/1/ echo '<BR>'; } foreach( $subfields as $subfield ){ $code = $subfield->getAttribute('code'); $sf_value = $subfield->firstChild->nodeValue; echo '$'.$code.$sf_value.'<BR>'; } echo '<BR>'; } ?> Code: [Select] <leader>01026ngm a22002773a 4500</leader> <controlfield tag="001">16429180</controlfield> <controlfield tag="005">20100823131409.0</controlfield> <controlfield tag="007">vffcjaho|</controlfield> <controlfield tag="008">100823s2010 xxu060 mleng </controlfield> <datafield tag="906" ind1=" " ind2=" "> <subfield code="a">0</subfield> <subfield code="b">cbc</subfield> <subfield code="c">orignew</subfield> <subfield code="d">u</subfield> <subfield code="e">ncip</subfield> <subfield code="f">20</subfield> <subfield code="g">y-movingim</subfield> </datafield> <datafield tag="955" ind1=" " ind2=" "> <subfield code="b">qm12 2010-08-23</subfield> </datafield> Hi, I am new to xml parsing and I just want to know how to check whether a node has attributes: Here is my xml file to use: ================= Code: [Select] <?xml version="1.0" encoding="ISO-8859-1"?> <email> <message> <to> <toFirstName>Tove</toFirstName> <toLastName toType="common" style="swag">Smith</toLastName> </to> <from> <fromFirstName>Jani</fromFirstName> <fromLastName fromType="unique">Dravison</fromLastName> </from> <heading>Reminder</heading> <body> <prologue>Tis the night before Xmas...</prologue> <paragraph1>Don't forget me this weekend!</paragraph1> <paragraph2>Jump the gun!</paragraph2> <epilogue>The end of the world.</epilogue> </body> </message> <message> <to>employees</to> <from>CEO</from> <heading>Power Lunch</heading> <body> <prologue></prologue> <paragraph1>Year over year data</paragraph1> <paragraph2>Downsizing</paragraph2> <epilogue>The end.</epilogue> </body> </message> </email> Here the simple script that I cannot get to work: ================================== Code: [Select] <?php $simpleXMLObj=simplexml_load_file("email.xml"); if($simpleXMLObj->to[0]->toLastName[0]->attributes()->getName) print "YES: this node has attributes!"; else print "NO:"; ?> Please I really need help, it is simple I know but I am new to xml parsing and mixed up. I have the following code below: Hi Can you call Class A's methods or properties from Class B's methods? Thanks. |