Jump to content

Archived

This topic is now archived and is closed to further replies.

Ph0enix

Inserting and Updating

Recommended Posts

Now the output is..
SELECT * FROM clans WHERE clantag='test' OR clanname='test'

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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]

Share this post


Link to post
Share on other sites
Hi i tried your code andy, and i dont get any output and nothing is submitted into the database. =/

Share this post


Link to post
Share on other sites
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]

Share this post


Link to post
Share on other sites
Please tell us what the probelm was with the code after the query was right im kinda lost....and before you tried andys code..

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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]

Share this post


Link to post
Share on other sites
The output is SELECT * FROM clans WHERE clantag='Test' OR clanname='Test' again.  :-\

Share this post


Link to post
Share on other sites
Erm, no cause i get the output SELECT * FROM clans WHERE clantag='Test' OR clanname='Test'.
What do i have to change to make it insert the info and update the users profile?

Share this post


Link to post
Share on other sites
No i just want to insert the data into my database and then if it has been inserted then i get an output saying "You have sucessfully registered a clan!"

Share this post


Link to post
Share on other sites
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]

Share this post


Link to post
Share on other sites

×

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.