PHP - Input Validation In Jquery/js
Hello Guys...
I need help about my validate scripts... $(document).ready(function(){ //Validation jQuery.validator.addMethod('validIPurl', function(value) { var ip = '^([01]?[0-9]{1,2}|2[0-4][0-9]|25[0-5]).([01]?[0-9]{1,2}|2[0-4][0-9]|25[0-5]).([01]?[0-9]{1,2}|2[0-4][0-9]|25[0-5]).([01]?[0-9]{1,2}|2[0-4][0-9]|25[0-5])$'; var URL = /^(http|https)?:\/\/[a-zA-Z0-9-\.]+\.[a-z]{2,4}/; //HOW TO JOIN AND VALIDATE BOTH VARIABLE IP AND URL???? } }, 'Invalid Address'); //if(/^(http|https|ftp):\/\/[a-z0-9]+([\-\.]{1}[a-z0-9]+)*\.[a-z]{2,5}(:[0-9]{1,5})?(\/.*)?$/i) $(".myfirstform").validate( { rules: { ip: { validIPurl: true } }, ); },I use jquery.validate javascripts to validate user input.. I also try to create if..else to join IP and URL but the control statement not working Hope you guys can help for the solution... Similar TutorialsThis topic has been moved to JavaScript Help. http://www.phpfreaks.com/forums/index.php?topic=359169.0 Hi there, I am using the jQuery, Ajax PHP code which is given at http://roshanbh.com.np/2008/04/ajax-login-validation-php-jquery.html The form I am using, which is in index.html, is: Code: [Select] <form method="post" action="" name="login" id="login_form"> <div class="field_row"> <div class="label_container"> <label>Email</label> </div> <div class="field_container"> <input type="text" placeholder="login with your email address..." name="email_address" id="email_address" value="" class="large" /> </div> <div class="clear"><span class="nodisp"> </span></div> </div> <div class="field_row"> <div class="label_container"> <label>Password</label> </div> <div class="field_container"> <input type="password" placeholder="...and password" name="password" id="password" value="" class="large" /> </div> <div class="clear"><span class="nodisp"> </span></div> </div> <div class="final_row"> <input type="image" src="images/login_blue.gif" id="user_login_button" name="user_login_button" value="login" id="submit" class="submit_button" /> <div class="final_row_text_container" > <a href="/login/forgot_password" style="color: #008ee8;" class="small_text">Forgot your Password?</a> <br /> <span id="msgbox" style="display:none"></span> </div> </div> <div class="clear"><span class="nodisp"> </span></div> </form> The Javascript, which is situated in the head of index.html. is: Code: [Select] <script language="javascript"> $(document).ready(function() { $("#login_form").submit(function() { //remove all the class add the messagebox classes and start fading $("#msgbox").removeClass().addClass('messagebox').text('Validating....').fadeIn(1000); //check the email address exists or not from ajax $.post("login_ajax.php",{ email_address:$('#email_address').val(),password:$('#password').val(),rand:Math.random() } ,function(data) { if(data=='yes') //if correct login detail { $("#msgbox").fadeTo(200,0.1,function() //start fading the messagebox { //add message and change the class of the box and start fading $(this).html('Logging in.....').addClass('messageboxok').fadeTo(900,1, function() { //redirect to secure page document.location='secure.php'; }); }); } else { $("#msgbox").fadeTo(200,0.1,function() //start fading the messagebox { //add message and change the class of the box and start fading $(this).html('Your login details are incorrect.').addClass('messageboxerror').fadeTo(900,1); }); } }); return false; //not to post the form physically }); //now call the ajax also focus move from $("#password").blur(function() { $("#login_form").trigger('submit'); }); }); </script> And the PHP, in login_ajax.php, is: <?php session_start(); $host = "localhost"; $user = "bford"; $pass = "bford"; $db = "bford"; $link = mysql_connect($host, $user, $pass); if (!link) { die('<strong>Error(s) occured:</strong> Could not connect: ' . mysql_error()); } $db_selected = mysql_select_db($db, $link); if (!db_selected) { die ('<strong>Error(s) occured:</strong> Cant use bford: ' . mysql_error()); } //get the posted values $email_address=$_GET['emailaddress']; $pass=$_GET['password']; //now validating the username and password $sql="SELECT * FROM users WHERE email_address='".$email_address."'"; $result=mysql_query($sql); $row=mysql_fetch_array($result); //if username exists if(mysql_num_rows($result)>0) { //compare the password if($row["password"],$pass)==1 { echo "yes"; //now set the session from here if needed $_SESSION["user_name"]=$userID; } else echo "no"; } else echo "no"; //Invalid Login ?> I have been working on this for days now, changing around the form names, database table names, php variables, allsorts! I still cannot get it functioning properly. When I input a correct email_address and password combination, the 'Your login details are incorrect.' message still appears. Help would be much appreciated. Ben. Where in the PHP manual can I find information about input validation? I looked and I seem to not find it. I am intending to create my own email input validation. i'm really sorry, if there is a word that makes you confused. Code: [Select] <?php $ip = $_SERVER['REMOTE_ADDR']; if($_POST['hapus']=='Hapus') { $qDelDetail = mysql_query("DELETE FROM tbl_u_pekerjaan WHERE id_u_pekerjaan = '".$_POST['id_u_pekerjaan']."'"); } ?> <!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> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <title>Untitled Document</title> <style> .suggestion { position:absolute; background-color:#eee; border:1px solid #CCC; display: none; width:400px; } .suggestion ul{ margin : 0 ; padding : 5px 5px ; } .suggestion ul li{ padding-top : 2px ; cursor : pointer ; list-style : none ; } .suggestion ul li:hover{ cursor : pointer ; list-style : none ; color : red ; /*font-weight : bold ;*/ } #form1 #pagu1 { border: 1px solid #999999; height: 21px; width: 355px; } </style> </head> <body> <table width="100%" border="0" cellspacing="0" cellpadding="0"> <tr> <td class="border_all" height="34" bgcolor="#CCCCCC"><strong><img src="image/icon_1.png" align="absmiddle" width="22" height="22" /> Pemeliharaan Komputer </strong></td> </tr> <tr> <td><hr size="1" color="#999999" /></td> </tr> <tr> <td> <table width="100%" border="0" cellspacing="2" cellpadding="3"> <form id="form1" name="form1" method="post" action=""> <tr> <td width="30%">Tahun Anggaran</td> <td width="2%">:</td> <td width="68%"><select name="thn_anggaran" id="thn_anggaran"> <?php $thn_on = date("Y"); ?> <option value="<?=$thn_on;?>"><?=$thn_on;?></option> <?php for($i = 2000; $i <= $thn_on; $i++) { ?> <option value="<?=$i;?>"><?=$i;?></option> <?php } ?> </select></td> </tr> <tr> <td width="30%">Jenis Anggaran</td> <td width="2%">:</td> <td width="68%"><select name="id_jns_anggaran"> <?php include "conn_ra.php"; ?> <?php $qRea = mysql_query("SELECT * FROM tbl_jns_anggaran ORDER BY id_jns_anggaran ASC"); while($dtRea = mysql_fetch_array($qRea)) { ?> <option value="<?=$dtRea['id_jns_anggaran'];?>"><?=$dtRea['nm_jns_anggaran'];?></option> <?php } ?> </select></td> </tr> <tr> <td align="left" valign="top">Nama Program</td> <td align="left" valign="top">:</td> <td align="left" valign="top"><input type="text" id="kd_program" name="kd_program" size="8" onkeyup="javascript:suggestme('program');" autocomplete="off" /> <input type="text" id="nm_program" name="nm_program" size="50" onkeyup="javascript:suggestme('program');" autocomplete="off" /> <div id="suggestion_program" class="suggestion"></div></td> </tr> <tr> <td align="left" valign="top">Nama Kegiatan</td> <td align="left" valign="top">:</td> <td align="left" valign="top"><input type="text" id="kd_kegiatan" name="kd_kegiatan" size="8" onkeyup="javascript:suggestme('kegiatan');" autocomplete="off" /> <input type="text" id="nm_kegiatan" name="nm_kegiatan" size="50" onkeyup="javascript:suggestme('kegiatan');" autocomplete="off" /> <div id="suggestion_kegiatan" class="suggestion"></div></td> </tr> <tr> <td align="left" valign="top">Nama Sub Kegiatan</td> <td align="left" valign="top">:</td> <td align="left" valign="top"><input type="text" id="kd_sub_kegiatan" name="kd_sub_kegiatan" size="8" onkeyup="javascript:suggestme('sub_kegiatan');" autocomplete="off" /> <input type="text" id="nm_sub_kegiatan" name="nm_sub_kegiatan" size="50" onkeyup="javascript:suggestme('sub_kegiatan');" autocomplete="off" /> <div id="suggestion_sub_kegiatan" class="suggestion"></div></td> </tr> <tr> <td align="left" valign="top">MAK</td> <td align="left" valign="top">:</td> <td align="left" valign="top"><input type="text" id="kd_mak" name="kd_mak" size="8" onkeyup="javascript:suggestme('mak');" autocomplete="off" /> <input type="text" id="nm_mak" name="nm_mak" size="50" onkeyup="javascript:suggestme('mak');" autocomplete="off" /> <div id="suggestion_mak" class="suggestion"></div></td> </tr> <!-- <tr> <td align="left" valign="top"><strong>Pagu</strong></td> <td align="left" valign="top"><strong>:</strong></td> <td align="left" valign="top"><div id="pagu1"></div> <input name="pagu" type="text" id="pagu" size="60" maxlength="250" /></td> </tr> --> <tr> <td width="30%"> Komputer </td> <td width="2%">:</td> <td width="68%"><select name="id_inventaris" id="id_inventaris"> <?php include "conn.php"; if(isset($_POST['id_inventaris'])) { $qKomputer = mysql_query("SELECT a.id_inventaris, a.nmr_inventaris, a.merk, a.type, a.processor_type FROM v_inventaris a WHERE id_inventaris = '".$_POST['id_inventaris']."'"); $dtKomputer = mysql_fetch_array($qKomputer); ?> <option value="<?=$dtKomputer['id_inventaris']?>"><?=$dtKomputer['nmr_inventaris'];?> | <?=$dtKomputer['merk'];?> <?=$dtKomputer['type'];?> <?=$dtKomputer['processor_type'];?></option> <?php }else { ?> <option>-Pilih Komputer-</option> <?php } ?> <?php $qKomputer = mysql_query("SELECT a.id_inventaris, a.nmr_inventaris, a.merk, a.type, a.processor_type FROM v_inventaris a WHERE EXISTS ( SELECT b.id_inventaris FROM tbl_memiliki b WHERE a.id_inventaris = b.id_inventaris ) ORDER BY id_inventaris ASC"); while($dtKomputer = mysql_fetch_array($qKomputer)) { ?> <option value="<?=$dtKomputer['id_inventaris']?>"><?=$dtKomputer['nmr_inventaris'];?> | <?=$dtKomputer['merk'];?> <?=$dtKomputer['type'];?> <?=$dtKomputer['processor_type'];?></option> <? } ?> </select> </td> </tr> <tr> <td>Jenis Pemeliharaan </td> <td>:</td> <td><select name="id_jenis" id="id_jenis"> <?php include "conn.php"; if(isset($_POST['id_jenis'])) { $qJenis = mysql_query("SELECT * FROM tbl_jenis WHERE id_jenis = '".$_POST['id_jenis']."'"); $dtJenis = mysql_fetch_array($qJenis); ?> <option value="<?=$dtJenis['id_jenis'];?>"><?=$dtJenis['nm_jenis'];?></option> <?php }else { ?> <option>-Pilih Jenis Pemeliharaan-</option> <?php } ?> <?php $qJenis = mysql_query("SELECT * FROM tbl_jenis ORDER BY id_jenis ASC"); while($dtJenis = mysql_fetch_array($qJenis)) { ?> <option value="<?=$dtJenis['id_jenis'];?>"><?=$dtJenis['nm_jenis'];?></option> <? } ?> </select> </td> </tr> <tr> <td>No. Surat/Memo</td> <td>:</td> <td><input name="no_surat" type="text" id="no_surat" size="50" /></td> </tr> <tr> <td>Tanggal Surat/Memo </td> <td>:</td> <td><input name="tgl_surat" type="text" id="tgl_surat" size="10" value="<?=$_POST['tgl_surat'];?>" /> <script language="JavaScript" type="text/javascript"> new tcal ({ // form name 'formname': 'form1', // input name 'controlname': 'tgl_surat' }); </script></td> </tr> <tr> <td>Asal Surat </td> <td>:</td> <td><input name="asal_surat" type="text" id="asal_surat" size="50" /></td> </tr> <tr> <td>Penanggung Jawab Pemeliharaan </td> <td>:</td> <td><select name="nip" id="nip"> <?php if(isset($_POST['nip'])) { $qNip = mysql_query("SELECT * FROM tbl_pegawai WHERE nip = '".$_POST['nip']."'"); $dtNip = mysql_fetch_array($qNip); ?> <option value="<?=$dtNip['nip'];?>"><?=$dtNip['nama'];?></option> <?php }else { ?> <option>-Pilih Penanggung Jawab Pemeliharaan-</option> <?php } ?> <?php $qNip = mysql_query("SELECT * FROM tbl_pegawai ORDER BY nama ASC"); while($dtNip = mysql_fetch_array($qNip)) { ?> <option value="<?=$dtNip['nip'];?>"><?=$dtNip['nama'];?></option> <? } ?> </select> </td> </tr> <tr> <td>No. SPK/Kuitansi </td> <td>:</td> <td><input name="no_spk" type="text" id="no_spk" size="50" /></td> </tr> <tr> <td>Tanggal SPK/Kuitansi </td> <td>:</td> <td><input name="tgl_pemeliharaan" type="text" id="tgl_pemeliharaan" size="10" value="<?=$_POST['tgl_pemeliharaan'];?>" /> <script language="JavaScript" type="text/javascript"> new tcal ({ // form name 'formname': 'form1', // input name 'controlname': 'tgl_pemeliharaan' }); </script></td> </tr> <tr> <td align="left" valign="top">Nama Rekanan </td> <td align="left" valign="top">:</td> <td align="left" valign="top"><input name="nm_rekanan" value="<?=$_POST['nm_rekanan'];?>" type="text" id="nm_rekanan" size="35" /></td> </tr> <tr> <td> </td> <td> </td> <td><input type="submit" name="Submit" value="Simpan" /></td> </tr> <?php if($_POST['Submit']=='Simpan') { // data sudah ada atau belum $qCr = mysql_query("SELECT id_pemeliharaan FROM tbl_pemeliharaan WHERE tgl_pemeliharaan = STR_TO_DATE('".$_POST['tgl_pemeliharaan']."','%m/%d/%Y') AND id_jenis = '".$_POST['id_jenis']."' AND nm_rekanan = '".$_POST['nm_rekanan']."' AND id_pemeliharaan = '".$_POST['id_pemeliharaan']."'"); $dtCr = mysql_num_rows($qCr); if($dtCr <= 0) { /* $qId = mysql_query("SELECT id_pemeliharaan FROM tbl_pemeliharaan ORDER BY id_pemeliharaan DESC"); $dtId = mysql_fetch_array($qId); $id_pemeliharaan = $dtId[0] + 1; $id_realisasi_anggaran = $dtId[0] + 1; $qInsertData = mysql_query("INSERT INTO tbl_pemeliharaan(id_pemeliharaan, id_inventaris, id_jenis, nip, tgl_input, tgl_pemeliharaan, nm_rekanan, no_surat, tgl_surat, asal_surat, no_spk) VALUES('".$id_pemeliharaan."', '".$_POST['id_inventaris']."', '".$_POST['id_jenis']."', '".$_POST['nip']."', CURRENT_DATE(), STR_TO_DATE('".$_POST['tgl_pemeliharaan']."','%m/%d/%Y'), '".$_POST['nm_rekanan']."', '".$_POST['no_surat']."', STR_TO_DATE('".$_POST['tgl_surat']."','%m/%d/%Y'), '".$_POST['asal_surat']."', '".$_POST['no_spk']."')")or die(mysql_error()); include "include/conn_ra.php"; $qInsertData = mysql_query("INSERT INTO tbl_realisasi_anggaran(thn_anggaran, id_jns_anggaran, kd_program, kd_kegiatan, kd_sub_kegiatan, kd_bas, tgl_realisasi) VALUES('".$_POST['thn_anggaran']."', '".$_POST['id_jns_anggaran']."', '".$_POST['kd_program']."', '".$_POST['kd_kegiatan']."', '".$_POST['kd_sub_kegiatan']."', '".$_POST['kd_bas']."', STR_TO_DATE('".$_POST['tgl_pemeliharaan']."','%m/%d/%Y'))")or die(mysql_error()); */ $qId = mysql_query("SELECT id_pemeliharaan FROM tbl_pemeliharaan ORDER BY id_pemeliharaan DESC"); $dtId = mysql_fetch_array($qId); $id_pemeliharaan = $dtId[0] + 1; include("conn_ra.php"); $kd_sub_sistem = "PMKOM-".$id_pemeliharaan; //kd sub sistem di sistem anggaran $queryAlokasi = "SELECT alokasi_anggaran FROM tbl_alokasi_anggaran WHERE thn_anggaran = '".$_POST['thn_anggaran']."' AND id_jns_anggaran = '".$_POST['id_jns_anggaran']."' AND kd_program = '".$_POST['kd_program']."' AND kd_kegiatan = '".$_POST['kd_kegiatan']."' AND kd_sub_kegiatan = '".$_POST['kd_sub_kegiatan']."' AND kd_bas = '".$_POST['kd_mak']."' AND pj_anggaran = 'Bagian Sistem Informasi'"; $qAlokasi = mysql_query($queryAlokasi); $dtAlokasi = mysql_fetch_array($qAlokasi); $queryRealisasi = "SELECT realisasi_anggaran FROM tbl_realisasi_anggaran WHERE thn_anggaran = '".$_POST['thn_anggaran']."' AND id_jns_anggaran = '".$_POST['id_jns_anggaran']."' AND kd_program = '".$_POST['kd_program']."' AND kd_kegiatan = '".$_POST['kd_kegiatan']."' AND kd_sub_kegiatan = '".$_POST['kd_sub_kegiatan']."' AND kd_bas = '".$_POST['kd_mak']."' AND pj_anggaran = 'Bagian Sistem Informasi'"; $qRealisasi = mysql_query($queryRealisasi); $dtRealisasi = mysql_fetch_array($qRealisasi); $sisaAnggaran = $dtAlokasi['alokasi_anggaran'] - $dtRealisasi['realisasi_anggaran']; $qInsertAnggaran = mysql_query("INSERT INTO tbl_realisasi_anggaran(thn_anggaran, id_jns_anggaran, kd_program, kd_kegiatan, kd_sub_kegiatan, kd_bas, kd_sub_sistem, pj_anggaran, tgl_realisasi) VALUES('".$_POST['thn_anggaran']."', '".$_POST['id_jns_anggaran']."', '".$_POST['kd_program']."', '".$_POST['kd_kegiatan']."', '".$_POST['kd_sub_kegiatan']."', '".$_POST['kd_mak']."', '".$kd_sub_sistem."', 'Bagian Sistem Informasi', STR_TO_DATE('".$_POST['tgl_pemeliharaan']."','%m/%d/%Y'))") or die(mysql_error()); mysql_close($link1); include("conn.php"); /* $qInsertData = mysql_query("INSERT INTO tbl_pemeliharaan(thn_anggaran, id_jns_anggaran, kd_program, kd_kegiatan, kd_sub_kegiatan, kd_bas, id_pemeliharaan, id_kendaraan, id_jenis, nip, tgl_input, tgl_pemeliharaan, nm_bengkel, no_surat, tgl_surat, asl_surat, no_spk, pagu) VALUES('".$_POST['thn_anggaran']."', '".$_POST['id_jns_anggaran']."', '".$_POST['kd_program']."', '".$_POST['kd_kegiatan']."', '".$_POST['kd_sub_kegiatan']."', '".$_POST['kd_mak']."','".$id_pemeliharaan."', '".$_POST['id_kendaraan']."', '".$_POST['id_jenis']."', '".$_POST['nip']."', CURRENT_DATE(), STR_TO_DATE('".$_POST['tgl_pemeliharaan']."','%m/%d/%Y'), '".$_POST['nm_bengkel']."', '".$_POST['no_surat']."', STR_TO_DATE('".$_POST['tgl_surat']."','%m/%d/%Y'), '".$_POST['asl_surat']."', '".$_POST['no_spk']."', '".$sisaAnggaran."')") or die(mysql_error()); */ if(empty($_POST['thn_anggaran']) OR empty($_POST['id_jns_anggaran']) OR empty($_POST['kd_program']) OR empty($_POST['kd_kegiatan']) OR empty($_POST['kd_sub_kegiatan'])OR empty($_POST['kd_mak'])OR empty($_POST['id_inventaris'])OR empty($_POST['id_jenis'])OR empty($_POST['no_surat'])OR empty($_POST['tgl_surat'])OR empty($_POST['asal_surat'])OR empty($_POST['nip'])OR empty($_POST['no_spk'])OR empty($_POST['tgl_pemeliharaan'])OR empty($_POST['nm_rekanan'])) { echo '<script>alert("Data masih ada yang kosong!");</script>'; echo '<html><head> <meta http-equiv="refresh" content="0;url=index.php?p=tambah_pemeliharaan"> </head></html>'; } elseif($qInsertData = mysql_query("INSERT INTO tbl_pemeliharaan(thn_anggaran, id_jns_anggaran, kd_program, kd_kegiatan, kd_sub_kegiatan, kd_bas, id_pemeliharaan, id_inventaris, id_jenis, nip, tgl_input, tgl_pemeliharaan, nm_rekanan, no_surat, tgl_surat, asal_surat, no_spk) VALUES('".$_POST['thn_anggaran']."', '".$_POST['id_jns_anggaran']."', '".$_POST['kd_program']."', '".$_POST['kd_kegiatan']."', '".$_POST['kd_sub_kegiatan']."', '".$_POST['kd_mak']."','".$id_pemeliharaan."', '".$_POST['id_inventaris']."', '".$_POST['id_jenis']."', '".$_POST['nip']."', CURRENT_DATE(), STR_TO_DATE('".$_POST['tgl_pemeliharaan']."','%m/%d/%Y'), '".$_POST['nm_rekanan']."', '".$_POST['no_surat']."', STR_TO_DATE('".$_POST['tgl_surat']."','%m/%d/%Y'), '".$_POST['asal_surat']."', '".$_POST['no_spk']."')") or die(mysql_error())) /*if($qInsertData) {*/ ?>{ <script type="text/javascript"> var answer = confirm("Input data berhasil, Lanjutkan ke uraian pekerjaan ?") if (answer) { window.location = "index.php?p=u_pekerjaan&id_pemeliharaan=<?=$id_pemeliharaan;?>"; } else{ window.location = "index.php?p=pemeliharaan"; } </script> } <? /*}else { echo ("<script> alert (\"Input data gagal dilakukan !!\");</script><br>"); echo "<html><head> <meta http-equiv='refresh' content='0;url=index.php?p=tambah_pemeliharaan'> </head></html>"; }*/ } else { echo ("<script> alert (\"Data yang dimasukkan sudah ada\");</script><br>"); echo "<html><head> <meta http-equiv='refresh' content='0;url=index.php?p=pemeliharaan'> </head></html>"; } } ?> </form> </table> </td> </tr> <tr> <td><hr size="1" color="#999999" /></td> </tr> </table> </body> </html> I tried to use ctype_alnum as input validation for the name and the password, so that only letters and numbers are allowed with no spaces. If I use ctype_alnum only with the nickname, then the nickname will not get entered properly into the database, it will get entered as "1" into the database. And the password does not make it past the elseif statement: Code: [Select] // check password char length } elseif (strlen($password) > 25 || strlen($password) < 6) { Here's the script: Code: [Select] /* REGISTER FORM */ // check if submit button has been clicked if (isset($_POST['submit_signup'])) { // process and assign variables after post submit button has been clicked $user_email = strip_tags($_POST['email']); $user_email = filter_var($user_email, FILTER_VALIDATE_EMAIL); $nickname = ctype_alnum(strip_tags($_POST['nickname'])); $password = ctype_alnum($_POST['password']); $repassword = ctype_alnum($_POST['repassword']); $month = $_REQUEST['month']; $day = $_REQUEST['day']; $year = $_REQUEST['year']; $dob = $year . "-" . $month . "-" . $day; $find_us_question = strip_tags(trim($_POST['find_us_question'])); // connect to database $dbc = mysqli_connect(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME); $check_query = "SELECT * FROM user WHERE nickname = '$nickname'"; $check_connect = mysqli_query($dbc, $check_query) or die(mysqli_error($dbc)); $check_count = mysqli_num_rows($check_connect); // Check if the email exists twice $query_get = "SELECT email FROM user WHERE email = '$user_email'"; $query_run = mysqli_query($dbc, $query_get); $num_rows = mysqli_num_rows($query_run); if(!$nickname) { echo 'Please do fill out the name in letters and numbers only, without spaces and special characters.'; } elseif(!$password || !$repassword) { echo 'Please choose a password which conists of letters and numbers only, without spaces and special characters.'; // check if username is already taken }elseif ($check_count != 0) { echo "Username already exists!"; } elseif ($num_rows != 0) { echo "This email address is already registered in the database, you can not register it twice."; // check if fields are empty } elseif (empty($user_email) || empty($nickname) || empty($password) || empty($day) || empty($month) || empty($year)) { echo "Please fill out all the fields!"; // check char length of input data } elseif (strlen($nickname) > 30 || strlen($user_email) > 50) { echo "Maximum allowed character length for nickname/firstname/lastname are 30 characters!"; // check password char length } elseif (strlen($password) > 25 || strlen($password) < 6) { echo "Your password must be between 6 and 25 characters!"; // check if passwords match with each other } elseif ($password != $repassword) { echo "Please make sure your passwords are matching!"; } else { // encrypt password $password = sha1($password); // generate random number for activation process $random = rand(1212121212, 9854241752); // write into database Any ideas why I am getting these problems with ctype_alnum() ? First, Happy X-Mas to all! I want to do a form for entering dog-show results. On first site of form the user is able to enter how many dogs for each class (there are youth and open class for example) he want to insert. So on second site there will be formfields for every dog in every class, created with php. User should be able to take dogname from jquery autocomplete - this works for multiple fields. But i need the according id to the dogname - and actual only one id is given - the first one is changing by choosing from autocomplete in next fields... Data came from a json array like 0: {dogidindatabase: "9892", value: "Excalibur Khali des Gardiens de la Cour ",…} dogidindatabase: "9892" label: "<img src='../main/img/female.png' height='20'>Excalibur Khali des Gardiens de la Cour " value: "Excalibur Khali des Gardiens de la Cour " 1: {dogidindatabase: "15942", value: "Excalibur from Bandit's World Kalli",…} dogidindatabase: "15942" label: "<img src='../main/img/male.png' height='20'>Excalibur from Bandit's World Kalli" value: "Excalibur from Bandit's World Kalli"all i need is inside ... the script in form is <script type='text/javascript'> //<![CDATA[ $(function() { $(".dog").autocomplete({ source: "xxx.php", minLength: 3, select: function(event, ui) { $('#dogidindatabase').val(ui.item.dogidindatabase); } }); $["ui"]["autocomplete"].prototype["_renderItem"] = function( ul, item) { return $( "<li></li>" ) .data( "item.autocomplete", item ) .append( $( "<a></a>" ).html( item.label ) ) .appendTo( ul ); }; }); //]]> </script>and the form looked like <input type='text' name='dog' class='dog' value='".strip_tags(${'dogname' .($countbabymale+1)})."' size='35' data-required='true' /><br> <input class='readonly' readonly='readonly' type='text' id='dogidindatabase' name='dogidindatabase' size='5' />I changed in script and form id='dogidindatabase' to class, but it doesn´t work. Testsite is under http://www.wolfdog-d...how.php?lang=de (only german at first) - Insert a number (higher than 1) under baby 3-6 (first box, the others are not working for testing); submit to get to page 2; you see all post-variables (for testing). Try to insert a dogname in first input-field (choose "exc") and insert first one - the id is under dogname. In second dogname inputfield you can choose second dog - the id for the first one changes to id of seond one .... How can i get both for every dog? I hope I can explain what is happening. I have created two forms in PHP. The first 'almost' works, i.e. it shows the data. But I have two problems - 1) the second pulldown menu is always empty and 2) $value from the first pulldown menu ALWAYS equals the last entry thus the last 'if' in the function subdomains ($domains) is always called (but still empty). The code may explain this better than me:
<!DOCTYPE html> <html> <body> <!-- processDomains.php is this file - it calls itself (for testing purposes so I can see what is happening) --> <form action="processDomains.php" method="post"> <?php // create the domains array (there are actually several entries in the array but I cut it down for testing) $domains = array (1 => 'Decommission', 'Migration'); echo "Select Domain:"; echo "<br>"; // Make the domain pull-down menu - this displays correctly echo '<select name="domain">'; foreach ($domains as $key => $value) { echo "<option value=\"$key\">$value</option>\n"; } echo '</select>'; // input doesn't matter what is 'submitted', always goes to last $value echo '<input type="submit" name="submit" value="Submit">'; // call function subdomains subdomains ($value); function subdomains ($domains) { // define values for each array - each array contains available choices for the subdomain pulldown menu $migration = array (1 => 'Application Migration', 'Application Patch', 'Application Upgrade'); $decommission = array (1 => 'Applications', 'Servers', 'Storage'); if ($domains === 'Migration') { echo "Select subdomain:"; echo "<br>"; // Make the Migration pull-down menu echo '<select name="migration">'; foreach ($migration as $key => $value) { echo "<option value=\"$key\">$value</option>\n"; } echo '</select>'; } else if ($domains === 'Decommission') { /* === * since 'Decommission' is the last entry in the 'Domains' pulldown list, $value ALWAYS equals * 'Decommission' and $domains equals $value. So this menu SHOULD work but is always * empty. Thus, two problems - the pulldown menu is always empty and $value isn't based * upon user input. */ echo "Select subdomain:"; // this prints so I know I'm in 'Decommission (I eliminated the echo "$domain" to show I'm always coming here)' echo "<br>"; // Make the 'Decommission' pull-down menu echo '<select name="decommission">'; foreach ($decommission as $key => $value) { echo "<option value=\"$key\">$value</option>\n"; } echo '</select>'; echo '<input type="submit" name="submit" value="Submit">' ) // end of 'if-else' } // end of function 'subdomain' ?> </form> </body> </html>Let me say thank you in advance and I appreciate the help! I know I'm doing something (or more than one thing) wrong and I hope someone can tell me what it is. Best Regards! Edited by mac_gyver, 19 January 2015 - 09:37 PM. code tags around posted code please I am writing a script that will parse my PHP classes and check for things like coupling, visualize my objects and connections, dependencies, check for convention usage, etc.
So, I have a simple file upload. I'm never saving the files, just get contents and dump the file and work with the string version.
I'm writing it for me, but I figure I might want to open it for others to use in the future, so I may as well write it that way to begin with -- so I need to validate user input. Problem is, the user input is supposed to be valid PHP code. I'm thinking that, as long as I'm careful, I shouldn't be executing any code contained in strings, but I'm no security expert and I want a warm fuzzy that my thought on this is correct. What kinds of things do I need to look out for? Is it possible to inject when working with strings?
My initial thought is to regex the entire file and replace key portions with known replacements. So ( and ) would become !* and !^ or $ would become @~ (combinations that -- I think -- don't make sense to php?) But that may be completely unnecessary processing time if I'm not in any danger, here. Thanks ahead of time for any help.
PS - as a side question -- what's the best way to verify a file is a php file? I know of getimagesize for images, but should I just check for <? to verify it's php? That seems like it would be too easy to fool -- then again, it might not matter much.
-Adam
I have a calendar select date function for my form that returns the date in the calendar format for USA: 02/16/2012. I need to have this appear as is for the form and in the db for the 'record_date' column, but I need to format this date in mysql DATE format (2012-02-16) and submit it at the same time with another column name 'new_date' in the database in a hidden input field. Is there a way to do this possibly with a temporary table or something? Any ideas would be welcome. Doug Hi people, I really hope you guys can help me out today. I'm just a newbe at php and i'm having real trouble. Bassically all I want to do is have a user type in a company name in a html form. If what the user types in the form matches the company name in my php script i want the user to be sent to another page on my site. If what the user types in the form doesnt match the company name in my php script i want the user to be sent to a differnt page like an error page for example. this is my html form: Code: [Select] <form id="form1" name="form1" method="post" action="form_test.php"> <p>company name: <input type="text" name="company_name" id="company_name" /> </p> <p> <input type="submit" name="button" id="button" value="Submit" /> </p> </form> And this is the php code I'm trying to process the information on: Code: [Select] <?php $comp_name = abc; if(isset ($_POST["company_name"])){ if($_POST["company_name"] == $comp_name){ header("Location: http://www.hotmail.com"); exit(); } else{ header("Location: http://www.yahoo.com"); exit(); } } ?> The thing is i'm getting this error when i test it: Warning: Cannot modify header information - headers already sent by (output started at D:\Sites\killerphp.com\form_test.php:10) in D:\Sites\killerphp.com\form_test.php on line 17 Please can some one help me out, i'm sure this is just basic stuff but i just cant get it to work Cheers. Im wondering if i should use jQuery or Php. and how about i would go about doing this. Code: [Select] <?php print "<table border=\"0\" cellpadding=\"0\" width=\"100%\" height=\"100\"cellspacing=\"0\" style=\"border-collapse:collapse\"bordercolor=\"grey\" bgcolor=\"white\" valign=\"top\"> <td align=\"left\" width=\"100%\" onclick=\"I3.location.href='getuserdetail.php?prop=$ownerid'\"><b>Property Name</b></td><td><b>Tenant</b></td><td><b>Property Status</b></td><td>Rent Amount</td>"; $connect = mysql_connect("localhost","root",""); mysql_select_db("magic"); $query = "SELECT * FROM props WHERE ownerid = '$ownerid' ORDER BY name ASC "; $result = mysql_query($query); while($row = mysql_fetch_assoc($result)) { $propertyid = $row['propid']; $propertyname = $row['name']; $propertydesc = $row['description']; $propertycity = $row['city']; $propertystate = $row['state']; $propertyzip = $row['zip']; $active = $row['active']; $lease = $row['lease']; $leaseamt = $row['leaseamt']; if($active == "1"){ $propertystatus = "Active"; } else { $propertystatys = "Unknown"; } print"<tr onMouseOver=\"this.bgColor = '#CEE3F6'\" onMouseOut =\"this.bgColor = '#FFFFFF'\"> <td align=\"left\" width=\"25%\" onclick=\"window.open('viewpropdetail.php?prop=$propertyid','mywindow','width=1200,height=600,scrollbars=1')\">$propertyname</td><td>$ownerfirstname $ownerlastname</td><td>$propertystatus</td><td>$$leaseamt</td> "; } print"</td></table>"; ?> Basically i have a link under that is add property. it pops up a box. with a form you fill it out, and it inserts the record into database. What I'm trying to do. is get it to "Refresh" the property list ( ex. code above). so it shows the new property in the table. i have never used jQuery. but was wondering if i could do that with php. Is there a way to say if records are changed.. update? Hi I am in the process of teaching myself web development, coming from a vb and mssql background. I am building a small page that will display my film library, I just want something quick and simple that gets things working. I have three img tags on my page that display the film posters. The current film and the one previous and next. What I would like is a left and a right arrow that just scroll through the library. I am thinking I need to read the sub folder of D:\movies and story the full path name into an array, and then when the user presses a arrow it moves forward or back. Everything is local and I am unsure about how to handle the event of the left/arrow being pressed. Does PHP handle that kind of event or would Jquery be more suitable or something else completely?? thanks for any pointers. Hey, I have a foreach loop displaying some data from my table, what i need to do is run a Jquery each function on the repeated element so it fadesIn each element one at a time. I am guessing i need to set somesort of interval for this to work. I have been messing with it for a good hour or so now and i cant seem to get it working. Has anyone done this before or seen it done else were? I keep saying I'm going to have to learn javascript and then the library jQuery but find myself learning Swift now instead.
Short one today. I want these two functions to occur back to back. Second function only begins after the first function is complete.
$(function() { $('.tlt').textillate(); }) $(function() { $('.tlt1').textillate(); })If you can please help me with this not only in just code to make that happen but also an explanation of what you did I sure would appreciate it. I've read all morning on promises etc. but have yet to be successful in implementing this. As you can tell I'm using the plug-in textillate to fade text out one letter at a time. Works great! But I have multiple paragraphs I'm wanting to apply this too so I can't make the div class .tlt since I then lose all paragraphs since it's strips it into spans. That would be ideal of course but I think I forced into making different classes for each paragraph. This will become problematic in the future though since the content is generated dynamically and I will have no idea how many paragraphs that dynamic content will contain. So if there was a way to keep my <p> and </p> that would be even better. Thanks! Alright guys, I have a bit of a problem here. I am deleting records using isset($_POST) on the current page but when it submits the records i deleted are still visible. I was thinking of echoing some jquery/ajax to re-load the div that displays the records. Has anyone ever done this before? I dont want the entire page to re-load just that specific area. Hi All (Again) I am looking to pick up variables in jquery from a string created: function search_by() { var search_term = $('#search_for', $(this).attr('value')); alert(search_term); } I cant seem to get the value i am trying to into a "var". This is the code on the page i am using a onClick="search_by();" i.e: <a class="show_cats" search_cat="PDAs & Accessories" search_for="fire" onclick="search_by();" href="#"> I am trying to get the value inside the "search_for" field. Any ideas???? I am using this to open contents into a modal window, but in the process I am passing it through loop.php to check if the page exists and then load. Is there a way to completely skip the loop.php file and load my clicked link?
$(document).ready(function(){ ///////LINK in a Modal Window//////// $('#all').delegate('a.pop-lnk', 'click', function(){ var page = $(this).attr('id'); $('#gr-out').css({ opacity: 0.7, 'width':$(document).width(),'height':$(document).height()}).show(); $('#popup').css({'display': 'block'}); $('#popup').load("../help-file/loop.php?page="+ page); }); });The id attr I am getting from this code is my page's name but I need to add the .php extension if is possible so I can load the page. Edited by Pavlos1316, 18 November 2014 - 03:04 PM. Hello all,
So I found this html and jquery example online. Works great if I just copy the below code in a file call test.html and run it from the browser, however if I create a PHP project in netbeans and create a file called index.php and put the same code and the jquery.min.js in the same directory, for some reason it doesn't work. The java script portion give strange behavor. I am new to all these, can someone please help?
<!DOCTYPE html> <!--Code by Chris Youderian, ContactMetrics.com, http://contactmetric...act-form-jquery, Code released under an MIT license, http://opensource.org/licenses/MIT --> <html lang="en"> <head> <script type='text/javascript' src='jquery.min.js'></script> </head> <!-- Styles --> <style> #contact label{ display: inline-block; width: 100px; text-align: right; } #contact_submit{ padding-left: 100px; } #contact div{ margin-top: 1em; } textarea{ vertical-align: top; height: 5em; } .error{ display: none; margin-left: 10px; } .error_show{ color: red; margin-left: 10px; } input.invalid, textarea.invalid{ border: 2px solid red; } input.valid, textarea.valid{ border: 2px solid green; } </style> <!-- JavaScript Code --> <script> $(document).ready(function() { <!-- Real-time Validation --> <!--Name can't be blank--> $('#contact_name').on('input', function() { var input=$(this); var is_name=input.val(); if(is_name){input.removeClass("invalid").addClass("valid");} else{input.removeClass("valid").addClass("invalid");} }); <!--Email must be an email --> $('#contact_email').on('input', function() { var input=$(this); var re = /^[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+@[a-zA-Z0-9-]+(?:\.[a-zA-Z0-9-]+)*$/; var is_email=re.test(input.val()); if(is_email){input.removeClass("invalid").addClass("valid");} else{input.removeClass("valid").addClass("invalid");} }); <!--Website must be a website --> $('#contact_website').on('input', function() { var input=$(this); if (input.val().substring(0,4)=='www.'){input.val('http://www.' input.v...substring(4));} var re = /(http|ftp|https):\/\/[\w-]+(\.[\w-]+)+([\w.,@?^=%&:\/~+#-]*[\w@?^=%&\/~+#-])?/; var is_url=re.test(input.val()); if(is_url){input.removeClass("invalid").addClass("valid");} else{input.removeClass("valid").addClass("invalid");} }); <!--Message can't be blank --> $('#contact_message').keyup(function(event) { var input=$(this); var message=$(this).val(); console.log(message); if(message){input.removeClass("invalid").addClass("valid");} else{input.removeClass("valid").addClass("invalid");} }); <!-- After Form Submitted Validation--> $("#contact_submit button").click(function(event){ var form_data=$("#contact").serializeArray(); var error_free=true; for (var input in form_data){ var element=$("#contact_"+form_data[input]['name']); var valid=element.hasClass("valid"); var error_element=$("span", element.parent()); if (!valid){error_element.removeClass("error").addClass("error_show"); error_free=false;} else{error_element.removeClass("error_show").addClass("error");} } if (!error_free){ event.preventDefault(); } else{ alert('No errors: Form will be submitted'); } }); }); </script> <body> <form id="contact" method="post" action=""> <!-- Name --> <div> <label for="contact_name">Name:</label> <input type="text" id="contact_name" name="name"></input> <span class="error">This field is required</span> </div> <!-- Email --> <div> <label for="contact_email">Email:</label> <input type="email" id="contact_email" name="email"></input> <span class="error">A valid email address is required</span> </div> <!--Website --> <div> <label for="contact_website">Website:</label> <input type="url" id="contact_website" name="website"></input> <span class="error">A valid url is required</span> </div> <!-- Message --> <div> <label for="contact_message">Message:</label> <textarea id="contact_message" name="message"></textarea> <span class="error">This field is required</span> </div> <!-- Submit Button --> <div id="contact_submit"> <button type="submit">Submit</button> </div> </form> </body> </html> I am trying to limit comments and replies to comments and display an error message once the limit is reached. I have successfully limited comments and comment replies, and successfully provided the error message when prompted ONLY for the comments, and not the comment replies. The comment replies have a little bit of jquery working with them, so that's the only thing I can see that would be causing the message not to display. I have tried other methods then the one currently being used. https://gist.github.com/8972a8343c6fd2b878b1 thanks in advance. |