Jump to content

Why this doens't work?


powerdot

Recommended Posts

Hello,

I hope to find here some help. I have a great php contact form that send the content to different email addresses.

Only for one department I want that the script look into an existing database if the username is accurate. If not a warning message need to be given and saying to fix the ticket.

I have insert this:

[quote]


if ((isset($_POST['form_subject'])) && ($_POST['form_subject'] == $subject_option[1]['subj']))
    {
        $link = mysql_connect('localhost', 'powerdo_web', "*******");
        mysql_select_db(powerdo_accounts', $link);
        $query = "SELECT `username` FROM `member_list` WHERE `username`='" . mysql_real_escape_string($_POST['$var_username']) . "' LIMIT 1";
       
        if (mysql_num_rows(mysql_query($query)) != 1)
        {
            print "<font color=\"#660000\"><strong>* Required field -- \"Your cPanel Username\" is not valid. Please fix this and re-submit.</strong></font><br>\n";
            $skipflag = true;
        }
    }

[/quote]

All tickets are send: without username; with a valid username and with a unvalid username.
It seems the script doesn't look into the database for verify the usernames.  :-[


Can somebody help me out this problem please?
Thank you,
Natalia.
Link to comment
Share on other sites

there meny ways i show you here you are mate.

example 1
[code]
if ((isset($_POST['form_subject'])) && ($_POST['form_subject'] == $subject_option[1]['subj']))
    {
        $link = mysql_connect('localhost', 'powerdo_web', "*******");
        mysql_select_db(powerdo_accounts', $link);
        $query = "SELECT `username` FROM `member_list` WHERE `username`='" . mysql_real_escape_string($_POST['$var_username']) . "' LIMIT 1";
       $result=mysql_query($query);
        if (mysql_num_rows($result) != 1)
        {
            print "<font color=\"#660000\"><strong>* Required field -- \"Your cPanel Username\" is not valid. Please fix this and re-submit.</strong></font>
\n";
            $skipflag = true;
        }
    }

[/code]

example 2
[code]
if ((isset($_POST['form_subject'])) && ($_POST['form_subject'] == $subject_option[1]['subj']))
    {
        $link = mysql_connect('localhost', 'powerdo_web', "*******");
        mysql_select_db(powerdo_accounts', $link);
        $query = "SELECT `username` FROM `member_list` WHERE `username`='" . mysql_real_escape_string($_POST['$var_username']) . "' LIMIT 1";
      $result=mysql_query($query);
        if (!mysql_num_rows($result) == 1)
        {
            print "<font color=\"#660000\"><strong>* Required field -- \"Your cPanel Username\" is not valid. Please fix this and re-submit.</strong></font>
\n";
            $skipflag = true;
        }
    }

[/code]



example 3
[code]
if ((isset($_POST['form_subject'])) && ($_POST['form_subject'] == $subject_option[1]['subj']))
    {
        $link = mysql_connect('localhost', 'powerdo_web', "*******");
        mysql_select_db(powerdo_accounts', $link);
        $query = "SELECT `username` FROM `member_list` WHERE `username`='" . mysql_real_escape_string($_POST['$var_username']) . "' LIMIT 1";
      $result=mysql_query($query);
while($record=mysql_fetch_assoc($result)){

if($record['username']==0)
        {
            print "<font color=\"#660000\"><strong>* Required field -- \"Your cPanel Username\" is not valid. Please fix this and re-submit.</strong></font>
\n";
            $skipflag = true;
        }
    }
}
[/code]
Link to comment
Share on other sites

dear friend,
  It seems that the script does look into the database for verifying  the usernames.Please look or check the posted variables 'form_subject' and whether the checking condition  if ((isset($_POST['form_subject'])) && ($_POST['form_subject'] == $subject_option[1]['subj']))   meets or not
bye
Link to comment
Share on other sites

Thank you for your post!  :D

redarrow : I tried the 3 codes but all unsuccessfull.

prm : sorry, this must be right since this variables are used by the script for select the one specific departement where I want to verify the username.

Ohter suggestions?

Again Thank You All.
Link to comment
Share on other sites

Aside from a parse error in this: mysql_select_db(powerdo_accounts[b]'[/b], $link);

First thing I notice: [b]$_POST['$var_username'].[/b]

Please check if you have a form element named "$var_username", and not, for example, "var_username".

Futhermore, lines like [i]if (mysql_num_rows(mysql_query($query)) != 1) [/i] aren't exactly recommended.

Try
[code]<?php
$res = mysql_query($query) or die('Query Failed. '.mysql_error()."\n")
if(mysql_num_rows($res)) {
etc etc
?>[/code]
Link to comment
Share on other sites

echo out the username then see it it is set from the Query ok.

[code]
if ((isset($_POST['form_subject'])) && ($_POST['form_subject'] == $subject_option[1]['subj']))
   {
       $link = mysql_connect('localhost', 'powerdo_web', "*******");
       mysql_select_db(powerdo_accounts', $link);
       $query = "SELECT `username` FROM `member_list` WHERE `username`='" . mysql_real_escape_string($_POST['$var_username']) . "' LIMIT 1";
      $result=mysql_query($query);
while($record=mysql_fetch_assoc($result)){

echo $record['username'];
       {
           print "<font color=\"#660000\"><strong>* Required field -- \"Your cPanel Username\" is not valid. Please fix this and re-submit.</strong></font>
\n";
           $skipflag = true;
       }
   }
}
[/code]
Link to comment
Share on other sites

dear friend
    your code goes like this
 
 
if ((isset($_POST['form_subject'])) && ($_POST['form_subject'] == $subject_option[1]['subj']))
    {
 
    }
after the form_subject is set then will the validity will be checked otherwise
not , chances are that this condition must be evaluating to false
bye.
Link to comment
Share on other sites

OK, this make me mat  :(

I'm sure from the first and therefore I have put the suggestion from "redarrow" (thanks) for echo out the username in a single script named test.php.

This is the script:
[quote]

<?php

$var_username = " ";

$skipflag = FALSE;
$link = mysql_connect("localhost", "powerdo_web", "*******") or die("Error: " . mysql_error());
        mysql_select_db("powerdo_accounts", $link);
        $query = "SELECT `username` FROM `host_list` WHERE `username`='" . mysql_real_escape_string($_POST['$var_username']) . "' LIMIT 1";
      $result=mysql_query($query)or die('Query Failed. '.mysql_error()."\n");
while($record=mysql_fetch_assoc($result)){

echo $record['username'];
{
            print "<font color=\"#660000\"><strong>* Required field -- \"Your Username\" is not valid. Please fix this and re-submit.</strong></font>
\n";
            $skipflag = true;
        }
}


?>

[/quote]

I receive only a blank page, no errors, no username, nothing.

Link to comment
Share on other sites

Please echo out both $query and $_POST.

[code]<?php
echo $query;
echo '<pre>';
print_r($_POST);
echo '</pre>';
?>[/code]

Also please post your form. Something is wrong with this $var_username thing I can almost taste it.  :P

You do know that '$var' won't expand to the value of $var, right?

Also, check your error reporting level. Something's fishy.

[code]<?php
$oldlevel = error_reporting(E_ALL);
echo $oldlevel;
?>[/code]

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.