/    Sign up×
Community /Pin to ProfileBookmark

sql not working

I’m building a site which includes a part for the administrator to add users and view all users in the system.
I don’t have much experience with PHP, so I might got stuck on a very simple or stupid thing, anyway: I can’t solve it.

The page can be found at [url]http://reynearts.awardspace.com[/url] and the source is below.

When I try to add a user, it just doesn’t work.
Where do I go wrong?

[code]
<?php
include(“../Scripts/dbconnect.php”);

?>
<html>
<head>
<title></title>
<link rel=”Stylesheet” type=”text/css” href=”CSS/admin.css”>
</head>
<body>
<table>
<tr><td class=”useradminleft”>
<?php
if ($toevoegen && $Gebruiker && $wachtwoord && $Voornaam && $Tussenvoegsel && $Achternaam) {
$toevoegquery = “INSERT INTO login (username, password, Voornaam, Tussenvoegsel, Achternaam) VALUES(‘$Gebruiker’, ‘$wachtwoord’, ‘$Voornaam’, ‘$Tussenvoegsel’, ‘$Achternaam’)”;
if (!mysql_query($toevoegquery)) {
echo “Toevoegen mislukt!”;
exit;
} else {
echo “Gebruiker toegevoegd!”;
exit;
}
}
?>

Gebruikers toevoegen<br><br>
<form name=”adduser” method=”post” action=”<?php echo $PHP_SELF ?>”>
Gebruikersnaam:
<input type=”text” name=”Gebruiker” value=””><br>
Wachtwoord:
<input type=”text” name=”wachtwoord” value=”fotosite”><br>
Voornaam:
<input type=”text” name=”Voornaam” value=””><br>
Tussenvoegsel:
<input type=”text” name=”Tussenvoegsel” value=””><br>
Achternaam:
<input type=”text” name=”Achternaam” value=””><br>
<input type=”Submit” name=”toevoegen” value=”gebruiker aanmaken”>
</form>
</td>
<td class=”useradminright”>
Gebruikersoverzicht<br><br>
<?php

$overzichtquery = “SELECT * FROM login”;
$overzicht = mysql_query($overzichtquery);
while ($rij = mysql_fetch_array($overzicht)) {
echo $rij[“username”].”&nbsp;”;
echo $rij[“active”].”&nbsp;”;
echo $rij[“Voornaam”].”&nbsp;”;
echo $rij[“Tussenvoegsel”].”&nbsp;”;
echo $rij[“Achternaam”].”&nbsp;”;
}

?>
</td></tr>
</table>
</body>
</html>
<?php
include(“../Scripts/dbclose.php”);
?>
[/code]

to post a comment
PHP

1 Comments(s)

Copy linkTweet thisAlerts:
@NogDogMar 05.2007 — A couple things to try/consider:

  • 1. Start your script with the following lines (at least until you get it running nicely):
    [code=php]
    <?php
    ini_set('display_errors', 1);
    error_reporting(E_ALL);
    [/code]

  • 2. Reference form value via the $_POST array, so that you don't have to depend upon whether or not register_globals is enabled, for example [b]$_POST['Gebruiker'][/b] instead of just [b]$Gebruiker[/b].


  • 3. You might want to grab some more debug info if your query fails:
    [code=php]
    <?php
    $toevoegquery = "INSERT INTO login (username, password, Voornaam, Tussenvoegsel, Achternaam) VALUES('$Gebruiker', '$wachtwoord', '$Voornaam', '$Tussenvoegsel', '$Achternaam')";
    if (!mysql_query($toevoegquery))
    {
    echo "Toevoegen mislukt! ($toevoegquery): " . mysql_error();
    exit;
    }[/code]

  • 4. You could add the following debug code to verify exactly what values got posted:
    [code=php]
    if(count($_POST))
    {
    printf("<pre>%s</pre>n", print_r($_POST, TRUE));
    }
    [/code]

    Hopefully some of that will help you find the problem.
  • ×

    Success!

    Help @renevanh spread the word by sharing this article on Twitter...

    Tweet This
    Sign in
    Forgot password?
    Sign in with TwitchSign in with GithubCreate Account
    about: ({
    version: 0.1.9 BETA 5.18,
    whats_new: community page,
    up_next: more Davinci•003 tasks,
    coming_soon: events calendar,
    social: @webDeveloperHQ
    });

    legal: ({
    terms: of use,
    privacy: policy
    });
    changelog: (
    version: 0.1.9,
    notes: added community page

    version: 0.1.8,
    notes: added Davinci•003

    version: 0.1.7,
    notes: upvote answers to bounties

    version: 0.1.6,
    notes: article editor refresh
    )...
    recent_tips: (
    tipper: @AriseFacilitySolutions09,
    tipped: article
    amount: 1000 SATS,

    tipper: @Yussuf4331,
    tipped: article
    amount: 1000 SATS,

    tipper: @darkwebsites540,
    tipped: article
    amount: 10 SATS,
    )...