PHP and HTML - Getting Values From Database And Display It In the Textbox -


Scenario:

The user inputs on the reference number and its reference number, let me display it Should have equal space.

SQL:

  need_once ('conn.php'); $ Refnum = (isset ($ _ POST ['refOff'])); // Set the name of the file $ query = mysql_query ("SELECT * FROM pilot WHERE geo = $ refnum"); // Display query results ($ row = mysql_fetch_array ($ query)) {$ rname = $ row ['rname']; $ Pname = $ row ['pname']; $ Mname = $ row ['mname']; }  

HTML:

  & lt; Tr & gt; & Lt; Td width = "283" height = "32" & gt; Region: & lt; / Span & gt; & Lt; / TD & gt; & Lt; Td width = "407" & gt; & Lt; Input type = "text" value = "& lt ;? php echo $ rname;? & Gt;" /> & Lt; / Td> & Lt; / TR & gt; & Lt; TR & gt; & Lt; Td width = "283" height = "32" & gt; Province: & lt; / Span & gt; & Lt; / TD & gt; & Lt; Td width = "407" & gt; & Lt; Input type = "text" value = "& lt ;? php echo $ pname;? & Gt;" /> & Lt; / Td> & Lt; / TR & gt; & Lt; TR & gt; & Lt; Td width = "283" height = "32" & gt; City: & lt; / Span & gt; & Lt; / TD & gt; & Lt; Td width = "407" & gt; & Lt; Input type = "text" value = "& lt ;? php echo $ mname ;? & gt;" /> & Lt; / Td> & Lt; / TR & gt;  

Problem:

Errors are being shown that rname, pname, and mname are undefined. Firstly, I believe that you have its input element in your HTML Sort:

  & lt; Label for = 'refOff' & gt; Reference number: & lt; / Label & gt; & Lt; Input type = 'text' id = 'refOff' name = 'refOff' />  

This code is in your code:

  $ refnum = (isset ($ _ POST ['refOff']))  

returns only a boolean value (i.e. true or false) and returns the actual value to the user who entered the 'rickoff' html input element. It should work well with the use of a Ternary operator:

$ refnum = (isset ($ _ POST ['refOff']))? $ _POST ['refOff']: Zero; If ($ refnum) {$ query = mysql_query ("select * pilot WHERE geo = $ refnum"); // Display query results ($ row = mysql_fetch_array ($ query)) {$ rname = $ row ['rname']; $ Pname = $ row ['pname']; $ Mname = $ row ['mname']; }}

Good luck!


Comments

Popular posts from this blog

sqlite3 - UPDATE a table from the SELECT of another one -

c# - Showing a SelectedItem's Property -

javascript - Render HTML after each iteration in loop -