Page 1 of 1

checking db for data then doing one of two things.

Posted: Fri Oct 10, 2003 11:28 am
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.

?>

Posted: Fri Oct 10, 2003 12:53 pm
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?

Posted: Fri Oct 10, 2003 1:34 pm
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?

Posted: Fri Oct 10, 2003 2:37 pm
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

Posted: Fri Oct 10, 2003 3:04 pm
by Cruzado_Mainfrm
i think u have to use

Code: Select all

<?php
extract($_POST);
?>

Posted: Sat Oct 11, 2003 3:28 am
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">";
    } 
}

?>