Jump to content

khalidorama

Members
  • Posts

    30
  • Joined

  • Last visited

    Never

Everything posted by khalidorama

  1. I already knew about this. Thanks anyway. I googled the net for the source code of such a script, I found nothing
  2. I tried it and it only returns the webserver host name. I want to know the domains hosted by the webserver , how can i do that ?
  3. how can i list all domains hosted in a nameserver ? I want to make reverse IP lookup to view all domains hosted in an IP address . how this could be made in PHP . waiting your replies
  4. hi, Refer to this : http://www.php24hours.com/viewtopic.php?f=39&t=18&p=27#p27
  5. HI, your code should query the column in the table. and then load the stored value to memory , just increment it and update the value in the table... so simple to do..
  6. Hi, It is possible , and in this case you have to use sessions as you need to save the array's key as session variable so that if the script is run by two separate users it would be viewed to the second one what the changes of the first user. <? .... $i=0; //$i is used to save to a different location in the array $array_to_save_data_insteadof_txt_file[$i]; $i++; .... ?> the fact that $i is incremented later does not mean that if the script is run by a separate user it will start by taking the last viewed value by the first user.Instead, new variable $i will be created in the web server to the handle the first user and hence its value will be 0. so in order to solve the issue , you have to register $i as session variable and make sure that the session in started in the beginning of the script .. <? start_session(); .... //$i is used to save to a different location in the array if (isset($_session['i'])) $i = $_session['i'] else $i =0; $array_to_save_data_insteadof_txt_file[$i]; $i++; $_session['i']= $i; ..... ?> Try the above code as i don't have much time to test it . Reply to me in case you need further help.
  7. Yep sure you need HTML file to login. I made some changes in the code. and here is the newer version save this code under login.php <?php include("functions.php"); $mixed = loadarray(); sarabiccname = $_GET['username']; UNIficATion = $_GET['password']; for($i=0;$i<count($mixed);$i++) { if (fmod($i,2) == 0) $registeredusers[$i] = $mixed[$i]; } if (in_array($username,$registeredusers)) { echo "You logged in succefully"; echo "<BR>"; echo "<a href=\"logout.php\">Click here to log out</a>"; } else { array_push($mixed,$username,$password); savearray(count($mixed),$mixed); echo "The user did not exist , however it has been created and logged in."; echo "<BR>"; echo "<a href=\"logout.php\">Click here to log out</a>"; } ?> and save this code under logout.php <?PHP session_start(); session_destroy(); echo "You have been successfully logged out"; echo "<BR>"; echo "<a href=\"test.html\">Click here to login again</a>"; ?> keep the functions.php intact, i did not change it. and this code under test.html <html> <body> <form action="login.php" name="test"> <input type="text" name="username"><br> <input type="password" name="password"><br> <input type="submit" value="click to login"> </form> </body> </html> So whenever you try to login using test.html , if the user does not exsist in the file then it is added automatically to it . Great , isn't it !
  8. HI, I made a mistake in the first code. Here is the code to be saved as functions.php <?php function savearray($arraylength,$tobesavedarray) { $fp = fopen("arraycontent.txt","w"); if(!$fp) { echo "Error! The file array could not be loaded"; } for ($i=0;$i<$arraylength;$i++) { $data = $tobesavedarray[$i]; fwrite($fp,$data."@"); } } function loadarray() { $handle = fopen("arraycontent.txt","r"); $contents = fread($handle, filesize("arraycontent.txt")); $mixed = explode("@",$contents); //@ will be put between usernames just to enable return $mixed; } ?>
  9. Hi Tajh, On the contrary !. I love programming. It is like a passion for me , programming . So, I decided to think of your problem and write super perfect code just for you !. But hey, afterwards , you have to tweak your mind a little , then you will find solutions for your problems. I spent much time on this code, so you have to thank me . hehe Here is the first php file that you have to create. Just copy past the code to a file , and name it functions.php <?php include("functions.php"); $mixed = loadarray(); $username = $_GET['username']; $password = $_GET['password']; for($i=0;$i<count($mixed);$i++) { if (fmod($i,2) == 0) $registeredusers[$i] = $mixed[$i]; } if (in_array($username,$registeredusers)) { echo "The user exists"; } else { array_push($mixed,$username,$password); savearray(count($mixed),$mixed); print_r($mixed); echo "The user did not exist , however it has been created"; } ?> Here is the second file to be created in a second file <?php include("functions.php"); $mixed = loadarray(); $username = $_GET['username']; $password = $_GET['password']; for($i=0;$i<count($mixed);$i++) { if (fmod($i,2) == 0) $registeredusers[$i] = $mixed[$i]; } if (in_array($username,$registeredusers)) { echo "The user exists"; } else { array_push($mixed,$username,$password); savearray(count($mixed),$mixed); print_r($mixed); echo "The user did not exist , however it has been created"; } ?> Sadly at the end I tested my the above codes. It worked great !. However, I don't know why It needs two registerations for the same username in order to inform the user is already been registered. I don't have much time now. I will revise the code later for you. But i think there is something wrong with the first element in $registeredusers array. Regards
  10. HI, You can do that by making onchange event on the combo box. You have to use submit() HTML method. Here is an example code for two combo boxes. When The value of the first one is chosen , the html form is submitted and then php reloaded again reading the submitted html variable and passing it to the query which will populate the second combo box. This code is very dynamic , meaning that event the whole values code be changed dynamically which is really very useful . Try it and you won't forget me ! Don't forget to create the queried tabels or you can change the query according to your needs. <html> <body> <?php $host = "put your host name here"; $user = "sarab"; $pass = "khaled"; $query = "select id,name from brand"; $db = mysql_connect($host,$user,$pass); mysql_select_db("data base name",$db); $result = mysql_query($query); if(!$result){die(mysql_error());}; $rows = mysql_num_rows($result); echo "<form action =\"populate.php\" name=\"pop\" method=\"get\">"; echo "<b>please click to choose brand:</b>"; echo "<select name=\"combo\" onchange=\"submit();\">"; for($i=0; $i < $rows; $i++) { $id =mysql_result($result,$i,"id"); $name =mysql_result($result,$i,"name"); $sel = ($_REQUEST['combo'] == $id)?"selected=\"selected\"":""; //ADDED echo "<option value=\"$id\" $sel>$name</option>"; //UPDATED }; echo "</select>"; echo "<b>please click to choose product</b>"; echo "<select name=\"combo2\" onchange=\"submit();\">"; $var = $_REQUEST['combo']; $query2 ="select id,name,brandid from products where brandid= $var"; $result2 = mysql_query($query2); $rows2 = mysql_num_rows($result2); $var2 = $_REQUEST['combo2']; $query3 = "select name from products where id = $var2"; $chosen = mysql_result(mysql_query($query3),0,"name"); echo "you have chosed $chosen"; for($i=0; $i < $rows2; $i++) { $id =mysql_result($result2,$i,"id"); $name =mysql_result($result2,$i,"name"); $sel2 = ($_REQUEST['combo2'] == $id)?"selected=\"selected\"":""; //ADDED echo "<option value=\"$id\" $sel2>$name</option>"; //UPDATED }; echo "</select>"; echo "</form>"; ?> </body> </html>
  11. HI, can anyone of you tell me what is wrong with my code?. I tried it in my hosting server, but nothing happens when i click the button. However, when i store the file in my computer and then run it in my browser it works!. so why , in your opinion, it does not work from the hosting server?. <html> <head> <script language="javascript" type="text/javascript"> function button() { document.form.group[2].checked = true; } </script> </head> <body> <form name="form"> <table border=2> <tr> <td align=left> <INPUT TYPE="radio" NAME="group" VALUE="Title" onclick="inform(document.form.group[0].value);"> <font size="4"> Ansewer One</font> </td> </tr> <tr> <td align=left> <INPUT TYPE="radio" NAME="group" VALUE="Description" onclick="inform(document.form.group[1].value);"> <font size="4"> Answer two</font> </td> </tr> <tr> <td align=left> <INPUT TYPE="radio" NAME="group" VALUE="URL" onclick="inform(document.form.group[2].value);"> <font size="4"> Answer three</font> </tr> <tr> <td align=left> <INPUT TYPE="radio" NAME="group" VALUE="URL2" onclick="inform(document.form.group[3].value);"> <font size="4"> Answer four</font> </tr> </table> <input type="button" name="but" value="click to change" onclick="button();"> </form> </body> </html>
  12. Hi, I tested it . It worked. Great and many thanks. I am really proud of my browser! Regards
  13. Here is the code of record.php file: <? //"ip.php" example- display user IP address on any page Header("content-type: application/x-javascript"); echo "function populate(var1 ,var2 ) { alert(var1." ".var2); }"; ?>
  14. Hi, I am developing simple exam proprame in PHP. I want when I click the answer to update a record in a table for the chosen answer, so users can complete the test any time later. So,whenever the user clicks one of the choices, a corresponding record to the chosen answer should be added to DB. Technically, I have some difficulties. I want to put onclick event handler for the radio group buttons I am using. So , I need to pass exam question and chosen answer variables to javascript. It seems that I am doing a mistake cus I can't pass the variables. Could you please advise? <html> <script type="text/javascript src="record.php"></script> <body> <?php $db = mysql_connect("localhost", "sarabicc_khaled", "khaled"); mysql_select_db("sarabicc_Test", $db) or die(mysql_errno() . ": " . mysql_error() . "<br>"); $nav = new navbar; // set how many records to show at a time $nav->numrowsperpage = 1; $sql = "SELECT * FROM exam_questions"; // the third parameter of execute() is optional $result = $nav->execute($sql, $db, "mysql"); // handle the returned result set $rows = mysql_num_rows($result); for ($y = 0; $y < $rows; $y++) { $data = mysql_fetch_object($result); $selected = $_REQUEST['group']; $selquery = "insert into exam_tests(questions,answers) values(\"1\",\"2\")"; if (isset($selected)) { mysql_query($selquery); } echo $data->id ." - " . $data->question . "<br>\n"; echo "<br>\n"; // build the returned array of navigation links $links = $nav->getlinks("sides", "on"); for ($y = 0; $y < count($links); $y++){ echo $links[$y] . " "; } function dolinks() { $links = $nav->getlinks("sides", "on"); for ($y = 0; $y < count($links); $y++){ echo $links[$y] . " "; } } echo "<form action =\"navbar.php\" name=\"bar\" method=\"get\">"; echo "<table border=2>"; echo "<tr>"; echo "<td align=left>"; echo "<INPUT TYPE=\"radio\" NAME=\"group\" VALUE=\"1\" onclick=\"populate(document.bar.group[0].value,'$_REQUEST[row]');\">"; echo "<font size=\"4\">$data->ch1</font>"; echo "</td>"; echo "</tr>"; echo "<tr>"; echo "<td align=left>"; echo "<INPUT TYPE=\"radio\" NAME=\"group\" VALUE=\"2\" onclick=\"populate(document.bar.group[1].value,$_REQUEST[row]);\" >"; echo "<font size=\"4\">$data->ch2</font>"; echo " </td>"; echo "</tr>"; echo "<tr>"; echo "<td align=left>"; echo "<INPUT TYPE=\"radio\" NAME=\"group\" VALUE=\"3\" onclick=\"populate(document.bar.group[2].value,$_REQUEST[row]);\>"; echo "<font size=\"4\">$data->ch3</font>"; echo "</tr>"; echo "<tr>"; echo "<td align=left>"; echo "<INPUT TYPE=\"radio\" NAME=\"group\" VALUE=\"4\" onclick=\"populate(document.bar.group[3].value,$_REQUEST[row]);\>"; echo "<font size=\"4\">$data->ch4</font>"; echo "</tr>"; echo "</table>"; } echo "<hr>\n"; echo "</form>"; /* Class navbar Copyright Joao Prado Maia (jpm@musicalidade.net) Sweet little class to build dynamic navigation links. Please notice the beautiful simplicity of the code. This code is free in any way you can imagine. If you use it on your own script, please leave the credits as it is. Also, send me an e-mail if you do, it makes me happy Below goes an example of how to use this class: =============================================== <?php $nav = new navbar; $nav->numrowsperpage = 3; $sql = "SELECT * FROM links "; $result = $nav->execute($sql, $db, "mysql"); $rows = mysql_num_rows($result); for ($y = 0; $y < $rows; $y++) { $data = mysql_fetch_object($result); echo $data->url . "<br>\n"; } echo "<hr>\n"; $links = $nav->getlinks("all", "on"); for ($y = 0; $y < count($links); $y++) { echo $links[$y] . " "; } ?> */ class navbar { // Default values for the navigation link bar var $numrowsperpage = 10; var $str_previous = "Previous question"; var $str_next = "Next question"; // Variables used internally var $file; var $total_records; // The next function runs the needed queries. // It needs to run the first time to get the total // number of rows returned, and the second one to // get the limited number of rows. // // $sql parameter : // . the actual SQL query to be performed // // $db parameter : // . the database connection link // // $type parameter : // . "mysql" - uses mysql php functions // . "pgsql" - uses pgsql php functions function execute($sql, $db, $type = "mysql") { global $total_records, $row, $numtoshow; $numtoshow = $this->numrowsperpage; if (!isset($row)) $row = 0; $row = $_REQUEST['row']; $start = $row * $numtoshow; if ($type == "mysql") { $result = mysql_query($sql, $db); $total_records = mysql_num_rows($result); $sql .= " LIMIT $start, $numtoshow"; $result = mysql_query($sql, $db); } elseif ($type == "pgsql") { $result = pg_Exec($db, $sql); $total_records = pg_NumRows($result); $sql .= " LIMIT $numtoshow, $start"; $result = pg_Exec($db, $sql); } return $result; } // This function creates a string that is going to be // added to the url string for the navigation links. // This is specially important to have dynamic links, // so if you want to add extra options to the queries, // the class is going to add it to the navigation links // dynamically. function build_geturl() { global $REQUEST_URI, $REQUEST_METHOD, $HTTP_GET_VARS, $HTTP_POST_VARS; list($fullfile, $voided) = explode("?", $REQUEST_URI); $this->file = $fullfile; $cgi = $REQUEST_METHOD == 'GET' ? $HTTP_GET_VARS : $HTTP_POST_VARS; reset ($cgi); while (list($key, $value) = each($cgi)) { if ($key != "row") $query_string .= "&" . $key . "=" . $value; } return $query_string; } // This function creates an array of all the links for the // navigation bar. This is useful since it is completely // independent from the layout or design of the page. // The function returns the array of navigation links to the // caller php script, so it can build the layout with the // navigation links content available. // // $option parameter (default to "all") : // . "all" - return every navigation link // . "pages" - return only the page numbering links // . "sides" - return only the 'Next' and / or 'Previous' links // // $show_blank parameter (default to "off") : // . "off" - don't show the "Next" or "Previous" when it is not needed // . "on" - show the "Next" or "Previous" strings as plain text when it is not needed function getlinks($option = "all", $show_blank = "off") { global $total_records, $row, $numtoshow; $extra_vars = $this->build_geturl(); $file = $this->file; $number_of_pages = ceil($total_records / $numtoshow); $subscript = 0; for ($current = 0; $current < $number_of_pages; $current++) { if ((($option == "all") || ($option == "sides")) && ($current == 0)) { if ($row != 0) $array[0] = '<A HREF="' . $file . '?row=' . ($row - 1) . $extra_vars . '" onclick=\"submit();\">' . $this->str_previous . '</A>'; elseif (($row == 0) && ($show_blank == "on")) $array[0] = $this->str_previous; } if (($option == "all") || ($option == "pages")) { if ($row == $current) $array[++$subscript] = ($current > 0 ? ($current + 1) : 1); else $array[++$subscript] = '<A HREF="' . $file . '?row='. $current . $extra_vars . '" onclick=\"submit();\">' . ($current + 1) . '</A>'; } if ((($option == "all") || ($option == "sides")) && ($current == ($number_of_pages - 1))) { if ($row != ($number_of_pages - 1)) $array[++$subscript] = '<A HREF="' . $file . '?row=' . ($row + 1) . $extra_vars . '" onclick=\"submit();\">' . $this->str_next . '</A>'; elseif (($row == ($number_of_pages - 1)) && ($show_blank == "on")) $array[++$subscript] = $this->str_next; } } return $array; } } ?>
  15. HI, It is better if you use two tables. cus any empployees has only one address and when it changes you can update it. however,each employee has different and several likes and dislikes ..hence , it is better to save those records in a separate table. You have to make primary key in first table (for example, emp_id) and forign key in the second table which stores employee ids. First Table: Emp_id first_name last_name address gender etc Second Table: ref_Emp_id likes/dislikes //this has to be of boolean data type content //this field will save what he/she likes or dislikes etc
  16. Cool ! I tried it on my hosting server and I got the Ip Address of the webserver macine. I got this Ip 195.229.241.181 regards
  17. Hi, Here is how your code should look like. <? $dom = new DOMDocument(); # Initializing the DOM [Document Object Model] $html = "the html file.html"; $dom->loadHTMLFile($html); # Loads the source for parsing $xpath = new DOMXPath($dom); $books = $dom->getElementsByTagName( "tr" ); $b = 0; $i=0; while ( $i < 7) { foreach( $books as $book ) { $authors = $book->getElementsByTagName( "td" ); $record = $authors->item(floor($b))->nodeValue; echo htmlentities($record); echo "<br>"; $b+=0.5; } $i++; echo "<BR>"; } ?> I have tried the code and it worked in my hosting server . Try if But I need to know one more thing, Does anyone of you know how to dynamically know the length of the inner array of "td" tags. In my code, as I aready know the content of html file , I put $i < 7 .. Any can help in this ? Regards
  18. hi, Change your select statement to this code. It seems that there is a mistake in your current select statement. $sSql="Select mem_password from '.MEMBER_TABLE.' where mem_email = \"$_REQUEST['mem_email']\";";
  19. sorry, i submitted the code with some mistakes . here is the correct code <html> <body> <form action ="testt.php" name="thisform" method="get"> <INPUT TYPE="text" NAME="name" SIZE="30"> <br><input type="submit" value="click to delete!" onclick="submit();"><br> <?php $var = $_REQUEST['name']; //enter the table name and primary key name $delete = "delete from tablename where primarykeyname = \"$var\""; //you have to put the database connection code yourself. $db = mysql_connect("", "", ""); mysql_select_db("", $db) or die(mysql_errno() . ": " . mysql_error() . "<br>"); $result =mysql_query($delete); if ($result ==true) { echo "The row has been deleted successfully"; } else echo "No rows has been deleted"; ?> </form> </body> </html>
  20. Hi, Try to save the below mentioned code in .php file and upload it to your webserver under a secured direcotry so that only you have access to this script. Now all what you need is to provide the Primary key id and then clik delete button. Also, don't forget the connection related php code and the name of your table and primarky key. <html> <body> <form action ="testt.php" name="thisform" method="get"> <INPUT TYPE="text" NAME="name" SIZE="30"> <br><input type="submit" value="click to delete!" onclick="submit();"><br> <?php $var = $_REQUEST['name']; $delete = "delete from exam_tests where id = \"$var\""; //you have to put the database connection code yourself. $db = mysql_connect("localhost", "sarabicc_khaled", "khaled"); mysql_select_db("sarabicc_Test", $db) or die(mysql_errno() . ": " . mysql_error() . "<br>"); $result =mysql_query($delete); if ($result ==true) { echo "The row has been deleted successfully"; } else echo "No rows has been deleted"; ?> </form> </body> </html>
  21. Hi, I am developing simple test program in PHP. I am querying my Sql database . I am using Next/Previous buttons so that I can review all questions. I want to add additional code so that when i chose an answer by clicking the combo box , a DML statement is issued so that I save a record in the database for the chosen choice. I want a solution without java script. This is done by sumbit() method. So how can I handle the submit() method with two variables , one for the question number and a second one for the chosen choice?!. when i add the submit() method to onclick event on the combo box , only the combo box variable is passed . so i need another method to pass a variable containing the chosen choice to URL and then when i click next/previous button , the submit() method will be called with two variables, one the chosen choice and the second question number. does anyone of you know how to achieve this ?. Thanks a lot for your help in advance. Regards
  22. hi, It does not make sense to use $_request() method here, as it is returning the value of the currently selected item from the combo box. What we need in this case, is a function which can return the index of the currently selected item.. do you this function?. or simply , i changed your code so that I can compare values.. instead of comparing to $i , I have to compare to $id.. anyway , thanks a lot for your help.. my problem is solved now . echo "<b>please click to choose brand:</b>"; echo "<select name=\"combo\" onchange=\"submit();\">"; for($i=0; $i < $rows; $i++) { $id =mysql_result($result,$i,"id"); $name =mysql_result($result,$i,"name"); $sel = ($_REQUEST['combo'] == $id)?"selected=\"selected\"":""; //ADDED echo "<option value=\"$id\" $sel>$name</option>"; //UPDATED }; echo "</select>"; Regards
  23. hi barand, I took the third solution.. I amended the code .. it worked !! .. great and thanks for your help.. but I still have a small problem, when i chose a value from the first combo box , it is always showing as if i selected the first choice.. however, in the URL , i see that the right selection is processed and also the second combo box is populated based on my selection. It is just that after selecting from the first combo box, i always see the first choice.. how can i solve this ?. i want the user to see what he selected.. <html> <body> <?php $host = "localhost"; $user = "sarabicc_khaled"; $pass = "khaled"; $query = "select id,name from brand"; $db = mysql_connect($host,$user,$pass); mysql_select_db("sarabicc_Test",$db); $result = mysql_query($query); if(!$result){die(mysql_error());}; $rows = mysql_num_rows($result); echo "<form action =\"populate.php\" name=\"pop\" method=\"get\">"; echo "<b>please click to choose brand:</b>"; echo "<select name=\"combo\" onchange=\"submit();\">"; for($i=0; $i < $rows; $i++) { $id =mysql_result($result,$i,"id"); $name =mysql_result($result,$i,"name"); echo "<option value=\"$id\">$name</option>"; }; echo "</select>"; echo "<b>please click to choose product</b>"; echo "<select name=\"combo2\">"; $var = $_REQUEST['combo']; $query2 ="select id,name,brandid from products where brandid= $var"; $result2 = mysql_query($query2); $rows2 = mysql_num_rows($result2); for($i=0; $i < $rows2; $i++) { $id =mysql_result($result2,$i,"id"); $name =mysql_result($result2,$i,"name"); echo "<option value=\"$id\">$name</option>"; }; echo "</select>"; echo "</form>"; ?> </body> </html>
  24. Dear All, I need to query two tables using two combo boxes. The tables are of this type : author/publications , brand/products ..etc.. Whenever I chose a value in the first ComboBox , the second one should be populated based on the value chosen in the first one. The first combo box is populated, so I can tell that nothing is wrong for the first combo box code. however, when i try to change it's value nothing happens , "the scond one is not populated". I don't know what is the problem.. Maybe it is a mistake to pass javascript variable to php using IEwindow.location.href ?!. If it is a mistake ,then how can i pass javascript variable to php variable???. Please your helppppp !!!! <html> <head> <script language="javascript"> function change(event) { var myindex = form.combo.selectedindex; var brandid = form.combo.options[myindex].value; IEwindow.location.href = "http://mywebsiteaddress/populate.php?brandid=" + brandid; } </script> </head> <body> <?php $host = ""; $user = ""; $pass = ""; $query = "select id,name from brand"; $db = mysql_connect($host,$user,$pass); mysql_select_db("sarabicc_Test",$db); $result = mysql_query($query); if(!$result){die(mysql_error());}; $rows = mysql_num_rows($result); /* function change2() { $myindex = form.combo.selectedindex; $brandid = form.combo.options[$myindex].value; $query2 ="select id,name,brandid from products where brandid= $brandid "; $result2 = mysql_query($query2); $rows2 = mysql_num_rows($result2); for($i=0; $i < $rows; $i++) { $id =mysql_result($result2,$i,"id"); $name =mysql_result($result2,$i,"name"); echo "<option value=\"$id\">$name</option>"; }; } */ echo "<form action =\"populate.php\" name=\"pop\" method=\"get\">"; echo "<select name=\"combo\" onchange=\"change(this);\">"; for($i=0; $i < $rows; $i++) { $id =mysql_result($result,$i,"id"); $name =mysql_result($result,$i,"name"); echo "<option value=\"$id\">$name</option>"; }; echo "</select>"; echo "<select name=\"combo2\" >"; $query2 ="select id,name,brandid from products where brandid= $brandid"; $result2 = mysql_query($query2); $rows2 = mysql_num_rows($result2); for($i=0; $i < $rows2; $i++) { $id =mysql_result($result2,$i,"id"); $name =mysql_result($result2,$i,"name"); echo "<option value=\"$id\">$name</option>"; }; echo "</select>"; echo "</form>"; ?> </body> </html>
×
×
  • 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.