Jump to content

[SOLVED] New User PHP script ( thanks for all your help )


PC Nerd

Recommended Posts

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]
Link to comment
Share on other sites

[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]
Link to comment
Share on other sites

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
Link to comment
Share on other sites

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
Link to comment
Share on other sites

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.
Link to comment
Share on other sites

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"
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.