Jump to content

abs0lut

Members
  • Posts

    111
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

abs0lut's Achievements

Member

Member (2/5)

0

Reputation

  1. if port 3306 is not being blocked by my server or other server? I give a file to my friend then I want to know the url if he upload it. is it possible? what will I put in the file that I will give?
  2. I want to insert the data in the database (mysql).
  3. I don't know how to get the data from the other server. I give my friend a file then I want to know the url if he upload it. is it possible?
  4. is it possible to insert data in another server? I need to insert the value of a variable from other server to my server. could you please help me?
  5. Does anyone know hove to invert binary code? For example 00110101 to 11001010
  6. I have an input field username. how to check if username already exists in 2 tables? could you please help me?
  7. ajax.js var xmlHttp function checkForm(str, id) { xmlHttp=GetXmlHttpObject() if (xmlHttp==null) { alert ("Browser does not support HTTP Request") return } var url="AJAX.php?q="+str+"&id="+id xmlHttp.onreadystatechange = function() { if(xmlHttp.readyState==4) { text = xmlHttp.responseText document.getElementById(id).style.borderColor = text.substring(0,7); document.getElementById(id+"v").innerHTML = text.substring( if(id == "pass1" & document.getElementById("rpass").value != "") { checkForm(document.getElementById("rpass").value, "rpass"); } } } xmlHttp.open("GET",url,true) xmlHttp.send(null) } function GetXmlHttpObject() { var xmlHttp=null; try { xmlHttp=new XMLHttpRequest(); } catch (e) { try { xmlHttp=new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) { xmlHttp=new ActiveXObject("Microsoft.XMLHTTP"); } } return xmlHttp; } function ClearBox() { document.getElementById("user").value = "" document.getElementById("mail").value = "" document.getElementById("fdate").value = "m - d - Y" SetTimer(); } function SetTimer() { timers=GetXmlHttpObject() if (timers==null) { alert ("Browser does not support HTTP Request") return } var url="AJAX.php?act=time" timers.onreadystatechange = function() { if(timers.readyState==4) { document.getElementById("timer").innerHTML = timers.responseText } } timers.open("GET",url,true) timers.send(null) setTimeout("SetTimer()", 1000); } function SetDate(format) { dates=GetXmlHttpObject() if (timers==null) { alert ("Browser does not support HTTP Request") return } var url="AJAX.php?act=date&f="+format dates.onreadystatechange = function() { if(dates.readyState==4) { document.getElementById("date").innerHTML = dates.responseText } } dates.open("GET",url,true) dates.send(null) } ajax.php <?php session_start(); if(isset($_GET['q'])){ $q = $_GET['q']; } if(isset($_GET['id'])){ $id = $_GET['id']; } if(isset($_GET['act'])){ $act = $_GET['act']; } $con = mysql_connect('localhost', 'root', ''); if (!$con){ die('Could not connect: ' . mysql_error()); } mysql_select_db("validator", $con); if($id == "user") { $sql="SELECT * FROM users WHERE username = '$q'"; $result = mysql_query($sql); $rows = mysql_num_rows($result); if(strlen($q) < 4 || strlen($q) > 25) { echo "#FF0000 <img src=\"images/bad.gif\" />Username must be between 4 - 25 characters long."; } elseif($rows > 0) { echo "#FF0000 <img src=\"images/bad.gif\" />That username is in use."; } else { echo "#00FF00 <img src=\"images/good.gif\" />"; } } elseif($id == "pass1") { $_SESSION['p1'] = $q; if(strlen($q) < 4 || strlen($q) > 30) { echo "#FF0000 <img src=\"images/bad.gif\" />Password must be between 4 - 30 characters long."; } else { echo "#00FF00 <img src=\"images/good.gif\" />"; } } elseif($id == "rpass") { if($q != $_SESSION['p1']) { echo "#FF0000 <img src=\"images/bad.gif\" />Passwords do not match."; } else { echo "#00FF00 <img src=\"images/good.gif\" />"; } } elseif($id == "mail") { $sql="SELECT * FROM users WHERE user_email = '$q'"; $result = mysql_query($sql) or die(mysql_error()); $rows = mysql_num_rows($result); if($rows > 0) { echo "#FF0000 <img src=\"images/bad.gif\" />That email is already registered."; } elseif(!eregi("^[[:alnum:]][a-z0-9_.-]*@[a-z0-9.-]+\.[a-z]{2,4}$", $q)) { echo "#FF0000 <img src=\"images/bad.gif\" />That email is invalid."; } else { echo "#00FF00 <img src=\"images/good.gif\" />"; } } else { if($act == "time") { echo date("h:i:s a", time()); } elseif($act == "date") { $format = $_GET['f']; echo date($format); } } mysql_close($con); ?> AJAX_Register.php <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <script type="text/javascript" src="AJAX.js"></script> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Registration</title> </head> <body onload="ClearBox()"> <form action="register.php" method="post" name="Register"> <table bgcolor="#CCCCCC" width="640" align="center" cellpadding="2px"> <tr valign="middle"> <td> <table align="center" width="630" style="border-collapse:collapse;"> <tr bgcolor="#CCCCCC"> <td align="center" class="inside" bgcolor="#FFFFFF"><label class="title">AJAX Validator v1.00</label></td> </tr> <tr bgcolor="#CCCCCC"> <td> </td> </tr> </table> <table align="center" width="630" bgcolor="#FFFFFF" style="border:solid 1px #666666; border-collapse:collapse;"> <tr> <td width="300" align="right" class="inside"><label>Username: <input type="text" name="user" id="user" style="border-style: solid; border-width:1px;" onchange="checkForm(this.value, this.id)" /></label></td><td align="left" class="inside"><label id="userv" class="error"></label></td> </tr> <tr> <td width="300" align="right" class="inside"><label>Password: <input type="password" name="pass1" id="pass1" style="border-style: solid; border-width:1px;" onchange="checkForm(this.value, this.id)" /></label></td><td align="left" class="inside"><label id="pass1v" class="error"></label></td> </tr> <tr> <td width="300" align="right" class="inside"><label>Re-Type Password: <input type="password" id="rpass" style="border-style: solid; border-width:1px;" onchange="checkForm(this.value, this.id)" /></label></td><td align="left" class="inside"><label id="rpassv" class="error"></label></td> </tr> <tr bgcolor="#CCCCCC"> <td> </td><td> </td> </tr> <tr> <td width="300" align="right" class="inside"><label>Email: <input type="text" name="mail" id="mail" style="border-style: solid; border-width:1px;" onchange="checkForm(this.value, this.id)" /></label></td><td align="left" class="inside"><label id="mailv" class="error"></label></td> </tr> <tr bgcolor="#CCCCCC"> <td> </td><td> </td> </tr> <tr> <td width="300" align="right" class="inside"><label>Time offset from server: <select name="time" style="border-style: solid; border-width:1px;text-align:right;"> <option value="+12">+12</option> <option value="+11">+11</option> <option value="+10">+10</option> <option value="+9">+9</option> <option value="+8">+8</option> <option value="+7">+7</option> <option value="+6">+6</option> <option value="+5">+5</option> <option value="+4">+4</option> <option value="+3">+3</option> <option value="+2">+2</option> <option value="+1">+1</option> <option value="0" selected="selected">0</option> <option value="-1">-1</option> <option value="-2">-2</option> <option value="-3">-3</option> <option value="-4">-4</option> <option value="-5">-5</option> <option value="-6">-6</option> <option value="-7">-7</option> <option value="-8">-8</option> <option value="-9">-9</option> <option value="-10">-10</option> <option value="-11">-11</option> <option value="-12">-12</option> </select></label></td><td align="left" class="inside"><div id="timer" align="center"></div></td> </tr> <tr> <td width="300" align="right" class="inside"><label>Date Format: <input type="text" id="fdate" value="m - d - Y" style="border-style: solid; border-width:1px;" onkeyup="SetDate(this.value)" /></label></td><td align="left" class="inside"><div id="date" align="center"><?php echo date("m - d - Y"); ?></div></td> </tr> </table> <table align="center" width="630" style="border-collapse:collapse;"> <tr bgcolor="#CCCCCC"> <td> </td><td> </td><td> </td> </tr> <tr bgcolor="#CCCCCC"> <td width="275"> </td><td width="50" align="center" class="inside" bgcolor="#FFFFFF"><label><input type="submit" name="submit" value="Submit" /></label></td><td> </td> </tr> </table> </td> </tr> </table> </form> <div class="footer"><a href="http://pyr0.commoncritics.com" style="color: #666666;text-decoration: none;">Pyr0 Cre@tions<br /><label style="font-size: 8.5px;">Programmed by ©Todd Withers</label></a></div> </body> </html> register.php <?php $con = mysql_connect('localhost', 'root', ''); if (!$con){ die('Could not connect: ' . mysql_error()); } mysql_select_db("validator", $con); if(isset($_POST['submit'])){ $username = addslashes(trim($_POST['user'])); $email = addslashes(trim($_POST['mail'])); $pass = addslashes(trim($_POST['pass1'])); $date=date('Ymd'); $query = mysql_query("INSERT INTO users (username, password, user_email, date) VALUES ('$username','$pass','$email','$date')") or die(mysql_error()); if($query){ echo 'thanks for registering'; } } ?> the user could not submit if there are errors such as 'Username must be between 4 - 25 characters long', 'That username is in use', etc.. could you please help me?
  8. validate.php <?php // start PHP session session_start(); // load error handling script and validation class require_once ('error_handler.php'); require_once ('validate.class.php'); // Create new validator object $validator = new Validate(); // read validation type (PHP or AJAX?) $validationType = ''; if (isset($_GET['validationType'])) { $validationType = $_GET['validationType']; } // AJAX validation or PHP validation? if ($validationType == 'php') { // PHP validation is performed by the ValidatePHP method, which returns // the page the visitor should be redirected to (which is allok.php if // all the data is valid, or back to index.php if not) $username=$_POST['txtUsername']; $email=$_POST['txtEmail']; // check if the username exists in the database //$query2 = mysql_query("INSERT INTO users (user_name, Email) VALUES ('".$_POST['txtUsername']."','".$_POST['txtEmail']".')") or die(mysql_error()); $query2 = $validator->mMysqli->query("INSERT INTO users (user_name, Email) VALUES ('$username','$email')"); header("Location:" . $validator->ValidatePHP()); } else { // AJAX validation is performed by the ValidateAJAX method. The results // are used to form an XML document that is sent back to the client $response = '<?xml version="1.0" encoding="UTF-8" standalone="yes"?>' . '<response>' . '<result>' . $validator->ValidateAJAX($_POST['inputValue'], $_POST['fieldID']) . '</result>' . '<fieldid>' . $_POST['fieldID'] . '</fieldid>' . '</response>'; // generate the response if(ob_get_length()) ob_clean(); header('Content-Type: text/xml'); echo $response; } ?> validate.class.php <?php require_once ('config.php'); // Class supports AJAX and PHP web form validation class Validate { // stored database connection private $mMysqli; // constructor opens database connection function __construct() { $this->mMysqli = new mysqli(DB_HOST, DB_USER, DB_PASSWORD, DB_DATABASE); } // destructor closes database connection function __destruct() { $this->mMysqli->close(); } // supports AJAX validation, verifies a single value public function ValidateAJAX($inputValue, $fieldID) { // check which field is being validated and perform validation switch($fieldID) { // Check if the username is valid case 'txtUsername': return $this->validateUserName($inputValue); break; // Check if the name is valid case 'txtName': return $this->validateName($inputValue); break; // Check if a gender was selected case 'selGender': return $this->validateGender($inputValue); break; // Check if birth month is valid case 'selBthMonth': return $this->validateBirthMonth($inputValue); break; // Check if birth day is valid case 'txtBthDay': return $this->validateBirthDay($inputValue); break; // Check if birth year is valid case 'txtBthYear': return $this->validateBirthYear($inputValue); break; // Check if email is valid case 'txtEmail': return $this->validateEmail($inputValue); break; // Check if phone is valid case 'txtPhone': return $this->validatePhone($inputValue); break; // Check if "I have read the terms" checkbox has been checked case 'chkReadTerms': return $this->validateReadTerms($inputValue); break; } } // validates all form fields on form submit public function ValidatePHP() { // error flag, becomes 1 when errors are found. $errorsExist = 0; // clears the errors session flag if (isset($_SESSION['errors'])) unset($_SESSION['errors']); // By default all fields are considered valid $_SESSION['errors']['txtUsername'] = 'hidden'; $_SESSION['errors']['txtName'] = 'hidden'; $_SESSION['errors']['selGender'] = 'hidden'; $_SESSION['errors']['selBthMonth'] = 'hidden'; $_SESSION['errors']['txtBthDay'] = 'hidden'; $_SESSION['errors']['txtBthYear'] = 'hidden'; $_SESSION['errors']['txtEmail'] = 'hidden'; $_SESSION['errors']['txtPhone'] = 'hidden'; $_SESSION['errors']['chkReadTerms'] = 'hidden'; // Validate username if (!$this->validateUserName($_POST['txtUsername'])) { $_SESSION['errors']['txtUsername'] = 'error'; $errorsExist = 1; } // Validate name if (!$this->validateName($_POST['txtName'])) { $_SESSION['errors']['txtName'] = 'error'; $errorsExist = 1; } // Validate gender if (!$this->validateGender($_POST['selGender'])) { $_SESSION['errors']['selGender'] = 'error'; $errorsExist = 1; } // Validate birth month if (!$this->validateBirthMonth($_POST['selBthMonth'])) { $_SESSION['errors']['selBthMonth'] = 'error'; $errorsExist = 1; } // Validate birth day if (!$this->validateBirthDay($_POST['txtBthDay'])) { $_SESSION['errors']['txtBthDay'] = 'error'; $errorsExist = 1; } // Validate birth year and date if (!$this->validateBirthYear($_POST['selBthMonth'] . '#' . $_POST['txtBthDay'] . '#' . $_POST['txtBthYear'])) { $_SESSION['errors']['txtBthYear'] = 'error'; $errorsExist = 1; } // Validate email if (!$this->validateEmail($_POST['txtEmail'])) { $_SESSION['errors']['txtEmail'] = 'error'; $errorsExist = 1; } // Validate phone if (!$this->validatePhone($_POST['txtPhone'])) { $_SESSION['errors']['txtPhone'] = 'error'; $errorsExist = 1; } // Validate read terms if (!isset($_POST['chkReadTerms']) || !$this->validateReadTerms($_POST['chkReadTerms'])) { $_SESSION['errors']['chkReadTerms'] = 'error'; $_SESSION['values']['chkReadTerms'] = ''; $errorsExist = 1; } // If no errors are found, point to a successful validation page if ($errorsExist == 0) { return 'allok.php'; } else { // If errors are found, save current user input foreach ($_POST as $key => $value) { $_SESSION['values'][$key] = $_POST[$key]; } return 'index.php'; } } // validate user name (must be empty, and must not be already registered) private function validateUserName($value) { // trim and escape input value $value = $this->mMysqli->real_escape_string(trim($value)); // empty user name is not valid if ($value == null) return 0; // not valid // check if the username exists in the database $query = $this->mMysqli->query('SELECT user_name FROM users ' . 'WHERE user_name="' . $value . '"'); if ($this->mMysqli->affected_rows > 0) return '0'; // not valid else return '1'; // valid } // validate name private function validateName($value) { // trim and escape input value $value = trim($value); // empty user name is not valid if ($value) return 1; // valid else return 0; // not valid } // validate gender private function validateGender($value) { // user must have a gender return ($value == '0') ? 0 : 1; } // validate birth month private function validateBirthMonth($value) { // month must be non-null, and between 1 and 12 return ($value == '' || $value > 12 || $value < 1) ? 0 : 1; } // validate birth day private function validateBirthDay($value) { // day must be non-null, and between 1 and 31 return ($value == '' || $value > 31 || $value < 1) ? 0 : 1; } // validate birth year and the whole date private function validateBirthYear($value) { // valid birth year is between 1900 and 2000 // get whole date (mm#dd#yyyy) $date = explode('#', $value); // date can't be valid if there is no day, month, or year if (!$date[0]) return 0; if (!$date[1] || !is_numeric($date[1])) return 0; if (!$date[2] || !is_numeric($date[2])) return 0; // check the date return (checkdate($date[0], $date[1], $date[2])) ? 1 : 0; } // validate email private function validateEmail($value) { // valid email formats: *@*.*, *@*.*.*, *.*@*.*, *.*@*.*.*) return (!eregi('^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$', $value)) ? 0 : 1; } // validate phone private function validatePhone($value) { // valid phone format: ###-###-#### return (!eregi('^[0-9]{3}-*[0-9]{3}-*[0-9]{4}$', $value)) ? 0 : 1; } // check the user has read the terms of use private function validateReadTerms($value) { // valid value is 'true' return ($value == 'true' || $value == 'on') ? 1 : 0; } } ?> index.php <?php require_once ('index_top.php'); ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>Practical AJAX: Form Validation</title> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <link href="validate.css" rel="stylesheet" type="text/css" /> <script type="text/javascript" src="validate.js"></script> </head> <body onload="setFocus();"> <fieldset> <legend class="txtFormLegend">New User Registration Form</legend> <br /> <form name="frmRegistration" method="post" action="validate.php?validationType=php"> <!-- Username --> <label for="txtUsername">Desired username:</label> <input id="txtUsername" name="txtUsername" type="text" onblur="validate(this.value, this.id)" value="<?php echo $_SESSION['values']['txtUsername'] ?>" /> <span id="txtUsernameFailed" class="<?php echo $_SESSION['errors']['txtUsername'] ?>"> This username is in use, or empty username field. </span> <br /> <!-- Name --> <label for="txtName">Your name:</label> <input id="txtName" name="txtName" type="text" onblur="validate(this.value, this.id)" value="<?php echo $_SESSION['values']['txtName'] ?>" /> <span id="txtNameFailed" class="<?php echo $_SESSION['errors']['txtName'] ?>"> Please enter your name. </span> <br /> <!-- Gender --> <label for="selGender">Gender:</label> <select name="selGender" id="selGender" onblur="validate(this.value, this.id)"> <?php buildOptions($genderOptions, $_SESSION['values']['selGender']); ?> </select> <span id="selGenderFailed" class="<?php echo $_SESSION['errors']['selGender'] ?>"> Please select your gender. </span> <br /> <!-- Birthday --> <label for="selBthMonth">Birthday:</label> <!-- Month --> <select name="selBthMonth" id="selBthMonth" onblur="validate(this.value, this.id)"> <?php buildOptions($monthOptions, $_SESSION['values']['selBthMonth']); ?> </select> - <!-- Day --> <input type="text" name="txtBthDay" id="txtBthDay" maxlength="2" size="2" onblur="validate(this.value, this.id)" value="<?php echo $_SESSION['values']['txtBthDay'] ?>" /> - <!-- Year --> <input type="text" name="txtBthYear" id="txtBthYear" maxlength="4" size="2" onblur="validate(document.getElementById('selBthMonth').options[document.getElementById('selBthMonth').selectedIndex].value + '#' + document.getElementById('txtBthDay').value + '#' + this.value, this.id)" value="<?php echo $_SESSION['values']['txtBthYear'] ?>" /> <!-- Month, Day, Year validation --> <span id="selBthMonthFailed" class="<?php echo $_SESSION['errors']['selBthMonth'] ?>"> Please select your birth month. </span> <span id="txtBthDayFailed" class="<?php echo $_SESSION['errors']['txtBthDay'] ?>"> Please enter your birth day. </span> <span id="txtBthYearFailed" class="<?php echo $_SESSION['errors']['txtBthYear'] ?>"> Please enter a valid date. </span> <br /> <!-- Email --> <label for="txtEmail">E-mail:</label> <input id="txtEmail" name="txtEmail" type="text" onblur="validate(this.value, this.id)" value="<?php echo $_SESSION['values']['txtEmail'] ?>" /> <span id="txtEmailFailed" class="<?php echo $_SESSION['errors']['txtEmail'] ?>"> Invalid e-mail address. </span> <br /> <!-- Phone number --> <label for="txtPhone">Phone number:</label> <input id="txtPhone" name="txtPhone" type="text" onblur="validate(this.value, this.id)" value="<?php echo $_SESSION['values']['txtPhone'] ?>" /> <span id="txtPhoneFailed" class="<?php echo $_SESSION['errors']['txtPhone'] ?>"> Please insert a valid US phone number (xxx-xxx-xxxx). </span> <br /> <!-- Read terms checkbox --> <input type="checkbox" id="chkReadTerms" name="chkReadTerms" class="left" onblur="validate(this.checked, this.id)" <?php if ($_SESSION['values']['chkReadTerms'] == 'on') echo 'checked="checked"' ?> /> I've read the Terms of Use <span id="chkReadTermsFailed" class="<?php echo $_SESSION['errors']['chkReadTerms'] ?>"> Please make sure you read the Terms of Use. </span> <!-- End of form --> <hr /> <span class="txtSmall">Note: All fields are required.</span> <br /><br /> <input type="submit" name="submitbutton" value="Register" class="left button" /> </form> </fieldset> </body> </html> index_top.php <?php // enable PHP session session_start(); // Build HTML <option> tags function buildOptions($options, $selectedOption) { foreach ($options as $value => $text) { if ($value == $selectedOption) { echo '<option value="' . $value . '" selected="selected">' . $text . '</option>'; } else { echo '<option value="' . $value . '">' . $text . '</option>'; } } } // initialize gender options array $genderOptions = array("0" => "[select]", "1" => "Male", "2" => "Female"); // initialize month options array $monthOptions = array("0" => "[select]", "1" => "January", "2" => "February", "3" => "March", "4" => "April", "5" => "May", "6" => "June", "7" => "July", "8" => "August", "9" => "September", "10" => "October", "11" => "November", "12" => "December"); // initialize some session variables to prevent PHP throwing Notices if (!isset($_SESSION['values'])) { $_SESSION['values']['txtUsername'] = ''; $_SESSION['values']['txtName'] = ''; $_SESSION['values']['selGender'] = ''; $_SESSION['values']['selBthMonth'] = ''; $_SESSION['values']['txtBthDay'] = ''; $_SESSION['values']['txtBthYear'] = ''; $_SESSION['values']['txtEmail'] = ''; $_SESSION['values']['txtPhone'] = ''; $_SESSION['values']['chkReadTerms'] = ''; } if (!isset($_SESSION['errors'])) { $_SESSION['errors']['txtUsername'] = 'hidden'; $_SESSION['errors']['txtName'] = 'hidden'; $_SESSION['errors']['selGender'] = 'hidden'; $_SESSION['errors']['selBthMonth'] = 'hidden'; $_SESSION['errors']['txtBthDay'] = 'hidden'; $_SESSION['errors']['txtBthYear'] = 'hidden'; $_SESSION['errors']['txtEmail'] = 'hidden'; $_SESSION['errors']['txtPhone'] = 'hidden'; $_SESSION['errors']['chkReadTerms'] = 'hidden'; } ?> could you please help me?
  9. I have a big table with many float fields. I can see the fields in the tables filled with information, but when i query the table i get empty sets but not for all values. example: i can see in the table(using query browser) that there are values 1.25 in a field called fldName, when i query select * from table where fldName=1.25 i get an empty result set. with integer i get the correct results sets. Could you please help me?
  10. thanks <?php $e = mysql_query("SELECT * FROM users WHERE email = '$email'") or die(mysql_error()); if(mysql_num_rows($e) > 0){ echo 'email already in use'; } ?> how about if the error is 'email already in use', is it possible in php to erase/clear only the email field?
×
×
  • 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.