Jump to content


Photo

Inserting and Updating


  • Please log in to reply
42 replies to this topic

#1 Ph0enix

Ph0enix
  • Members
  • PipPipPip
  • Advanced Member
  • 64 posts

Posted 30 July 2006 - 02:15 PM

Hi, yes i have another very annoying error in my script.
This is my script..

<?php
session_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"; 
}  
}
?>
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..
Thanks
Max
[url=http://www.slimphoenix.com][/url]

#2 Balmung-San

Balmung-San
  • Members
  • PipPipPip
  • Advanced Member
  • 327 posts

Posted 30 July 2006 - 02:29 PM

Are the fields in the clans table named that exact name? That's the only error I can see with it.
"Paranoia is very useful in this work. ...If your cryptographic system can survive the paranoia model, it has at least a fighting chance of surviving in the real world." - Niels Ferguson & Bruce Schneier

They say there's more then one way to skin a cat.
In programming, there's no wrong way to skin a cat, just more efficent ways of doing so.

#3 Ph0enix

Ph0enix
  • Members
  • PipPipPip
  • Advanced Member
  • 64 posts

Posted 30 July 2006 - 02:34 PM

Yep they are the same..
[url=http://www.slimphoenix.com][/url]

#4 xyn

xyn
  • Members
  • PipPipPip
  • Advanced Member
  • 779 posts
  • LocationNorthampton

Posted 30 July 2006 - 02:44 PM

Hey Try this instead of your SQL code.

$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());

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.

#5 Ph0enix

Ph0enix
  • Members
  • PipPipPip
  • Advanced Member
  • 64 posts

Posted 30 July 2006 - 03:56 PM

Nope it still isnt working =/
[url=http://www.slimphoenix.com][/url]

#6 redarrow

redarrow
  • Members
  • PipPipPip
  • Advanced Member
  • 7,308 posts
  • Locationlondon

Posted 30 July 2006 - 04:12 PM

try this please cheers.

<?php
session_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"; 
}  
 }
?>


Wish i new all about php DAM i will have to learn
((EMAIL CODE THAT WORKS))
http://simpleforum.ath.cx/mail2.inc
((PAYPAL INTEGRATION THAT WORKS))
http://simpleforum.a...aypal1_info.inc

#7 redarrow

redarrow
  • Members
  • PipPipPip
  • Advanced Member
  • 7,308 posts
  • Locationlondon

Posted 30 July 2006 - 04:19 PM

fully tested try it ok.

<?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"; 
}  
 }
?>

Wish i new all about php DAM i will have to learn
((EMAIL CODE THAT WORKS))
http://simpleforum.ath.cx/mail2.inc
((PAYPAL INTEGRATION THAT WORKS))
http://simpleforum.a...aypal1_info.inc

#8 Ph0enix

Ph0enix
  • Members
  • PipPipPip
  • Advanced Member
  • 64 posts

Posted 30 July 2006 - 04:51 PM

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 31
You have sucessfully registered a clan" 
Line 31 is..
$rows = mysql_num_rows($result);
Is there anything else i can try?
Thanks for your help.

[url=http://www.slimphoenix.com][/url]

#9 redarrow

redarrow
  • Members
  • PipPipPip
  • Advanced Member
  • 7,308 posts
  • Locationlondon

Posted 30 July 2006 - 05:01 PM

<?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"; 
}  
 }
?>

Wish i new all about php DAM i will have to learn
((EMAIL CODE THAT WORKS))
http://simpleforum.ath.cx/mail2.inc
((PAYPAL INTEGRATION THAT WORKS))
http://simpleforum.a...aypal1_info.inc

#10 Ph0enix

Ph0enix
  • Members
  • PipPipPip
  • Advanced Member
  • 64 posts

Posted 30 July 2006 - 05:06 PM

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
[url=http://www.slimphoenix.com][/url]

#11 redarrow

redarrow
  • Members
  • PipPipPip
  • Advanced Member
  • 7,308 posts
  • Locationlondon

Posted 30 July 2006 - 05:10 PM

This will echo the query out becouse you got a query problam ok post your findings ok.
<?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"; 
}  
 }
