Jump to content


Photo

Why this doens't work?


  • Please log in to reply
9 replies to this topic

#1 powerdot

powerdot
  • New Members
  • Pip
  • Newbie
  • 3 posts

Posted 26 July 2006 - 09:01 AM

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:



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;
        }
    }


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.


#2 redarrow

redarrow
  • Members
  • PipPipPip
  • Advanced Member
  • 7,308 posts
  • Locationlondon

Posted 26 July 2006 - 09:07 AM

there meny ways i show you here you are mate.

example 1
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; 
        } 
    } 


example 2
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; 
        } 
    } 




example 3
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; 
        } 
    } 
}

Wish i new all about php DAM i will have to learn
((EMAIL CODE THAT WORKS))
http://simpleforum.ath.cx/mail2.inc
((PAYPAL INTEGRATION THAT WORKS))
http://simpleforum.a...aypal1_info.inc

#3 rpm

rpm
  • New Members
  • Pip
  • Newbie
  • 5 posts

Posted 26 July 2006 - 09:32 AM

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

#4 powerdot

powerdot
  • New Members
  • Pip
  • Newbie
  • 3 posts

Posted 26 July 2006 - 09:46 AM

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.

#5 redarrow

redarrow
  • Members
  • PipPipPip
  • Advanced Member
  • 7,308 posts
  • Locationlondon

Posted 26 July 2006 - 10:17 AM

check your query strange innit.
Wish i new all about php DAM i will have to learn
((EMAIL CODE THAT WORKS))
http://simpleforum.ath.cx/mail2.inc
((PAYPAL INTEGRATION THAT WORKS))
http://simpleforum.a...aypal1_info.inc

#6 448191

448191
  • Staff Alumni
  • Advanced Member
  • 3,545 posts
  • LocationNetherlands

Posted 26 July 2006 - 10:23 AM

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

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

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

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

Try
<?php
$res = mysql_query($query) or die('Query Failed. '.mysql_error()."\n")
if(mysql_num_rows($res)) {
etc etc
?>


#7 redarrow

redarrow
  • Members
  • PipPipPip
  • Advanced Member
  • 7,308 posts
  • Locationlondon

Posted 26 July 2006 - 10:24 AM

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

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; 
        } 
    } 
}

Wish i new all about php DAM i will have to learn
((EMAIL CODE THAT WORKS))
http://simpleforum.ath.cx/mail2.inc
((PAYPAL INTEGRATION THAT WORKS))
http://simpleforum.a...aypal1_info.inc

#8 rpm

rpm
  • New Members
  • Pip
  • Newbie
  • 5 posts

Posted 26 July 2006 - 01:00 PM

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.

#9 powerdot

powerdot
  • New Members
  • Pip
  • Newbie
  • 3 posts

Posted 26 July 2006 - 03:53 PM

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:


<?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;
        }
}


?>


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



#10 448191

448191
  • Staff Alumni
  • Advanced Member
  • 3,545 posts
  • LocationNetherlands

Posted 26 July 2006 - 04:04 PM

Please echo out both $query and $_POST.

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

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.

<?php
$oldlevel = error_reporting(E_ALL);
echo $oldlevel;
?>






0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users