Can't get variables from table to form

Hi Guys,

I’m new to mysql and php. Having had 2 strokes doesn’t help much either :smiley: I need help getting data from a mysql table to a form. There will be only one record which will be read and edited. I am including a shortened version of the code. Please help!
Thanks
[php]

<?php // Make a MySQL Connection mysql_connect("localhost", "root", "ka3pmw") or die(mysql_error()); mysql_select_db("my_setup") or die(mysql_error()); // Get a specific result from the "example" table $result = mysql_query("SELECT * FROM myinfo WHERE id='1'") or die(mysql_error()); // get the first (and hopefully only) entry from the result $row = mysql_fetch_array( $result ); // Print out the contents of each row into a table echo $row['mycall']." - ".$row['id']; $mycall= $row["mycall"]; ?> KA3PMW Logger Setup

 KA3PMW Logger V 3.0
General Setup

    <label>&nbsp;KA3PMW Logger V 3.0 </label><input type="text" name="cb" id="cb" value="KA3PMW Logger V 3.0 " size="30" /> 
    <label>&nbsp;&nbsp;&nbsp;&nbsp;UTC Offset:&nbsp;</label><input type="text" name="utc" value="" size="3" />
    <label>&nbsp;&nbsp;&nbsp;&nbsp;Band:
    <select name="band" id="band">
    	<option value="0">    </option>
    	<option value="1">ALL</option>
        <option value="2">160M</option>
        <option value="3">80M</option>
        <option value="4">40M</option>
        <option value="5">20M</option>
        <option value="6">15M</option>
		<option value="7">10M</option>
      </select></label> 
     <label>&nbsp;&nbsp;&nbsp;&nbsp;Mode:
     <select name="mode" id="mode">
    	<option value="0">     </option>
    	<option value="1">CW</option>
        <option value="2">SSB</option>
        <option value="3">RTTY</option>
        <option value="4">PSK</option>
        <option value="5">SSTV</option>
       </select></label>
    <label>&nbsp;&nbsp;&nbsp;&nbsp;My Call:&nbsp;</label><input type="text" name="mycall" value="" size="10" /> 
    <label>&nbsp;&nbsp;&nbsp;&nbsp;ARRL Sect:&nbsp;</label><input type="text" name="sect" value="" size="6" />
     <br/><br /> 
    <label>&nbsp;Class:&nbsp;</label><input type="text" name="class" value="" size="10" /> 
    <label>&nbsp;&nbsp;&nbsp;&nbsp;ITU Zone:&nbsp;</label><input type="text" name="zone" value="" size="4" />
    <label>&nbsp;&nbsp;&nbsp;&nbsp;ITU Region:&nbsp;</label><input type="text" name="region" value="" size="4" />
    <label>&nbsp;&nbsp;&nbsp;&nbsp;Grid:&nbsp;</label><input type="text" name="grid" value="" size="10" />
	<label>&nbsp;&nbsp;&nbsp;&nbsp;Contest:&nbsp;</label><input type="text" name="contest" value="" size="25" />
    <label>&nbsp;&nbsp;&nbsp;&nbsp;Log Name:&nbsp;</label><input type="text" name="logname" value="" size="12" />
    <br/><br />
    <label>&nbsp;Cross Mode:&nbsp;</label><input type="text" name="CM" value="" size="12" />
    <label>&nbsp;&nbsp;&nbsp;&nbsp;Transmitter # (0 or 1):&nbsp;</label><input type="text" name="tn" value="" size="1" />
    <label>&nbsp;&nbsp;&nbsp;&nbsp;# Operators:
    <select name="catop" id="catop">
        <option value="0">           </option>
        <option value="1">Single-Op</option>
        <option value="2">Multi-Op</option>
        <option value="3">Checklog</option>
   	 </select></label> 
     <Label>&nbsp;Assisted:
        <select name="cata" id="cata">
        <option value="0">       </option>
        <option value="1">Un-Assisted</option>
        <option value="2">Assisted</option>
        </select></Label>
     <Label>&nbsp;&nbsp;&nbsp;&nbsp;Power:
       <select name="pow" id="pow">
        <option value="0">   </option>
        <option value="1">QRP</option>
        <option value="2">Low</option>
        <option value="3">High</option>
       </select></Label>
        <br /><br />
     <label>&nbsp;# Overlay:
    <select name="co" id="co">
        <option value="0">        </option>
        <option value="1">ROOKIE </option>
        <option value="2">TB-WIRES </option>
        <option value="3">NOVICE-TECH</option>
        <option value="3">OVER-50</option>
       </select></label>
     <Label>&nbsp;&nbsp;&nbsp;&nbsp;Transmitters: 
        <select name="xmit" id="xmit">
        <option value="0">    </option>
        <option value="1">One</option>
        <option value="2">Two</option>
        <option value="3">Unlimited</option>
        </select> </Label> 
    <label>&nbsp;&nbsp;&nbsp;&nbsp;Claimed Score:&nbsp;</label><input type="text" name="cscore" value="" size="7" />
     <Label>&nbsp;&nbsp;&nbsp;&nbsp;Dupes: 
        <select name="dupe" id="dupe">
        <option value="01">          </option>
        <option value="1">Don't Allow</option>
        <option value="2">Warn Only</option>
        <option value="3">Warn and Allow</option>
        </select></Label>  
    <label>&nbsp;&nbsp;&nbsp;&nbsp;Club Name:&nbsp;</label><input type="text" name="club" value="" size="30" />
     <br /><br />
    <label> &nbsp;Email:&nbsp;</label><input type="text" name="email" value="" size="30" />
    <label>&nbsp;&nbsp;&nbsp;&nbsp;Name:&nbsp;</label><input type="text" name="name" value="" size="30" />
    
    <label>&nbsp;&nbsp;&nbsp;&nbsp;Address 1:&nbsp;</label><input type="text" name="add1" value="" size="45" />
    <br /><br />
    <label>&nbsp;Address 2:&nbsp;</label><input type="text" name="add2" value="" size="45" />
    <label>&nbsp;&nbsp;&nbsp;&nbsp;City:&nbsp;</label><input type="text" name="city" value="" size="30" />
   
    <label>&nbsp;State-Province:&nbsp;</label><input type="text" name="state" value="" size="3" />
    <label>&nbsp;&nbsp;&nbsp;&nbsp;Postal Code:&nbsp;</label><input type="text" name="zip" value="" size="10" />
     <br /><br /> 
    <label>&nbsp;Country:&nbsp;</label><input type="text" name="country" value="" size="30" />
    <br /><br />
    <label>&nbsp;Operator 1:&nbsp;</label><input type="text" name="op1" value="" size="10" />
    <label>&nbsp;Operator 2:&nbsp;</label><input type="text" name="op2" value="" size="10" /> 
    <label>&nbsp;Operator 3:&nbsp;</label><input type="text" name="op3" value="" size="10" /> 
    <label>&nbsp;Operator 4:&nbsp;</label><input type="text" name="op4" value="" size="10" /> 
    <label>&nbsp;Operator 5:&nbsp;</label><input type="text" name="op5" value="" size="10" />
    <label>&nbsp;Operator 6:&nbsp;</label><input type="text" name="op6" value="" size="10" /> 
    <label>&nbsp;Operator 7:&nbsp;</label><input type="text" name="op7" value="" size="10" />
    <label>&nbsp;Operator 8:&nbsp;</label><input type="text" name="op8" value="" size="10" />
    <label>&nbsp;Operator 9:&nbsp;</label><input type="text" name="op9" value="" size="10" />
	<br /><br /><center><h2>Fields You Want To Log </h2></center><br />
	<label>&nbsp;&nbsp;&nbsp;&nbsp;RST Send:&nbsp;</label><input name="logrstsnd" type="text" value="N" size="1" maxlength="1"/>
	<label>&nbsp;&nbsp;&nbsp;&nbsp;RST Get:&nbsp;</label><input name="logrstrcv" type="text" value="N" size="1" maxlength="1"/>
    <label>&nbsp;&nbsp;&nbsp;&nbsp;ARRL Sect:&nbsp;</label><input type="text" name="logsect" value="N" size="1" maxlength="1" />
    <label>&nbsp;&nbsp;&nbsp;&nbsp;Class:&nbsp;</label><input type="text" name="logclass" value="N" size="1"  maxlength="1"/> 
    <label>&nbsp;&nbsp;&nbsp;&nbsp;ITU Zone:&nbsp;</label><input type="text" name="logzone" value="N" size="1"  maxlength="1"/>
    <label>&nbsp;&nbsp;&nbsp;&nbsp;ITU Region:&nbsp;</label><input type="text" name="logregion" value="N" size="1"  maxlength="1"/>
    <label>&nbsp;&nbsp;&nbsp;&nbsp;Grid:&nbsp;</label><input type="text" name="loggrid" value="N" size="1"  maxlength="1"/>
    <label>&nbsp;&nbsp;&nbsp;&nbsp;Date:&nbsp;</label><input type="text" name="logdate" value="N" size="1"  maxlength="1"/>
    <label>&nbsp;&nbsp;&nbsp;&nbsp;Time:&nbsp;</label><input type="text" name="logtime" value="N" size="1"  maxlength="1"/>
    <br /><br /> <br /><center><INPUT TYPE="submit" name = "submit" value="Submit Changes to Setup">
	</center></div></form>
