Jump to content
xisto Community
coldasice

[mysql/php]need Som Basic Help

Recommended Posts

<?phpsession_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>
";

?
Edited by coldasice (see edit history)

Share this post


Link to post
Share on other sites

try moving $username above before your update query like this

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

Share this post


Link to post
Share on other sites

try moving $username above before your update query like this

WHERE username = '$username'"; linenums:0'>$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 :D so all go blank :P

Share this post


Link to post
Share on other sites

this just delete the whole row in my user name :D so all go blank :P


post your other code too

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

and also include your database table layout

Share this post


Link to post
Share on other sites
<?/** * 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

Share this post


Link to post
Share on other sites

try this

$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 linkecho "<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

Share this post


Link to post
Share on other sites

try this



$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";

linenums:0'>$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 linkecho "<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 :P it still deletes the whole username row ;/

Share this post


Link to post
Share on other sites

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

$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";

Edited by sonesay (see edit history)

Share this post


Link to post
Share on other sites

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



$all = mysql_fetch_array($query);

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

echo "$email";
echo "$msn";
echo "$info";
linenums:0'>$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";

well as far as i register.. the update querry dont do *BLEEP*.......

and i moved echo.. dosnt work ;O

Share this post


Link to post
Share on other sites

the query update looks ok to me. The only reasons it wont update is if there is no record to update, If there is error because of wrong field names etc the error should return.I would check and make sure $username is assigned when used in your query, and check your database it self. say if you want to update user 'bob' check if 'bob' exist in users and 'bob' is assigned properly to $username before doing query, maybe output it just to test on the screen. I cant think of any other reasons why it will not work if its not givng back any errors.Also try to remember to assign your variables before attempting to use it. It wont work if you try and use $username and you actually assign it futher down the code because it will be blank when you are calling it before.

Edited by sonesay (see edit history)

Share this post


Link to post
Share on other sites

the query update looks ok to me. The only reasons it wont update is if there is no record to update, If there is error because of wrong field names etc the error should return.
I would check and make sure $username is assigned when used in your query, and check your database it self. say if you want to update user 'bob'

check if 'bob' exist in users and 'bob' is assigned properly to $username before doing query, maybe output it just to test on the screen. I cant think of any other reasons why it will not work if its not givng back any errors.

Also try to remember to assign your variables before attempting to use it. It wont work if you try and use $username and you actually assign it futher down the code because it will be blank when you are calling it before.



well i replaced $username with my username... coldasice... as in db.. and it still wouldnt work :D

well all i can say is that update dosnt work :D


<?phpsession_start();
include "database.php";
include "edit.inc.php";

if (!$_SESSION["valid_user"])
{
// User not logged in, redirect to login page
Header("Location: main.php");
}

$username = $_SESSION["username"];
if(isset($_POST['submit'])){

$email2 = $_POST['email'];
$msn2 = $_POST['msn'];
$info2 = $_POST['info'];

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

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

echo "info updated";
}

echo "$username";
echo "$email";

$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>
";

echo "<p><a href=\"member.php\">Click here to go back to info page!</a></p>";
?>



this is my current code

yes phpmyadmin.. is what i use evry time i press submit..

well.. i go pms.. and insert email = asdasdasd info = asdasdasdasdasdasdasdasdasdasdasdasdasdasdasdasdsadasdasda

and then i go to edit.php.. and all is there.. then i press submit... boom.. all emty.. it emptyes.. my damn row where the user name is inserted...................

now my guess is that its somthing wrong with update :P
Edited by coldasice (see edit history)

Share this post


Link to post
Share on other sites
$username = $_SESSION["username"];
have you tried single quotes here?

Basic debugging would suggest that you display (print) the data in the query before and after the query, along with the results of the query after the select. This will confirm the values the query is using, and the results it is getting.

And does the select work correctly in phpmyadmin?

Share this post


Link to post
Share on other sites

i need some bigger glasses :P

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

change the name='' to the corret names

<td width='160'><input tabindex=1 type=text name='email' value='$email' style='width:150;'></td></tr><tr><td>MSN: </td><td><input type=text name='msn' value='$msn' style='width:150'></td></tr><tr><td>Info: </td><td><textarea rows=\"10\" cols=\"45\" name='info' >$info</textarea></td>

man this is what happens when you ignore the obvious

Edited by sonesay (see edit history)

Share this post


Link to post
Share on other sites

$username = $_SESSION["username"];
have you tried single quotes here?

 

Basic debugging would suggest that you display (print) the data in the query before and after the query, along with the results of the query after the select. This will confirm the values the query is using, and the results it is getting.

 

And does the select work correctly in phpmyadmin?


thanks for ur respons.. but.. lol ;O that dont help =D and yeah.. its a part of a learning login.. so basicly my username is in the session :D thanks for trying :D

 

and its solved here is code =D

 

 

 

 

and thank to you sonesay. for helping me =D

 

this happende bcouse i made the thig from scratch.. but..... i got some kind of error.. but i dont remember what error it was...

 

so i found some boxes on net.. and copyed source and edited it to fit what i wanted.. :P

 

and just so you know be4 u posted.. i solved this.. i got fed up.. and saw trough code. and saw it..

 

 

<?phpsession_start(); include "database.php";if (!$_SESSION["valid_user"]){// User not logged in, redirect to login pageHeader("Location: main.php");}$username = $_SESSION["username"];if(isset($_POST['submit'])){$email2 = $_POST['email'];$msn2 = $_POST['msn'];$info2 = $_POST['info'];$updateemail = "UPDATE users SET email='$email2', msn='$msn2', info='$info2'  WHERE username='$username'";       mysql_query($updateemail) or die("culd not edit your info");	  	  echo "info updated";}$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=email value='$email' style='width:150;'></td>  </tr>  <tr>  <td>MSN: </td>  <td><input type=text name=msn 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>          </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>";echo "<p><a href=\"member.php\">Click here to go back to info page!</a></p>";?>

[sOLVED]
Edited by coldasice (see edit history)

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...

Important Information

Terms of Use | Privacy Policy | Guidelines | 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.