Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Page 1 of 4 123 ... LastLast
Results 1 to 15 of 56
  1. #1
    Regular Coder
    Join Date
    Aug 2013
    Posts
    141
    Thanks
    22
    Thanked 0 Times in 0 Posts

    mysql query echo results into html form

    I have the following forms in details.html:

    <form target="_blank" name="detailsForm" action="info.php" method="POST">
    Forename: <input type="text" name="fName" id="Fname"/>
    <br/>
    <br/>
    </form>
    <form method="POST" action="" method="POST">
    Search Criteria: <input type="text" name="sCriteria" id="Scriteria"/>
    <br/>
    <br/>
    <input type="submit" name="query" value="Run Query"/>
    </form>

    And I have the following query:

    SELECT CUST_Forename FROM Customers WHERE CUST_Forename = Daniel;

    What I am trying to do is that I want the result of the query to be displayed in the textbox above which is called fName. The second form is where the user will key in the name that they want to receive. Note that I want the textbox to still be able to have data keyed into it as well.

    Thanks
    Last edited by daniel0816; 09-10-2013 at 02:02 PM.

  • #2
    0x3
    0x3 is offline
    New Coder
    Join Date
    Sep 2013
    Location
    Somewhere on a map
    Posts
    37
    Thanks
    0
    Thanked 5 Times in 5 Posts
    PHP Code:
    <input type="text" name="fName" id="Fname" value='<?php print $result?>'/>
    If this what you're going for, than print the result to the value attribute.

  • Users who have thanked 0x3 for this post:

    daniel0816 (09-10-2013)

  • #3
    Regular Coder
    Join Date
    Aug 2013
    Posts
    141
    Thanks
    22
    Thanked 0 Times in 0 Posts
    Appreciate the suggestion but it just displays the value in the text box am not sure if my other code is correct can u show me an example if possible. Thanks

  • #4
    0x3
    0x3 is offline
    New Coder
    Join Date
    Sep 2013
    Location
    Somewhere on a map
    Posts
    37
    Thanks
    0
    Thanked 5 Times in 5 Posts
    http://jsfiddle.net/EVjpL/ this is how it would look like.

  • #5
    Regular Coder
    Join Date
    Aug 2013
    Posts
    141
    Thanks
    22
    Thanked 0 Times in 0 Posts
    Yea is it supposed to be like that because I need the text box to be blank as the form needs to receive data keyed in as well

  • #6
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,978
    Thanks
    4
    Thanked 2,659 Times in 2,628 Posts
    I don't understand what you're talking about here.
    Your options are to either have an input with or without a value. You cannot have it with multiple values. What you can do is add [] to the name of an input and have multiple with different values which will create an array for PHP to pull in.
    Putting a value into a text field does *not* stop you from changing it. That is simply the default value for it. The only thing that will stop you is by placing a readonly on it (disabled will also work, but disabled fields are qualified as un-successful so you will not receive the data server side).
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 

  • #7
    Senior Coder
    Join Date
    Sep 2010
    Posts
    1,899
    Thanks
    15
    Thanked 226 Times in 226 Posts
    About the only other thing you can do is use an if(isset statement.
    PHP Code:
    <?php if(isset($result)) print $result?>
    To prevent an error code from being printed if result is not set.
    Welcome to http://www.myphotowizard.net

    where you can edit images, make a photo calendar, add text to images, and do much more.


    When you know what you're doing it's called Engineering, when you don't know, it's called Research and Development. And you can always charge more for Research and Development.

  • #8
    Regular Coder
    Join Date
    Aug 2013
    Posts
    141
    Thanks
    22
    Thanked 0 Times in 0 Posts

    still no joy

    This is what I have now:
    All the below code is on the same page details.html:

    First I have a query in a function called query(). I also have an if statement that is supposed to call the query if sCriteria is posted.

    Code:
    <?php
    if (isset($_POST['sCriteria'])) {
        echo query();
        return;
    }
    
    function query()
    {
    	error_reporting(E_ALL);
    	$connect = mysql_connect("dbinfo", "dbinfo", "dbinfo");
    	//select database
    	mysql_select_db("dbinfo", $connect);
    
    	$criteria = $_POST['sCriteria'];
    
    	$sql="	SELECT DISTINCT Customers.CUST_ID, Customers.CUST_Forename, Customers.CUST_Surname, Customers.CUST_Email,
    			Customers.CUST_Mobile, Customers.CUST_HomeNum, Customers.CUST_AddressL1, Customers.CUST_AddressL2,
    			Customers.CUST_AddressL3, Customers.CUST_Postcode, Jobs.J_RefNum, Manufacturers.MANU_ID,
    			Manufacturers.MANU_Name,
    			Jobs.J_Model, OperatingSystems.OS_ID, OperatingSystems.OS_Name, 
    			Jobs.J_ReceivedBy, Jobs.J_DateRec, Jobs.J_FaultDesc, Jobs.J_PassWinAdmin,
    			Jobs.J_DataRecYN, Jobs.J_PowerSuppYN, JobStatus.JS_Status, 
    			
    			FROM Customers, Jobs, JobStatus, OperatingSystems, Manufacturers
    			WHERE (Jobs.J_RefNum = '$criteria' AND Jobs.J_RefNum = Customers.CUST_ID)
    			AND (OperatingSystems.OS_ID = Jobs.J_RefNum) AND (Manufacturers.MANU_ID = Jobs.J_RefNum)
    		 ";	
    	$result=mysql_query($sql);
    	$result2=mysql_fetch_array($result);
    }
    ?>
    Next I have a HTML form that I have created in an zxcAlertPopUp box:
    I have tried to set the value for customer ID to
    Code:
    value="<?php echo $result2['CUST_ID']?>"
    My problem is that it doesn't display the result from the query in the customer ID text box. Am not sure whether the query function is being called or not or have I set the value for customer ID incorrectly. Thanks

    Code:
    <form method="POST" action="">
    Search Criteria: <input type="text" name="sCriteria" id="Scriteria"/>
    <br/>
    <br/>
    <input type="button" name="query" value="Run Query" onmouseup="zxcAlertPopUp.Open('drop4',true);"/>
    <div id="drop4">
    <div style="float:left;"><p>Customer Details</p>
    Customer ID: <input type="int" name="custID2" id="Custid2" value="<?php echo $result2['CUST_ID']?>" disabled/>
    <br/>
    <br/>
    Forename: <input type="text" name="fName2" id="Fname2" value="" disabled/>
    <br/>
    <br/>
    Surname: <input type="text" name="sName2" id="Sname2" value=""/>
    <br/>
    <br/>
    Email Address: <input type="email" name="eAdd2" id="Eadd2" value=""/>
    <br/>
    <br/>
    Mobile Number: <input type="int" name="mNum2" id="Mnum2" value=""/>
    <br/>
    <br/>
    Home Number: <input type="int" name="hNum2" id="hNum2" value=""/>
    <br/>
    <br/>
    Address Line 1: <input type="text" name="adline1" id="Adline1" value=""/>
    <br/>
    <br/>
    Address Line 2: <input type="text" name="adline2" id="Adline2" value=""/>
    <br/>
    <br/>
    Address Line 3: <input type="text" name="adline3" id="Adline3" value=""/>
    <br/>
    <br/>
    Postcode: <input type="text" name="pCode2" id="Pcode2" value=""/>
    <br/>
    <br/>
    </div>
    </form>
    Last edited by daniel0816; 09-11-2013 at 01:57 PM.

  • #9
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,978
    Thanks
    4
    Thanked 2,659 Times in 2,628 Posts
    Where are you setting the $result2 in the main method? I see a call in an isset block that prints the query, but nothing that captures the results. There is no default relationship between $result2 within query() and $result2 outside of query().
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 

  • #10
    Senior Coder
    Join Date
    Sep 2010
    Posts
    1,899
    Thanks
    15
    Thanked 226 Times in 226 Posts
    I can see you need to be grounded on the way that php handles return, and how you use it. It returns a single variable or an array, so if you have more than one item to return you have to compose an array. Also, return has to be the last statement in the function, the function 'closes shop' after it returns the data. And it gets returned to the function caller.
    PHP Code:
            AND (OperatingSystems.OS_ID = Jobs.J_RefNum) AND (Manufacturers.MANU_ID = Jobs.J_RefNum)
             ";    
        $result=mysql_query($sql);
        $result2=mysql_fetch_array($result);
    $results=array($result,$result2);
    return $results;  // $results is an array.
    }
    ?>
    $my_results=query(); // The function caller is $my_results.

    value="<?php echo $my_results[1]; ?>"
    Welcome to http://www.myphotowizard.net

    where you can edit images, make a photo calendar, add text to images, and do much more.


    When you know what you're doing it's called Engineering, when you don't know, it's called Research and Development. And you can always charge more for Research and Development.

  • Users who have thanked DrDOS for this post:

    daniel0816 (09-11-2013)

  • #11
    Regular Coder
    Join Date
    Aug 2013
    Posts
    141
    Thanks
    22
    Thanked 0 Times in 0 Posts
    $result2 is being set here $result2=mysql_fetch_array($result);
    Its the last piece of code in the php section.

  • #12
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,978
    Thanks
    4
    Thanked 2,659 Times in 2,628 Posts
    Quote Originally Posted by daniel0816 View Post
    $result2 is being set here $result2=mysql_fetch_array($result);
    Its the last piece of code in the php section.
    That's inside the function.
    What you need to do is return from the function and capture the results. As said, there is no relationship between $result2 within query() and $result2 outside of query().
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 

  • Users who have thanked Fou-Lu for this post:

    daniel0816 (09-11-2013)

  • #13
    Regular Coder
    Join Date
    Aug 2013
    Posts
    141
    Thanks
    22
    Thanked 0 Times in 0 Posts
    Thanks but it still isn't working its just displaying the value for customer ID as if it were a string so in the text box so it literally displays <?php echo $my_results[1];?> this is what I have now:

    Code:
    <?php
    function query()
    {
    	error_reporting(E_ALL);
    
    
    Code:
    $connect = mysql_connect("dbinfo", "dbinfo", "dbinfo");
    	//select database
    	mysql_select_db("dbinfo", $connect);
    $criteria = $_POST['sCriteria']; $sql=" SELECT DISTINCT Customers.CUST_ID, Customers.CUST_Forename, Customers.CUST_Surname, Customers.CUST_Email, Customers.CUST_Mobile, Customers.CUST_HomeNum, Customers.CUST_AddressL1, Customers.CUST_AddressL2, Customers.CUST_AddressL3, Customers.CUST_Postcode, Jobs.J_RefNum, Manufacturers.MANU_ID, Manufacturers.MANU_Name, Jobs.J_Model, OperatingSystems.OS_ID, OperatingSystems.OS_Name, Jobs.J_ReceivedBy, Jobs.J_DateRec, Jobs.J_FaultDesc, Jobs.J_PassWinAdmin, Jobs.J_DataRecYN, Jobs.J_PowerSuppYN, JobStatus.JS_Status, FROM Customers, Jobs, JobStatus, OperatingSystems, Manufacturers WHERE (Jobs.J_RefNum = '$criteria' AND Jobs.J_RefNum = Customers.CUST_ID) AND (OperatingSystems.OS_ID = Jobs.J_RefNum) AND (Manufacturers.MANU_ID = Jobs.J_RefNum) "; $result=mysql_query($sql); $result2=mysql_fetch_array($result); $results=array($result, $result2); return $results; } $my_results=query(); if (isset($_POST['sCriteria'])) { $my_results(); } ?>
    Code:
    <form method="POST" action="">
    Search Criteria: <input type="text" name="sCriteria" id="Scriteria"/>
    <br/>
    <br/>
    <input type="button" name="query" value="Run Query" onmouseup="zxcAlertPopUp.Open('drop4',true);"/>
    <div id="drop4">
    <div style="float:left;"><p>Customer Details</p>
    Customer ID: <input type="int" name="custID2" id="Custid2" value='<?php echo $my_results[1];?>' disabled/>
    <br/>
    <br/>
    Last edited by daniel0816; 09-11-2013 at 03:23 PM.

  • #14
    Senior Coder
    Join Date
    Sep 2010
    Posts
    1,899
    Thanks
    15
    Thanked 226 Times in 226 Posts
    <?php echo $my_results[1]; ?> not <?php echo $my_results[1];?>
    Welcome to http://www.myphotowizard.net

    where you can edit images, make a photo calendar, add text to images, and do much more.


    When you know what you're doing it's called Engineering, when you don't know, it's called Research and Development. And you can always charge more for Research and Development.

  • #15
    Regular Coder
    Join Date
    Aug 2013
    Posts
    141
    Thanks
    22
    Thanked 0 Times in 0 Posts
    Sorry still no change


  •  
    Page 1 of 4 123 ... LastLast

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •