Jump to content

pritam79

Members
  • Content Count

    92
  • Joined

  • Last visited

Everything posted by pritam79

  1. pritam79

    Php Lifetime

    Hi all, I am very fond of the PHP language because of its ease of use. I feel that its overall structure gives a coder the ease for coding web pages. But there are lot of articles on the web that say that PHP is losing its ground as far as server-side scripting technologies are concerned. How far is this true and if so what language might replace PHP? Thanks to all
  2. Hi all, I have configured IIS for running ASP files and they execute properly. I am trying to execute ASP.NET files similarly after configuring them in IIS, but I am not able to do so. Does IIS need to be configured separately and differently for running aspx files or is the process same for .asp and .aspx files? One more question, can u do ASP.NET development in both IIS and Visual Studio.NET? whats the difference among the two? thanks
  3. Hi there, i have installed IIS on my machine as directed in w3schools but now when i try accessing localhost in my browser, i get a popup dialogue box which says " authentication required ", and asks for a username and password for http://localhost. Please tell me how to access IIS. thanks to all.
  4. That response did not help me, i wanted a clear description kind of thing about these because i have found such claims on the net. anyway thanks. hoping for a more descriptive explanation in the next post........
  5. Hi everyone, I am new to this web development thing and the benefits from owning a website and generating income from such source. As far as web development is concerned, I have just started off learning PHP-MySql and its use in developing a site. Also creating a site with PHP-MySql would definitely need some experience with the language. So, I would like to know if there are ways to earn money from a site ( I want to earn while I learn) as I have heard about things like blogspot, google adsense, etc that help one earn money through adds. Are these ( blogs, adsense etc) such an easy way to earn from a site/blog without having any programming experience? Can anyone give me a detailed description of these things? Thanking everyone………..
  6. pritam79

    Validation

    ok, but if the validation is done in php, will that bring extra overhead on the server since the form would be validated only after posting, or there are methods to validate in php before posting?
  7. pritam79

    Validation

    A mistake, sorry.. Would it be better to use PHP form validation and not consider javascript validation at all?
  8. pritam79

    Validation

    I tried a few sample email addresses with the following email address validation javascript code. <html><head><script type="text/javascript">function validate_required(field,alerttxt){with (field) { if (value==null||value=="") { alert(alerttxt);return false; } else { return true; } }}function validate_form(thisform){with (thisform) { if (validate_required(email,"Email must be filled out!")==false) {email.focus();return false;} }}</script></head><body><form action="submit.htm" onsubmit="return validate_form(this)" method="post">Email: <input type="text" name="email" size="30"><input type="submit" value="Submit"></form></body></html> But even when I entered a wrong email address like- .@w. , there was no error even if the address was not valid. So how can a form be validated properly before sending the data to the server? Also, the form’s action field has ‘submit.htm’ and it posts to itself, how will the form get processed?
  9. pritam79

    Cookies

    In that case when javascript is disabled, would it be better to not use 'javascript cookie handling' and instead use 'PHP cookie handling' ?
  10. pritam79

    Cookies

    Creating a session for a user in a PHP script is required only when the user logs in to the site and carries out tasks that are specific to that user, and later when the user logs out, that session is over. Can Javascript handle both sessions and cookies or only cookies? Also if cookie handling in both PHP and Javascript are the same then isn’t it better to use ‘PHP cookies’ because if Javascript is disabled in a browser, Javascript cookies won’t work. Also, what do ‘Javascript cookies’ do more than just getting stored on the visitor's computer and later sending the cookie each time the same computer requests a page.
  11. pritam79

    Cookies

    This code below creates a cookie for a user for the first time he enters his name and until the cookie associated with that particular user expires, he is greeted with the same welcome message each time the same page is loaded by the same user. Now my question is do cookies used in Javascript code for users perform the same task as cookies used in PHP? Which one is useful- creating and using cookies in PHP code (setcookie, $_cookie etc ) or Javascript cookies as below? Are PHP cookies more secure? What are the overheads in both the cases? What if a browser doesnt support cookies <html><head><script type="text/javascript">function getCookie(c_name){if (document.cookie.length>0) { c_start=document.cookie.indexOf(c_name + "="); if (c_start!=-1) { c_start=c_start + c_name.length+1; c_end=document.cookie.indexOf(";",c_start); if (c_end==-1) c_end=document.cookie.length; return unescape(document.cookie.substring(c_start,c_end)); } }return "";}function setCookie(c_name,value,expiredays){var exdate=new Date();exdate.setDate(exdate.getDate()+expiredays);document.cookie=c_name+ "=" +escape(value)+((expiredays==null) ? "" : ";expires="+exdate.toGMTString());}function checkCookie(){username=getCookie('username');if (username!=null && username!="") { alert('Welcome again '+username+'!'); }else { username=prompt('Please enter your name:',""); if (username!=null && username!="") { setCookie('username',username,365); } }}</script></head><body onload="checkCookie()"></body></html>
  12. <html><body><script type="text/javascript">var browser=navigator.appName;var b_version=navigator.appVersion;var version=parseFloat(b_version);document.write("Browser name: "+ browser);document.write("<br />");document.write("Browser version: "+ version);</script></body></html> This code gives the browser name and version of my browser. I am using Mozilla firefox version 3.0, but the output I am getting is-Browser name: NetscapeBrowser version: 5Why is it so?Again using another piece of code as below- <html><head><script type="text/javascript">function detectBrowser(){var browser=navigator.appName;var b_version=navigator.appVersion;var version=parseFloat(b_version);if ((browser=="Netscape"||browser=="Microsoft Internet Explorer") && (version>=4)) { alert("Your browser is good enough!"); }else { alert("It's time to upgrade your browser!"); }}</script></head><body onload="detectBrowser()"></body></html> I get the output “Your browser is good enough!”. But according to the “if” condition neither my browser if “Netscape” nor the version is “>=4” as stated in the code. Please help.
  13. Hi there, my poll script worked when I did it the way 'dsonesuk' showed but the race condition is also something that should strictly be considered. This is the modified poll_vote.php script—<?php$vote = $_POST['vote']; // $vote is 1 if YES is selected // and $vote is 0 if NO is selected $con=mysql_connect("localhost","root","");if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("poll");$result=mysql_query("SELECT * FROM poll_result");while($row = mysql_fetch_array($result)) { $no = $row['No']; $yes= $row['Yes']; if($vote == 1) { mysql_query("UPDATE poll_result SET Yes = Yes + 1"); } if($vote == 0) { mysql_query("UPDATE poll_result SET No = No + 1"); }?><html><body bgcolor="silver"><center>TOTAL VOTES-<?php echo $yes + $no; ?><br><br><br><table><tr><td>Yes votes:<?php echo $yes;?></td><td><img src="poll.gif" width='<?php echo(100*round($yes/($no+$yes),2)); ?>' height='20'><?php echo(100*round($yes/($no+$yes),2)); ?>%</td></tr><br><tr><td>No votes:<?php echo $no; ?></td><td><img src="poll.gif"width='<?php echo(100*round($no/($no+$yes),2)); ?>' height='20'><?php echo(100*round($no/($no+$yes),2)); ?>%</td></tr></table></center></body></html> But now I am getting this error Parse error: parse error in C:\wamp\www\poll\poll_vote.php on line 52 This is what happened after implementing your code. Please help…
  14. What kind of race condition could that bring about? Any solutions for its prevention?
  15. After using mysql_query("UPDATE poll_result SET YES = '{$row['Yes']}', NO = '{$row['No']}'");i get no errors but the database doesn't get updated. Plz tell me whats wrong with the code? What i want is the 'yes' and 'no' votes to get incremented in the database as the user selects the option.
  16. pritam79

    Ajax Poll

    Thanks dsonesuk, it worked..the image got displayed.
  17. I am trying the poll script using MySql with PHP, this is what I have done so far.This is the poll.htm file <html><head></head><body><div id="poll"><h3>Do you like PHP and AJAX so far?</h3><form action="poll_vote.php" method="post">Yes:<input type="radio" name="vote" value="1"><br>No:<input type="radio" name="vote" value="0"><input type="submit"></form></div></body></html> And this is the poll_vote.php- <?php$vote = $_POST['vote'];$con=mysql_connect("localhost","root","");if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("poll");$result=mysql_query("SELECT * FROM poll_result");while($row = mysql_fetch_array($result)) { if($vote == 1) { $row['Yes'] += 1; // increment values in the database } if($vote == 0) { $row['No'] += 1; } }mysql_query("UPDATE poll_result SET YES = '$row['Yes']' AND NO = '$row['No']'");while($row = mysql_fetch_array($result)) { echo "<p>Total votes= ".($row['Yes'] + $row['No'])."</p>"; echo "<p>Yes= ".$row['Yes']."</p>"; echo "<p>No= ".$row['No']."</p>"; }?> On selecting either Yes or No option from the html form, I am getting this error- Parse error: parse error, expecting `T_STRING' or `T_VARIABLE' or `T_NUM_STRING' in C:\wamp\www\poll\poll_vote.php on line 27. The database is not getting updated anyway, but is there anything wrong with the script? Also please suggest the simplest form of this same script using PHP MySQL. I would also like to know where I am going wrong with my current scripts. Thanks……
  18. pritam79

    Ajax Poll

    Found firebug, Is it just a Firefox add-on? I guess it can only be used when the pages to be debugged are online, can that be done offline? I have not installed it yet….
  19. pritam79

    Ajax Poll

    The image opens in IE as well as firefox
  20. pritam79

    Ajax-reosponsexml

    I am trying this example from w3schools, but it’s not working at all.This is ‘AJAX-ResponseXML.htm’- <html><head><script type="text/javascript" src="responsexml.js"></script></head><body><form>Select a User:<select name="users" onchange="showUser(this.value)"><option value="1">Peter Griffin</option><option value="2">Lois Griffin</option><option value="3">Glenn Quagmire</option><option value="4">Joseph Swanson</option></select></form><h2><span id="firstname"></span> <span id="lastname"></span></h2><span id="job"></span><div style="text-align: right"> <span id="age_text"></span> <span id="age"></span> <span id="hometown_text"></span> <span id="hometown"></span></div></body></html> This is ‘responsexml.js’- var xmlhttp;function showUser(str){xmlhttp=GetXmlHttpObject();if (xmlhttp==null) { alert ("Browser does not support HTTP Request"); return; }var url="responsexml.php";url=url+"?q="+str;url=url+"&sid="+Math.random();xmlhttp.onreadystatechange=stateChanged;xmlhttp.open("GET",url,true);xmlhttp.send(null);}function stateChanged(){if (xmlhttp.readyState==4) { xmlDoc=xmlhttp.responseXML; document.getElementById("Firstname").innerHTML= xmlDoc.getElementsByTagName("Firstname")[0].childNodes[0].nodeValue; document.getElementById("Lastname").innerHTML= xmlDoc.getElementsByTagName("Lstname")[0].childNodes[0].nodeValue; document.getElementById("Job").innerHTML= xmlDoc.getElementsByTagName("Job")[0].childNodes[0].nodeValue; document.getElementById("age_text").innerHTML="Age: "; document.getElementById("Age").innerHTML= xmlDoc.getElementsByTagName("Age")[0].childNodes[0].nodeValue; document.getElementById("hometown_text").innerHTML="<br/>From: "; document.getElementById("Hometown").innerHTML= xmlDoc.getElementsByTagName("Hometown")[0].childNodes[0].nodeValue; }}function GetXmlHttpObject(){if (window.XMLHttpRequest) { // code for IE7+, Firefox, Chrome, Opera, Safari return new XMLHttpRequest(); }if (window.ActiveXObject) { // code for IE6, IE5 return new ActiveXObject("Microsoft.XMLHTTP"); }return null;} And this is- ‘responsexml.php ‘ <?php$q=$_GET["q"];$con = mysql_connect('localhost', 'root', '');if (!$con) { die('Could not connect: ' . mysql_error()); }mysql_select_db("ajax_demo", $con);$sql="SELECT * FROM user WHERE id = ".$q."";$result = mysql_query($sql);echo '<?xml version="1.0" encoding="ISO-8859-1"<person>';while($row = mysql_fetch_array($result)) { echo "<firstname>" . $row['FirstName'] . "</firstname>"; echo "<lastname>" . $row['LastName'] . "</lastname>"; echo "<age>" . $row['Age'] . "</age>"; echo "<hometown>" . $row['Hometown'] . "</hometown>"; echo "<job>" . $row['Job'] . "</job>"; }echo "</person>";mysql_close($con);?> In localhost I on clicking the html file I get a dropdown box where from I get to select the options but on doing so I do not get any output. I have created the database as well. What could be the reason? Please help.
  21. pritam79

    Ajax Poll

    All my files (poll.gif, poll.htm, poll.js, poll_result.txt, poll_vote.php) are in the same location under the "www" directory. Everything is working except that the image is not getting displayed. The image dimensions are height=’20’ and length=’100’. I had created this image with these dimensions before running the entire script. Could that be the reason? Never used Firebug before, dont have that thing... any way of getting that?
  22. pritam79

    Ajax Poll

    The AJAX-poll script bellow is used to demonstrate a poll where a web page can get results without reloading.This is the html file poll.htm - <html><head><script type="text/javascript" src="poll.js"></script></head><body><div id="poll"><h3>Do you like PHP and AJAX so far?</h3><form>Yes:<input type="radio" name="vote" value="0" onclick="getVote(this.value)" /><br />No:<input type="radio" name="vote" value="1" onclick="getVote(this.value)" /></form></div></body></html> This is the javascript poll.js - var xmlhttp;function getVote(int){xmlhttp=GetXmlHttpObject();if (xmlhttp==null) { alert ("Browser does not support HTTP Request"); return; }var url="poll_vote.php";url=url+"?vote="+int;url=url+"&sid="+Math.random();xmlhttp.onreadystatechange=stateChanged;xmlhttp.open("GET",url,true);xmlhttp.send(null);}function stateChanged(){ if (xmlhttp.readyState==4) { document.getElementById("poll").innerHTML=xmlHttp.responseText; }}function GetXmlHttpObject(){var objXMLHttp=null;if (window.XMLHttpRequest) { objXMLHttp=new XMLHttpRequest(); }else if (window.ActiveXObject) { objXMLHttp=new ActiveXObject("Microsoft.XMLHTTP"); }return objXMLHttp;} And this is the PHP script poll_vote.php – <?php$vote = $_REQUEST['vote'];//get content of textfile$filename = "poll_result.txt";$content = file($filename);//put content in array$array = explode("||", $content[0]);$yes = $array[0];$no = $array[1];if ($vote == 0) { $yes = $yes + 1; }if ($vote == 1) { $no = $no + 1; }//insert votes to txt file$insertvote = $yes."||".$no;$fp = fopen($filename,"w");fputs($fp,$insertvote);fclose($fp);?><h2>Result:</h2><table><tr><td>Yes:</td><td><img src="poll.gif" width="<?php echo(100*round($yes/($no+$yes),2)); ?>" height="20"><?php echo(100*round($yes/($no+$yes),2)); ?>%</td></tr><tr><td>No:</td><td><img src="poll.gif" width="<?php echo(100*round($no/($no+$yes),2)); ?>"height="20"><?php echo(100*round($no/($no+$yes),2)); ?>%</td></tr></table> Firstly, I get the html form with two radio buttons for “Yes” and “No”. On selecting either “Yes” or “No” the text file poll_result.txt gets updated properly, but the gif image that corresponds to the poll is not displayed in the html page. I have the image file in the same location as the above files. Please help.
×
×
  • Create New...