crmamx Posted February 14, 2011 Share Posted February 14, 2011 The ID field doesn't display the data but it must be there because it was the key for the query. It is an int if that makes any difference. <html> <head> </head> <body> <?php // Connect to database===================================================== include("connect_db.php"); // retrieve form data ====================================================== $id = $_POST['id']; // sending query =========================================================== $query = "SELECT ama,model_name,model_mfg,wingspan,engine,decibels FROM airplanes WHERE id='$id'"; if( !$result = mysql_query($query) ) { echo "<br>Query $query<br>Failed with error: " . mysql_error() . '<br>'; } else { $fetch = mysql_fetch_array( $result ); } // Output form with retrieved data ========================================== ?> <h3>Change the data and then click the CHANGE button</h3><br> <form name="Form51" action="update_db_airplane.php" method="post"> ID #:<input type="text" name="id" value="<?=$fetch[id]?>" /><br> AMA #:<input type="text" name="ama" value="<?=$fetch[ama]?>" /><br> Model Name:<input type="text" name="model_name" value="<?=$fetch[model_name]?>" /><br> Model Mfg:<input type="text" name="model_mfg" value="<?=$fetch[model_mfg]?>" /><br> Wingspan:<input type="text" name="wingspan" value="<?=$fetch[wingspan]?>" /><br> Engine:<input type="text" name="engine" value="<?=$fetch[engine]?>" /><br> Decibels:<input type="text" name="decibels" value="<?=$fetch[decibels]?>" /><br><br> <input name="submit" id="submit" value="CHANGE!" type="submit"> </form> <br> <body> </html> Link to comment https://forums.phpfreaks.com/topic/227680-one-of-my-form-fields-not-displaying-data/ Share on other sites More sharing options...
Pikachu2000 Posted February 14, 2011 Share Posted February 14, 2011 Couple things: First, the short tag syntax, <? and <?= is deprecated, and will end up causing you problems in the future. It would be advisable to always use long <?php open tags, and the full <?php echo rather than <?= If you had error reporting on, you'd see a ton of errors regarding undefined constants. You need to quote array indices when not already enclosed in a quoted string. i.e. <?php echo $fetch['ama']; ?>, otherwise php first looks for them as constants, wasting time and resources before deciding it should treat them as string values. For your original question, you didn't list `id` in the fields that want retrieved in the query, so it won't be present in the $fetch array. Since the query is designed to retrieve only one record, you can either add `id` to the list of fields, or just echo it as $id, since it's already defined. Link to comment https://forums.phpfreaks.com/topic/227680-one-of-my-form-fields-not-displaying-data/#findComment-1174289 Share on other sites More sharing options...
crmamx Posted February 14, 2011 Author Share Posted February 14, 2011 Now I am beginning to wonder if I will ever catch on to php. I assumed (I know, never assume anything) that since id was available in the POST command I could echo it. Except, whoops, I am echoing FETCH...damn. Have noted your other two suggestions and will change them in my other 3 programs also. Pikachu, could you please take a look at "Something other than the standard form" posted under HTML Help. Thanks again. Link to comment https://forums.phpfreaks.com/topic/227680-one-of-my-form-fields-not-displaying-data/#findComment-1174295 Share on other sites More sharing options...
Pikachu2000 Posted February 14, 2011 Share Posted February 14, 2011 I will later this evening. Almost dinner time now . . . Link to comment https://forums.phpfreaks.com/topic/227680-one-of-my-form-fields-not-displaying-data/#findComment-1174297 Share on other sites More sharing options...
crmamx Posted February 15, 2011 Author Share Posted February 15, 2011 I see where the error was and made the change but still not displaying id. Once again, id is an integer. Is that it? <html> <head> </head> <body> <?php // Connect to database===================================================== include("connect_db.php"); // retrieve form data ====================================================== $id = $_POST['id']; // sending query =========================================================== $query = "SELECT id,ama,model_name,model_mfg,wingspan,engine,decibels FROM airplanes WHERE id='$id'"; if( !$result = mysql_query($query) ) { echo "<br>Query $query<br>Failed with error: " . mysql_error() . '<br>'; } else { $fetch = mysql_fetch_array( $result ); } // Output form with retrieved data ========================================== ?> <h3>Change the data and then click the CHANGE button</h3><br> <form name="Form51" action="update_db_airplane.php" method="post"> // <?php echo $fetch['ama']; ?> ID #:<input type="text" name="id" value="<?php echo $fetch['id']; ?>" /><br> AMA #:<input type="text" name="ama" value="<?php echo $fetch['ama']; ?>" /><br> Model Name:<input type="text" name="model_name" value="<?php echo $fetch['model_name']; ?>" /><br> Model Mfg:<input type="text" name="model_mfg" value="<?php echo $fetch['model_mfg']; ?>" /><br> Wingspan:<input type="text" name="wingspan" value="<?php echo $fetch['wingspan']; ?>" /><br> Engine:<input type="text" name="engine" value="<?php echo $fetch['engine']; ?>" /><br> Decibels:<input type="text" name="decibels" value="<?php echo $fetch['decibels']; ?>" /><br><br> <input name="submit" id="submit" value="CHANGE!" type="submit"> </form> <body> </html> Link to comment https://forums.phpfreaks.com/topic/227680-one-of-my-form-fields-not-displaying-data/#findComment-1174304 Share on other sites More sharing options...
Pikachu2000 Posted February 17, 2011 Share Posted February 17, 2011 Did you get this sorted out? Link to comment https://forums.phpfreaks.com/topic/227680-one-of-my-form-fields-not-displaying-data/#findComment-1175393 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.