?>
  


Wish i new all about php DAM i will have to learn
((EMAIL CODE THAT WORKS))
http://simpleforum.ath.cx/mail2.inc
((PAYPAL INTEGRATION THAT WORKS))
http://simpleforum.a...aypal1_info.inc

#12 Ph0enix

Ph0enix
  • Members
  • PipPipPip
  • Advanced Member
  • 64 posts

Posted 30 July 2006 - 05:13 PM

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
[url=http://www.slimphoenix.com][/url]

#13 legohead6

legohead6
  • Members
  • PipPipPip
  • Advanced Member
  • 434 posts

Posted 30 July 2006 - 05:17 PM

removes the spaces before and after the = sign
"Syntax error" .. WHERE THE **** IS IT?!

#14 redarrow

redarrow
  • Members
  • PipPipPip
  • Advanced Member
  • 7,308 posts
  • Locationlondon

Posted 30 July 2006 - 05:20 PM

its the space well done post your findings doing this blind you know.
Wish i new all about php DAM i will have to learn
((EMAIL CODE THAT WORKS))
http://simpleforum.ath.cx/mail2.inc
((PAYPAL INTEGRATION THAT WORKS))
http://simpleforum.a...aypal1_info.inc

#15 AndyB

AndyB
  • Staff Alumni
  • Advanced Member
  • 5,465 posts
  • LocationToronto

Posted 30 July 2006 - 05:20 PM

RedArrow - what the heck is this supposed to do, and why?

$username=$_SESSION['username']=$username;
$username=($_POST['username']);

To Ph0enix. This line is wrong since == is the equality comparison operator.
if ($_POST[clanname]="" OR $_POST['clantag']="") {

It should be (improved to):
if (($_POST['clanname'] == "") || ($_POST['clantag'] == "")) {

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

Legend has it that reading the manual never killed anyone.
My site

#16 legohead6

legohead6
  • Members
  • PipPipPip
  • Advanced Member
  • 434 posts

Posted 30 July 2006 - 05:22 PM

its the space well done post your findings doing this blind you know.


whats that supposed to mean?
"Syntax error" .. WHERE THE **** IS IT?!

#17 redarrow

redarrow
  • Members
  • PipPipPip
  • Advanced Member
  • 7,308 posts
  • Locationlondon

Posted 30 July 2006 - 05:23 PM

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']);
Wish i new all about php DAM i will have to learn
((EMAIL CODE THAT WORKS))
http://simpleforum.ath.cx/mail2.inc
((PAYPAL INTEGRATION THAT WORKS))
http://simpleforum.a...aypal1_info.inc

#18 redarrow

redarrow
  • Members
  • PipPipPip
  • Advanced Member
  • 7,308 posts
  • Locationlondon

Posted 30 July 2006 - 05:24 PM



i am blind so what

Wish i new all about php DAM i will have to learn
((EMAIL CODE THAT WORKS))
http://simpleforum.ath.cx/mail2.inc
((PAYPAL INTEGRATION THAT WORKS))
http://simpleforum.a...aypal1_info.inc

#19 legohead6

legohead6
  • Members
  • PipPipPip
  • Advanced Member
  • 434 posts

Posted 30 July 2006 - 05:26 PM


edit: 'remove the spaces' Huh??? $x="1" is just the same as $x = "1", the spaces only affect readability


just by the looks of it the clantag='' is working without and the clanname isnt.. and it has spaces...(its happened to me before
"Syntax error" .. WHERE THE **** IS IT?!

#20 Ph0enix

Ph0enix
  • Members
  • PipPipPip
  • Advanced Member
  • 64 posts

Posted 30 July 2006 - 05:27 PM

Well my code i started with is the one right at the start.
The code i have now is

<?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"; 
}  
 }
 }
?>

I'm not sure if this code is doing the same as what the first bit of code was trying to do..
[url=http://www.slimphoenix.com][/url]




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users