Jump to content

proud

Members
  • Posts

    57
  • Joined

  • Last visited

    Never

Everything posted by proud

  1. Okay, this explains a big part of the program mystery, so a last question would be: Why did we use the variable $using: $using=6 - ($from + $to)? what part of the problem does it solve?
  2. This code below solves the towers of hanoi problem which is an old chinese game that consists of the following rules: There are three towers T1 T2 T3 on a platform and n>0 disks (D1…….Dn) of different diameters placed on the first tower T1. The disks are in the order of decreasing diameter as one scans up the tower T1.Monks were reputedly supposed to move the disks from tower T1 to tower T3 obeying the following rules 1.only one disk can be moved at a time 2. no disk can be placed on top of another disk with a smaller diameter 3. to complete the task, the disk should be stacked on tower T3exactly like they are on tower at1. http://javaboutique.internet.com/Tower/ (You can try the game on this site to understand it) <?php function hanoi($plates, $from, $to) { while($plates > 0) { $using = 6 - ($from + $to); hanoi(--$plates, $from, $using); ////////line 5/////// print "Move plate from $from to $to<br>"; $from = $using; } } //Arguments: No of plates, From stick(1,2 or 3), To stick(1,2 or 3; except From stick) hanoi(3, 1, 3); ?> All I want is an explanation of the logic behind the code,specially line 5... because I tried hard but couldn't figure it out!
  3. proud

    for each

    My array contains names e.g. (clark, daniel and mike) .. I want to print all the possible combination with numbers from 1 to 100 e.g. (clark1,clark2,clark3,etc.. daniel1,daniel2 etc..) and at the end of every combination I want to add a certain character e.g. (clark1 absent,clark2 absent, daniel1 absent etc..) I tried this code but it didn't work: <?php $names = "dave darko dalton"; for ($i=1, $i<101, $i++) { foreach( $names as $key => $k){ echo $names. $i. 'absent'; ?>
  4. If I have the names john richard and jack.. I want them to be written in the formula "john","richard","jack" .. what is the easiest solution to use because I have got hundreds of names on which I want to apply on them the formula I mentioned above and the only thing that separates them is spaces e.g. (john richard jack mark etc..)
  5. In my database i have got a field called (ID) of type integer and i have assigned it an (auto_increment) attribute... My problem is that when i delete all the records from the table and add a new record thenafter, the (ID) of that new record continues to increment from the last deleted record, so how can i set the (ID) of the new record to 1 in case all the previous records were deleted?
  6. This query just selects the username and the password but it doesnt check if they are both in the same case. i.e (jack) and (JACK) will both be accepted by this query and that's not what I want.
  7. I designed a login form and when the user logs in with his username and password I want to make sure that they are identical to the ones in the database (case sensitive), so I tried this code but it did not work; if you login with (jack) or (JACK) both are accepted. $sql = "SELECT user_name FROM users WHERE STRCMP(user_name,'$userid') = 0 UNION SELECT user_pass FROM users WHERE STRCMP(user_pass,'$password') = 0"; $result=mysql_query($sql); $row = mysql_fetch_array( $result ); So is there any idea what is going wrong?
  8. I'm trying to subtract 2 days from the current date using strtotime, so this is the formula: $valid_time=date('d/m/Y g:i a', strtotime('-2 days')) ; but the problem comes when I try to assign the number of days to a variable: i.e. day_to_subtract=2; $valid_time=date('d/m/Y g:i a', strtotime(' - ."day_to_subtract". days')) ; when I try the code above I get this error: Warning: date() [function.date]: Windows does not support dates prior to midnight (00:00:00), January 1, 1970 in D:\AppServ\www\user_exec9.php on line 24 So is there any idea how to solve this problem?
  9. I want to know how i can subtract 1 minute from the current date. e.g. $date = date("d/m/Y g:i a"); echo $date; // the result is 25/04/2007 8:14 pm now how can i subtract one minute from $date and put it in a new variable so that it's value will be 25/04/2007 8:13 pm ?
  10. To describe the problem more furtherly I designed a chatroom, and when the user logs to the chatroom he is added in a users list using this command: if(session_is_registered("user_name")){ $chat_user=$user_name; session_register("chat_user"); $sql="INSERT INTO current_chatters VALUES('0','$chat_user')"; $result=mysql_query($sql); } Now when the user wants to logout he is supposed to click on an exit button which will direct him to page logout.php; In this page i can end his session and delete his name from table current_chatters : page logout.php: session_unregister("chat_user"); $query = "delete from current_chatters where chatter='$chat_user'"; $result = mysql_query($query); But imagine if he closes the browser? how can I delete his name from table current_chatters?
  11. I was asking whether there is a way to end a user's session in a site when he closes the browser? Any help will be appreciated indeed.
  12. $sql = "INSERT INTO video_sem (id,src,name,spkr) VALUES ( ' ' , ' $a ' , ' $b ' , ' $c ')"; $sql2 = "INSERT INTO video_sem (id,src,name,spkr) VALUES ( ' ' , ' $d ' , ' $e ' , ' $f ')"; $result=mysql_query($sql); $result2=mysql_query($sql2); Do you mean multiple queries like this one above? I've tried this one and the result of the insertion in the database is like this: id src title spkr 30 Array Array Array
  13. I'm trying to insert multiple records from a form here is my form page: <form name="video" action="http://localhost/video_exec.php" method="post"> Video Src 1 : <input name="src1" size="20" ><br> Title 1:<input name="title1" size="20"><br> Speaker 1 : <input name="spkr1" size="20"> <br><br> Video Src 2 : <input name="src2" size="20" ><br> Title 2:<input name="title2" size="20" ><br> Speaker 2: <input name="spkr2" size="20"> </form> here is the page in which the data is posted and then inserted into the database: <?php include( 'connect.php' ); $a=$_POST['src1']; $b=$_POST['title1']; $c=$_POST['spkr1']; $d=$_POST['src2']; $e=$_POST['title2']; $f=$_POST['spkr2']; $sql = "INSERT INTO video_sem (src,name,spkr) VALUES ('$a','$b','$c'), ('$d','$e','$f')"; mysql_query( $sql); ?> Although this query worked with me when i tried it with forms i dont know what went wrong.
  14. I'm using a html select tag with the following code: <select size="1" name="sq"> <option selected>Select One</option> <option>Who is your best childhood friend?</option> <option>What is your favorite meal?</option> <option>What is your favorite hobby?</option> <option>Who is your favorite teacher?</option> <option>What is your favorite movie?</option> </select> what I'm trying to do is to set the value of the select tag to one of these options when a certain condition occurs: i.e. <select size="1" name="sq" <? if ($questionv!=="Select One") ?> value="<option> Who is your best childhood friend? </option>" > <option selected>Select One</option> <option>Who is your best childhood friend?</option> <option>What is your favorite meal?</option> <option>What is your favorite hobby?</option> <option>Who is your favorite teacher?</option> <option>What is your favorite movie?</option> </select> But this doesnt seem to work so how can I set the value of the select tag to the option I want?
  15. I'm trying to design a registration form so that when the user fills the form fields if he made a mistake i.e (forgot to fill the last name field) and then returned back to the form page he finds all the fields he has filled existing only the one with the mistake highlighted. So is there a way to design such a form using php? and if it's possible please give me a code example consisting of two fields (first name, last name). Any help would be appreciated indeed.
  16. I'm trying to write a script that will allow me to reverse the maximum values with the minimum values, for example lets assume I have a table in which I have got two fields named (photo_id , photo_name ) and there are 30 photos In this table ; now I'm trying to assign the photo_id with the value equal to 1 a value of 30, and the photo_id with the value equal to 2 a value of 29 and so going on... To make it more clear: 1=30 2=29 3=28 4=27 . . . etc... So what is the code that will allow me to do this?
  17. I'm trying to design a chatroom in which the messages are displayed in the CSS content because when the text becomes too much a scrollbar appears allowing the content to remain in it's original size and allowing the user to read the long message at the same time. By the way I tried your advise about the (overflow:auto;) and it was the right solution for the problem, so thanks very much and I appreciate your help.
  18. I was wondering whether there is someway to fix the area of a content in CSS so that it wont expand if too much text was entered, just similar to the html code that fixes the area of the table. i.e. <table style="table-layout: fixed;"> This code lets the table stay in a fixed size no matter how much text is entered...
  19. Recently i'm trying to design a php chatroom... I use mysql insert commands to insert the message into the database and select commands to retrieve the data, in this project i was forced to use frames in order to let the form used to submit messages in a seperate page and the displayed messages in another page with a (meta-tag) used to refresh that page only in order to get the new messages from the database but without refreshing the page containing the form used to submit messages... The problem occured when i tried to design a logout link to exit the chatroom ; the problem is that if i made this logout link in the form page it will only log me out of the form page but the displaying page remains still in the frame and vice versa... So how can i logout of the frame page entirely? Other wise is there any php solution for this problem but putting in consideration that i need to refresh the part of the page containing the displayed messages without refreshing the form for submitting messages?
  20. I want to design 2 seperate content boxes in one page but this code doesnt generate but only one content box so what code is missing or what is supposed to be corrected? <style type="text/css"> <!-- #contentbox { background: #E5E5E5; padding: 5px; width: 500px; height: 340px; overflow: auto; } --> </style> echo "<div id=\"contentbox\">\n"; echo "hello"; echo "</div>\n"; echo "<div id=\"contentbox\">\n"; echo "hello"; echo "</div>\n";
  21. I'm trying to design a shoutbox for my site... This shoutbox code works good but recently i added to it a (meta tag) because i want the page to referesh every five seconds and get the new messages from the database... My problem is that the meta-tag makes the entire page refresh including the form in which i'm supposed to enter the message, so my objective is to let the part of the page which contains the form to be excluded from refreshing so how can i do that? and without needing to divide the code into two different files? <?php include( 'connect.php' ); $name = $_POST['name']; $message = $_POST['message']; $ip = $_POST['ip']; $mlen = strlen($message); $maxlength = 150; $date = date("M jS Y"); if ($_POST['submit']) { if ($name == "") { echo "<strong>Error: Please enter your nickname.</strong>"; } else if ($message == "") { echo "<strong>Error: No message to be sent.</strong>"; } else if ($mlen > $maxlength) { echo "<strong>Error: Message too long.</strong>"; } else { mysql_query("INSERT INTO shoutbox(name,message,date,ip) VALUES('$name','$message','$date','$ip')"); } } ?> <html> <head> <title>Display Messages</title> //////////<meta http-equiv="refresh" content="5;url=shoutbox.php">///////////// </head> <body> <? $query = "SELECT * FROM shoutbox ORDER BY id DESC LIMIT 20"; $result = mysql_query($query); echo "<div id=\"contentbox\">\n"; echo "<ul id=\"shoutboxmessage\">\n"; while($r = mysql_fetch_array($result)) { $name = $r['name']; $name = strip_tags($name); $message = $r['message']; $message = strip_tags($message); echo "<li><strong>>$name</strong>: $message</li>\n"; } echo "</ul>\n"; echo "</div>\n"; mysql_close($conn); ?> <form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>"> <strong>Nickname:</strong><br/> <input type="text" name="name" maxlength="20"><br/> <strong>Message:</strong><br/> <textarea name="message"></textarea><br/> <input type="submit" name="submit" value="Shout It!"> <input type="hidden" name="ip" value="<?php echo $_SERVER['REMOTE_ADDR']; ?>"> </form> </div> </body> </html>
  22. This script is supposed to submit an email to a user who forgot his password, but i dont know whats wrong with the script although i tried my best i keep getting this error . Warning: mail() [function.mail]: Failed to connect to mailserver at "localhost" port 25, verify your "SMTP" and "smtp_port" setting in php.ini or use ini_set() in C:\AppServ\www\forgotpassck.php on line 44. By the way if this script wont work does anyone know an alternative? note:I added a comment in Line 44. <? include "connect.php"; ?> <html> <head> <title>Forgot Pass CK</title> </head> <body bgcolor="#ffffff" text="#000000" link="#0000ff" vlink="#800080" alink="#ff0000"> <? $email=mysql_real_escape_string($email); $status = "OK"; //error_reporting(E_ERROR | E_PARSE | E_CORE_ERROR); if (!stristr($email,"@") OR !stristr($email,".")) { $msg="Your email address is not correct<BR>"; $status= "NOTOK";} if($status=="OK"){ $query="SELECT * FROM users WHERE users.user_email = '$email'"; $st=mysql_query($query); $recs=mysql_num_rows($st); $row=mysql_fetch_object($st); $em=$row->user_email;// email is stored to a variable if ($recs == 0) { echo "<center><font face='Verdana' size='2' color=red><b>No Password</b><br> Sorry Your address is not there in our database . You can signup and login to use our site. <BR><BR><a href='login.php'> Login</a> </center>"; exit;} $headers4="yassirca@hotmail.com"; ///// Change this address within quotes to your address /// $headers.="Reply-to: $headers4\n"; $headers .= "From: $headers4\n"; $headers .= "Errors-to: $headers4\n"; //$headers = "Content-Type: text/html; charset=iso-8859-1\n".$headers;// for html mail un-comment this line //////// line44 //////// if(mail("$em","Your Request for login details","This is in response to your request for login detailst at site_name \n \nLogin ID: $row->user_id \n Password: $row->user_pass \n\n Thank You \n \n siteadmin","$headers")){echo "<center><font face='Verdana' size='2' ><b>THANK YOU</b> <br>Your password is posted to your email address . Please check your mail after some time. </center>";} else{ echo " <center><font face='Verdana' size='2' color=red >There is some system problem in sending login details to your address. Please contact site-admin. <br><br><input type='button' value='Retry' onClick='history.go(-1)'></center></font>";} } else {echo "<center><font face='Verdana' size='2' color=red >Your email address is not correct <br><br><input type='button' value='Retry' onClick='history.go(-1)'></center></font>";} ?> </body> </html>
  23. I was wondering whether javascript has a header function like the one in php that directs the one to another page? and if there exists please i would like to know it's syntax?
  24. I'm trying to subtract 1 from a field called reply but i dont know what is the right syntax to use? The red part is where the syntax needs to be corrected... UPDATE `forum_question` SET `reply` = `reply-1` WHERE `forum_question`.`id` =3 ;";
  25. I'm trying to design a user administration area for a forum, my target is that when a user logs to the system with his username and password if he is an administrator he is supposed to see three links (admin,main forum and logout) but when he is not an admin he must only see two links (main forum and logout). so this piece of code works when I log into the system as an admin with my username and password and i see the three links but when I enter the main forum link and return back I just find the two links (main forum and logout) without the admin link... could anyone know what is wrong with this piece of the code, i dont know whether the problem has to do with the session or something else? note:This part of the code is where i think the problem is existing although i'm not definitely sure. if(session_is_registered("valid_user")) { $sql2 = "SELECT * FROM users WHERE user_name = '$userid'"; $result2 = mysql_query( $sql2 ); $row = mysql_fetch_array( $result2 ); if( $row['user_admin'] == 'y' ) { echo"<a href='admin.php'>admin</a><br><br>"; echo"<a href='main_forum.php'>Main forum</a><br><br>"; echo"<a href='21.php'>Logout</a><br>"; } if( $row['user_admin'] == 'n' ) { echo"<a href='main_forum.php'>Main forum</a><br><br>"; echo"<a href='21.php'>Logout</a><br>"; } }
×
×
  • 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.