Click here to Skip to main content
15,884,298 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello forum!,

I have an issue with a script to do with PHP.

I'm creating a website which requires a register script that connects to "MSSQL" database, So far I've managed to script and make it connect to the database and be successful but the issue is that when entering in a field and submits the function it will "Echo" a command and places it on to the page up top somewhere which is not where I want it to go.

Is there any function using HTML/PHP instead of jquery that I could return that command into a "DIV AP" and print text when submitted?


[HTML] This is the Forum Container
HTML
<div id="BlogRegPanelHolder">
<form action="<?php echo $PHP_SELF?>" method="post" id="RegisterForm">

<div id="UserForm"><input name="name" type="Text" style="width: 458px; height: 31px; background:transparent; color: silver; border: 0px" value="" size="70" /></div>

<div id="UserPassForm"><input name="password" type="Password" style="width: 458px; height: 31px; background:transparent; color: silver; border: 0px" value="" size="70" /></div>

<div id="UserConfirmPassForm"><input name="password2" type="password" style="width: 458px; height: 31px; background:transparent; color: silver; border: 0px" value="" size="70" /></div>

<div id="UserEmailForm"><input name="email" type="Text" style="width: 458px; height: 31px; background:transparent; color: silver; border: 0px" value="" size="70" /></div>

<div id="RegButtonHolder">

<input
	type="image"
	name="submit"
	src="../../Images/RegButton.png"
	/>
<div id="UserField">Showing!</div>
<div id="UserPassField"></div>
<div id="UserPass2Field"></div>
<div id="UserEmailField"></div>
<!--<a href="#" ><img src="../../Images/RegButton.png" width="293" height="67" id="RegButton" /></a></div>-->
</div>
</form>



[PHP] This is the script that follows
PHP
<?php

$myServer = "127.0.0.1,1433";
$myUser = "User";
$myPass = "Pass";
$myDB = "Databse";

$name = $_POST['name'];
$pass = $_POST['password'];
$pass2 = $_POST['password2'];
$email = $_POST['email'];

$str_len1 = strlen($name);
$str_len2 = strlen($pass);
$str_len3 = strlen($email);


$s = @mssql_connect( $myServer, $myUser, $myPass )
    or die( "Couldn't connect to SQL Server on $myServer" );

$d = @mssql_select_db($myDB, $s)
    or die( "Couldn't open database $myDB" );


if ($str_len1 <= 0){
echo "<center><font color=red size=2> Enter your login information </font></center>";
exit();}

if ($str_len2 <= 0){
echo "<center><font color=red size=2> Enter the password </font></center>";
exit();}

if ($str_len1 < 4){
echo "<center><font color=red size=2> Login name is too short </font></center>";
exit();}

if ($str_len2 < 4){
echo "<center><font color=red size=2> Password is too short </font></center>";
exit();}

if ($pass != $pass2){
echo "<center><font color=red size=2> Enter a different password twice </font></center>";
exit();}

if ($str_len3 < 4){
echo "<center><font color=red size=2> email malformed </font></center>";
exit();}

if ($str_len1 > 12){
echo "<center><font color=red size=2> Login name is too long </font></center>";
exit();}

if ($str_len2 > 12){
echo "<center><font color=red size=2> Password is too long </font></center>";
exit();}

if (!preg_match("#^[a-z0-9]+$#i", $name)){
echo "<center><font color=red size=2> Login name must consist of letters or numbers </font></center>";
exit();}

if (!preg_match("#^[a-z0-9]+$#i", $pass)){
echo "<center><font color=red size=2> The password must be composed of letters or numbers </font></center>";
exit();}

$result = mssql_query( "[dbo].[DN_REGISTER] N'$name',N'$pass',N'$email'" );
mssql_close();

$row = mssql_fetch_array($result);
mssql_free_result($result);

if($row[0] == "2")
echo "<center><font color=red size=2> Account registration failed exist!</font></center>";
else if ($row[0] == "3")
echo "<center><font color=red size=2> Email use registration failed!</font></center>";
else
echo "<center><font color=green size=2> Congratulations, registration is successful!</font></center>";
?>


I've also had a look around and got no result other than jquery functions which I don't want to use. If any one could help me out I would be much grateful!
Posted
Updated 6-Nov-14 9:08am
Comments
vbmike 6-Nov-14 15:40pm    
PHP will 'echo' some text where the php code is placed. If you place the php segment where you want it to be 'echo'ed that is where it will show up. Look at http://www.w3schools.com/php/php_syntax.asp. Not sure but that may be why it is not showing up where you want it to.
Syngravez 6-Nov-14 16:05pm    
I will give this a shot, but I just can't see why there isn't a simple function or command to put it that area of where I want it to be.

But thank you anyways!

1 solution

I've manage to solve this by having an other intense look around upon the Internets and found a slight solution to what I wanted.


[PHP] This is the php script above my Container DIV which holds the form.
PHP
<?php
$error = "";

if(isset($_POST['login'])) 
{	
if( !empty($_POST['username'])) 
{
	
}
else
{
$error = "You must supply a username!.";
}

if( !empty($_POST['password'])) 
{
	
}
else
{
$error = "You must supply a password!.";
}
}
}
?>


[HTML] These are the container bits on the site to function the form.

HTML
<div id="BlogRegPanelHolder">
<form action="Register.php" method="post" id="RegisterForm">


<div id="NotifyForm">
<div><?php echo $error; ?></div>
</div>

<div id="UserForm">
<input type="text" name="username" style="width: 458px; height: 31px; background:transparent; color: silver; border: 0px" value="" size="70" />
</div>



<div id="UserPassForm">
<input type="password" name="password" style="width: 458px; height: 31px; background:transparent; color: silver; border: 0px" value="" size="70" />
</div>

<div id="UserConfirmPassForm">
<input name="password2" type="password" style="width: 458px; height: 31px; background:transparent; color: silver; border: 0px" value="" size="70" />
</div>

<div id="UserEmailForm">
<input name="email" type="Text" style="width: 458px; height: 31px; background:transparent; color: silver; border: 0px" value="" size="70" />
</div>

<div id="RegButtonHolder">
<input name="login" value="" type="Submit" style="background:url(../../Images/RegButtonHover.png) no-repeat; width:292px; height:71px; " />

</div>
</form>
</div>



Hope this is helpful to anyone else that has this same problem!
 
Share this answer
 
v3

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900