Updating data in a mysql table [closed] - php

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
I am trying to code a website where users have profile pages. I want them to be able to edit their profile information that they have already entered. But there is an about me section where users are expected to include a large amount of detail about themselves.
I have used the SQL UPDATE statement which works fine to override the data which is already there but I'm wondering if there is a way to extract the data that is there and allow the user to edit this and then post the updated version back to the table?
Any help on an approach to this would be great.

You simply have to make a SELECT to display user infos on their user page and incorporate the values into a form, and then you will handle the form to update the datas (either in the same php file or another one)
I suggest you to visit this tutorial : Create user editing area

The below code fetch the user info from the database and display it in a form.
<?php $sql = "SELECT * FROM user_table where username = '$username'";
$query = mysqli_query($database_connection, $sql);
$fetch = mysqli_fetch_assoc($query);
echo "<form action='update_user_info.php' method='post'>
<input type='text' name='full_name' value='$fetch['full_name']' >
<input type='text' name='address' value='$fetch['address']' >
<textarea title='about' name='about'>$fetch['about_user']</textarea>
<input type='submit' name='btn_update' value='Save'>
</form>?>
Here is what the update_user_info will look like.
<?php $sql = "UPDATE user_table SET full_name = '$_POST['full_name']' WHERE username = '$username'";
$query = mysqli_query($database_connection, $sql);
//I hope you can find your way from here ?>

Related

Having issues with Select statement in PHP script [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
Ok so I am having issues selecting the data I want from the table in MySQL. The database connection is successful and active, I started a session before anything else, and the Session is created on login and working. The issue is this pice of code and I can't seem to figure it out.
$sql = 'SELECT * FROM Authentication WHERE `id` LIKE ('.$_SESSION['id'].')';
Any help would be appreciated.
I would do like so:
<?php
$session = $_SESSION['id'];
$sql = "SELECT * FROM Authentication WHERE `id` LIKE '%$session%'";
?>
However, as #nody says, if your id is an integer use equal to operator instead of LIKE.
Try this:
$sql = 'SELECT * FROM Authentication WHERE `id` LIKE '".$_SESSION['id']."'';
first of all check ur table name correct or not.
Check your Authentication table id column data type.
if it is varchar ,it should be
$sql = 'SELECT * FROM Authentication WHERE `id` LIKE "'.$_SESSION['id'].'"';
if it is Integer
$sql = 'SELECT * FROM Authentication WHERE `id` LIKE '.$_SESSION['id'];
see this for more
http://dev.mysql.com/doc/refman/5.0/en/pattern-matching.html

Making posts,getting data from mysql table [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
how i can make example: post.php and when somebody goes to post.php to show all posts and when somebody click on one post to show in URL post.php?id=1(id=1 by id in database? and when it types post.php?id=2 to go to id 2 in database and show all datas from row of table by id 2)
Use the $_GET method to pass the url. At the top of the php file you can access the information posted in the url using the global $_GET['id']. You can check if it is set, and depending on whether or not it is, show information regarding that id from the database.
It might look something like this:
if (isset($_GET["id"])) {
$id = $_GET["id"];
$query = "SELECT * table WHERE id = {$id} LIMIT 1;";
$result = mysqli_query($connection, $query);
while ($row = mysqli_fetch_assoc($result)){
echo $row["id"];
echo $row["name"];
echo $row["someOtherAttribute"];
}
}
Make sure you have your connection and your database set up and whatnot, but thats how you would accomplish this.

How to print data from SQL database to HTML table based on query [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
so I have records in my database that I would like to print to a HTML table IF they belong to the user.
$sql="SELECT * FROM ".$tbl_name." WHERE Username='".$username."'";
The table would read :
Date, Room, Period , Cancel
With cancel being a red cross designed to delete that specific entry from the database :
Booking ID, Date, Period,Type,RoomID, Username are the fields in the database.
How would I go about doing this? I was thinking echoing a table using a for loop but I wouldn't know where to begin?
Try:
$query_rsSearch = "SELECT * FROM ".$tbl_name." WHERE Username='".$username."'";
$rsSearch = mysql_query($query_rsSearch) or die(mysql_error());
$row_rsSearch = mysql_fetch_assoc($rsSearch);
$totalRows_rsSearch = mysql_num_rows($rsSearch);
do {
echo $row_rsSearch['Date']." | ".$row_rsSearch['Room']." | ".$row_rsSearch['Period'];
} while($row_rsSearch = mysql_fetch_assoc($rsSearch));

PHP to input email to database [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 9 years ago.
Improve this question
This is the site that I am trying to create the script for http://facechat.louisdickinson.com/
The idea is people can save there email to my database, and another button called "Start Call" will randomly select a email and call it using:
facetime://email#email.com
Effectively this will create a "omegle" style web-based facetime chat site.
I am new to MySQL and PHP and don't know where to start, any help will be appreciated!
I don't know, what kind of help do you need.. First of all, you should have a php script, witch can take the posted name/e-mail pair.
In this script, you should sanitize the posted values, than you can add it to your database with the following:
$query = "INSERT INTO <tableName> (`name`, `e-mail`) VALUES ( '".$postedName."', '".$postedMail."' )";
On button press, you should have another php script, for selecting the random e-mail:
$query = "SELECT COUNT(*) FROM <tableName>";
$max should be the query result.
$random = rand( 0 , $max - 1 );
$query = "SELECT `e-mail` FROM <tableName>" LIMIT $random, 1";
With this query you got a random e-mail.
Do you need more exact code? Please be more exact on what you need!
Kind regards,
hotzu
In php:
mysql_connect("host", "user", "password") or die(mysql_error());
mysql_selectdb("database"); // '' for an auto increment column
mysql_query("INSERT INTO TABLE VALUES ('$email', ''));
And for more info http://www.w3schools.com/php/php_mysql_intro.asp

How to Get Mysql Field Data [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I have a registration system , username, password, email id are stored in a table, how can i export or get all email ids of all my registered users in Phpmyadmin itself (or any other way).
Run query
select email_id from users
Then use export feature of phpmyadmin.After you run the query, click the export link and you can export the query result in many different formats (e.g CSV, Excel, Word...)
Please change table and column names according to you.
try this>>
$sql = "select email_id from table_name";
$result = mysql_query($sql);
$email_collector = array();
while( $row = mysql_fetch_assoc($result) ){
//store email in array
$email_collector[] = $row['email_id'];
}
print_r($email_collector);
Change email_id and table_name according to your database
If you want to get list of users and their email in a text file try the below query
SELECT username, email INTO OUTFILE 'data.txt'
FIELDS TERMINATED BY ','
LINES TERMINATED BY '\n'
FROM table2;

Categories