Jump to content

sniperscope

Members
  • Posts

    280
  • Joined

  • Last visited

Posts posted by sniperscope

  1. Hi

    I have some Ajax code using two different page. One page is working fine(this page send only one parameter to actual php script)

    But same code is not sending value.

    Here is register.php (which is not working) Is that possible to sending large data cause this?

     

    Regards

     

    <script type="text/javascript" src="js/wysiwyg/jquery.js"></script>
    <script type="text/javascript" src="js/jquery-1.6.2.js"></script>
    <script type="text/javascript">
    
    $(function(){
      $(document).ready(function(){$('#load').hide();});
      $(".sendme").click(function(){
    	// validate and process form
    	// first hide any error messages
        $('.error').hide();
    
    //hide the form
    //$('#signupForm').fadeOut();
    
    //show the loading bar
    $('.loader').append($('.bar'));
    $('.bar').css({display:'block'});
    
    	var name = $("input#GN").val();
    	if(name == "")
    	{
    		$("input#GN").focus();
    		return false;
    	}
    	var dl = 0;
    	if($("#dl:checked").length == 1)
    	{
    		dl = 1;
    	}
    	var radio_bx = "";
    	if($('input[name=vp]:radio:checked').length > 0 ){radio_bx = $('input[name=vp]:radio:checked').val();}
    
    	var age = $("input#Age").val();
    	if(age < 15)
    	{
    		alert("Must be atleast 15 years old");
    		$("input#Age").focus();
    		return false;
    	}
    
    	var ht = $("input#ht").val();
    	var bt = $("input#bt").val();
    	var cp = $("#cp").val();
    	var wt = $("input#wt").val();
    	var hi = $("input#hi").val();
    	var pt = $("#pt").val();
    	var sk = $("input#sk").val();
    	var tai = $("input#tai").val();
    	var OW = $("input#OW").val();
    	var pl = $("input#pl").val();
    	var mn = $("textarea#mn").val();
    	var gs = $("textarea#gs").val();
    	var i1 = $("#i1").val();
    	var i2 = $("#i2").val();
    	var o1 = 0;
    	var o2 = 0;
    	var o3 = 0;
    	var o4 = 0;
    	var o5 = 0;
    	var o6 = 0;
    	var o7 = 0;
    	var o8 = 0;
    	var o9 = 0;
    	var o10 = 0;
    	var o11 = 0;
    	var o12 = 0;
    	var o13 = 0;
    	if($("#o01:checked").length == 1){ o1 = 1;}
    	if($("#o02:checked").length == 1){ o2 = 1;}
    	if($("#o03:checked").length == 1){ o3 = 1;}
    	if($("#o04:checked").length == 1){ o4 = 1;}
    	if($("#o05:checked").length == 1){ o5 = 1;}
    	if($("#o06:checked").length == 1){ o6 = 1;}
    	if($("#o07:checked").length == 1){ o7 = 1;}
    	if($("#o08:checked").length == 1){ o8 = 1;}
    	if($("#o09:checked").length == 1){ o9 = 1;}
    	if($("#o10:checked").length == 1){ o10 = 1;}
    	if($("#o11:checked").length == 1){ o11 = 1;}
    	if($("#o12:checked").length == 1){ o12 = 1;}
    	if($("#o13:checked").length == 1){ o13 = 1;}
    
    	var op = o1 +'-'+ o2 +'-'+ o3 +'-'+ o4 +'-'+ o5 +'-'+ o6 +'-'+ o7 +'-'+ o8 +'-'+ o9 +'-'+ o10 +'-'+ o11 +'-'+ o12 +'-'+ o13;
    
    	var bl = $("input#blog").val();
    
    	var dataString = 'GN='+ name + '&dl=' + dl + '&vp=' + radio_bx + '&age=' + age + '&h=' + ht + '&b=' + bt + '&c=' + cp + '&w=' + wt + '&hi=' + hi + '&pt=' + pt + '&sk=' + sk + '&tai=' + tai + '&OW=' + OW + '&pl=' + pl + '&mn=' + mn + '&gs=' + gs + '&i1=' + i1 + '&i2=' + i2 + '&op=' + op + '&bl=' + bl;
    	alert(dataString);
    
    	$.ajax({
    		type: "POST",
    		url: "sql/add.php",
    		data: dataString,
    		success: function(){
    			$('#signupForm').html("<div id='message'></div>");
    			$('#message').html("<h2>it is done!</h2>")
    			.append("<p>you will be redirect</p>")
    			.hide()
    			.fadeIn(1500, function(){$('#message').append("<img id='checkmark' src='images/check.png' />");});
    		}
    	});
        return false;
    });
    });
    
    
    
    function KDi($AD)
    {
    	var i = document.getElementById($AD);
    	i.readOnly = true;
    	return false;
    }
    function KDa($AD)
    {
    	var i = document.getElementById($AD);
    	i.readOnly = false;
    }
    </script>
    
    <form method="post" action="" id="signupForm">
    <input type="text" id="GNe" name="GN" style="width:80px;" onblur="KDi('GalName');" onfocus="KDa('GalName');" />  
    <input type="checkbox" name="dl" id="dl" />  
    <input type="radio" name="vp" value="0" id="vp" checked="checked" />--<input type="radio" name="vp" id="vp" value="1" />1
    <input type="text" name="Age" id="Age" style="width:30px;" onblur="KDi('Age');" onfocus="KDa('Age');" />
    <input type="text" name="ht" id="ht" onblur="KDi('ht');" onfocus="KDa('ht');" size="3" />
    <input type="text" name="bt" id="bt" size="3" onblur="KDi('bt');" onfocus="KDa('bt');" />
    <select name="cp" id="cp"><option value="A" selected="selected">A</option><option value="B">B</option><option value="C">C</option><option value="D">D</option><option value="E">E</option>
    <option value="F">F</option><option value="G">G</option><option value="H">H</option><option value="I">I</option><option value="J">J</option></select>
    <input type="text" name="wt" id="wt" size="3" onblur="KDi('wt');" onfocus="KDa('wt');" />
    <input type="text" name="hi" id="hi" size="3" onblur="KDi('hi');" onfocus="KDa('hi');" />
    <select name="pt" id="pt"><option value="" selected="selected">--</option><option value="1">1</option></select>
    <input type="text" name="sk"  id="sk" onblur="KDi('sk');" onfocus="KDa('sk');" size="50" />
    <input type="text" name="tai"  id="tai" onblur="KDi('tai');" onfocus="KDa('tai');" size="50" />
    <input type="text" name="OW" id="OW" onblur="KDi('OW');" onfocus="KDa('OW');" size="50" maxlength="13" />
    <input type="text" name="pl" id="pl" onblur="KDi('pl');" onfocus="KDa('pl');" size="50" />
    <textarea name="mn" id="mn" cols="44" rows="7" onblur="KDi('mn');" onfocus="KDa('mn');" ></textarea>
    <textarea name="gs" id="gs" cols="44" rows="7" onblur="KDi('gs');" onfocus="KDa('gs');" ></textarea>
    <select name="i1" id="i1"><option value="0" selected="selected">--</option><option value="1">1</option><option value="2">1</option></select>
    <select name="i2" id="i2"><option value="0" selected="selected">--</option><option value="1">1</option><option value="2">2</option></select>
    <input name="o01" id="o01" type="checkbox">
    <input name="o02" id="o02" type="checkbox">
    <input name="o03" id="o03" type="checkbox">
    <input name="o04" id="o04" type="checkbox">
    <input name="o05" id="o05" type="checkbox">
    <input name="o06" id="o06" type="checkbox">
    <input name="o07" id="o07" type="checkbox">
    <input name="o08" id="o08" type="checkbox">
    <input name="o09" id="o09" type="checkbox">
    <input name="o10" id="o10" type="checkbox">
    <input name="o11" id="o11" type="checkbox">
    <input name="o12" id="o12" type="checkbox">
    <input name="o13" id="o13" type="checkbox">
    <input type="text" name="bl" id="bl" size="70" onblur="KDi('bl');" onfocus="KDa('bl');" />
    <input type="submit" id="sendme" class="button" value="sendme"> <input type="reset" class="button_grey" value="reset">
    </form>
    

     

    And here is how i check whether if it working or not (add.php)

    	$fp = fopen("t.txt", 'a');
    fwrite($fp, "This is test");
    fclose($fp);
    

  2. Hi

    I have some problem with ajax.

    My script connect query page but doesn't return any value.

     

    Regards

    Note: In same page DELETE function works fine but not display.

    Here is my index.php:

     

    <script type="text/javascript">
    
    $(function()
    {
    	$(".showme").click(function()
    	{
    		var commentContainer = $(this).parent();
    		var id = $(this).attr("imd");
    		var string = 'id='+ id ;
    
    		$.ajax({
    			type: "POST",
    			url: "sql/reservation.php",
    			data: string,
    			cache: false,
    			success: function()
    			{
    				$('#ajaxDiv').html(data);
    			}
    		});
    	});
    });
    </script>
    
    <?php
    
    while($ROW = mysql_fetch_array($SQL))
    {
    echo '<li style="text-align:right; width:100%;">' .$i;
    if($ROW['is_read'] == 0) echo '  <img src="images/email_unread.png" /> '; else echo '  <img src="images/email_read.png" /> ';
    echo '<a href="#" imd="' .$ROW['id']. '" class="showme">'. date("Y-n-d H:i", $ROW['RegDate']).'</a>';
    $i++;
    }
    ?>
    <div class="ajaxDiv" id="ajaxDiv"></div>

     

    And this is reservation.php:

    <?php
    include('../inc/cn.php');
    $SQL = "SELECT * FROM reservation WHERE id = '" .$_POST['id']. "' LIMIT 1";
    $SQL = mysql_query($SQL);
    $ROW = mysql_fetch_array($SQL);
    
    // Test purpose to see that if ajax connect this page or not.
    //	$fp = fopen("sql.txt", 'a');
    //	fwrite($fp, $SQL);
    //	fclose($fp);
    
    echo '<table width="100%" cellpadding="3" cellspacing="1" border="0" bgcolor="#000000">
    	<tr><td><table width="100%" border="0" cellspacing="1" cellpadding="4" bgcolor="#999999">
    		<tr><td width="100" bgcolor="#FFFFE5">name</td><td bgcolor="#FFFFFF">' .$ROW['Name']. '</td></tr>
    		<tr><td bgcolor="#FFFFE5">date</td><td bgcolor="#FFFFFF">' .$ROW['resDate']. '</td></tr>
    		<tr><td bgcolor="#FFFFE5">user id</td><td bgcolor="#FFFFFF">' .$ROW['memID']. '     '; if($ROW['is_new'] == 1) echo '<span style="font-weight:bold; color:red;">new user</span>';
    			echo '</td></tr>
    		<tr><td bgcolor="#FFFFE5">email add</td><td bgcolor="#FFFFFF"><a href="mailto:' .$ROW['memMail']. '">' .$ROW['memMail']. '</a></td></tr>
    		<tr><td bgcolor="#FFFFE5">phone</td><td bgcolor="#FFFFFF">' .$ROW['memPhone']. '</td></tr>
    		<tr><td bgcolor="#FFFFE5">remarks</td><td bgcolor="#FFFFFF">' .nl2br($ROW['memQuest']). '</td></tr></table>
    	</td></tr>
    </table>';
    ?>

  3. Okay i solved my problem something like this.

    I hope this solution saves someones hours.

     

    Regards

     

    login.php :

     

    <html>
    <head>
    <script type="text/javascript">
    var servername = "";
    
    function showUser(str)
    {
    	if (str=="")
    	{
    		return;
    	}
    	if (window.XMLHttpRequest)
    	{// code for IE7+, Firefox, Chrome, Opera, Safari
    		xmlhttp=new XMLHttpRequest();
    	}
    	else
    	{// code for IE6, IE5
    		xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
    	}
    	xmlhttp.onreadystatechange=function()
    	{
    		if (xmlhttp.readyState==4 && xmlhttp.status==200)
    		{
    			servername = xmlhttp.responseText;
    		}
    	}
    	xmlhttp.open("GET","check.php?domain="+str,true);
    	xmlhttp.send();
    }
    
    
    function craftAction()
    {
    	document.getElementById("errorspace").innerHTML = '';
    	var launch = 1;
    	var output = false;
    
    	if(document.loginform.domain.value == '')
    	{
    		document.getElementById("errorspace").innerHTML += '<font color=#FF0000><?php echo $LOGIN['error1']; ?></font><br />';
    		launch = 0;
    	}
    
    	if(document.loginform.pass.value == '')
    	{
    		document.getElementById("errorspace").innerHTML += '<font color=#FF0000><?php echo $LOGIN['error3']; ?></font><br />';
    		launch = 0;
    	}
    
    	if(document.loginform.user.value == '')
    	{
    		document.getElementById("errorspace").innerHTML += '<font color=#FF0000><?php echo $LOGIN['error2']; ?></font><br />';
    		launch = 0;
    	}
    
    	if(launch == 0)
    	{
    		output = false;
    	}
    	else{
    		var port = document.loginform.port.value;
    		var theaction = "https://" + servername + ".winhostings.com:2083/login/"
    		document.loginform.action = theaction;
    		output = true;
    	}
    
    	return output;
    
    }
    </script>
    </head>
    
    <body>
    <form name="loginform" id="loginform" method="post" action="">
    <table width="300px" class="login" cellpadding="5" cellspacing="2" style="margin:auto;">
    	<tr><td align="left" colspan="2"> </td></tr>
    	<tr class="row2"><td class="login_lines">username</td>
    		<td class="login_lines"><input id="user" type="text" name="user" size="20" onBlur="showUser(this.value);" /></td></tr>
    	<tr><td class="login_lines">password</td>
    		<td class="login_lines"><input id="pass" type="password" name="pass" size="20" /></td></tr>
    	<tr><td colspan="2" style="text-align: center"><input type="submit" value="login" class="input-button" /></td></tr>
    </table>
    </form>
    </body>
    </html>

  4. Hello

    I want to make some login panel with ajax but have no idea where to start. Please let me explain a little what i want to do.

     

    When a user type his login name i want to send(onblur()) typed value to db.php and returning value assign to a javascript valiable.

     

    My login.php is:

    <form name="loginform" id="loginform" method="post" action="">
    <table width="300px" class="login" cellpadding="5" cellspacing="2" style="margin:auto;">
    	<tr><td align="left" colspan="2"> </td></tr>
    	<tr class="row2"><td class="login_lines">username</td>
    		<td class="login_lines"><input id="user" type="text" name="user" size="20" onBlur="GotoAjax();" /></td></tr>
    	<tr><td class="login_lines">password</td>
    		<td class="login_lines"><input id="pass" type="password" name="pass" size="20" /></td></tr>
    	<tr><td colspan="2" style="text-align: center"><input type="submit" value="login" class="input-button" /></td></tr>
    </table>
    </form>

     

    And db.php is:

    <?php
        include('../inc/cn.php');
        $SQL = mysql_query("SELECT * FROM users WHERE username = '" .$_POST['user']. "'");
        $ROW = mysql_fetch_array($SQL);
    ?>

     

    i want to assign $ROW data into a javascript variable something like this :

    login.php

    <script language="text/javascript">
       function GotoAjax(){
       // AJAX MAY RUN HERE.
       }
       var id = <?php echo $ROW['id']; ?>;  // Return Value from Ajax query
       var username = <?php echo $ROW['username']; ?>;  // Return Value from Ajax query
       var mail = <?php echo $ROW['mail']; ?>;  // Return Value from Ajax query
    ...
    ...
    ... so on
    </script>

     

    How can i make this?

     

    Regards

  5. My first problem solved.. Thanks for who provide code....

    however, i want to know how can i paginate something like <<PREV | 1 2 3 4 5 | NEXT>> when user reach page #5 and click NEXT link then page number should change <<PREV | 6 7 8 9 10 | NEXT>>

  6. Dear micmania 1

    Thanks for your afford and code. Unfortunately this is not what i am looking for.

    Let's say i have 10 records in my DB and those records are:

     

    4

    5

    9

    10

    11

    19

    28

    47

    48

    62

     

    And again let's say my visitor arrived index.php at first time. So, visitor will see record #62(because ORDER BY id DESC LIMIT 1).

    When visitor click the NEXT >> page i want to get record #48 (as you can see between #48 and #62 is empty).

    How can i skip those empty record lines and assign #48 into anchor <a href="index.php?id=48">NEXT >></a>

     

    My displaying order is newer to older so NEXT means older record and PREV means newer record.

  7. Hi gurus!

    Recently i am facing a tiny problem. I want to do is pagination like (<< PREVIOUS | INDEX | NEXT >>).

    My codes are below.

     

    Regards

     

    <?php
        $SQL = mysql_query("SELECT id FROM blogmaster ORDER BY id DESC");
        while($ROW = mysql_fetch_array($SQL))
        {
            $MYARRAY[] = $ROW['id'];
        }
        
        $ARRAYCOUNT = count($MYARRAY);
        if($MYARRAY[0] != $_GET['id'])
        {
            $DESC = $MYARRAY[0] + 1;
            
            echo '<a href="/blog/detail.php?id=' .$MYARRAY[$DESC]. '" class="p-link"><< PREV</a>  ';
        }
        echo '<a href="/blog/index.php" class="p-link">INDEX</a>  ';
        if($MYARRAY[$ARRAYCOUNT] != $_GET['id'])
        {
            $ASC = $MYARRAY[$ARRAYCOUNT] - 1;
            
            echo '<a href="/blog/detail.php?id=' .$MYARRAY[$ASC]. '" class="p-link">NEXT >></a>  ';
        }
    ?>

     

    Also how can i paginate something like <<PREV | 1 2 3 4 5 | NEXT>> when user reach page #5 and click NEXT link then page number should change <<PREV | 6 7 8 9 10 | NEXT>>

  8. Okay here is the code i use.

    <?php
    include('../inc/cn.php');    // database connection file
    require_once('../inc/functions.php');
    
    if(!isset($_GET['id']) || $_GET['id'] < 1)
    	header('location: ../top/index.php');
    else
    	$ID = (int)$_GET['id'];
    
    $TODAY = mktime(0, 0, 0, date("n"), date("d") - $midnight_num, date("Y"));
    
    $SQL = mysql_query("SELECT * FROM personals WHERE id = '$_GET[id]' LIMIT 1", $cn);
    $ROW = mysql_fetch_array($SQL);   // where the error occur.
    ?>
    

  9. I always use my queries like below

    mysql_query("SELECT id FROM someTable", $cn);

     

    but some times i see in my error_log says: mysql_fetch_array(): supplied argument is not a valid MySQL result resource. Why is this happening?

    I mean, there is no problem with my sites and all they are working as they should be but why php generates this error?

  10. This is what i found in php.net

    <?php
    function mi_dir_list($a_path=".", $a_mask="*")
    {
        $dir = @ dir("$a_path");
    
        //List files in images directory
        while (($file = $dir->read()) !== false)
        {
           if($file !="." && $file!=".." && fnmatch($a_mask, $file))
             $l_vdir[] = $file;
        }
    
        $dir->close();
    
        return($l_vdir);
    }
    
    $lv = mi_dir_list( "../pruebas/", "*.*");
    print_r($lv);
    ?>

  11. Dear Thorpe

    Thanks for your reply.

    so, do have any suggestion(s) to learn classes painless?

     

    I am reading class tutorails on phpfreaks but frankly i did not get the idea exactly. Because there is still a lot of question marks in my mind.

  12. First of all, i am very very very beginner of class.

    All i want to do is autorun class when it created. Then Skip to OldName and parse same variable.

    Check that variable, if it is true then go to NewName else return error message.

     

    Like i said i am new about OOP. I can do what i want with functions but i want to learn class.

  13. Hello

    First of all i am very weak about OOP and classes in php. I am learning now but i stuck with very silly problem.

    My codes are below.

    <?php
       class myTestClass
       {
           function __construct()
           {
             $this->OldName("This is Old Name");
           }
           
           function OldName($VeryOld)
           {
               if($VeryOld == "This is Old Name")
                   $this->NewName();
                else
                   $VeryOld = "Something Wrong";
                return $VeryOld;
           }
           
           function NewName()
           {
               echo "This is Brand New Name";
           }
       }
       
       $i = new myTestClass();
    ?>

     

    if i send value to  OldName "This is Old Name" then codes works fine.

    But if i send "This is Old Nameeee" then does not appear anything.

     

    what i want to do is print "Something Wrong" text if i enter different value. I have no idea what return do and how it do? How to retrieve/print "Something Wrong"?

    i can do that with echo but i want to transfer result of return to another function.

     

    Really appreciate for any help/idea.

  14. Hi all.

    I always create my sql queries like below.

            $user	= "user";
    $pass	= "123456";
    $host	= "localhost";
    $base	= "test";
    
    $cn = mysql_connect($host, $user, $pass) or trigger_error("SQL", E_USER_ERROR);
    mysql_select_db($base,$cn) or trigger_error("SQL", E_USER_ERROR);
    
           $QUERY = mysql_query("SELECT id FROM someTable", [size=14pt][color=red][b]$cn[/b][/color][/size]) or die(mysql_error());
    
    while ($list = mysql_fetch_assoc($QUERY)){
                  echo "Some Text over loop";
            }
    

     

    Okay here is the question (or problem). What if i have 5000 records in my Table. Doesn't this code connect DB 5000 times?

    If yes, then how can i optimize it?

  15. Okay so far i saw is you are directly using a variable without assigned.

    $variable = mysql_real_escape_string($_POST['YOUR_FORM_USER_NAME_TEXT']);  You are assigning value of User name which comes from your post into a variable. So, when your code keep running on next line you will have user entered plain text, stripped out any dangerous code inside. Then put this plain text into your sql query.

     

    $query =sprintf("SELECT * FROM  idb1 WHERE username = '%s' AND authority = 'Banned'", $variable);

     

    But, i can not see your whole page code and this all i do my best.

     

    Let us know if you have any further problem.

×
×
  • 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.