powerdot Posted July 26, 2006 Share Posted July 26, 2006 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. Quote Link to comment https://forums.phpfreaks.com/topic/15666-why-this-doenst-work/ Share on other sites More sharing options...
redarrow Posted July 26, 2006 Share Posted July 26, 2006 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] Quote Link to comment https://forums.phpfreaks.com/topic/15666-why-this-doenst-work/#findComment-63871 Share on other sites More sharing options...
rpm Posted July 26, 2006 Share Posted July 26, 2006 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 notbye Quote Link to comment https://forums.phpfreaks.com/topic/15666-why-this-doenst-work/#findComment-63881 Share on other sites More sharing options...
powerdot Posted July 26, 2006 Author Share Posted July 26, 2006 Thank you for your post! :Dredarrow : 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. Quote Link to comment https://forums.phpfreaks.com/topic/15666-why-this-doenst-work/#findComment-63887 Share on other sites More sharing options...
redarrow Posted July 26, 2006 Share Posted July 26, 2006 check your query strange innit. Quote Link to comment https://forums.phpfreaks.com/topic/15666-why-this-doenst-work/#findComment-63906 Share on other sites More sharing options...
448191 Posted July 26, 2006 Share Posted July 26, 2006 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] Quote Link to comment https://forums.phpfreaks.com/topic/15666-why-this-doenst-work/#findComment-63910 Share on other sites More sharing options...
redarrow Posted July 26, 2006 Share Posted July 26, 2006 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] Quote Link to comment https://forums.phpfreaks.com/topic/15666-why-this-doenst-work/#findComment-63911 Share on other sites More sharing options...
rpm Posted July 26, 2006 Share Posted July 26, 2006 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 otherwisenot , chances are that this condition must be evaluating to false bye. Quote Link to comment https://forums.phpfreaks.com/topic/15666-why-this-doenst-work/#findComment-63983 Share on other sites More sharing options...
powerdot Posted July 26, 2006 Author Share Posted July 26, 2006 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. Quote Link to comment https://forums.phpfreaks.com/topic/15666-why-this-doenst-work/#findComment-64122 Share on other sites More sharing options...
448191 Posted July 26, 2006 Share Posted July 26, 2006 Please echo out both $query and $_POST.[code]<?phpecho $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. :PYou 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] Quote Link to comment https://forums.phpfreaks.com/topic/15666-why-this-doenst-work/#findComment-64130 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.