Jump to content

doforumda

Members
  • Posts

    300
  • Joined

  • Last visited

    Never

Posts posted by doforumda

  1. that works thanks

     

    now when logged user wants to edit his info and when he clicks edit he will be taken to this site. lets say he already has some data in db so when he gets to this form he should see that db data in this form so if he wants to edit or remove any data he will be able to do so.

     

    i tried this with the code below. let me provide my db table

    imid                userid                  username                  im

    1                      48                        alex                          gtalk

    2                      48                        alex4                        skype

     

    here one user has two data. but the problem is when he comes to this form he sees this data in this way

     

    IM Screen Name: alex(this is text field of the form and he sees his username in it) gtalk (this is select menu in which he see)

    IM Screen Name: alex(this is text field of the form and he sees his username in it) gtalk (this is select menu in which he see)

    IM Screen Name: alex4(this is text field of the form and he sees his username in it) skype (this is select menu in which he see)

    IM Screen Name: alex4(this is text field of the form and he sees his username in it) skype (this is select menu in which he see)

     

    as there is only two data of this user so it should appear only two. how can we do this?

     

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
                        "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
        <title></title>
        <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.3/jquery.min.js"></script>
    
        <script type="text/javascript">
            $(document).ready(function() {
                $('#btnAdd').click(function() {
                    var num     = $('.clonedInput').length;
                    var newNum  = new Number(num + 1);
                    var newElem = $('#input' + num).clone().attr('id', 'input' + newNum);
                    newElem.children(':first').attr('id', 'name' + newNum).attr('name', 'name' + newNum);
                    $('#input' + num).after(newElem);
                });
    
            });
        </script>
        <style>
    #myForm div {
    font-size:14px;
    margin-bottom: 10px;
    clear: left;
    }
    #myForm label {
    width: 125px;
    display: block;
    font-size:14px;
    font-weight: bold;
    color: #999;
    float: left;
    }
    #btnAdd {
    margin-left:130px;
    }
    </style>
    
    </head>
    
    <body>
    <form id="myForm" method="post" action="process.php">
    <div>
        <label>First Name: </label><input type="text" name="fname" id="fname"><br>
        </div>
        <div>
        <label>Last Name: </label><input type="text" name="lname" id="lname"><br>
        </div>
        <?php
    $connect = mysql_connect("localhost","user","pass");
    mysql_select_db("db");
    $get_im = mysql_query("SELECT * FROM contactim WHERE userid='$_SESSION[userid]'");
    $count = mysql_num_rows($get_im);
    while($get_contactim = mysql_fetch_assoc($get_im)) {
    	$userim_db = $get_contactim['username'];
    	$im_db = $get_contactim['im'];
    	//echo $userim_db."<br>";
    
    	for($i = 1; $i <= $count; $i++) {
    ?>
        <div id="input1" class="clonedInput">
          <label>IM Screen Names:</label>
            <input type="text" name="name[]" id="name1" value="<?php if($userim_db == "") { echo ""; } else { echo $userim_db; } ?>" />
            <select name="screenname[]" id="screenname1">
              <option value="AIM" <?php if($im_db == "AIM") { echo "SELECTED"; } ?>>AIM</option>
              <option value="gtalk" <?php if($im_db == "gtalk") { echo "SELECTED"; } ?>>Google Talk</option>
              <option value="skype" <?php if($im_db == "skype") { echo "SELECTED"; } ?>>Skype</option>
              <option value="windows" <?php if($im_db == "windows") { echo "SELECTED"; } ?>>Windows Live</option>
              <option value="yahoo" <?php if($im_db == "yahoo") { echo "SELECTED"; } ?>>Yahoo</option>
            </select><br />
            <?php
    	}
    }
    	?>
        </div>
    
        <div>
        	<a href="#" id="btnAdd">Add another</a>
        </div>
        <input type="submit" name="submit" value="Submit">
    </form>
    
    </body>
    </html>

  2. A workaround is this

    <input type="text" name="name[]" id="name1" />

            <select name="screenname[]" id="screenname1">

     

    I have changed it so that your names are now an array. Do with it as you wish.

     

     

    HTH

    Teamatomic

     

    i want to display it this way

     

    name: screenname

  3. thanks it is working

     

    now how can i display it. i used two for loops is fine or is there a better way to do this

    $fname = $_POST['fname'];
    $lname = $_POST['lname'];
    $name = $_POST['name'];
    $screenname = $_POST['screenname'];
    echo $fname."<br>";
    echo $lname."<br>";
    
    for($i=0; $i<count($_POST['name']); $i++)
    {
    echo $_POST['name'][$i]."<br>";
    }
    
    for($i=0; $i<count($_POST['screenname']); $i++)
    {
    echo $_POST['screenname'][$i]."<br>";
    }

  4. thanks for your help but if you look at my html form you find out that i am not making firstname and lastname as dynamic fields which are added through jquery. i am only creating "IM Screen Name" dynamically via jquery and it contains one text field and one select menu. so firstname and lastname has no problem while posting the problem is with those which are creating dynamically.

    so how can that be accessed on php side?

     

  5. hi

     

    i create a form using jquery. i actually found jquery code from other website and modified it according to my needs. i need help in how can i get data in side all these fields to php file. on php side i am just echoing this data.

     

    html form

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
                        "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
        <title></title>
        <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.3/jquery.min.js"></script>
    
        <script type="text/javascript">
            $(document).ready(function() {
    
                $('#btnAdd').click(function() {
    
                    var num     = $('.clonedInput').length;
    
                    var newNum  = new Number(num + 1);
    
                    var newElem = $('#input' + num).clone().attr('id', 'input' + newNum);
         	 
                    newElem.children(':first').attr('id', 'name' + newNum).attr('name', 'name' + newNum);
                    $('#input' + num).after(newElem);
                });
    
            });
        </script>
        <style>
    #myForm div {
    font-size:14px;
    margin-bottom: 10px;
    clear: left;
    }
    #myForm label {
    width: 125px;
    display: block;
    font-size:14px;
    font-weight: bold;
    color: #999;
    float: left;
    }
    #btnAdd {
    margin-left:130px;
    }
    </style>
    
    </head>
    
    <body>
    
    <form id="myForm" method="post" action="process.php">
    <div>
        <label>Firstname: </label><input type="text" name="fname" id="fname"><br>
        </div>
        <div>
        <label>lastname: </label><input type="text" name="lname" id="lname"><br>
        </div>
        <div id="input1" class="clonedInput">
          <label>IM Screen Names:</label>
            <input type="text" name="name1" id="name1" />
            <select name="screenname1" id="screenname1">
              <option value="AIM" selected="selected">AIM</option>
              <option value="gtalk">Google Talk</option>
              <option value="skype">Skype</option>
              <option value="windows live">Windows Live</option>
              <option value="yahoo">Yahoo</option>
            </select><br />
        </div>
    
        <div>
        	<a href="#" id="btnAdd">Add another</a>
        </div>
        <input type="submit" name="submit" value="Submit">
    </form>
    
    </body>
    </html>

     

    process.php

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>Untitled Document</title>
    </head>
    
    <body>
    <?php
    $fname = $_POST['fname'];
    $lname = $_POST['lname'];
    $name1 = $_POST['name1'];
    $screenname1 = $_POST['screenname1'];
    
    echo $fname."<br>";
    echo $lname."<br>";
    echo $name1."<br>";
    echo $screenname1."<br>";
    
    ?>
    </body>
    </html>

     

  6. hi i need help in creating dynamic form using jquery. i create a form in this form i want when "add another" link is clicked then it adds one more set of fields.

     

    form is here

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>Untitled Document</title>
    <script type="text/javascript" src="lib/jquery-1.4.min(Production).js"></script>
    <script src="js/script.js" type="text/javascript"></script>
    <style>
    #form1 div {
    font-size:14px;
    margin-bottom: 10px;
    clear: left;
    }
    #form1 label {
    width: 125px;
    display: block;
    font-size:14px;
    font-weight: bold;
    color: #999;
    float: left;
    }
    #link {
    margin-left:125px;
    }
    </style>
    </head>
    
    <body>
    <form id="form1" name="form1" method="post" action="">
    <div>
      <label>IM Screen Names:</label>
        <input type="text" name="textfield" id="textfield" />
        <select name="select" id="select">
          <option value="AIM" selected="selected">AIM</option>
          <option value="gtalk">Google Talk</option>
          <option value="skype">Skype</option>
          <option value="windows live">Windows Live</option>
          <option value="yahoo">Yahoo</option>
        </select><br />
        <div id="link"><a href="">Add another</a></div>
    </div>
    </form>
    </body>
    </html>

  7. hi I am trying below code but it is not displaying date from database in select menus. the format of the date in mysql table is DATE here the value is 2008-04-04.

     

    code

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>Untitled Document</title>
    </head>
    
    <body>
    <?php
    //session_start();
    include("dbConnect.php");
    $query = mysql_query("SELECT * FROM basicinfo_age WHERE userid='1'");
    while($row = mysql_fetch_assoc($query)) {
       $date = $row['dob'];
       //echo $date;
    list($year, $month, $day) = explode("-", $date);
    //$years = $year;
    //$months = $month;
    //$days = $day;
    //echo $years;
    }
    ?>
    <form id="form1" name="form1" method="post" action="">
      Date of Birth:
      <select name="month" id="month">
        <option value="Jan" <?php if($month=="Jan") { echo "SELECTED"; } ?>>Jan</option>
        <option value="Feb" <?php if($month=="Feb") { echo "SELECTED"; } ?>>Feb</option>
        <option value="Mar" <?php if($month=="Mar") { echo "SELECTED"; } ?>>Mar</option>
        <option value="Apr" <?php if($month=="Apr") { echo "SELECTED"; } ?>>Apr</option>
      </select>
      <select name="day" id="day">
        <option value="1" <?php if($day=="1") { echo "SELECTED"; } ?>>1</option>
        <option value="2" <?php if($day=="2") { echo "SELECTED"; } ?>>2</option>
        <option value="3" <?php if($day=="3") { echo "SELECTED"; } ?>>3</option>
        <option value="4" <?php if($day=="4") { echo "SELECTED"; } ?>>4</option>
      </select>
      <select name="year" id="year">
        <option value="2010" <?php if($year=="2010") { echo "SELECTED"; } ?>>2010</option>
        <option value="2009" <?php if($year=="2009") { echo "SELECTED"; } ?>>2009</option>
        <option value="2008" <?php if($year=="2008") { echo "SELECTED"; } ?>>2008</option>
      </select>
    </form>
    </body>
    </html>

  8. ok then lets say if a user who has not prechecked in anyone of Men and Women and when he checks one of it or both or them then there update query i think wont work so this case what should we do?

     

    Crap um... for both, sorry forgot to answer that part, for both then just do the same thing except add an addition line to the sudo code that checks for the both. Question is though how are you handling if both are checked? I mean how are you recording the data into the database? it's subject on that... and changes some things too as to how we handle it when you pull it out of the database. Anyrate this can still just be deteremined by conditional cases, but this may be more efficient to change it over to loops instead so we don't get a dozen if statements too.

     

    i am practicing lets see what happens

  9. $string = "first  second third";
    
    echo preg_replace('/[ ]+/', ',', ucwords($string));
    
    //Output: First,Second,Third
    

    great thats working thanks

     

    now what if there is string with only commas between words in that string so can we capital first letter of each word after comma. the above example works but it first remove space and capitalize first letter

     

  10. how can we select date of birth from db and break it into three variables so year stores in $year month stores in $month and day stores in $day. i need this because i have a form with three select menus so when user clicks edit to edit his date of birth then it select dob from db put the current dob in those select menus. my form is below

     

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>Untitled Document</title>
    </head>
    
    <body>
    <?php
    session_start();
    include("dbconnect.php");
    $query = mysql_query("SELECT * FROM dob WHERE userid='$_SESSION[userid]'");
    while($row = mysql_fetch_assoc($query)) {
    $date = $row['dob'];
    ?>
    <form id="form1" name="form1" method="post" action="">
      Date of Birth: 
      <select name="month" id="month">
        <option value="Jan" SELECTED>Jan</option>
        <option value="Feb" >Feb</option>
        <option value="Mar" >Mar</option>
        <option value="Apr" >Apr</option>
      </select>
      <select name="day" id="day">
        <option value="1" selected>1</option>
        <option value="2">2</option>
        <option value="3">3</option>
        <option value="4">4</option>
      </select>
      <select name="year" id="year">
        <option value="2010" selected>2010</option>
        <option value="2009">2009</option>
        <option value="2008">2008</option>
      </select>
    </form>
    </body>
    </html>

  11. Mmmm, would basically do the same thing as when you add the checked items to the db. But depending on how you are setup for example say you have an update page where you lists all the items that can be checked with the items in their database section prechecked. With that setup then when they hit update this way you just clear the data from the database and re-enter the data to the db as you did before but with the new set of checked boxes.

     

    ok then lets say if a user who has not prechecked in anyone of Men and Women and when he checks one of it or both or them then there update query i think wont work so this case what should we do?

  12. Use isset to see if it ever was checked, will never appear in the post array (or get array if u want to use get instead) if never checked. So just a simple if statement below for all you check boxes to see if any was checked for each checkbox variable. Use the if statement to check then do the your script to deal with the checkboxes later in an else statement if they are.

    if(!isset($_POST['interest']))
    echo "The checkbox intererst isn't checked"; 
    

     

    thanks

     

    it is working now the problem is lets say a loggedin user already has selected Men and Women in interest in. Now he wants to remove Women so he will uncheck then it should also remove it from db. how can we achieve this task???

  13. hi

     

    i am testing checkboxes with php. I have a form there are 6 checkboxes. what i want is when user does not check any checkbox then it should not return false. The form which i have has this problem when i dont select any box and press submit then it displays error. how can i fix it so it should not display error.

     

    html file

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>Untitled Document</title>
    </head>
    
    <body>
    <form id="form1" name="form1" method="post" action="checkboxesprocess.php">
      <p>Interested In: 
        <label>
          <input type="checkbox" name="interest[]" value="m" id="checkbox" />
          Men</label>
        <label>
          <input type="checkbox" name="interest[]" value="w" id="checkbox2" />
          Women</label>
      </p>
      <p>Looking For: 
        <label>
          <input type="checkbox" name="looking[]" value="f" id="checkbox3" />
          Friendship</label> 
        <label>
          <input type="checkbox" name="looking[]" value="d" id="checkbox4" />
          Dating</label> 
        <label>
          <input type="checkbox" name="looking[]" value="r" id="checkbox5" />
          A Relationship</label> 
        <label>
          <input type="checkbox" name="looking[]" value="n" id="checkbox6" />
          Networking</label>
      </p>
      <p>
        <label>
          <input type="submit" name="button" id="button" value="Submit" />
        </label>
      </p>
    </form>
    </body>
    </html>

     

    php file

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>Untitled Document</title>
    </head>
    
    <body>
    <?php
    $interest = $_POST['interest'];
    $look = $_POST['looking'];
    $connect = mysql_connect("localhost","user","pass");
    mysql_select_db("test");
    foreach($interest as $int) {
    $queryinterest = mysql_query("INSERT INTO interestin VALUES ('','$int')");
    }
    
    foreach($look as $lo) {
    $queryinterest = mysql_query("INSERT INTO lookingfor VALUES ('','$lo')");
    }
    
    ?>
    </body>
    </html>

     

  14. hi

     

    i have html form in which i want to send its data to php file using ajax but the problem i think is in php file because when i use firebug then it displays error in php file which says "Undefined index:  comment in php file" here is my code

     

    php file

    <?php
    $comment = strip_tags($_POST['comment']);
    //$postId = strip_tags($_POST['postId']);
    $commentDate = date("Y-m-d");
    $commentTime = date("h:i:s A");
    
    echo $comment;
    ?>

     

    html file

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>Untitled Document</title>
    <script type="text/javascript" src="lib/jquery-1.4.min(Production).js"></script>
    <script src="js/script.js" type="text/javascript"></script>
    </head>
    
    <body>
    <form id="form1" name="form1" method="post" action="">
      <p>
        <label>
          <textarea name="textarea" id="comment" cols="45" rows="5"></textarea>
        </label>
      </p>
      <p>
        <label>
          <input type="button" name="button" id="button" value="Submit" onclick="postcomment()" />
        </label>
      </p>
    </form>
    </body>
    </html>

     

    and js file

    function postcomment() {
          var url = 'comments.php';
          //var queryString = $("#commentForm").serialize();
          var comment = $('#comment').val();
           //var postId = $('input#postId').val();
          
          var queryString = 'comment=' + comment;// + '&postId=' + postId;
          alert(queryString);
          $.ajax ({
             type: 'POST',
             url: url,
             data: 'html',
             dataType: queryString,
             success: displayComments
          });
          
          function displayComments(resultData) {
             $('#displayComments').html(resultData);
          }
    }

  15. I have html form and i want to send data from this form to php file using ajax. currently i am having problem with this which is when i submit data it displays error which says

    undefined variable comment in php file.

     

    this html form

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>Untitled Document</title>
    <script type="text/javascript" src="lib/jquery-1.4.min(Production).js"></script>
    <script src="js/script.js" type="text/javascript"></script>
    </head>
    
    <body>
    <form id="form1" name="form1" method="post" action="">
      <p>
        <label>
          <textarea name="textarea" id="comment" cols="45" rows="5"></textarea>
        </label>
      </p>
      <p>
        <label>
          <input type="button" name="button" id="button" value="Submit" onclick="postcomment()" />
        </label>
      </p>
    </form>
    </body>
    </html>
    

     

    this is js

    function postcomment() {
    	var url = 'comments.php';
    	//var queryString = $("#commentForm").serialize();
    	var comment = $('#comment').val();
        	//var postId = $('input#postId').val();
    
    	var queryString = 'comment=' + comment;// + '&postId=' + postId;
    	alert(queryString);
    	$.ajax ({
    		type: 'POST',
    		url: url,
    		data: 'html',
    		dataType: queryString,
    		success: displayComments
    	});
    
    	function displayComments(resultData) {
    		$('#displayComments').html(resultData);
    	}
    }

    and this is php

    <?php
    $comment = strip_tags($_POST['comment']);
    //$postId = strip_tags($_POST['postId']);
    $commentDate = date("Y-m-d");
    $commentTime = date("h:i:s A");
    
    echo $comment;
    ?>

     

    please tell me what am i doing wrong in my code

  16. hi

    i need help in adding preloader to ajax code. in the following code i want to add preloader when user clicks on Tab One and also when user enter its username and password and after pressing submit button there i want to add preloader. i have a loader.gif image so please help me how and where can i add it

    loginTab.html

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
        <head>
            <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
            <title>Untitled Document</title>
            <link rel="stylesheet" href="style.css"/>
        </head>
    
        <body>
            <div class="tabs" onclick="tabOne()">Tab One</div>
            <div id="message"></div>
            <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4/jquery.min.js"></script>
            <script type="text/javascript" src="script.js"></script>
        </body>
    </html>
    

     

    script.js

    function tabOne() {
        $('div#message').load('login.html');
    }
    function login () {
        var url = 'login.php';
        var user = $('input#user').val();
        var pass = $('input#pass').val();
    
        var queryString = 'user=' + user + '&pass=' + pass;
    
        $.post(url,queryString,display);
        function display(data) {
            $("#content").html(data);
        }
    }
    

     

    login.html

    <div id="content"></div>
    <form>
        Username:<br />
        <input type="text" name="user" id="user" /><br />
        Password:<br />
        <input type="password" name="pass" id="pass" /><br />
        <input type="button" name="submit" id="submit" value="Login" onclick="login()" />
    </form>

     

    login.php

    <?php
    $email = strip_tags($_POST['user']);
    $password = strip_tags($_POST['pass']);
    
    //echo $email;
    //echo $password;
    
    if($email&&$password) {
    
        $connect = mysql_connect("localhost","user","pass");
        mysql_select_db("facebook");
        $query = mysql_query("SELECT email FROM users WHERE email='$email'");
        $count = mysql_num_rows($query);
        if($count == 0) {
            echo "You are registered thanks.";
        }
        else {
            die("That email address already exist.");
        }
    }
    else {
        die("please fill in both fields!");
    }
    ?>

×
×
  • 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.