bigrossco Posted December 19, 2006 Share Posted December 19, 2006 I am trying to make a form to display results from a MySQL Database but dont know how to do it, what I want is the information from the database to be shown in the form so people can change any details on it i.e. a update formI know how to put data in to the forum and update the databse, but would like the form to show all the user's information on the form sections i.e. Name, Address, Phone Number etcThanks in advanceRoss Quote Link to comment https://forums.phpfreaks.com/topic/31225-solved-php-mysql-help/ Share on other sites More sharing options...
HuggieBear Posted December 19, 2006 Share Posted December 19, 2006 OK, a few simple questions first.[list][*]Do you know how to create HTML forms with default values?[*]Do you know how to retrieve an individual row from your database?[/list]RegardsHuggie Quote Link to comment https://forums.phpfreaks.com/topic/31225-solved-php-mysql-help/#findComment-144428 Share on other sites More sharing options...
bigrossco Posted December 19, 2006 Author Share Posted December 19, 2006 Thanks for getting back[list][*]yes i know how to make forms with default values[*]yes I know how to retreve rows from the database[/list] Quote Link to comment https://forums.phpfreaks.com/topic/31225-solved-php-mysql-help/#findComment-144432 Share on other sites More sharing options...
HuggieBear Posted December 19, 2006 Share Posted December 19, 2006 OK, in that case, it should be as simple as this:[code]<?php// connect to dbinclude('connect.php');// query for the record$sql = "SELECT col1, col2, col3 FROM table WHERE condition = 'value'";$result = mysql_query($sql);// get the details into a single row$row = mysql_fetch_array($result, MYSQL_ASSOC);// echo the formecho '<input type="text" name="column1" value="'. $row['col1'] .'"><br>\n';echo '<input type="text" name="column2" value="'. $row['col2'] .'"><br>\n';echo '<input type="text" name="column3" value="'. $row['col3'] .'"><br>\n';?>[/code]RegardsHuggie Quote Link to comment https://forums.phpfreaks.com/topic/31225-solved-php-mysql-help/#findComment-144437 Share on other sites More sharing options...
bigrossco Posted December 19, 2006 Author Share Posted December 19, 2006 I got the message : Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in C:\wamp\www\CMS-Sys\update.php on line 88and nothing displays just 3 empty box's Quote Link to comment https://forums.phpfreaks.com/topic/31225-solved-php-mysql-help/#findComment-144439 Share on other sites More sharing options...
HuggieBear Posted December 19, 2006 Share Posted December 19, 2006 In that case your sql statement is incorrect...Change this:[code=php:0]$result = mysql_query($sql);[/code] To this:[code=php:0]$result = mysql_query($sql) or die ("Can't execute $sql: " . mysql_error());[/code] And then run it again.RegardsHuggie Quote Link to comment https://forums.phpfreaks.com/topic/31225-solved-php-mysql-help/#findComment-144441 Share on other sites More sharing options...
bigrossco Posted December 19, 2006 Author Share Posted December 19, 2006 I get the message : Can't execute : Query was emptythis is my code: <?php $host = "$lang_dbhost"; $user = "$lang_dbuser"; $pass = "$lang_dbpass"; $db = "$lang_dbase"; // open connection $connection = mysql_connect($host, $user, $pass) or die ("Unable to connect!"); // select database mysql_select_db($db) or die ("Unable to select database!");// query for the record $query = "SELECT * FROM clients WHERE id = '".$_SESSION["search"]."'";$result = mysql_query($sql) or die ("Can't execute $sql: " . mysql_error()); // get the details into a single row$row = mysql_fetch_array($result, MYSQL_ASSOC);// echo the formecho '<input type="text" name="column1" value="'. $row['col1'] .'"><br>';echo '<input type="text" name="column2" value="'. $row['col2'] .'"><br>';echo '<input type="text" name="column3" value="'. $row['col3'] .'"><br>';?> Quote Link to comment https://forums.phpfreaks.com/topic/31225-solved-php-mysql-help/#findComment-144454 Share on other sites More sharing options...
HuggieBear Posted December 19, 2006 Share Posted December 19, 2006 You have the wrong variable name. Change this...[code=php:0]$result = mysql_query($sql) or die ("Can't execute $sql: " . mysql_error());[/code] To this:[code=php:0]$result = mysql_query($query) or die ("Can't execute $sql: " . mysql_error());[/code] Also, you've left all my column names in, you need to change those to your column names.RegardsHuggie Quote Link to comment https://forums.phpfreaks.com/topic/31225-solved-php-mysql-help/#findComment-144461 Share on other sites More sharing options...
bigrossco Posted December 19, 2006 Author Share Posted December 19, 2006 thanks working great nowI take it i will just need to add a submit button and the update query so people can change the info and update it? Quote Link to comment https://forums.phpfreaks.com/topic/31225-solved-php-mysql-help/#findComment-144465 Share on other sites More sharing options...
HuggieBear Posted December 19, 2006 Share Posted December 19, 2006 Yes, that's correct.Don't forget to use the new 'Solved' button to mark this topic as solved.RegardsHuggie Quote Link to comment https://forums.phpfreaks.com/topic/31225-solved-php-mysql-help/#findComment-144471 Share on other sites More sharing options...
bigrossco Posted December 19, 2006 Author Share Posted December 19, 2006 just before I solve it could you tell me the code for updating it, I know you can update records using something like:[code]$query = "UPDATE INTO clients (fullname, date, location) VALUES ('$fullname', '$date', '$location') WHERE id = '".$_SESSION["search"]."'";[/code]But not sure how to put it in to update it, I have the "submit" button added just unsure what to put after that.Thanks again,Ross Quote Link to comment https://forums.phpfreaks.com/topic/31225-solved-php-mysql-help/#findComment-144475 Share on other sites More sharing options...
HuggieBear Posted December 19, 2006 Share Posted December 19, 2006 Sure...[code=php:0]UPDATE table_name SET col1 = 'value1', col2 = 'value2', col3 = 'value3' WHERE condition = 'something'[/code] RegardsHuggie Quote Link to comment https://forums.phpfreaks.com/topic/31225-solved-php-mysql-help/#findComment-144482 Share on other sites More sharing options...
bigrossco Posted December 19, 2006 Author Share Posted December 19, 2006 thanks for that tooke me a few mins to figure out I needed to add some extra code to get it to work fully :) thanks for your helpRoss Quote Link to comment https://forums.phpfreaks.com/topic/31225-solved-php-mysql-help/#findComment-144510 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.