Jump to content
xisto Community
Sign in to follow this  
Roly

I think I am one of the best PHP programers here ... and thats why I will help you

Recommended Posts

Just post your PHP problem here and I will try to help you. Having trouble writing a script? I am here come to me here. And no offense but I think I know more PHP than the admin. BTW, I don't want you to think of me as a person who gloats about himself a lot because I don't. I'm just saying this because it's been proved and I'm sure there are other great PHP programers here and I ask them to come here and help asnwer your questions.

Share this post


Link to post
Share on other sites

So, im making a chatroom in wml/php with no database. I have most of it covered but I have a few problems. When a user enters the chat he/she has to enter the nickname. After the user has entered one message the chatroom "forgets" the nickname so if he/she enters another message, the name wont be displayed. I tried using sessions and cookies and such but I cant get em to work.

Share this post


Link to post
Share on other sites

So, im making a chatroom in wml/php with no database. I have most of it covered but I have a few problems. When a user enters the chat he/she has to enter the nickname. After the user has entered one message the chatroom "forgets" the nickname so if he/she enters another message, the name wont be displayed. I tried using sessions and cookies and such but I cant get em to work.

Mind showing me your source? And yes cookies is the best way. Your source should look something like this:

<?php[br]if(isset($_POST['nickname'])[/br]  setcookie('nickname', htmlentities($_POST['nickname']), 999999);[br]?>[br][/br]<form>[/br]<input name=nickname value="<?= isset($_COOKIE['nickname']) ? isset($_COOKIE['nickname']) : NULL; ?>"[br]<input name=message><input type=submit value="Say It"></form>
[/br]And remember you need to set the cookie before you write anything to the page. That means before the <html> tag ;)

Share this post


Link to post
Share on other sites

Ahem , am asking for the best News system u can offer me  ;) appreciate if it is easy to setup , and can manage templates and things like that ,

thnx  :P

You should go to http://php.resourceindex.com/ and search for one. Before I knew PHP I went to that site to get my scripts and I slowly learned from them. I still go sometimes just to look for some examples.

Share this post


Link to post
Share on other sites

No, cookies are not the best way to go. Sessions are most definately better than cookies, assuming nothing needs to be 'remembered' outside of the current session.

Some browsers don't allow cookies, and some people turn them off (due to security threats etc), so if your site uses cookies, not all users will be able to view it - or some may even choose to leave based on this reason alone.

On the other hand, sessions always work. And the user can't disable sessions (unless they close their browser window).

And as for your code:

