Welcome Guest ( Log In | Register)



2 Pages V   1 2 >  
Reply to this topicStart new topic
> [mysql/php]need Som Basic Help
coldasice
post Dec 21 2007, 11:21 PM
Post #1


Newbie [Level 2]
**

Group: Members
Posts: 34
Joined: 10-December 07
From: Norway
Member No.: 54,556



QUOTE
<?php
session_start();
include "database.php";
include "edit.inc.php";
if (!$_SESSION["valid_user"])
{
// User not logged in, redirect to login page
Header("Location: main.php");
}
if(isset($_POST['submit'])){

$email = $_POST['email'];
$msn = $_POST['msn'];
$info = $_POST['info'];

$updateemail = "UPDATE users SET email = '$email', msn = '$msn', info = '$info'
WHERE username = '$username'";

mysql_query($updateemail) or die("culd not edit your info");

echo "info updated";
}
// Display logout link
echo "<p><a href=\"member.php\">Click here to go back to info page!</a></p>";

echo "$email";
echo "$msn";
echo "$info";

$username = $_SESSION["username"];

$query = mysql_query("SELECT * FROM users WHERE username='$username'");

$all = mysql_fetch_array($query);

$email = $all['email'];
$msn = $all['msn'];
$info = $all['info'];





echo "
<table width=\"100%\" border=0 cellpadding=1 cellspacing=0>
<form name=login action='$PHP_SELF' method=post>
<tr>

<td width=80>Email: </td>
<td width='160'><input tabindex=1 type=text name=username value='$email' style='width:150;'></td>
</tr>
<tr>
<td>MSN: </td>
<td><input type=text name=password value='$msn' style='width:150'></td>
</tr>
<tr>
<td>Info: </td>
<td><textarea rows=\"10\" cols=\"45\" name=\"'info'\" id=\"'info'\">$info</textarea></td>
</tr>
";
echo "
</tr>
<tr>
<td>
<td colspan=\"3\">
<table border=0 cellspacing=0 cellpadding=0 width=100%>
<tr>
<td width=50%>
<input type=\"submit\" name=\"submit\" id=\"submit\" value=\"submit\" />
</form>
</table>
";
?

This post has been edited by coldasice: Dec 21 2007, 11:22 PM
Go to the top of the page
 
+Quote Post
sonesay
post Dec 21 2007, 11:27 PM
Post #2


|||[ n00b King ]|||
*********

Group: [HOSTED]
Posts: 643
Joined: 20-June 07
From: Auckland
Member No.: 45,102



try moving $username above before your update query like this

CODE
$username = $_SESSION["username"];

$updateemail = "UPDATE users SET email = '$email', msn = '$msn', info = '$info'
WHERE username = '$username'";
Go to the top of the page
 
+Quote Post
coldasice
post Dec 21 2007, 11:34 PM
Post #3


Newbie [Level 2]
**

Group: Members
Posts: 34
Joined: 10-December 07
From: Norway
Member No.: 54,556



QUOTE(sonesay @ Dec 22 2007, 12:27 AM) *
try moving $username above before your update query like this

CODE
$username = $_SESSION["username"];

$updateemail = "UPDATE users SET email = '$email', msn = '$msn', info = '$info'
WHERE username = '$username'";



this just delete the whole row in my user name sad.gif so all go blank sad.gif
Go to the top of the page
 
+Quote Post
sonesay
post Dec 21 2007, 11:36 PM
Post #4


|||[ n00b King ]|||
*********

Group: [HOSTED]
Posts: 643
Joined: 20-June 07
From: Auckland
Member No.: 45,102



QUOTE(coldasice @ Dec 22 2007, 12:34 PM) *
this just delete the whole row in my user name sad.gif so all go blank sad.gif



post your other code too

include "database.php";
include "edit.inc.php";

and also include your database table layout
Go to the top of the page
 
+Quote Post
coldasice
post Dec 21 2007, 11:43 PM
Post #5


Newbie [Level 2]
**

Group: Members
Posts: 34
Joined: 10-December 07
From: Norway
Member No.: 54,556



CODE
<?

/**
* Connect to the mysql database.
*/
$conn = mysql_connect("localhost", "root", "cold") or die(mysql_error());
mysql_select_db('new', $conn) or die(mysql_error());

?>


thats my database..

inc is not a script i was just testing out to see what happened if i made the last part a function ;=)

basilcy the same

it deletes all ;O
Go to the top of the page
 
+Quote Post
sonesay
post Dec 21 2007, 11:46 PM
Post #6


|||[ n00b King ]|||
*********

Group: [HOSTED]
Posts: 643
Joined: 20-June 07
From: Auckland
Member No.: 45,102



try this

CODE

$username = $_SESSION["username"];

if(isset($_POST['submit'])){

$email = $_POST['email'];
$msn = $_POST['msn'];
$info = $_POST['info'];

$updateemail = "UPDATE users SET email = '$email', msn = '$msn', info = '$info'
WHERE username = '$username'";

mysql_query($updateemail) or die("culd not edit your info");

echo "info updated";
}
// Display logout link
echo "<p><a href=\"member.php\">Click here to go back to info page!</a></p>";

echo "$email";
echo "$msn";
echo "$info";



$username = $_SESSION["username"]; before the if statement
Go to the top of the page
 
+Quote Post
coldasice
post Dec 21 2007, 11:51 PM
Post #7


Newbie [Level 2]
**

Group: Members
Posts: 34
Joined: 10-December 07
From: Norway
Member No.: 54,556



QUOTE(sonesay @ Dec 22 2007, 12:46 AM) *
try this

CODE

$username = $_SESSION["username"];

if(isset($_POST['submit'])){

$email = $_POST['email'];
$msn = $_POST['msn'];
$info = $_POST['info'];

$updateemail = "UPDATE users SET email = '$email', msn = '$msn', info = '$info'
WHERE username = '$username'";

mysql_query($updateemail) or die("culd not edit your info");

echo "info updated";
}
// Display logout link
echo "<p><a href=\"member.php\">Click here to go back to info page!</a></p>";

echo "$email";
echo "$msn";
echo "$info";



$username = $_SESSION["username"]; before the if statement


still dont work sad.gif it still deletes the whole username row ;/
Go to the top of the page
 
+Quote Post
sonesay
post Dec 22 2007, 12:01 AM
Post #8


|||[ n00b King ]|||
*********

Group: [HOSTED]
Posts: 643
Joined: 20-June 07
From: Auckland
Member No.: 45,102



what do you mean delete? I only see an update statement and a select statement for displaying. If you get empty fields maybe the mysql database table is empty.

maybe try move the echo after the query is done

CODE


$username = $_SESSION["username"];

$query = mysql_query("SELECT * FROM users WHERE username='$username'");

$all = mysql_fetch_array($query);

$email = $all['email'];
$msn = $all['msn'];
$info = $all['info'];

echo "$email";
echo "$msn";
echo "$info";


This post has been edited by sonesay: Dec 22 2007, 12:03 AM
Go to the top of the page
 
+Quote Post
coldasice
post Dec 22 2007, 12:13 AM
Post #9


Newbie [Level 2]
**

Group: Members
Posts: 34
Joined: 10-December 07
From: Norway
Member No.: 54,556