lonesoac0 Posted January 5, 2014 Share Posted January 5, 2014 Hello all, I am really new to PHP coding and what it can do. I recently found an example of how to populate HTML select boxes based off of information contained in MySQL tables. After I select and submit from my page I get an error code of just Error. I know that my php code is just telling me something went wrong but I have no idea. At one time I had it to where the PHP form was submitting data but in my table the value was always 0 even though I was selecting different records within the table. Some how I managed to lose that code. I have attached the two php pages that I am trying to pass values from page to another and the MySQL table layouts that I am using. My code will never see the light of the WWW so security is not an issue. showing_table_layout.txt testing.php settings_table.php Quote Link to comment https://forums.phpfreaks.com/topic/285114-up-one-wall-and-down-another/ Share on other sites More sharing options...
hansford Posted January 5, 2014 Share Posted January 5, 2014 make sure you have display errors on at the top of your php pages during debugging - then remove for production environment error_reporting(E_ALL); ini_set('display_errors', '1'); I'll look at your code. Quote Link to comment https://forums.phpfreaks.com/topic/285114-up-one-wall-and-down-another/#findComment-1463964 Share on other sites More sharing options...
TinyI Posted January 5, 2014 Share Posted January 5, 2014 Hey, I've just had a look in your settings_table.php file and at the select box code you have. Line 12: <option value="<php echo $line['table_number'];?>"> <?php echo $line['main_theme'];?> </option> After value=", you're missing the ? before php. So your value bit should be value="<?php ... instead of value="<php. Hope this helps and fixes you problem? If not, let me know. Quote Link to comment https://forums.phpfreaks.com/topic/285114-up-one-wall-and-down-another/#findComment-1463965 Share on other sites More sharing options...
lonesoac0 Posted January 5, 2014 Author Share Posted January 5, 2014 (edited) So, yeah. I added the code of: error_reporting(E_ALL);ini_set('display_errors', '1'); to both of my php pages. I have attached them and the message I now get when I try to reload the settings_table.php page. Deprecated: mysql_connect(): The mysql extension is deprecated and will be removed in the future: use mysqli or PDO instead in[/size]/var/www/whos_turn/php/settings_table.php on line [/size]5Warning: mysql_connect(): Access denied for user 'root'@'localhost' (using password: NO) in [/size]/var/www/whos_turn/php/settings_table.php on line [/size]5Connection Failed[/size] I am using a password, but for security reasons I removed it. testing.php settings_table.php Edited January 5, 2014 by lonesoac0 Quote Link to comment https://forums.phpfreaks.com/topic/285114-up-one-wall-and-down-another/#findComment-1463967 Share on other sites More sharing options...
hansford Posted January 5, 2014 Share Posted January 5, 2014 This section of code - is 'value' a column in your database table - if not it has to be. // Insert data into mysql $sql="INSERT INTO $tbl_name(value) VALUES('$select')"; $result=mysql_query($sql); Also, you will get more help if you post the code instead of attaching files. Post the code in the flow order - meaning, page 1 with any forms that calls another page and so on. Post any error msgs you are getting. Post a better table layout - table name, column1, column2 etc Quote Link to comment https://forums.phpfreaks.com/topic/285114-up-one-wall-and-down-another/#findComment-1463969 Share on other sites More sharing options...
lonesoac0 Posted January 5, 2014 Author Share Posted January 5, 2014 I do have the value field defined in my database table that the php page is pointing to. I will definitely keep you postage advice under advisement for next time. Quote Link to comment https://forums.phpfreaks.com/topic/285114-up-one-wall-and-down-another/#findComment-1463972 Share on other sites More sharing options...
Solution hansford Posted January 5, 2014 Solution Share Posted January 5, 2014 As was mentioned by another member, this code is not right. <?php while ($line = mysql_fetch_array($result, MYSQL_ASSOC)) { ?> <option value="<php echo $line['table_number'];?>"> <?php echo $line['main_theme'];?> </option> <?php } ?> Should be something like: <?php while ($line = mysql_fetch_array($result, MYSQL_ASSOC)) { ?> <option value="<?php echo $line['table_number']; ?>"> <?php echo $line['main_theme'];?></option> <?php } ?> Quote Link to comment https://forums.phpfreaks.com/topic/285114-up-one-wall-and-down-another/#findComment-1463973 Share on other sites More sharing options...
lonesoac0 Posted January 5, 2014 Author Share Posted January 5, 2014 Thank you soo much for pointing out my bad code! I caught the <?php part first time but I 100% missed the other two errors. After those were corrected I actually managed select and submit my data. The information is actually showing correct as well. It is no longer 0's but the actual id field value! Thank you guys! Quote Link to comment https://forums.phpfreaks.com/topic/285114-up-one-wall-and-down-another/#findComment-1463975 Share on other sites More sharing options...
lonesoac0 Posted January 5, 2014 Author Share Posted January 5, 2014 Do I need to mark this string as resolved or anything? Quote Link to comment https://forums.phpfreaks.com/topic/285114-up-one-wall-and-down-another/#findComment-1463976 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.