<?php[/br]if(isset($_POST['nickname'])[br] setcookie('nickname', htmlentities($_POST['nickname']), 999999);[/br]?>

Shouldn't it be:

<?php[/br]if(isset($_POST['nickname']) {[br]       setcookie('nickname', htmlentities($_POST['nickname']), 999999);[/br]}// edit: IF statements need to be enclosed in { }.[br][/br]?>

(edit: I read it wrong the first time)
Edited by Sauron (see edit history)

Share this post


Link to post
Share on other sites

So, im making a chatroom in wml/php with no database. I have most of it covered but I have a few problems. When a user enters the chat he/she has to enter the nickname. After the user has entered one message the chatroom "forgets" the nickname so if he/she enters another message, the name wont be displayed. I tried using sessions and cookies and such but I cant get em to work.

Mind showing me your source? And yes cookies is the best way. Your source should look something like this:

<?php[br]if(isset($_POST['nickname'])[/br]  setcookie('nickname', htmlentities($_POST['nickname']), 999999);[br]?>[br][/br]<form>[/br]<input name=nickname value="<?= isset($_COOKIE['nickname']) ? isset($_COOKIE['nickname']) : NULL; ?>"[br]<input name=message><input type=submit value="Say It"></form>
[/br]And remember you need to set the cookie before you write anything to the page. That means before the <html> tag ;)

Actualy the source for the page where user inputs his/her name is

<?php [/br]session_start( ); session_register("nick"); [br]header("Content-type: text/vnd.wap.wml"); [/br]echo "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>"; [br]echo "<!DOCTYPE wml PUBLIC \"-//WAPFORUM//DTD WML 1.1//EN\"" [/br]. " \"http://http://www.wapforum.org/DTD/wml_1.1.xml;; [br]?> [/br]<wml> [br]<card id="en" title="Enter nickname">[/br]<p>[br]<?php $session=session_id(); ?>[/br]</p>[br]<p>[/br]  [br]            <do type="accept">     [/br]            <go href="viewroom.php?nick=<?echo $session?>" method="post"> [br]            <postfield name="nick" value="$nick"/>  [/br]            </go> [br]        </do> [/br]        Enter nickname: [br]        <input title="nick" name="nick" type="text" /> <br/>  [/br]               [br]</p>[/br]</card>[br]</wml>[/br]

I dont think thats correct though.

I dont know if its neede but heres also the code for the page that writes the data into the file

<?php [/br]session_start(); [br]header("Content-type: text/vnd.wap.wml"); [/br]echo "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>"; [br]echo "<!DOCTYPE wml PUBLIC \"-//WAPFORUM//DTD WML 1.1//EN\"" [/br]. " \"http://http://www.wapforum.org/DTD/wml_1.1.xml;; [br]?> [/br]<wml> [/br]<card id="msgadd" title="message added">[br]<p align="center">[/br]<br/>Your message has been added[br]</p>[/br]<p><?php $session=session_id();  ?></p>[br]<p><a href="viewroom.php?nick=<?echo $session?>">Chat</a></p>[br][/br]<p>[/br]<?php [br][/br]//use the fopen() function [br]$fp=fopen("msgs.txt",  "r");   [/br]$data = fread( $fp, filesize( "msgs.txt" )); [br]fclose( $fp ); [br][/br]$fp2 = fopen( "msgs.txt", "w" ); [br][/br]//using the fputs() function [/br]fputs($fp2, " [br]<p> [/br]//I was just testing so dont even notice the session varaible below[br]$session: $msg <br/>[/br]</p> [br]". $data ); [/br]   [br]fclose($fp2);   [br][/br]?> [br][/br]</p>[/br]</card>[br]</wml>[/br]

Share this post


Link to post
Share on other sites

I optimized your source, replaced doublequotes with singlequotes because it's faster and change your file functions a bit:

<?php [/br]session_start(); [br]header('Content-type: text/vnd.wap.wml'); [/br]echo "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>"; [br]echo '<!DOCTYPE wml PUBLIC "-//WAPFORUM//DTD WML 1.1//EN\ '.[/br].' "http://http://www.wapforum.org/DTD/wml_1.1.xml;; [br]?> [/br]<wml> [br]<card id="msgadd" title="message added">[/br]<p align="center">[br]<br/>Your message has been added[/br]</p>[br]<p><?php $session=session_id();  ?></p>[/br]<p><a href="viewroom.php?nick=<?echo $session?>">Chat</a></p>[br][/br]<p>[br]<?php [/br]$data = file_get_contents('msgs.txt');[br][/br]$fp2 = fopen( "msgs.txt", "w" ); [br]fputs($fp2, ' [/br]<p> [br]//I was just testing so dont even notice the session varaible below[/br]'.$session.': '.$msg.' <br/>[br]</p> [/br]'. $data );   [br]?> [/br][br]</p>[/br]</card></wml>

Share this post


Link to post
Share on other sites

I am making a page that has a text box to do an area code lookup. Can you give me some tips to make it work? I have a text box for the area code and then a Go! button. Here is the code for the text box/button:

[br]<form id="headerSearch" action="./index.html" method="get">[/br]<div>[br]<input class="text" type="text" value="Area Code Search"[/br]onFocus="if (this.value == 'Area Code Search') this.value=''; else this.select();"[br]onBlur="if (this.value == '') this.value='Area Code Search';" />[/br]<input type="submit" class="submit" value="Go!" />[br]</div>[/br]</form>[br]

How can I make this work with a PHP script?

Thanks![/br]Dennis

Share this post


Link to post
Share on other sites

I'm not sure what you mean with getting that to work but I'll try to help. The way I would do it is I would put all the area codes in a database and then search the database to see if the area code submitted matches.

<?php[/br]// insert database connection here[br][/br]if(isset($_POST['area']))[br]{[/br]  $result = mysql_query('SELECT location FROM areacodes WHERE area = \''.$_POST['area'].'\'');[br]  if(mysql_num_rows($result) > 0)[/br]  {[br]    $row = mysql_fetch_row($result);[/br]    echo 'The area code you submitted is in '.$row[0].'.';[br]  } else[/br]    echo 'No matches were found for the area code you submitted.';[br]}[/br]?>[br][/br]<form id="headerSearch" method="post">[br]<div>[/br]<input class="text" type="text" name="area" value="Area Code Search"[br]onFocus="if (this.value == 'Area Code Search') this.value=''; else this.select();"[/br]onBlur="if (this.value == '') this.value='Area Code Search';" />[br]<input type="submit" class="submit" value="Go!" />[/br]</div>[br]</form>[/br]

Share this post


Link to post
Share on other sites

Ok I am using this. I have a database called db2, and a table in db2 called 'area'. This is an example of an entry in that table:

acode=201
state=NJ
details: blah blah all the cities, etc.
zone: Eastern

Below, when you said

[br]('SELECT location FROM area WHERE area ....[/br]

What do I put in location? Can I echo a table of all the above variables for the query? Can I make this a popup box with the table in that?

[/br]<?php[br]// insert database connection here[/br]$db = mysql_connect("localhost", "root","");[br]mysql_select_db("db2",$db);[br][/br]if(isset($_POST['area']))[/br]{[br] $result = mysql_query('SELECT location FROM area WHERE area = \''.$_POST['area'].'\'');[/br] if(mysql_num_rows($result) > 0)[br] {[/br]   $row = mysql_fetch_row($result);[br]   echo 'The area code you submitted is in '.$row[0].'.';[/br] } else[br]   echo 'No matches were found for the area code you submitted.';[/br]}[br]?>[/br]

Share this post


Link to post
Share on other sites

Oh ok that works better. Yes that is possible, this is how:

<?php[/br]// insert database connection here[br]$db = mysql_connect("localhost", "root","");[/br]mysql_select_db("db2",$db);[br][/br]if(isset($_POST['area']))[br]{[/br]$result = mysql_query('SELECT * FROM area WHERE acode = \''.$_POST['area'].'\'');[br]if(mysql_num_rows($result) > 0)[br]{[/br]  $row = mysql_fetch_assoc($result);[/br]  echo '<b>Area Code:</b> '.$row['acode'];[br]  echo '<b>State:</b> '.$row['state'];[/br]  echo '<b>Details:</b> '.$row['details'];[br]  echo '<b>Zone:</b> '.$row['zone'];[/br]} else[br]  echo 'No matches were found for the area code you submitted.';[/br]}?>

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×
×
  • Create New...

Important Information

Terms of Use | Privacy Policy | Guidelines | 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.