Page 1 of 1
Checking if id exists.. lol
Posted: Fri Apr 16, 2004 2:02 pm
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.
Posted: Fri Apr 16, 2004 2:22 pm
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
}
?>
Posted: Fri Apr 16, 2004 2:27 pm
by magicrobotmonkey
SELECT * SELECT FROM
to
SELECT * FROM
Posted: Fri Apr 16, 2004 2:29 pm
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їname]) || (!$_POSTїGID]) || (!$_POSTїpassword]) || (!$_POSTїemail]) || (!$_POSTїage])) {
Print ("Please hit the back button and make sure you filled in all the text fields correctly!");
}
##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ї'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
print ("I'm sorry this Game ID already exists please hit the back button!");
exit;
}
else
{
#select#
mysql_select_db($db_name) or die(mysql_error());
#insert data#
$sql = "INSERT INTO $table_name(name, GID, password, email, age) VALUES('$_POSTїname]', '$_POSTїGID]', password('$_POSTїpassword]'), '$_POSTїemail]', '$_POSTїage]')";
#results#
$result = @mysql_query($sql, $connection) or die(mysql_error());
?>
<?#print results/email#
mail($_POSTї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");
?>
Posted: Fri Apr 16, 2004 2:31 pm
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.
Posted: Fri Apr 16, 2004 2:33 pm
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!
Posted: Fri Apr 16, 2004 2:34 pm
by nick2
Nevermyn found the problem.. needed a ending }
thx guys!
Posted: Fri Apr 16, 2004 2:34 pm
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
Posted: Fri Apr 16, 2004 2:38 pm
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.

Posted: Fri Apr 16, 2004 2:41 pm
by magicrobotmonkey
Posted: Fri Apr 16, 2004 2:42 pm
by malcolmboston
god, use this

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.............
Posted: Fri Apr 16, 2004 2:44 pm
by nick2
Thanks magic.. I forgot to select it.. lol >_>
Posted: Fri Apr 16, 2004 2:48 pm
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.
Posted: Fri Apr 16, 2004 5:11 pm
by tim
i would sugget using empty() to check if the fields were left blank:
http://us2.php.net/manual/en/function.empty.php