PHP/MySQL Question

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
KiLlEr_TaCo
Forum Newbie
Posts: 1
Joined: Thu May 30, 2002 9:09 pm

PHP/MySQL Question

Post 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.
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post 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]
Last edited by volka on Thu May 30, 2002 10:53 pm, edited 1 time in total.
jason
Site Admin
Posts: 1767
Joined: Thu Apr 18, 2002 3:14 pm
Location: Montreal, CA
Contact:

Post by jason »

KiLlEr_TaCo:

Um..you forgot a mysql_query() function on Edit2.php
User avatar
mikeq
Forum Regular
Posts: 512
Joined: Fri May 03, 2002 3:33 am
Location: Edinburgh, Scotland

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