Welcome to Dream.In.Code
Getting PHP Help is Easy!

Join 132,688 PHP Programmers for FREE! Get instant access to thousands of PHP experts, tutorials, code snippets, and more! There are 1,291 people online right now. Registration is fast and FREE... Join Now!




Comparing Form data to table

 
Reply to this topicStart new topic

Comparing Form data to table

rjolitz
post 25 May, 2008 - 04:39 PM
Post #1


D.I.C Head

Group Icon
Joined: 17 May, 2008
Posts: 86



Thanked 1 times

Dream Kudos: 75
My Contributions


I'm sure you all are tired of me already however.... here I go again smile.gif

I've stuck my rather long code at the bottom of this. But reader's digest condensed version:

I'm setting up a registration form. I want query the user table to see if the user name already exists and if not then exit. If the user name is available then check a ship name to see if it already exists. Both fields are set to unique in the table btw. There are no records in the table at present.

However, no matter what I put in it tells me the user name is not available. Which I know it should be. I put in echo checks to ensure the form data is being passed and the correct values are being shown so the $_POST info is setting the variable.

This is the snippet of code that I am doing the check with

CODE

$query=" SELECT * FROM users WHERE `user_name` = '$user'";

$mysqli->query($query);

$result=$mysqli->query($query, MYSQLI_STORE_RESULT);

if (!$result) {
  printf("Invalid query: %s", $mysqli->error);
exit();
}

$row=$result->fetch_object();

$row_user_name=$row->user_name;

if ($row_user_name = $user)
  {
printf("Sorry but character name %s is already taken.", $user);
exit();
}


I am using a similar version to check the ship name.

The syntax from the reference books I have seems to be correct but obviously something is horribly wrong. The $row_user_name and $row_vessel_name variables should both have nothing in them from the empty table.

Am I on the right track here?






Here is the full code leaving out the stupid long list of variables.


CODE

if ($password != $confirm)
  {  
     print("<span style='color:red'>ERROR: Passwords do not match! </span>");
  }

   $mysqli = new mysqli($host, $dbuser, $pw, $db);
  
    if ( $mysqli->errno)
   {
      printf("Unable to connect to the database: <br />  %s", $mysqli->error);
      exit();
    }


$query=" SELECT * FROM users WHERE `user_name` = '$user'";

$mysqli->query($query);
$result=$mysqli->query($query, MYSQLI_STORE_RESULT);

if (!$result) {
  printf("Invalid query: %s", $mysqli->error);
exit();
}

$row=$result->fetch_object();

$row_user_name=$row->user_name;



if ($row_user_name = $user)
  {
printf("Sorry but character name %s is already taken.", $user);
exit();
}


$query=" SELECT * FROM users WHERE `vessel_name` = '$vessel_name'";

$mysqli->query($query);
$result=$mysqli->query($query, MYSQLI_STORE_RESULT);

if (!$result) {
  printf("Invalid query: %s", $mysqli->error);
exit();
}

$row=$result->fetch_object();

$row_vessel_name=$row->vessel_name;

if ($row_vessel_name = $vessel_name)
{
    printf("Sorry but there is already a vessel named %s.", $vessel_name);
    exit();
}
    
$query="INSERT INTO users (`user_name`, `password`, `rank`, `affiliation`, `admin`, `subscription`, `beta_test`, `email`, `country`, `points`, `wins`, `losses`, `vessel_name`, `pos_x`, `pos_y`, `class`, `point_value`, `shield`, `max_shield`, `heavy_weapon`, `max_heavy_weapon`, `main_phaser`, `max_main_phaser`, `defensive_phaser`, `max_defensive_phaser`, `hull`, `max_hull`, `lab`, `max_lab`, `trans`, `max_trans`, `bridge`, `max_bridge`, `sub_light_engines`, `max_sub_light_engines`, `auxillary_power`, `max_auxillary_power`, `battery_power`, `max_battery_power`, `small_craft`, `max_small_craft`, `extra_damage`, `max_extra_damage`, `light_engines`, `max_light_engines`, `NOT_USED`, `NOT_USED1`, `NOT_USED2`, `NOT_USED3`, `NOT_USED4`, `NOT_USED5`, `NOT_USED6`, `NOT_USED7`, `NOT_USED8`, `NOT_USED9`, `NOT_USED10`, `NOT_USED11`)  VALUES ('$user',
'$password',
'$confirm',
'$faction',
'$email',
'$vessel_name',
'$rank',
'$admin',
'$subscription',
'$beta_test',
'$class',
'$country',
'$points',
'$wins',
'$losses',
'$point_value',
'$pos_x',
'$pos_y',
'$shield'
'$max_shield',
'$heavy_weapon',
'$max_heavy_weapon'
'$main_phaser',
'$max_main_phaser',
'$defensive_phaser',
'$max_defensive_phaser',
'$hull',
'$max_hull',
'$lab',
'$max_lab',
'$trans',
'$max_trans',
'$bridge',
'$max_bridge',
'$sub_light_engines',
'$max_sub_light_engines',
'$auxillary_power',
'$max_auxillary_power',
'$battery_power',
'$max_battery_power',
'$small_craft',
'$max_small_craft',
'$extra_damage',
'$max_extra_damage',
'$light_engines',
'$max_light_engines',
'$NOT_USED',
'$NOT_USED1',
'$NOT_USED2',
'$NOT_USED3',
'$NOT_USED4',
'$NOT_USED5',
'$NOT_USED6',
'$NOT_USED7',
'$NOT_USED8',
'$NOT_USED9',
'$NOT_USED10',
'$NOT_USED11');";

$mysqli->query($query);

$result=$mysqli->query($query);

if (!$result) {
  printf("Invalid query: %s", $mysqli->error);
exit();
}



}


?>

User is offlineProfile CardPM

Go to the top of the page

rjolitz
post 25 May, 2008 - 04:57 PM
Post #2


D.I.C Head

Group Icon
Joined: 17 May, 2008
Posts: 86



Thanked 1 times

Dream Kudos: 75
My Contributions


QUOTE(rjolitz @ 25 May, 2008 - 05:39 PM) *

I'm sure you all are tired of me already however.... here I go again smile.gif

I've stuck my rather long code at the bottom of this. But reader's digest condensed version:

I'm setting up a registration form. I want query the user table to see if the user name already exists and if not then exit. If the user name is available then check a ship name to see if it already exists. Both fields are set to unique in the table btw. There are no records in the table at present.

However, no matter what I put in it tells me the user name is not available. Which I know it should be. I put in echo checks to ensure the form data is being passed and the correct values are being shown so the $_POST info is setting the variable.

This is the snippet of code that I am doing the check with



Please disregard.

I did something very stupid and finally found it after I posted this.

Rich
User is offlineProfile CardPM

Go to the top of the page

Fast ReplyReply to this topicStart new topic
Time is now: 11/23/08 07:31AM

Live PHP Help!

PHP Tutorials

Reference Sheets

PHP Snippets

Bye Bye Ads

Free DIC T-Shirt

T-Shirt Example

Related Sites

Monthly Drawing

Thumb Drive

Partners

Top Contributors

Top 10 Kudos This Month