Jump to content

Archived

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

Ph0enix

Inserting and Updating

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

Share this post


Link to post
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.

Share this post


Link to post
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]

Share this post


Link to post
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]

Share this post


Link to post
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.

Share this post


Link to post
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]

Share this post


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

Share this post


Link to post
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]

Share this post


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

Share this post


Link to post
Share on other sites
its the space well done post your findings doing this blind you know.

Share this post


Link to post
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

Share this post


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

Share this post


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

Share this post


Link to post
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

Share this post


Link to post
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..

Share this post


Link to post
Share on other sites
$result=mysql_query(query); should have $ sign

in 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]

Share this post


Link to post
Share on other sites
After changing that the warning has gone.. and the output is now..
SELECT * FROM clans WHERE clantag='test' OR clanname=''

Share this post


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

Share this post


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

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.