Page 1 of 1

PHP/MySQL Question

Posted: Thu May 30, 2002 9:09 pm
by KiLlEr_TaCo
Hey, I'm working on making a little "staff only" section of my site where the staff (aka members) can update their profile (i.e. username, password, etc) but for some reason I can't get the mysql UPDATE command to work. I'm a bit of a newbie so this might be a stupid question to most of you, but anyways. It keep telling me that the information was edited, but when I check the db nothing has changed.

Here's edit1.php:

Code: Select all

<?

$db=mysql_connect("localhost","root","password"); 
mysql_select_db("staff",$db); 

$login=mysql_query("select * from staff WHERE usrname='$loggedin&#1111;usr]' LIMIT 1", $db)
  or die(mysql_error());
  
$rows=mysql_fetch_array($login);

?>
<form action="edit2.php" method="post">
UserName: <input type="text" name="username" value="<? echo $rows&#1111;usrname] ?>">
<br>
Password: <input type="text" name="password" value="<? echo $rows&#1111;password] ?>">
<br>
Real Name: <input type="text" name="rlname" value="<? echo $rows&#1111;rlname] ?>">
<br>
E-Mail: <input type="text" name="email" value="<? echo $rows&#1111;email] ?>">
<br>
Location: <input type="text" name="location" value="<? echo $rows&#1111;location] ?>">
<br>
<input type="hidden" name="oun" value="<? echo $rows&#1111;usrname] ?>">
<input type="submit" name="submit" value="Edit Info">
Edit2.php:

Code: Select all

<?
$db=mysql_connect("localhost","root","password"); 
mysql_select_db("staff",$db); 
  
$login="UPDATE staff SET usrname='$username', password='$password', rlname='$rlname', email='$email', location='$location' where usrname='$_POST&#1111;oun]'";

echo "Thank you, your information was successfully updated $usrname.";

?>
Ok, this is probably completely wrong but I was just messing around with taking things out and adding things in, so feel free to edit as much code as needed to get this working. Thanks.

Posted: Thu May 30, 2002 9:16 pm
by volka
Edit2.php:
insert a print($login); to your script to check the string
and: is it a copy&paste error or is there no mysql_query for this?

you really should write $array['index'] instead of $array[index]

Posted: Thu May 30, 2002 10:34 pm
by jason
KiLlEr_TaCo:

Um..you forgot a mysql_query() function on Edit2.php

Posted: Fri May 31, 2002 3:10 am
by mikeq
echo "Thank you, your information was successfully updated $usrname.";

would that work? where is $usrname set, would it not be $_POST['oun'] or $_POST['username'] which is the name of the field on the Edit1.php?

and

Why are you using a mixture of $_POST variables and things like $username, if you NEED to use $_POST variables then I suggest you keep things consistant.

Mike