Ph0enix Posted July 30, 2006 Share Posted July 30, 2006 Hi, yes i have another very annoying error in my script.This is my script..[code]<?phpsession_start();include "connect.php";$username= $_SESSION['username'];if ($_POST[clanname]="" OR $_POST['clantag']="") { echo "Clan Tag and Clan Name are required fields.";}else{$result = mysql_query("SELECT * FROM clans WHERE clantag = '$_POST[clantag]' OR clanname = '$_POST[clanname]'");$rows = mysql_num_rows($result);if ($rows > 0) { echo "The Clan Tag or Clan Name you have chosen are allready in use.";}else{$add_clan = ("INSERT INTO clans (clantag, clanname, clansite) VALUES ('$_POST[clantag]', '$_POST[clanname]', '$_POST[clansite]')");mysql_query($add_clan) or die(mysql_error());$update_name = ("UPDATE users SET clanname = '$_POST[clanname]' WHERE username = '$username' ");mysql_query($update_name) or die(mysql_error());$update_tag = ("UPDATE users SET clantag = '$_POST[clantag]' WHERE username = '$username' ");mysql_query($update_tag) or die(mysql_error());$update_rank = ("UPDATE users SET rank = 'Leader' WHERE username = '$username' ");mysql_query($update_rank) or die(mysql_error());echo "You have sucessfully registered a clan"; } }?>[/code]Now the annoything is that it says "You have successfully registered a clan" and a new row has been added in the database, but only the name of the website is submitted into it. Both the clanname and clantag fields are empty. Its sooooo annoying. Please help me.. ThanksMax Quote Link to comment https://forums.phpfreaks.com/topic/16026-inserting-and-updating/ Share on other sites More sharing options...
Balmung-San Posted July 30, 2006 Share Posted July 30, 2006 Are the fields in the clans table named that exact name? That's the only error I can see with it. Quote Link to comment https://forums.phpfreaks.com/topic/16026-inserting-and-updating/#findComment-65900 Share on other sites More sharing options...
Ph0enix Posted July 30, 2006 Author Share Posted July 30, 2006 Yep they are the same.. Quote Link to comment https://forums.phpfreaks.com/topic/16026-inserting-and-updating/#findComment-65901 Share on other sites More sharing options...
xyn Posted July 30, 2006 Share Posted July 30, 2006 Hey Try this instead of your SQL code.[code=php:0]$add_clan = "INSERT INTO clans (clantag, clanname, clansite) VALUES ('".strtolower($_POST['clantag'])."', '".strtolower($_POST['clanname'])."', '".$_POST['clansite']."')";mysql_query($add_clan) or die(mysql_error());[/code]Explaination:Strtolower = All LowerCase, This will stop the clan name being registered twice ie:AshClan + ashclan are the same but both will be inserted into the Database. Quote Link to comment https://forums.phpfreaks.com/topic/16026-inserting-and-updating/#findComment-65903 Share on other sites More sharing options...
Ph0enix Posted July 30, 2006 Author Share Posted July 30, 2006 Nope it still isnt working =/ Quote Link to comment https://forums.phpfreaks.com/topic/16026-inserting-and-updating/#findComment-65935 Share on other sites More sharing options...
redarrow Posted July 30, 2006 Share Posted July 30, 2006 try this please cheers.[code]<?phpsession_start();include "connect.php";$username=$_SESSION['username']=$username;$username=($_POST['username']);$clantag=($_POST['clantag']);$clanname=($_post[clanname']);$clansite=($_post[clansite']);if ($_POST[clanname]="" OR $_POST['clantag']="") { echo "Clan Tag and Clan Name are required fields.";}else{$result = mysql_query("SELECT * FROM clans WHERE clantag='$clantag' OR clanname = '$clanname'");$rows = mysql_num_rows($result);if ($rows > 0) { 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());$update_name = ("UPDATE users SET clanname = '$clanname' WHERE username='$username'");mysql_query($update_name) or die(mysql_error());$update_tag = ("UPDATE users SET clantag = '$clantag' WHERE username = '$username' ");mysql_query($update_tag) or die(mysql_error());$update_rank = ("UPDATE users SET rank = 'Leader' WHERE username='$username' ");mysql_query($update_rank) or die(mysql_error());echo "You have sucessfully registered a clan"; } }?>[/code] Quote Link to comment https://forums.phpfreaks.com/topic/16026-inserting-and-updating/#findComment-65942 Share on other sites More sharing options...
redarrow Posted July 30, 2006 Share Posted July 30, 2006 fully tested try it ok.[code]<?php session_start();include "connect.php";$username=$_SESSION['username']=$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]="" OR $_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);$rows = mysql_num_rows($result);if ($rows > 0) {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());$update_name = "UPDATE users SET clanname = '$clanname' WHERE username='$username'";$result1=mysql_query($update_name) or die(mysql_error());$update_tag = "UPDATE users SET clantag = '$clantag' WHERE username = '$username'";$result2=mysql_query($update_tag) or die(mysql_error());$update_rank ="UPDATE users SET rank = 'Leader' WHERE username='$username'";$result3=mysql_query($update_rank) or die(mysql_error());echo "You have sucessfully registered a clan"; } }?>[/code] Quote Link to comment https://forums.phpfreaks.com/topic/16026-inserting-and-updating/#findComment-65946 Share on other sites More sharing options...
Ph0enix Posted July 30, 2006 Author Share Posted July 30, 2006 lol!Now instead of the clansite being the thing that is put it, the clan tag is being put in, and nothing else. =/But now i get this..."Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in C:\wamp\www\league\clanck.php on line 31You have sucessfully registered a clan" Line 31 is.. $rows = mysql_num_rows($result);Is there anything else i can try?Thanks for your help. Quote Link to comment https://forums.phpfreaks.com/topic/16026-inserting-and-updating/#findComment-65984 Share on other sites More sharing options...
redarrow Posted July 30, 2006 Share Posted July 30, 2006 [code]<?php session_start();include "connect.php";$username=$_SESSION['username']=$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]="" OR $_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);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());$update_name = "UPDATE users SET clanname = '$clanname' WHERE username='$username'";$result1=mysql_query($update_name) or die(mysql_error());$update_tag = "UPDATE users SET clantag = '$clantag' WHERE username = '$username'";$result2=mysql_query($update_tag) or die(mysql_error());$update_rank ="UPDATE users SET rank = 'Leader' WHERE username='$username'";$result3=mysql_query($update_rank) or die(mysql_error());echo "You have sucessfully registered a clan"; } }?>[/code] Quote Link to comment https://forums.phpfreaks.com/topic/16026-inserting-and-updating/#findComment-65989 Share on other sites More sharing options...
Ph0enix Posted July 30, 2006 Author Share Posted July 30, 2006 No i get an error saying"Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in C:\wamp\www\league\clanck.php on line 30":s Quote Link to comment https://forums.phpfreaks.com/topic/16026-inserting-and-updating/#findComment-65993 Share on other sites More sharing options...
redarrow Posted July 30, 2006 Share Posted July 30, 2006 This will echo the query out becouse you got a query problam ok post your findings ok.[code]<?php session_start();include "connect.php";$username=$_SESSION['username']=$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]="" OR $_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());$update_name = "UPDATE users SET clanname = '$clanname' WHERE username='$username'";$result1=mysql_query($update_name) or die(mysql_error());$update_tag = "UPDATE users SET clantag = '$clantag' WHERE username = '$username'";$result2=mysql_query($update_tag) or die(mysql_error());$update_rank ="UPDATE users SET rank = 'Leader' WHERE username='$username'";$result3=mysql_query($update_rank) or die(mysql_error());echo "You have sucessfully registered a clan"; } }?> [/code] Quote Link to comment https://forums.phpfreaks.com/topic/16026-inserting-and-updating/#findComment-65996 Share on other sites More sharing options...
Ph0enix Posted July 30, 2006 Author Share Posted July 30, 2006 Now the output is..SELECT * FROM clans WHERE clantag='test' OR clanname = ''Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in C:\wamp\www\league\clanck.php on line 31 Quote Link to comment https://forums.phpfreaks.com/topic/16026-inserting-and-updating/#findComment-65998 Share on other sites More sharing options...
legohead6 Posted July 30, 2006 Share Posted July 30, 2006 removes the spaces before and after the = sign Quote Link to comment https://forums.phpfreaks.com/topic/16026-inserting-and-updating/#findComment-66000 Share on other sites More sharing options...
redarrow Posted July 30, 2006 Share Posted July 30, 2006 its the space well done post your findings doing this blind you know. Quote Link to comment https://forums.phpfreaks.com/topic/16026-inserting-and-updating/#findComment-66002 Share on other sites More sharing options...
AndyB Posted July 30, 2006 Share Posted July 30, 2006 RedArrow - what the heck is this supposed to do, and why?[code]$username=$_SESSION['username']=$username;$username=($_POST['username']);[/code]To Ph0enix. This line is wrong since == is the equality comparison operator.[code]if ($_POST[clanname]="" OR $_POST['clantag']="") {[/code]It should be (improved to):[code]if (($_POST['clanname'] == "") || ($_POST['clantag'] == "")) {[/code]Would you mind posting the code you actually have right now that's generating an error or not working the way you expect and then we'll work from there.edit: 'remove the spaces' Huh??? $x="1" is just the same as $x = "1", the spaces only affect readability Quote Link to comment https://forums.phpfreaks.com/topic/16026-inserting-and-updating/#findComment-66004 Share on other sites More sharing options...
legohead6 Posted July 30, 2006 Share Posted July 30, 2006 [quote author=redarrow link=topic=102337.msg406056#msg406056 date=1154280009]its the space well done post your findings doing this blind you know.[/quote]whats that supposed to mean? Quote Link to comment https://forums.phpfreaks.com/topic/16026-inserting-and-updating/#findComment-66007 Share on other sites More sharing options...
redarrow Posted July 30, 2006 Share Posted July 30, 2006 andy sorry at firs thort there was a seeion problam so i thort that adding the username to the session agin will defently set the session username sorry.$username=$_SESSION['username']=$username;$username=($_POST['username']); Quote Link to comment https://forums.phpfreaks.com/topic/16026-inserting-and-updating/#findComment-66009 Share on other sites More sharing options...
redarrow Posted July 30, 2006 Share Posted July 30, 2006 i am blind so what Quote Link to comment https://forums.phpfreaks.com/topic/16026-inserting-and-updating/#findComment-66012 Share on other sites More sharing options...
legohead6 Posted July 30, 2006 Share Posted July 30, 2006 [quote author=AndyB link=topic=102337.msg406058#msg406058 date=1154280028]edit: 'remove the spaces' Huh??? $x="1" is just the same as $x = "1", the spaces only affect readability[/quote]just by the looks of it the clantag='' is working without and the clanname isnt.. and it has spaces...(its happened to me before Quote Link to comment https://forums.phpfreaks.com/topic/16026-inserting-and-updating/#findComment-66015 Share on other sites More sharing options...
Ph0enix Posted July 30, 2006 Author Share Posted July 30, 2006 Well my code i started with is the one right at the start.The code i have now is [code]<?php session_start();include "connect.php";$username=$_SESSION['username']=$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());$update_name="UPDATE users SET clanname='$clanname' WHERE username='$username'";$result1=mysql_query($update_name) or die(mysql_error());$update_tag="UPDATE users SET clantag='$clantag' WHERE username='$username'";$result2=mysql_query($update_tag) or die(mysql_error());$update_rank="UPDATE users SET rank='Leader' WHERE username='$username'";$result3=mysql_query($update_rank) or die(mysql_error());echo "You have sucessfully registered a clan"; } } }?>[/code]I'm not sure if this code is doing the same as what the first bit of code was trying to do.. Quote Link to comment https://forums.phpfreaks.com/topic/16026-inserting-and-updating/#findComment-66016 Share on other sites More sharing options...
legohead6 Posted July 30, 2006 Share Posted July 30, 2006 $result=mysql_query(query); should have $ signin here[code]else{$query = "SELECT * FROM clans WHERE clantag='$clantag' OR clanname='$clanname'";echo $query;$result=mysql_query(query);while($row=mysql_fetch_assoc($result)){[/code] Quote Link to comment https://forums.phpfreaks.com/topic/16026-inserting-and-updating/#findComment-66017 Share on other sites More sharing options...
Ph0enix Posted July 30, 2006 Author Share Posted July 30, 2006 After changing that the warning has gone.. and the output is now..SELECT * FROM clans WHERE clantag='test' OR clanname='' Quote Link to comment https://forums.phpfreaks.com/topic/16026-inserting-and-updating/#findComment-66019 Share on other sites More sharing options...
redarrow Posted July 30, 2006 Share Posted July 30, 2006 Get rid of the session part at the top as i have already been told off ok.this is alredy working i think ok$username=$_SESSION['username']=$username; Quote Link to comment https://forums.phpfreaks.com/topic/16026-inserting-and-updating/#findComment-66020 Share on other sites More sharing options...
Ph0enix Posted July 30, 2006 Author Share Posted July 30, 2006 Ok got rid of that. It hasn't changed though. Quote Link to comment https://forums.phpfreaks.com/topic/16026-inserting-and-updating/#findComment-66021 Share on other sites More sharing options...
legohead6 Posted July 30, 2006 Share Posted July 30, 2006 remove the brackets... i dunno maybe this works but i dont use them... and make the last 2 $_post capitalize like below[code]$username=$_POST['username'];$clantag=$_POST['clantag'];$clanname=$_POST['clanname'];$clansite=$_POST['clansite'];[/code] Quote Link to comment https://forums.phpfreaks.com/topic/16026-inserting-and-updating/#findComment-66022 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.