Hello everyone. My objective for this script, was to create a registration script for my Mafia game, and add different things to the users profile. I wanted to add things like start date, so people know when the account was created. Below is the script. Currently all i get is a mysql_error <?php session_start(); include_once"includes/db_connect.php"; if (isset($_SESSION['username'])){ header("Location: /game/play.php"); exit(); } $referal=$_GET['ref']; $referal2=$_POST['ref2']; $scriptcheck=$_POST['scriptcheck']; $scriptcheck2=$_POST['scrip']; $sc=rand(111,999); if(!$referal2){ $referal2=0; } if ($_POST['Submit']){ // Define post fields into simple variables $reg_username = $_POST['reg_username']; $email = $_POST['email']; $email1 = $_POST['email1']; $location=strip_tags($_POST['location']); $reg_username=trim($reg_username); $today = date("F j, Y, g:i a"); $reg_username = stripslashes($reg_username); $email = stripslashes($email); $reg_username = strip_tags($reg_username); $email = strip_tags($email); if((!$reg_username) || (!$email) || (!$location)){ $message="Please fill in all fields"; }else{ if ($email != $email1){ $message="Emails do not match"; }elseif ($email == $email1){ if($scriptcheck != $scriptcheck2){ print"Script check wrong!"; }else{ if (preg_match('/[^A-Za-z]/',$reg_username)) { $message="Your username can only contain letters."; }elseif (!preg_match('/[^A-Za-z]/',$reg_username)) { if (strlen($reg_username) <= 3 || strlen($reg_username) >= 40){ $message= "Username too big or small."; }elseif (strlen($reg_username) > 3 || strlen($reg_username) < 40){ $sql_email_check = mysql_query("SELECT email FROM users WHERE email='$email' AND status='Alive'"); $sql_username_check = mysql_query("SELECT username FROM users WHERE username='$reg_username'"); $email_check = mysql_num_rows($sql_email_check); $username_check = mysql_num_rows($sql_username_check); if(($email_check > 0) || ($username_check > 0)){ echo "Im sorry but there has been an error please read on..<br />"; if($email_check > 0){ print"Your email address has already been used by another gangster!"; unset($email); } if($username_check > 0){ print"Your desired username is already in use!"; unset($reg_username); } }else{ $ip = $_SERVER['REMOTE_ADDR']; $random_password44=rand(1111111,99999999); $time=time(); mysql_query("INSERT INTO `user_info` ( `id` , `username`) VALUES ( '', '$reg_username')"); mysql_query("INSERT INTO `users` ( `id` , `username` , `password` , `money` , `regged` ,`startdate` , `email` , `location` , `homecity` ,`ip` , `r_ip`, `referal`) VALUES ('', '$reg_username', '$reg_password', '500', '$time', '$today', '$email', '$location', '$location', '$ip', '$ip', '$referal2')") or die(mysql_error); $userid = mysql_insert_id(); // Let's mail the user! $subject = "MafiaSyndicate"; $message = "Thank you for registering at Mafia Syndicate, You can login to the game at www.mafiasyndicate.co.cc with the following details: Username: $reg_username Password: $reg_password Thank you very much for registering Mafia Syndicate Staff Note: This is an automated email, please do not reply as you wont get response."; mail($email, $subject, $message, "From: MafiaSyndicate<mailserver@mafiasyndicate.co.cc>"); echo "Your account has been registered! You can now log in!"; } }}}}}} ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <title>Register</title> <link href="stylesheets/index.css" rel="stylesheet" type="text/css" /> <script language=JavaScript> function so(dis) { for (i=0;i<dis.elements.length;i++){ if (dis.elements.type=='submit') dis.elements.style.visibility='hidden'; } if(fs==false){ fs=true; return true; }else return false; } function goaway() { for(i=0;i<document.forms.length;i++) document.forms.onsubmit = function() {return so(this);}; } </script> </head> <body onLoad="goaway();"> <table border="0" align="center" cellpadding="0" cellspacing="0"> <tr> <td class="header">Mafia Syndicate</td> </tr> <tr> <td height="18" align="center"><div id="sectionLinks"> <a href="index.php">Home</a><a href="register.php">Register</a><a href="lostpass.php">Lost Password</a></div></td> </tr> <tr> <td height="300" class="main"><p> </p> <p> </p> <p> </p> <p> </p> <p> </p> <form action="" method="post" name="form2" id="form2"> <p> </p> <p> </p> <table width="300" border="0" align="center" cellpadding="0" cellspacing="0"> <tr> <td width="130" height="49" class="header"> Username: </td> <td width="57%"><input name="reg_username" type="text" id="reg_username" maxlength="40" /></td> </tr> <tr> <td width="130" height="49" class="header"> Password: </td> <td width="57%"><input name="reg_password" type="password" id="reg_password" maxlength="40" /></td> </tr> <tr> <td class="header">E-mail:</td> <td><input name="email" type="text" id="email" value="" /></td> </tr> <tr> <td class="header">Re-Type E-mail: </td> <td><input name="email1" type="text" id="email1" value="" /></td> </tr> <tr> <td height="20" class="header">Home City </td> <td><select name="location" class="ddm" id="location" > <option value="New York" selected="selected">New York</option> <option value="Philly">Philadelphia</option> <option value="Chicago">Chicago</option> <option value="Detroit">Detroit</option> <option value="Los Angeles">Los Angeles</option> <option value="Las Vegas">Las Vegas</option> <option value="New Jersey">New Jersey</option> <option value="Florida">Florida</option> </select></td> </tr> <tr> <td height="20" class="bodytext"><p><span class="header">Script Check:</span> <b><? print"$sc"; ?></b></p> </td> <td><input name="scriptcheck" type="text" id="scriptcheck" value="" /> <input type="hidden" value="<? print"$sc"; ?>" name="scrip"></td> </tr> <tr> <td height="20" class="header">Referal (optional) </td> <td> <? if(!$referal){ ?> <input name="ref2" type="text" id="ref2" value="<? print"$referal"; ?>" maxlength="40" /> <? }else{ ?> <input name="ref2" type="text" id="ref2" value="<? print"$referal"; ?>" maxlength="40" READONLY> <? } ?> </td> </tr> <tr> <td> </td> <td> <input name="Submit" type="submit" class="submit" value="Register!" /> </td> </tr> </table> </form> </td> </tr> </table> <center> </td> <td> </td> </tr> <tr> <td height="14"></td> </tr> </center> </body> </html>
Yeah, the error would be a great help. You should look into PHP Data Objects (PDO) for your database driver. It takes the hard work out of doing DB calls. You can use prepared statements and everything. Set PDO to throw an exception, and wrap it around a try/catch block. I find it easier to do DB things that way.
for each of the queries, after execution, just add: OR DIE(MySQL_ERROR()); for example $result = mysql_query($query) or die(mysql_error()); THis will then tell you which query is giving the script the problems