Jump to content

Up one wall and down another


Go to solution Solved by hansford,

Recommended Posts

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

Link to comment
https://forums.phpfreaks.com/topic/285114-up-one-wall-and-down-another/
Share on other sites

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.

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]5

Warning: mysql_connect(): Access denied for user 'root'@'localhost' (using password: NO) in [/size]/var/www/whos_turn/php/settings_table.php on line [/size]5
Connection Failed[/size]

 

I am using a password, but for security reasons I removed it.

testing.php

settings_table.php

Edited by lonesoac0

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

  • Solution

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
}
?>

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!

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.