Jump to content

Recommended Posts

Personally, I'd try this:

[code]<?php
session_start();
include "connect.php";

// either $username comes from a $_SESSION variable OR from a form, not both,
$username = $_SESSION['username']; // leave in if $username from a SESSION

$username = $_POST['username']; // leave in if $username comes from a form
$clantag = addslashes($_POST['clantag']);
$clanname = addslashes($_POST['clanname']);
$clansite = addslashes($_POST['clansite']);

if (($_POST['clanname'] == "") || ($_POST['clantag'] == "")) {
    echo "Clan Tag and Clan Name are required fields.";
} else {
    $query = "SELECT * FROM clans WHERE clantag='$clantag' OR clanname='$clanname'";
    $result = mysql_query($query) or die("Error: ". mysql_error(). " with query ". $query);
    while($row=mysql_fetch_assoc($result)){
        if($row['clanname'] == 1) {
            echo "The Clan Tag or Clan Name you have chosen are allready in use.";
        } else {
            $query = "INSERT INTO clans (clantag, clanname, clansite) VALUES ('$clantag', '$clanname', '$clansite')";
            $result = mysql_query($query) or die("Error: ". mysql_error(). " with query ". $query);

            $query = "UPDATE users SET clanname='$clanname' WHERE username='$username'";
            $result = mysql_query($query) or die("Error: ". mysql_error(). " with query ". $query);

            $query = "UPDATE users SET clantag='$clantag' WHERE username='$username'";
            $result = mysql_query($query) or die("Error: ". mysql_error(). " with query ". $query);

            $query = "UPDATE users SET rank='Leader' WHERE username='$username'";
            $result = mysql_query($query) or die("Error: ". mysql_error(). " with query ". $query);

            echo "You have sucessfully registered a clan";
        } 
    }
}
?>[/code]

There really isn't any need to have all those UPDATE queries separate, one update of multiple fields would do as well.
i think this is the correct code for mutipull updates not sure someone verify cheers.

[code]

$query = "UPDATE users SET clanname='$clanname' , rank='Leader' , clantag='$clantag'  WHERE username='$username'";
$result = mysql_query($query) or die("Error: ". mysql_error(). " with query ". $query);

[/code]
sorry

[code]
<?php session_start();

include "connect.php";

$username=$_SESSION['username'];


$username=($_POST['username']);
$clantag=($_POST['clantag']);
$clanname=($_POST['clanname']);
$clansite=($_POST['clansite']);

$username=addslashes($username);
$clantag=addslashes($clantag);
$clanname=addslashes($clanname);
$clansite=addslashes($clansite);



if (($_POST['clanname']=="") || ($_POST['clantag']=="")) {

  echo "Clan Tag and Clan Name are required fields.";

}else{

$query = "SELECT * FROM clans WHERE clantag='$clantag' OR clanname='$clanname'";

echo $query;
$result=mysql_query($query);

while($row=mysql_fetch_assoc($result)){

if($row['clanname']==1) {

echo "The Clan Tag or Clan Name you have chosen are allready in use.";

}else{

$add_clan="INSERT INTO clans (clantag, clanname, clansite) VALUES ('$clantag', '$clanname', '$clansite')";
mysql_query($add_clan) or die(mysql_error());

$query = "UPDATE users SET clanname='$clanname' , rank='Leader' , clantag='$clantag'  WHERE username='$username'";
$result = mysql_query($query) or die("Error: ". mysql_error(). " with query ". $query);


echo "You have sucessfully registered a clan";

  }
  }
?>
[/code]
Well before i tried andys code i used redarrow's code and got the output
SELECT * FROM clans WHERE clantag='test' OR clanname='test'

Then when i tried andys code i got no output, and nothing happened with my databases.

Now iv tried redarrow's code and i get the output..
SELECT * FROM clans WHERE clantag='test' OR clanname='test'
Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in C:\wamp\www\league\clanck.php on line 29
sorry $query

edited agin sorry

[code]
<?php session_start();

include "connect.php";

$username=$_SESSION['username'];


$username=($_POST['username']);
$clantag=($_POST['clantag']);
$clanname=($_POST['clanname']);
$clansite=($_POST['clansite']);

$username=addslashes($username);
$clantag=addslashes($clantag);
$clanname=addslashes($clanname);
$clansite=addslashes($clansite);



if (($_POST['clanname']=="") || ($_POST['clantag']=="")) {

  echo "Clan Tag and Clan Name are required fields.";

}else{

$query = "SELECT * FROM clans WHERE clantag='$clantag' OR clanname='$clanname'";

echo $query;
$result=mysql_query($query);

while($row=mysql_fetch_assoc($result)){

if(!$row['clanname']==1) {

echo "The Clan Tag or Clan Name you have chosen are allready in use.";

}else{

$add_clan="INSERT INTO clans (clantag, clanname, clansite) VALUES ('$clantag', '$clanname', '$clansite')";
mysql_query($add_clan) or die(mysql_error());

$query = "UPDATE users SET clanname='$clanname' , rank='Leader' , clantag='$clantag'  WHERE username='$username'";
$result = mysql_query($query) or die("Error: ". mysql_error(). " with query ". $query);


echo "You have sucessfully registered a clan";

  }
   }
?>
[/code]
Try it with insert only no update ok

[code]
<?php session_start();

include "connect.php";

$username=$_SESSION['username'];


$username=($_POST['username']);
$clantag=($_POST['clantag']);
$clanname=($_POST['clanname']);
$clansite=($_POST['clansite']);

$username=addslashes($username);
$clantag=addslashes($clantag);
$clanname=addslashes($clanname);
$clansite=addslashes($clansite);



if (($clanname=="none") || ($clantag=="none")) {

  echo "Clan Tag and Clan Name are required fields.";

}else{

$query = "SELECT * FROM clans WHERE clantag='$clantag' OR clanname='$clanname'";

echo $query;
$result=mysql_query($query);

while($row=mysql_fetch_assoc($result)){

if(!$row['clanname']==1) {

echo "The Clan Tag or Clan Name you have chosen are allready in use.";

}else{

$add_clan="INSERT INTO clans (clantag, clanname, clansite) VALUES('$clantag', '$clanname', '$clansite')";
mysql_query($add_clan) or die(mysql_error());

echo "You have sucessfully registered a clan";

  }
   }
?>
[/code]
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.