Jump to content


  • Content Count

  • Joined

  • Last visited

Community Reputation

0 Neutral

About holy24

  • Rank
  1. Hi, I have a form with drop down list for user to submit, and I can allow the user to edit the data afterward. Now, when the user try to edit, the drop down option that they choose previously should automatically be retrieved. Example: 1. User submit the form with Accountancy as industry. 2. Next, user click edit button, the "Accountancy" should shown automatically in the industry field. Problem: 1. If the user choose 'Others' as industry, there will be a textbox for him to enter. 2. I need that when user edit the form, the form will show "Others" in the industry and the textbox with the data that the user entered previously together. -> Can someone please kindly help on this? Thanks. Following is the code in the edit form: <script type="text/javascript">function showfield(name){ if(name=='others')document.getElementById('div1').style.display="block"; else document.getElementById('div1').style.display="none";}</script><html><body><?php$id=$_POST['idedit'];$result=mysql_query("SELECT * FROM test where id='$id'");$row=mysql_fetch_array($result);?><select name="industry" onchange="showfield(this.options[this.selectedIndex].value)"> <option value=""></option><option value="Accountancy" <?php if ($row['industry']=="Accountancy") echo "selected=selected";?>>Accountancy</option><option value="Automotive & Aerospace" <?php if ($row['industry']=="Automotive & Aerospace") echo "selected=selected";?>>Automotive & Aerospace</option><option value="others">Others</option></select><div id="div1"></br>Please enter other industry:</br><input type="text" name="others1"/></div></body></html>
  2. Hi,I have created 2 fields in a table (month & year). The month will be shown as January,February,March etc. The year will be shown as 2011,2012 etc.The following is the code that will capture the date format once user submit a form. <?php$jd=cal_to_jd(CAL_GREGORIAN,date("m"),date("d"),date("Y"));$Month=jdmonthname($jd,1);$Year=date(Y);mysql_query ("INSERT INTO Table1 (month,year) VALUES ('$Month','$Year')");?>Now, I have a problem in sorting the month in descending order (December,November,October etc). Can someone please kindly help me on the sorting and I need to make the month format remain as (December,November,October etc). Thanks.Below is the code to query the result, however it will sort by alphabetical order.<?phpmysql_query ("Select * from Table1 where year='$Year' order by month DESC"); ?>?>
  3. holy24

    If else statement

    Hi, I have created a form for user to fill and I need to ensure that some fields are filled in with the necessary requirements. Example: Identification number (9 alphabet/numberic) - S1234567A Can someone kindly advice how can I ensure that only 9 alphabet/numberic is keyed by user? I understand that using sql statement there is a WHERE clause with Like operator (identification LIKE '_________') Can it be done using if else statement? if (identification LIKE '_________'){ alert("You have not entered correct Identification number"); return false; }
  4. Hi, I have tried re-writing the codes, but I have no idea how to code inside the showfield part. By default, product field will not be shown and when user click a vendor name, only all the products belong to that vendor will be shown. Can someone please kindly advise? Thanks. Below are the database design and the codes. Database:I created 1 database with 2 tables:1) Table named "vendor" with fields - id (primary key, auto-increment) and vendorname2) Table named "product" with fields - id (primary key, auto-increment), productname, vendorid (this will be the foreign key that link to the id in vendor table to identify the vendor that the product belongs to) <script type="text/javascript">function hidefield(){document.getElementById('product').style.display='none'; } function showfield(name){?????? } </script> <body onload="hidefield()"><td> <select name="vendor" onchange="showfield(this.options[this.selectedIndex].value)"> <option value=""></option> <?php $result1=mysql_query("SELECT * FROM vendor"); while ($row1=mysql_fetch_array($result1)){ ?> <option value='<?php echo $row1["vendorname"]; ?>'><?php echo $row1["vendorname"]; ?></option> <?php } ?> </select></td> <div id="product"> <?php $total=2; //number of vendors for ($i=1; $i<=$total; $i++){ $vendor=$i; ?> <div id="<?php echo $vendor; ?>"> <select name="product"> <option value=""></option> <?php $result2=mysql_query("SELECT * FROM product WHERE vendorid='$vendor'"); while ($row2=mysql_fetch_array($result2)){ ?> <option value='<?php echo $row2["productname"]; ?>'><?php echo $row2["productname"]; ?></option> <?php } ?> </select> </div> <?php } ?></div> </body>
  5. Hi, I am trying to do an invoice, and I have been using float/absolute positioning etc but I still cant get the format I want. Can someone please kindly help me? Thanks. Attached example on the layout. Invoice layout.doc
  6. Hi, I have created a form and when user select the drop-down list in column A, column B will show a drop-down list of values based on column A selection. I have written the code below with only 2 values in column A, however if there is more values in column A, I have to create alot of div id for each value. Can someone please kindly advice how can I simplified the codes? Thanks.
  7. Hi, I have been reading this function document.getElementsByTagName but still do not understand how it work. I have tried implementing it on my existing code but it seems not working. Can kindly explain on this? Thanks. function validateForm(){var x=document.getElementsByTagName('name');var y=document.getElementsByTagName('company');var z=document.getElementsByTagName('address');if (x=="" || x==null){alert("Please fill in name field!");return false;}else if (y=="" || y==null){alert("Please fill in company field!");return false;}else if (z=="" || z==null){alert("Please fill in address field!");return false;}} <tr><name>< td><input type="text" name="name[]"></td></name><company>< td>< select name="company[]">< option value=""></option>< ?php while ($row=mysql_fetch_array($result)){ ?>< option value='<?php echo $row["company"] ?>'><?php echo $row["company"]; ?></option>< ?php } ?>< /select>< /td></company> <address>< td><input type="text" name="address[]"></td></address>< /tr>
  8. Hi, I have problem showing table border line when a field is empty. I tried using css: table{empty-cells:show;} but the border line still wont show. Can anyone please kindly help on this? Thanks. <html><head><link rel="stylesheet" type="text/css" href="style.css" /></head> <body><table align="center" border="1"> <tr> <td><b>Name</b></td> <td><b>Address</b></td> <td><b>Contact</b></td> </tr> <tr> <td><?php echo $row1['name']; ?></td> <td><?php echo $row1['address']; ?></td> <td><?php echo $row1['contact']; ?></td> </tr> </table> </body></html>
  9. holy24

    Problem using $_SESSION

    Thanks everyone for the advice. @justsomeguy: Just to confirm if my understanding as below is correct? So I need to use a unique session name once for each website in the same host? Example:1. http://testing/folder1/index.phpa) In folder1, i will create a config.php and call it at the start of each file. 2. http://testing/folder2/index.phpa) In folder2, i will create a config.php and call it at the start of each file.
  10. holy24

    Problem using $_SESSION

    Hi, I have created a logout page with session destroy and it will destroy the session upon logout. But if user did not do a logout there will be a problem. Eg. I login to my first website (eg. http://testing/folder1/index.php) and did not logout, then I login to another website (eg. http://testing/folder2/index.php) and did not logout. Then when i refresh my first website, the session["number"] i used in my first web application capture the session["number"] in my second web application. I suppose as you mentioned it is because both are on the same host (testing) and it could be possible to do a rename to all the session name. But if I created 10 or even more web applications, it will be quite difficult for me to memorise all the session name that I used in each web application. Is there any code that can be used for not capturing the same session name from different web application in the same host? Thanks in advance for the help.
  11. Hi, I have been trying to use $_SESSION when a user successfully login to a website (eg. abc.com), but I am not sure why when I login another website(eg. zzz.com) simutanuously, it capture zzz.com details and show in abc.com. Steps to reproduce:1. Login to abc.com2. Upon successful login, in home.php, i echo the $_SESSION["number"] . It correctly shows the staff's number (eg. E123).---------------------------------login.php-------------------------------------session_start(); $login=mysql_query("SELECT * FROM staff WHERE (username = '" . mysql_real_escape_string($_POST['username']) . "') and (password = '" . mysql_real_escape_string(md5($_POST['password'])) . "')");$row=mysql_fetch_array($login); if (mysql_num_rows($login)==1){$_SESSION["login"]=true;$_SESSION["number"]=$row['number']; header('Location: home.php');}------------------------------------------- -------------------------------------------home.php--------------------------------------<?phpsession_start();if(!$_SESSION["login"]){header('Location: index.php');} echo $_SESSION['number'];?>------------------------------------- 3. However, if i login to another website (eg. zzz.com) using username: E999 and I go back abc.com, the $_SESSION['number'] change from E123 to E999. Both abc.com and zzz.com are using different database, why the $_SESSION['number'] in abc.com is capturing the info from other website? Can anyone kindly advise on this? Thanks.
  12. Hi, I have re-write using my 1st code and now the layout looks fine and able to insert into the database. Now, I am trying to prompt user to fill in the field if it is blank. For the default first row, I am able to do so. But I am not sure why the appendchild fields are not prompting the user when field is empty upon submitting? Can kindly advice on this? Thanks. ---------------------------------------------<script type="text/javascript"> function validateForm(){var x=document.forms["form"]["name[]"].value;var y=document.forms["form"]["company[]"].value;var z=document.forms["form"]["address[]"].value; if (x=="" || x==null){alert("Please fill in name field!");return false;}else if (y=="" || y==null){alert("Please fill in company field!");return false;}else if (z=="" || z==null){alert("Please fill in address field!");return false;}} function addInput(){<?phpinclude 'connectdb.php';$result=mysql_query("SELECT * FROM table_name");?> var tbl = document.getElementById('tblAddress');var lastRow = tbl.rows.length;var row = tbl.insertRow(lastRow); var cell0 = row.insertCell(0);var el = document.createElement('input');el.type='text';el.name='name[]';cell0.appendChild(el); var cell1 = row.insertCell(1);var selector = document.createElement('select');selector.name='company[]';cell1.appendChild(selector); var option = document.createElement('option');option.value = '';option.appendChild(document.createTextNode(''));selector.appendChild(option); <?php while($row=mysql_fetch_array($result)){?>var option = document.createElement('option');option.value = '<?php echo $row["company"];?>';option.appendChild(document.createTextNode('<?php echo $row["company"];?>'));selector.appendChild(option);<?php } ?> var cell2 = row.insertCell(2);var el = document.createElement('input');el.type ='text';el.name='address[]';cell2.appendChild(el); el = document.createElement('input');el.type ='button';el.value='Remove';el.onmouseup=function(){ Remove(this); }cell2.appendChild(el);}function Remove(obj){while (obj.parentNode){if (obj.nodeName.toUpperCase()=='TR'){break;}obj=obj.parentNode;}obj.parentNode.removeChild(obj);return;}</script> <html><body> <form name="form" method="post" action="xxx.php" onsubmit="return validateForm()"> <?phpinclude 'connectdb.php';$result=mysql_query("SELECT * FROM table_name");?> <table align="center" border="1" id="tblAddress"> <tr><td><b>Name</b></td><td><b>Company</b></td><td><b>Address</b></td></tr> <tr><td><input type="text" name="name[]"></td><td><select name="company[]"><option value=""></option><?php while ($row=mysql_fetch_array($result)){ ?><option value='<?php echo $row["company"] ?>'><?php echo $row["company"]; ?></option><?php } ?></select></td><td><input type="text" name="address[]"></td></tr> </table><p align="center"><input type="button" value="Add" onClick="addInput();"></p></form></body></html>
  13. Hi, The following codes now correctly shown a table with 1 row and 3 fields. When user click on "add", another row will appear. My question is: If user entered 3 rows of data, how can I capture all these data and insert into a database? I tried echoing and the outcome is always getting the last record. Can someone please kindly advice on this? Thanks. Example:formName | Company | AddressUser1 | Company 1 | Address 1User2 | Company 2 | Address 2User3 | Company 3 | Address 3 database Name | Company | AddressUser1 | Company 1 | Address 1User2 | Company 2 | Address 2User3 | Company 3 | Address 3 ------------------------------------------------------------------------------------------------<script type="text/javascript"> $(function(){ var newRowNum = 0; $('#addnew').click(function(){ newRowNum += 1; var addRow = $(this).parent().parent(); var newRow = addRow.clone(); $('input', addRow).val(''); $('select', addRow).val(''); $('td:first-child', newRow).html(""); $('td:last-child', newRow).html('<a href="" class="remove">Remove<\/a>'); $('input', newRow).each(function(i){ var newID = newRowNum + '_' + i; $(this).attr('id',newID).attr('name',newID); }); $('select', newRow).each(function(i){ var newID = newRowNum + '_' + i; $(this).attr('id',newID).attr('name',newID); }); addRow.before(newRow); $('a.remove', newRow).click(function(){ $(this).parent().parent().remove(); return false; }); return false; });}); </script> <?php include 'connectdb.php'; $result=mysql_query("SELECT * FROM table_name");?> <table align="center" border="1"> <tr> <td></td> <td>Name</td> <td>Company</td> <td>Address</td> <td></td> </tr> <tr> <td><a id="addnew" href="">Add</a></td> <td><input name="name[]" type="text"></td> <td> <select name="company[]"> <option value=""></option> <?php while($row=mysql_fetch_array($result)){ ?> <option value="<?php echo $row['company']; ?>"><?php echo $row['company']; ?></option> <?php } ?> </select> </td> <td><input name="address[]" type="text"></td> <td></td> </tr> </table> -------------------------------------------------------------------------------------------------
  14. Hi, I am trying to create a form in a table format whereby there are 1 row and 3 columns(1 field in each column). There will be a "Add" button, and if user click on the button, another row will appear with the 3 fields. Below are the codes that I have wrote:- When user 1st view, they can see the table with header, 1 row with 3 fields, an add button- However, if user click on "Add" button, the 2nd row appear outside the table format. Can someone advise me how to make it appear inside the same table just after the 1st row? Thanks. <script type="text/javascript"> function addInput(divName){ <?php include 'connectdb.php'; $result=mysql_query("SELECT * FROM table_name"); ?> var newdiv1 = document.createElement('div1'); var newdiv2 = document.createElement('div2'); var newdiv3 = document.createElement('div3'); newdiv1.innerHTML = "<input type='text' name='name[]'>"; newdiv2.innerHTML = "<select name='company[]'><option value=''></option><?php while ($row=mysql_fetch_array($result) { ? ><option value=<?php echo $row['company'] ?>><?php echo $row['company'] ?></option><?php } ?></select>"; newdiv3.innerHTML = "<input type='text' name='address[]'><br>"; document.getElementById(divName).appendChild(newdiv1); document.getElementById(divName).appendChild(newdiv2); document.getElementById(divName).appendChild(newdiv3);}</script> <?php include 'connectdb.php'; $result=mysql_query("SELECT * FROM table_name");?> <div id="dynamicInput"> <table align="center" border="1"> <tr> <td><b>Name</b></td> <td><b>Company</b></td> <td><b>Address</b></td> </tr> <tr> <td><input type="text" name="name[]"></td> <td> <select name="company[]"> <option value=""></option> <?php while ($row=mysql_fetch_array($result)){ ?> <option value=<?php echo $row["company"] ?>><?php echo $row["company"] ?></option> <?php } ?> </select> </td> <td><input type="text" name="address[]"></td> </tr> </table> <p align=center><input type="button" value="Add" onClick="addInput('dynamicInput')"></p> </div>
  15. holy24

    strtotime() function

    Thanks guys..The problem is solved.
  • Create New...