Jump to content

Recommended Posts

Hello, i wish to allow users to update their profile settings.

Here if the code i have so far;

 

<?
include ('inc/global.php');
$query = mysql_query("SELECT * FROM users WHERE username=".$_SESSION['username']);
$result=mysql_query($query);
$num=mysql_numrows($result); 

$about=mysql_result($result,"about");
$interests=mysql_result($result,"interests");
$music=mysql_result($result,"music");
$film=mysql_result($result,"film");
$film=mysql_result($result,"quote");
?>

<form action="updated.php">
<input type="hidden" name="ud_id" value="<? echo $_SESSION['username']; ?>">
About Me: <input type="text" name="ud_about" value="<? echo "$about"?>"><br>
Interests: <input type="text" name="ud_interests" value="<? echo "$interests"?>"><br>
Music: <input type="text" name="ud_music" value="<? echo "$music"?>"><br>
Film: <input type="text" name="ud_film" value="<? echo "$film"?>"><br>
Quote: <input type="text" name="ud_quote" value="<? echo "$quote"?>"><br>
<input type="Submit" value="Update">
</form>

 

Its just showing me the form fields with no data in  :(

 

Any help would be great!

Link to comment
https://forums.phpfreaks.com/topic/50416-solved-updating-users-information/
Share on other sites

<?
include ('inc/global.php');
$query = mysql_query("SELECT * FROM users WHERE username=".$_SESSION['username']);
$result=mysql_query($query);
$num=mysql_num_rows($result); 

$about=mysql_result($result,"about");
$interests=mysql_result($result,"interests");
$music=mysql_result($result,"music");
$film=mysql_result($result,"film");
$film=mysql_result($result,"quote");
?>

<form action="updated.php">
<input type="hidden" name="ud_id" value="<? echo $_SESSION['username']; ?>">
About Me: <input type="text" name="ud_about" value="<? echo "$about"?>"><br>
Interests: <input type="text" name="ud_interests" value="<? echo "$interests"?>"><br>
Music: <input type="text" name="ud_music" value="<? echo "$music"?>"><br>
Film: <input type="text" name="ud_film" value="<? echo "$film"?>"><br>
Quote: <input type="text" name="ud_quote" value="<? echo "$quote"?>"><br>
<input type="Submit" value="Update">
</form>

 

You forgot the underscore "_" in mysql_num_rows.

1. don't use short tags (<?/?>)

2. you re-established the variable film, so it's only going to contain the 'quote', and not the 'film'

3. you don't need to add quotes around a $variable

4. you must have been getting an error because you forgot to put a semicolon `;` after your echo statements

5. you should put single quotes around your where clause

6. your query looks like this: $result = mysql_query(mysql_query($query); that is wrong

7. you need an error handler for your query

 

<?php
include ('inc/global.php');
$sql = "
        SELECT
                *
         FROM
                users
        WHERE
                username = '{$_SESSION['username']}'
";
$result = mysql_query($sql) OR die(mysql_error());

$num=mysql_num_rows($result); 

$about=mysql_result($result,"about");
$interests=mysql_result($result,"interests");
$music=mysql_result($result,"music");
$film=mysql_result($result,"film");
$quote=mysql_result($result,"quote");
?>

<form action="updated.php">
<input type="hidden" name="ud_id" value="<?php echo $_SESSION['username']; ?>">
About Me: <input type="text" name="ud_about" value="<?php echo $about; ?>"><br>
Interests: <input type="text" name="ud_interests" value="<?php echo $interests; ?>"><br>
Music: <input type="text" name="ud_music" value="<?php echo $music; ?>"><br>
Film: <input type="text" name="ud_film" value="<?php echo $film; ?>"><br>
Quote: <input type="text" name="ud_quote" value="<?php echo $quote; ?>"><br>
<input type="Submit" value="Update">
</form>

Thanks Ben, thats smashing, because it worked for pulling out the data!

BUT, i cant get the record to update;

this is the code i am using

 

$query="UPDATE users SET about='$ud_about', interests='$ud_interests', music='$ud_music', film='$ud_film', quote='$ud_quote' WHERE username = '{$_SESSION['username']}'";
mysql_query($query);
echo "Record Updated";
mysql_close();

try this and let me know what you get

 

$username = $_SESSION['username'];
$query="UPDATE users SET about='$ud_about', interests='$ud_interests', music='$ud_music', film='$ud_film', quote='$ud_quote' WHERE username = '$username'";
echo "Query: $query<br>";
mysql_query($query) or die(mysql_error());
echo "Record Updated";
mysql_close();

Ben, i included my session handling

 

<?php
include "include/session.php";
session_start();
header("Cache-control: private");
if (!$_SESSION['username']) {
    echo "You're not logged in!";
    include("index.php");
    exit();
}
?>

 

And your code worked fine!

Thank you very much!

Nick

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.