PC Nerd Posted January 4, 2007 Share Posted January 4, 2007 hi guys. ive been working on a text based game..., but i cannot for the life of me find the error in my scripting for adding a new user to the database ( mysql v5). my code is bellow, and the error is with the query to add the user[code]<?php$User_Name = $_POST['User_Name'];$Password = $_POST['Password'];$Email = $_POST['Email'];$Security_Number = $_POST['Security_Number'];$F_Name = $_POST['F_Name'];$L_Name = $_POST['L_Name'];$Age = $_POST['Age'];include("inc files\Database_link.inc");$New_Player_SQL = "INSERT INTO General_Stats ('User_Name', 'Password', 'Email', 'Security_Number', 'F_Name', 'L_Name', 'Age') VALUES ('$User_Name', '$Password', '$Email', '$Security_Number', '$F_Name', '$L_Name', '$Age')";$New_Player_Query = mysqli_query($DB_Server, $New_Player_SQL)or die("<h3>Error</h3>\n<br><br>\n<p>An error has occured while submitting your details to the Database. As a result your account has not been created, although you may still receive your confirmation email. If you do receive your Email, please ignore it, and resubmit your account request in 24 hours.</p><br><br>".mysqli_error($New_Player_SQL));#if(!@$New_Player_Query){# echo "#<h3>Error</h3>\n<br><br>\n<p>An error has occured while submitting your details to the Database. As a result your account has not been created, although you may still receive your confirmation email. If you do receive your Email, please ignore it, and resubmit your account request in 24 hours.</p>");#}#else{echo "<h3>Success</h3>\n<br><br>\n<p>Your account has been added to our database. Once you receive your confirmation email, follow the link, and your account will be activated, after which you will be able to play on Battle-Ages whenever you wish.</p>";#}[/code]The include file, Datatabse link is working fine, as the previous page use it with no problems. if you wish me to post it though, please just let me know.i know it must be tedious, debuggingother peoples scripts, but i could really use all the help i can get, becauase ive been working on solveing this error for the last 4 hours. Thanks all who help, PC Nerd[font=Verdana][/font][color=red][/color][color=red][/color] Quote Link to comment Share on other sites More sharing options...
trq Posted January 4, 2007 Share Posted January 4, 2007 Does the or die() get called? What error are you actually receiving and can we see the ouput of your query? Quote Link to comment Share on other sites More sharing options...
PC Nerd Posted January 4, 2007 Author Share Posted January 4, 2007 [code]Warning: mysqli_error() expects parameter 1 to be mysqli, string given in FILENAME HERE[/code] on line 21 Quote Link to comment Share on other sites More sharing options...
ShogunWarrior Posted January 4, 2007 Share Posted January 4, 2007 Should you be using mysql_query instead of mysqli_query? Quote Link to comment Share on other sites More sharing options...
PC Nerd Posted January 4, 2007 Author Share Posted January 4, 2007 no, im using the right query becauase im using mysql v5.0.21, xampp if anyone usaes it. but i still cant firgure it out Quote Link to comment Share on other sites More sharing options...
ShogunWarrior Posted January 4, 2007 Share Posted January 4, 2007 Previous page source code? Quote Link to comment Share on other sites More sharing options...
PC Nerd Posted January 4, 2007 Author Share Posted January 4, 2007 is that the Database link includefile, or the form validation Quote Link to comment Share on other sites More sharing options...
ShogunWarrior Posted January 4, 2007 Share Posted January 4, 2007 Database link I suppose, wouldn't hurt to have a look. Quote Link to comment Share on other sites More sharing options...
PC Nerd Posted January 4, 2007 Author Share Posted January 4, 2007 [code]<?php$host="localhost";$account="*****";$password="*****";$dbname="battle-ages_db";$Error_Log[1] = "";$Error_Log[2] = "";$DB_Server = mysqli_connect($host, $account);if(!$DB_Server){echo "<p>There was an error in connecting to the database server. Please try again later.</p>"; $Error_Log[1] = "DB_Server";}else{}$DB = mysqli_select_db($DB_Server, $dbname);if(!$DB){echo "<p>There was an error connecting to the Database. Please try Again later.</p>"; $Error_Log[2] = "DB_Connect";}else{}if(empty($Error_Log[1])){}elseif(empty($Error_Log[2])){}else{echo "<p>Battle_Ages apologises for any and all inconveniences caused by this fualt in the system. We are working on fixing the connection problem. Why not explore the public site for FAQ's and other help sections to become more aquainted with the game.</p>";}?>[/code]thats the database link, that will be included whenever i need to connect to the database.this is the code for the previous page[code]<html><head><link rel="stylesheet" type="text/css" href="B_A-CSS.css"><title>Battle Ages New Player</title></head><body><?php$Wrong = "NO";$Form = "NO";if($_POST['Email'] != $_POST['Re_Email']){$Wrong = "YES";}foreach($_POST as $field){ if(empty($field)){ $Wrong = "YES"; }}if($Empty == "YES"){ $Form = "YES";}else{ $Individual = "NO"; while($Individual == "NO"){ $Security_Number = rand(0, 9).rand(0, 9).rand(0, 9).rand(0, 9)." - ".rand(0, 9).rand(0, 9).rand(0, 9)." - ".rand(0, 9).rand(0,9).rand(0, 9); $S_N_SQL = "SELECT Security_Number FROM Table_1 WHERE Security_Number = '".$Security_Number."'"; include('inc files/Database_link.inc'); $Query = @mysql_query($S_N_Query, $DB_Server); if(!$Query){ $Individual = "YES"; } } }echo "<table>";echo "<thead>\n";echo "<td class = \"left\">\n";echo "<img src=\"Graphics\\Draft Logo.jpg\" alt=\"Logo\" width = \"75%\" hight = \"75%\" align = \"left\">\n";echo "</td>";echo "<td class = \"centre\">\n";echo "</td>";echo "<td class = \"right\">\n";echo "<img src=\"Graphics\\Draft Logo.jpg\" alt=\"Logo\" width = \"75%\" hight = \"75%\" align = \"right\">\n";echo " </td>";echo "</thead>";echo "<tbody>";echo "<tr>";echo "<td class = \"left\">\n";echo "</td>";echo "<td class = \"centre\">\n";echo "<center><h1>New Player</h1></center>";if($Form == "YES"){echo "<p>You left one of the fields blank, or your emails did not match. Please fill in the form again.</p>";include("inc_files/B_A-New_Player.inc");}else{ echo "<p>Every time you login to Battle Ages, you will be required to use your User Name and your password. In addition to this you need to fill in a sequrity section, just like the ine at the end of the previous page. This helps to stop automated scripts playing th game for you.</p>"; echo "<p>To activate your account you must use the security number that is displayed below. The security Number will be emailed to the address which you enter before, along wil your details (Username, Password etc.)</p>"; echo "<p>Your Security Number is: $Security_Number</p>"; echo "<br>"; echo "<p>Click Finish to submit the full form to us. Your email will be sent within 24 hours. After you recieve the email, login at the First Time Login page of the Battle Ages home Page. To view that page, <a href=\"B_A-First Login.html\" alt=\"First time Login\">Click here</a>.</p>"; echo "<p>Click the Re-Start link to restart the New Player Form. This will reset all information you have entered.</p>"; echo "<p><a href=\"B_A-New_Player.html\" alt=\"Re-Start\">Start again</a></p>\n"; echo "<form action=\"B_A-New_Player_Create.php\" action=\"POST\">\n"; echo "<p><input type = 'hidden' name = 'User_Name' value = "."'".$_POST['User_Name']."'"." ></p>\n"; echo "<p><input type = 'hidden' name = 'Password' value = "."'".$_POST['Password']."'"." ></p>\n"; echo "<p><input type = 'hidden' name = 'Re_Password' value = "."'".$_POST['Re_Password']."'"." ></p>\n"; echo "<p><input type = 'hidden' name = 'Email' value = "."'".$_POST['Email']."'"." ></p>\n"; echo "<p><input type = 'hidden' name = 'Re_Email' value = "."'".$_POST['Re_Email']."'"." ></p>\n"; echo "<p><input type = 'hidden' name = 'Security_Number' value = "."'".$Security_Number."'"." ></p>\n"; echo "<p><input type = 'hidden' name = 'F_Name' value = "."'".$_POST['F_Name']."'"." ></p>\n"; echo "<p><input type = 'hidden' name = 'L_Name' value = "."'".$_POST['L_Name']."'"." ></p>\n"; echo "<p><input type = 'hidden' name = 'Age' value = "."'".$_POST['Age']."'"." ></p>\n"; echo "<p><input type='submit' value='Finish'></p>"; echo "</form>";}echo "</td>";echo "<td right = \"right\">\n";echo "</td>";echo "</tr>";echo "</tbody>";echo "</table>";echo "</body>";echo "</html>";?>[/code] Quote Link to comment Share on other sites More sharing options...
PC Nerd Posted January 5, 2007 Author Share Posted January 5, 2007 also, does anyone think that this could be done another way, or is this the easiest way to create a new entry in the database ( new user ). ive been working on it for about a week Quote Link to comment Share on other sites More sharing options...
simcoweb Posted January 5, 2007 Share Posted January 5, 2007 Not sure what kind of server you're on but if it's Unix it won't allow this blank space in the path to your include fileinclude("inc files\Database_link.inc");Check that to make sure it doesn't contain an underscore between the inc and files. Quote Link to comment Share on other sites More sharing options...
PC Nerd Posted January 5, 2007 Author Share Posted January 5, 2007 no, sorry that doesnt work, im using xampp, ( very similar to wamp if yoiu know it)its running on windows, using apache and php 5, and mysql 5.0.21ive trie3d everything Quote Link to comment Share on other sites More sharing options...
PC Nerd Posted January 6, 2007 Author Share Posted January 6, 2007 ok, ive changed the directory to inc_files", but it makes no difference. anywayz, i think that if it was a problem with the database link, the error notice within that file would show up, an not the error message from the actual query.when i give mysqli_error(), the variable of the query, it gives an error that the variable is a boolean, so does a INSERT INTO query give a different output, since it doesnt retreive data. could that be the problem.???once again, thanks for all your suggestions,PC Nerd Quote Link to comment Share on other sites More sharing options...
PC Nerd Posted January 6, 2007 Author Share Posted January 6, 2007 ok, i got rid of the entire "or die" statement. and instead went to use "echo $New_Player_Query;" when that happened nothing happened on screen. but..... does that mean that it is returning NULL becauase its an INSTER INTO Query? when i put the "or die" back in, the "or die" ran every time. would it be better to run an "if ( !$New_Player_Query) {finnish script}" ???, or is "or die" still better???, all help is much appreciated..... thankyou Quote Link to comment Share on other sites More sharing options...
PC Nerd Posted January 7, 2007 Author Share Posted January 7, 2007 does anyone have any ideas for this error. i really dont know what to do from here. if no one knows, just say so, but i would really appreciate you guys helping me solve this, or else letting me know that no one knows whats wrong in my scipt.... pleaase. Quote Link to comment Share on other sites More sharing options...
PC Nerd Posted January 7, 2007 Author Share Posted January 7, 2007 please can someone help me, i have no idea whatso ever about this, i am completely stumped Quote Link to comment Share on other sites More sharing options...
marcus Posted January 7, 2007 Share Posted January 7, 2007 But the query variable before the database variable Quote Link to comment Share on other sites More sharing options...
PC Nerd Posted January 7, 2007 Author Share Posted January 7, 2007 when iput it the other way around, i get an error, anyother ideas??? Quote Link to comment Share on other sites More sharing options...
marcus Posted January 7, 2007 Share Posted January 7, 2007 do this[code=php:0]$connect = new mysqli("$host", "$account", "$password", "$dbname");$result = $connect->$New_Player_SQL;if($result){echo "inserted";}else {printf("Error: %s\n", $mysqli->error);}[/code] Quote Link to comment Share on other sites More sharing options...
PC Nerd Posted January 7, 2007 Author Share Posted January 7, 2007 is this in database_link.inc or the New_Player_Create.php Quote Link to comment Share on other sites More sharing options...
trq Posted January 7, 2007 Share Posted January 7, 2007 Dont worry about mgallforever's code.[code=php:0]mysqli_error($DB_Server)[/code] Quote Link to comment Share on other sites More sharing options...
PC Nerd Posted January 7, 2007 Author Share Posted January 7, 2007 !!! where is this??? database_link.inc OR New_PLayer_create.php????????????!!!!!!!!!!!!!!!!!!!!!!!!!!!!!1 Quote Link to comment Share on other sites More sharing options...
Jessica Posted January 7, 2007 Share Posted January 7, 2007 OMG OMG OMG!After your query!!!!!one!11 Quote Link to comment Share on other sites More sharing options...
trq Posted January 7, 2007 Share Posted January 7, 2007 On the line that is giving you the error!!!! Quote Link to comment Share on other sites More sharing options...
PC Nerd Posted January 7, 2007 Author Share Posted January 7, 2007 ok, this is what i got. "You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''User_Name', 'Password', 'Email', 'Security_Number', 'F_Name', 'L_Name', 'Age') ' at line 2" Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.