Checking if id exists.. lol

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
User avatar
nick2
Forum Contributor
Posts: 118
Joined: Fri Jul 25, 2003 2:34 pm

Checking if id exists.. lol

Post by nick2 »

Hey I am having trouble making it check if it exists ornot.. and if it does to exit the script and print a msg.. heres my code

Code: Select all

#do check #
$checkstring = " SELECT FROM $table_name WHERE GID='$_POSTїGID]' ";

if ($checkstring == '$_POSTїGID]') {
print ("I'm sorry this Game ID already exists please hit the back button!");
exit;
}
right now it just makes a new entry with same name.. like its ignoring this part.
malcolmboston
DevNet Resident
Posts: 1826
Joined: Tue Nov 18, 2003 1:09 pm
Location: Middlesbrough, UK

Post by malcolmboston »

Code: Select all

<?php
// lets simplify the var
// i always do this, makes it simpler for me in queries
$gid = $_POST['GID'];
$query = "SELECT * SELECT FROM $table_name WHERE GID= '$gid'";
$result = mysql_query($query) or die (mysql_error());
$rows = mysql_num_rows($result);
// now we'll use the conditional statements
if ($rows >= 1)
{
// the GID already in the database
header ("Location: ../index.php");
exit;
}
else
{
// the GID is new
// use a mysql insert to insert the new data
// ill leave that to you
}
?>
magicrobotmonkey
Forum Regular
Posts: 888
Joined: Sun Mar 21, 2004 1:09 pm
Location: Cambridge, MA

Post by magicrobotmonkey »

SELECT * SELECT FROM

to

SELECT * FROM
User avatar
nick2
Forum Contributor
Posts: 118
Joined: Fri Jul 25, 2003 2:34 pm

Post by nick2 »

Thanks..


Parse error: parse error in /home/virtual/site142/fst/var/www/html/game.pixelfriendly.com/signup.PHP on line 47


theres a max of 46 lines.. so ugh..

Code: Select all

<?php
 #check and see if the fields are empty.. if they are uh oh send them back to signup!
 if ((!$_POST&#1111;name]) || (!$_POST&#1111;GID]) || (!$_POST&#1111;password]) || (!$_POST&#1111;email]) || (!$_POST&#1111;age])) &#123;
 Print ("Please hit the back button and make sure you filled in all the text fields correctly!");
&#125;
##starting create user##
#variables#
$db_address = "localhost";
$db_name = "pixelfriendly_com";
$db_pass = "xxxxxx";
$table_name = "aprilacc";
$db_user = "pixel";                                                                     #do check #



#connection#
$connection  = @mysql_connect($db_address, $db_user, $db_pass) or die(mysql_error());

#do check #
// lets simplify the var
// i always do this, makes it simpler for me in queries
$gid = $_POST&#1111;'GID'];
$query = "SELECT * SELECT FROM $table_name WHERE GID= '$GID'";
$result = mysql_query($query) or die (mysql_error());
$rows = mysql_num_rows($result);
// now we'll use the conditional statements
if ($rows >= 1)
&#123;
// the GID already in the database
print ("I'm sorry this Game ID already exists please hit the back button!");
exit;
&#125;
else
&#123;
#select#
mysql_select_db($db_name) or die(mysql_error());

#insert data#
$sql = "INSERT INTO $table_name(name, GID, password, email, age) VALUES('$_POST&#1111;name]', '$_POST&#1111;GID]', password('$_POST&#1111;password]'), '$_POST&#1111;email]', '$_POST&#1111;age]')";
#results#
$result = @mysql_query($sql, $connection) or die(mysql_error());
?>
<?#print results/email#
mail($_POST&#1111;email], "Thank you", "Thankyou for signing up for closed beta, you will be contacted by email if you are accepted. Please do not reply to this email it is an automatic response.    Thanks, April 19th team", "From: admin@april19th.com");
header("location: Http://game.pixelfriendly.com");
?>
malcolmboston
DevNet Resident
Posts: 1826
Joined: Tue Nov 18, 2003 1:09 pm
Location: Middlesbrough, UK

Post by malcolmboston »

magicrobotmonkey wrote:SELECT * SELECT FROM

to

SELECT * FROM
yeah, sorry was typing it up fast and reading other posts

theres nothing wrong else wrong with that script so if your still getting parse errors then its something you've done.
magicrobotmonkey
Forum Regular
Posts: 888
Joined: Sun Mar 21, 2004 1:09 pm
Location: Cambridge, MA

Post by magicrobotmonkey »

if its a line after the last line then somethings open - quotes, {, ( or a missing ; - if the above was color-coded id look for you but its too hard all green!
User avatar
nick2
Forum Contributor
Posts: 118
Joined: Fri Jul 25, 2003 2:34 pm

Post by nick2 »

Nevermyn found the problem.. needed a ending }


thx guys!
malcolmboston
DevNet Resident
Posts: 1826
Joined: Tue Nov 18, 2003 1:09 pm
Location: Middlesbrough, UK

Post by malcolmboston »

magicrobotmonkey wrote:if its a line after the last line then somethings open - quotes, {, ( or a missing ; - if the above was color-coded id look for you but its too hard all green!
ditto, i wish people would do this, honestly if its long +80 lines and not color coded i skip to the comments
User avatar
nick2
Forum Contributor
Posts: 118
Joined: Fri Jul 25, 2003 2:34 pm

Post by nick2 »

ugh sorry.. guys its saying No database selected when.. a db does exist.. because I can obviously insert data.. so what could the problem be? I looked and dont see anything because im just a mere noob. :(
magicrobotmonkey
Forum Regular
Posts: 888
Joined: Sun Mar 21, 2004 1:09 pm
Location: Cambridge, MA

Post by magicrobotmonkey »

malcolmboston
DevNet Resident
Posts: 1826
Joined: Tue Nov 18, 2003 1:09 pm
Location: Middlesbrough, UK

Post by malcolmboston »

god, use this :lol: for your connection

Code: Select all

$host = "myhost";
$user = "myname";
$pass = "pass";
$db = "database";

mysql_connect('$host', '$user', '$pass') or die(mysql_error());
mysql_select_db('$db') or die(mysql_error());
obviously change teh var values to what is needed for you

i would look at your code and amend that but you havent colour coded it.............
User avatar
nick2
Forum Contributor
Posts: 118
Joined: Fri Jul 25, 2003 2:34 pm

Post by nick2 »

Thanks magic.. I forgot to select it.. lol >_>
User avatar
phice
Moderator
Posts: 1416
Joined: Sat Apr 20, 2002 3:14 pm
Location: Dallas, TX
Contact:

Post by phice »

When the error comes up with more lines (or usually to the last line) than the file has, it's usually because there's a missing bracket (}) somewhere.
Image Image
User avatar
tim
DevNet Resident
Posts: 1165
Joined: Thu Feb 12, 2004 7:19 pm
Location: ohio

Post by tim »

i would sugget using empty() to check if the fields were left blank:

http://us2.php.net/manual/en/function.empty.php
Post Reply