Jump to content

Recommended Posts

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

[code]
<?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";

}
?>
[/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..
Thanks
Max
Link to comment
https://forums.phpfreaks.com/topic/16026-inserting-and-updating/
Share on other sites

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.
Link to comment
https://forums.phpfreaks.com/topic/16026-inserting-and-updating/#findComment-65903
Share on other sites

try this please cheers.

[code]
<?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";

}
?>

[/code]
Link to comment
https://forums.phpfreaks.com/topic/16026-inserting-and-updating/#findComment-65942
Share on other sites

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]
Link to comment
https://forums.phpfreaks.com/topic/16026-inserting-and-updating/#findComment-65946
Share on other sites

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.
Link to comment
https://forums.phpfreaks.com/topic/16026-inserting-and-updating/#findComment-65984
Share on other sites

[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]
Link to comment
https://forums.phpfreaks.com/topic/16026-inserting-and-updating/#findComment-65989
Share on other sites

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]
Link to comment
https://forums.phpfreaks.com/topic/16026-inserting-and-updating/#findComment-65996
Share on other sites

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
Link to comment
https://forums.phpfreaks.com/topic/16026-inserting-and-updating/#findComment-66004
Share on other sites

[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
Link to comment
https://forums.phpfreaks.com/topic/16026-inserting-and-updating/#findComment-66015
Share on other sites

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..
Link to comment
https://forums.phpfreaks.com/topic/16026-inserting-and-updating/#findComment-66016
Share on other sites

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.