Jump to content


Photo

Inserting and Updating


  • Please log in to reply
42 replies to this topic

#21 legohead6

legohead6
  • Members
  • PipPipPip
  • Advanced Member
  • 434 posts

Posted 30 July 2006 - 05:29 PM

$result=mysql_query(query); should have $ sign

in here

else{

$query = "SELECT * FROM clans WHERE clantag='$clantag' OR clanname='$clanname'";

echo $query;
$result=mysql_query(query);

while($row=mysql_fetch_assoc($result)){

"Syntax error" .. WHERE THE **** IS IT?!

#22 Ph0enix

Ph0enix
  • Members
  • PipPipPip
  • Advanced Member
  • 64 posts

Posted 30 July 2006 - 05:30 PM

After changing that the warning has gone.. and the output is now..
SELECT * FROM clans WHERE clantag='test' OR clanname=''
[url=http://www.slimphoenix.com][/url]

#23 redarrow

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

Posted 30 July 2006 - 05:31 PM

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;
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

#24 Ph0enix

Ph0enix
  • Members
  • PipPipPip
  • Advanced Member
  • 64 posts

Posted 30 July 2006 - 05:33 PM

Ok got rid of that. It hasn't changed though.
[url=http://www.slimphoenix.com][/url]

#25 legohead6

legohead6
  • Members
  • PipPipPip
  • Advanced Member
  • 434 posts

Posted 30 July 2006 - 05:34 PM

remove the brackets... i dunno maybe this works but i dont use them... and make the last 2 $_post capitalize like below

$username=$_POST['username'];
$clantag=$_POST['clantag'];
$clanname=$_POST['clanname'];
$clansite=$_POST['clansite'];

"Syntax error" .. WHERE THE **** IS IT?!

#26 Ph0enix

Ph0enix
  • Members
  • PipPipPip
  • Advanced Member
  • 64 posts

Posted 30 July 2006 - 05:36 PM

Now the output is..
SELECT * FROM clans WHERE clantag='test' OR clanname='test'
[url=http://www.slimphoenix.com][/url]

#27 legohead6

legohead6
  • Members
  • PipPipPip
  • Advanced Member
  • 434 posts

Posted 30 July 2006 - 05:37 PM

ya..know the query is ok and working...
"Syntax error" .. WHERE THE **** IS IT?!

#28 redarrow

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

Posted 30 July 2006 - 05:38 PM

Does the code work know ?

sorry didnt see the problams


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

#29 AndyB

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

Posted 30 July 2006 - 05:38 PM

Personally, I'd try this:

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

There really isn't any need to have all those UPDATE queries separate, one update of multiple fields would do as well.
Legend has it that reading the manual never killed anyone.
My site

#30 redarrow

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

Posted 30 July 2006 - 05:48 PM

i think this is the correct code for mutipull updates not sure someone verify cheers.


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


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

#31 Ph0enix

Ph0enix
  • Members
  • PipPipPip
  • Advanced Member
  • 64 posts

Posted 30 July 2006 - 05:54 PM

Hi i tried your code andy, and i dont get any output and nothing is submitted into the database. =/
[url=http://www.slimphoenix.com][/url]

#32 redarrow

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

Posted 30 July 2006 - 05:57 PM

sorry

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

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

#33 legohead6

legohead6
  • Members
  • PipPipPip
  • Advanced Member
  • 434 posts

Posted 30 July 2006 - 05:58 PM

Please tell us what the probelm was with the code after the query was right im kinda lost....and before you tried andys code..
"Syntax error" .. WHERE THE **** IS IT?!

#34 Ph0enix

Ph0enix
  • Members
  • PipPipPip
  • Advanced Member
  • 64 posts

Posted 30 July 2006 - 06:01 PM

Well before i tried andys code i used redarrow's code and got the output
SELECT * 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

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

#35 redarrow

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

Posted 30 July 2006 - 06:04 PM

sorry $query

edited agin sorry

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

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

#36 Ph0enix

Ph0enix
  • Members
  • PipPipPip
  • Advanced Member
  • 64 posts

Posted 30 July 2006 - 06:07 PM

The output is SELECT * FROM clans WHERE clantag='Test' OR clanname='Test' again.  :-\
[url=http://www.slimphoenix.com][/url]

#37 redarrow

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

Posted 30 July 2006 - 06:13 PM

Does everythink work then.

good luck.
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

#38 Ph0enix

Ph0enix
  • Members
  • PipPipPip
  • Advanced Member
  • 64 posts

Posted 30 July 2006 - 06:17 PM

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

#39 redarrow

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

Posted 30 July 2006 - 06:21 PM

you can not insert data then show your form ok
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

#40 Ph0enix

Ph0enix
  • Members
  • PipPipPip
  • Advanced Member
  • 64 posts

Posted 30 July 2006 - 06:24 PM

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




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users