pcw Posted March 28, 2011 Share Posted March 28, 2011 Hi, I have this script which I would like to use to build an html form from a MySQL table. The <input text................ writes successfully to file but none of the other form types are written to file when using the elseif command Also, I would like this script to carry out the file write foreach row in the table It seems complicated and i am not sure if I am going about it in the right way, but here goes //// Create Forms from MySQL $result = mysql_query("SELECT * FROM forms"); while($row = mysql_fetch_assoc($result)){ $field_label = $row['field_label']; $column_name = $row['column_name']; $field_type = $row['field_type']; if ($row['field_type'] = 'Text') { $stringData = "$field_label<input type=text name=$column_name>\n"; fwrite($fh, $stringData); } elseif ($row['field_type'] = 'Text Area') { $stringData = "$field_label<input type=textarea name=$column_name></textarea>\n"; fwrite($fh, $stringData); } elseif ($row['field_type'] = 'Select Menu') { $stringData = "$field_label<select name=$column_name></select>\n"; fwrite($fh, $stringData); } elseif ($row['field_type'] = 'Checkbox') { $stringData = "$field_label<input type=checkbox name=$column_name></textarea>\n"; fwrite($fh, $stringData); } fclose($fh); As always, any help is much appreciated Quote Link to comment Share on other sites More sharing options...
Nudd Posted March 29, 2011 Share Posted March 29, 2011 Were you intending to 'assign' values to $row['field_type'] in your if statements? What's basically happening is you're making the first condition true, and the rest false, simply because you're assigning instead of comparing. = bad == good Unless it was somehow intentional, it's been a long day for me. Quote Link to comment Share on other sites More sharing options...
pcw Posted March 31, 2011 Author Share Posted March 31, 2011 Hi, thanks for your reply. $field_type = $row['field_type']; The above variable is passed from a form to this script. What I want is if the $field_type is text then write this $stringData = "$field_label<input type=text name=$column_name>\n"; whereas if $field_type is textarea then write this $stringData = "$field_label<input type=textarea name=$column_name></textarea>\n"; also if possible, i would like it to retrieve each row from the table and carry out the appropriate action for each of them. Im really stuck on this, but it is essential that it works. Help! lol Quote Link to comment Share on other sites More sharing options...
Nudd Posted March 31, 2011 Share Posted March 31, 2011 Did you fix your assignments to be comparisons? if ($row['field_type'] = 'Text') Will always be true because you're assigning the value, and not making a comparison. This line should read if ($row['field_type'] == 'Text') As should all of the elseifs. == is a proper comparison = is an assignment Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.