[/php]

What you are going to need to do (I think) is change mysql_fetch_array to mysql_fetch_object and then in your tags set the value to your sql data…

[php]
// Get a specific result from the “example” table
$result = mysql_query(“SELECT * FROM myinfo
WHERE id=‘1’”) or die(mysql_error());

// get the first (and hopefully only) entry from the result
$row = mysql_fetch_object( $result );

/*
This is an example of what one input in your phone will look like
*/

[/php]

I believe this is what you are asking… if not please elaborate

Thanks for the reply.

I have the table created and the data in it. What I want to do is load the data into my form so that it can be changed and put back in to the record in the database.

I removed the code to write the record back to save space and confusion. All I want this snipet to do is get the stored variables and put them in the form.

Dave

OK I got it working, but how do I get the value of the selections back? For example the band???

This is what I have done in the past for that…

[php]
    Band:

         <optgroup label="Current">
    	<option value="<?php echo $row->band; ?>"><?php echo $row->band; ?></option>
        </optgroup>

            <option value="0"></option>
    	<option value="1">ALL</option>
        <option value="2">160M</option>
        <option value="3">80M</option>
        <option value="4">40M</option>
        <option value="5">20M</option>
        <option value="6">15M</option>
    <option value="7">10M</option>
      </select></label>

[/php]

