checking db for data then doing one of two things.

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
chaza
Forum Newbie
Posts: 10
Joined: Fri Oct 10, 2003 11:28 am

checking db for data then doing one of two things.

Post by chaza »

I am having trouble getting this to work and it's driving me nuts!

Code: Select all

<?php

$conn = mysql_connect("localhost","******","*******");
$db = mysql_select_db("*******");

$result = MYSQL_QUERY("SELECT realname, member from users WHERE realname='$realname' and member='$member'") or die ("Name and membership number not found or not matched");
$worked = mysql_fetch_array($result);
$realname = $worked[realname];
$member = $worked[member];

?>

Code: Select all

&lt;form action="&lt;? echo $_SERVER&#1111;'PHP_SELF']; ?&gt;" method="post" id="register"&gt;
&lt;input type="text" name="realname" size="20" maxlength="30" value="name" class="clear"  /&gt;&lt;br /&gt;
&lt;input type="text" name="member" size="20" value="membership no." maxlength="15" class="clear"  /&gt;&lt;br /&gt;
username desired: &lt;br /&gt;
&lt;input type="text" name="username" size="20" maxlength="30" class="clear" value="" /&gt;&lt;br /&gt;
password desired: &lt;br /&gt;
&lt;input type="password" size="20" maxlength="30" name="password" value="" /&gt;&lt;br /&gt;
&lt;input type="submit" name="update" value="enter" /&gt;
&lt;/form&gt;

Code: Select all

<?
 
 if ( isset( $_POST['update'] ) ) {

if (( $_POST['realname'] == $realname) && ( $POST['member'] == $member)) {

  $sql = "UPDATE users SET username='".$_POST['username']."', password='".( $_POST['password'] )."' WHERE member='".$_POST['member']."'";

  mysql_query( $sql ) or die( mysql_error( ) );
  
writeMessage($message);

echo "<meta content="2; url=index.php" http-equiv="refresh">";  

}
 

if (( $_POST['realname'] != $realname) OR ( $POST['member'] != $member))   {

 echo "<meta content="0; url=nomatch.php" http-equiv="refresh">";

}
}
?>
Basically it's supposed to allow users to set their username and password if they have entered their name and member no. ( which are already defined )
If the name and/or member have not been entered correctly then it redirects to nomatch.php
If the name and member have been entered correctly the username and password get entered in the db and redirect to index.php
Well that's the idea but it's not working and I can't figure out why.

?>
User avatar
xisle
Forum Contributor
Posts: 249
Joined: Wed Jun 25, 2003 1:53 pm

Post by xisle »

I generally do not test other scripts because of time, tell us what happens or doesn't when you run it and maybe we can help..
any errors?
chaza
Forum Newbie
Posts: 10
Joined: Fri Oct 10, 2003 11:28 am

Post by chaza »

At the moment what is happening is all entries in the input are being brought to nomatch.php
the scripts seem to work separetly but maybe it is the way I have put them together?
Cruzado_Mainfrm
Forum Contributor
Posts: 346
Joined: Sun Jun 15, 2003 11:22 pm
Location: Miami, FL

Post by Cruzado_Mainfrm »

why do you expect $realname and $member to be equal to it's key in the $_POST[]

this is just not right:

Code: Select all

<?php
if (( $_POST['realname'] == $realname) && ( $POST['member'] == $member)) { 
?>
that won't work unless you have register_globals to true in the php.ini
Cruzado_Mainfrm
Forum Contributor
Posts: 346
Joined: Sun Jun 15, 2003 11:22 pm
Location: Miami, FL

Post by Cruzado_Mainfrm »

i think u have to use

Code: Select all

<?php
extract($_POST);
?>
chaza
Forum Newbie
Posts: 10
Joined: Fri Oct 10, 2003 11:28 am

Post by chaza »

I got this working now by doing:

Code: Select all

<?php
if ( isset( $_POST['update'] ) ) {
  $sql = "SELECT realname, member FROM users WHERE realname='".$_POST['realname']."' AND member='".$_POST['member']."'";
  $result = mysql_query( $sql ) or die( mysql_error( ) );
  $worked = mysql_fetch_array( $result );
  
  if ( $worked ) {
     $sql = "UPDATE users SET username='".$_POST['username']."', password='".( $_POST['password'] )."' WHERE member='".$_POST['member']."'";
      mysql_query( $sql ) or die( mysql_error( ) );


 echo "<meta content="0; url=index.php" http-equiv="refresh">";

}
 else {
 
// if ( ( $_POST['realname'] != $worked['realname'] ) or ( $_POST['member'] != $worked['member'] ) ) {


 echo "<meta content="0; url=nomatch.php" http-equiv="refresh">";
    } 
}

?>
Post Reply