Jump to content

Recommended Posts

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 form

I 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 etc

Thanks in advance

Ross
Link to comment
https://forums.phpfreaks.com/topic/31225-solved-php-mysql-help/
Share on other sites

OK, in that case, it should be as simple as this:

[code]<?php
// connect to db
include('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 form
echo '<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]

Regards
Huggie
Link to comment
https://forums.phpfreaks.com/topic/31225-solved-php-mysql-help/#findComment-144437
Share on other sites

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.

Regards
Huggie
Link to comment
https://forums.phpfreaks.com/topic/31225-solved-php-mysql-help/#findComment-144441
Share on other sites

I get the message : Can't execute : Query was empty

this 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 form
echo '<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>';
?>
Link to comment
https://forums.phpfreaks.com/topic/31225-solved-php-mysql-help/#findComment-144454
Share on other sites

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.

Regards
Huggie
Link to comment
https://forums.phpfreaks.com/topic/31225-solved-php-mysql-help/#findComment-144461
Share on other sites

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
Link to comment
https://forums.phpfreaks.com/topic/31225-solved-php-mysql-help/#findComment-144475
Share on other sites

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.