That code is giving me a current in the list and a 0 for the value in the box. It should return the value in the record and translate ti to the right selection.

did you change the php to match your sql query?

I changed it to look exactly as you sain:
[php]
    Band:


<?php echo $row->band; ?>

ALL
160M
80M
40M
20M
15M
10M

[/php]

It should work assuming your query is correct.

If the column name is not “band” in your table then you need to replace it with the correct name.

Ok, I got it working by changing the “#” to “something”.

Thanks, One last Question, how do I bump up your Karma?

I have another question on a different topic which I will start another topic for.

Thanks again and Merry Christmas! :smiley:

Underneath my picture there should be a +

Merry Christmas to you too

It says Karma: +2/-0 but they are not clickable.

just beneath that line click the plus sign

karma: +2/-0
[ + ] [ - ]

I see:
Posts: 112
Karma: +2/-0

But I have nothing clickable :frowning:

Beneath the + sign I have an email

http://www.phphelp.com/forum/index.php?action=modifykarma;sa=applaud;uid=46064;topic=18901.0;m=65609;debb8a5e7ca=90c4ac53797b137d243bf639569388de

Try that like, if it doesn’t work, oh well. I appreciate the effort

I believe you need 25 posts to submit karma. I added one for you mdahlke

Sponsor our Newsletter | Privacy Policy | Terms of Service