Jump to content

[SOLVED] I can't find the error, please help.


jrws

Recommended Posts

I have a script I am using, and as I am a beginer at PHP and OOP the code may have problems. I am trying to make an install page. So far it worked until I added the option of adding an admin via the install page. There are no user levels as of yet and so it was a test.

Heres the problem; I click submit and the form processes without going to another page, and the administrator is added, however the email is not there, I even echoed what the database thouht was happening and this is what I got:

INSERT INTO `site`.`user` ( `id` , `username` , `password` , `email` ) VALUES ( NULL , 'test', '68358d5d9cbbf39fe571ba41f26524b6', '' ); 

Now I can't figure out why, because when all forms are filled in that is the same continuous result. I've checked my code to make sure I got the names right,I do. I have also checked that the functions don't interfer with the code, and they  don't. So now I am lost.

 

Finially here is the code:

<?php

  $user = clean($_POST['user']);
    $email = clean($POST['email']);
    $password = clean($_POST['password']);
    $password = encrypt($password);

      $Add_Admin = "INSERT INTO `site`.`user` (
`id` ,
`username` ,
`password` ,
`email`
)
VALUES (
NULL , '$user', '$password', '$email'
); ";
    if ($mysql->query($Add_Admin)) {
        echo 'Admin user created succesfully!<br>';
        echo $Add_Admin;
    } else {
        echo 'Admin user failed to be created!<br>';
    }?>

PHP tags added for the sake of adding them. Heres the form:

<form method="post" action="<? $SERVER_['PHP_SELF']; ?>">
Admin Name: <input type="text" name="user"> <br>
Password: <input type="password" name="password"><br>
Email:<input type="text" name="email"><br>
<input type="submit" name ="submit" value="Submit">
</form>

 

When I said error_reporting(E_ALL) the only error I got was with the $SERVER variable...

 

If there is anything else you need to help me solve my problem please ask.

Thanks

Link to comment
Share on other sites

When I said error_reporting(E_ALL) the only error I got was with the $SERVER variable...

 

First thing Id do is fix that then.

 

<form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">

 

Also, where is $mysql created?

Link to comment
Share on other sites

Sorry I don't understand what you mean by where it it created? Do you mean where at the script? At the very top:

require_once ('config.php');
$mysql = new mysql();

Config has the autoload function, and I will try your suggestion :D

 

Just tried it, no change. BTW why do you add echo anyway? I have seen it done many times and now I am interested as to why, because just the server variable seems to work for me...

Link to comment
Share on other sites

if short tag (<? ) are not enable the code won't work and with long tags (<?php ) you need the echo..

but thats not the problem you had

you had

$SERVER_['PHP_SELF'];

the correct syntax is

$_SERVER['PHP_SELF'];

note the underscore position

..

in anycase..

 

can you change this line

$email = clean($POST['email']);

to

$email = clean($_POST['email']);

 

thats should fix it

Link to comment
Share on other sites

Actually looking again. <? $_SERVER['PHP_SELF']; ?> won't work either. You would need to use <?= $_SERVER['PHP_SELF']; ?> (which I still wouldn't recommend).

 

Your code would actually produce a blank action which as it be happens to default to the calling page.

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.