Ph0enix Posted July 30, 2006 Author Share Posted July 30, 2006 Now the output is..SELECT * FROM clans WHERE clantag='test' OR clanname='test' Quote Link to comment Share on other sites More sharing options...
legohead6 Posted July 30, 2006 Share Posted July 30, 2006 ya..know the query is ok and working... Quote Link to comment Share on other sites More sharing options...
redarrow Posted July 30, 2006 Share Posted July 30, 2006 Does the code work know ?sorry didnt see the problams Quote Link to comment Share on other sites More sharing options...
AndyB Posted July 30, 2006 Share Posted July 30, 2006 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. Quote Link to comment Share on other sites More sharing options...
redarrow Posted July 30, 2006 Share Posted July 30, 2006 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] Quote Link to comment Share on other sites More sharing options...
Ph0enix Posted July 30, 2006 Author Share Posted July 30, 2006 Hi i tried your code andy, and i dont get any output and nothing is submitted into the database. =/ Quote Link to comment Share on other sites More sharing options...
redarrow Posted July 30, 2006 Share Posted July 30, 2006 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] Quote Link to comment Share on other sites More sharing options...
legohead6 Posted July 30, 2006 Share Posted July 30, 2006 Please tell us what the probelm was with the code after the query was right im kinda lost....and before you tried andys code.. Quote Link to comment Share on other sites More sharing options...
Ph0enix Posted July 30, 2006 Author Share Posted July 30, 2006 Well before i tried andys code i used redarrow's code and got the outputSELECT * 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 Quote Link to comment Share on other sites More sharing options...
redarrow Posted July 30, 2006 Share Posted July 30, 2006 sorry $queryedited 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] Quote Link to comment Share on other sites More sharing options...
Ph0enix Posted July 30, 2006 Author Share Posted July 30, 2006 The output is SELECT * FROM clans WHERE clantag='Test' OR clanname='Test' again. :-\ Quote Link to comment Share on other sites More sharing options...
redarrow Posted July 30, 2006 Share Posted July 30, 2006 Does everythink work then.good luck. Quote Link to comment Share on other sites More sharing options...
Ph0enix Posted July 30, 2006 Author Share Posted July 30, 2006 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? Quote Link to comment Share on other sites More sharing options...
redarrow Posted July 30, 2006 Share Posted July 30, 2006 you can not insert data then show your form ok Quote Link to comment Share on other sites More sharing options...
Ph0enix Posted July 30, 2006 Author Share Posted July 30, 2006 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!" Quote Link to comment Share on other sites More sharing options...
redarrow Posted July 30, 2006 Share Posted July 30, 2006 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] Quote Link to comment Share on other sites More sharing options...
Ph0enix Posted July 30, 2006 Author Share Posted July 30, 2006 Thanks Mate! Quote Link to comment Share on other sites More sharing options...
legohead6 Posted July 30, 2006 Share Posted July 30, 2006 so its working know? if so please edit ur first post and put DONE in the title.. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.