Jump to content

Fahid

Members
  • Posts

    30
  • Joined

  • Last visited

    Never

Everything posted by Fahid

  1. I tried it myself, and it does delete the record from MS Access DB Thanks a lot again for help.
  2. Thanks a lot Mr. Mchl, I didn't found this thing in PHP documentation and was really troubled. Thanks a lot. 1 more little question please, can I delete a row/record from MS Access through PHP/ODBC ? I mean will this work DELETE FROM pNum WHERE `iRef`= '10' LIMIT 1
  3. Try changing the following portion better try copy/paste <?php $db = mysql_select_db("XXXXXXX_com_db", $con); $sql="INSERT INTO Enquiries (hear, name, email, contact, Schoolorcollege, date) VALUES (". $_POST['hear'] .",". $_POST['name'] .",". $_POST['email'] .",". $_POST['contact'] .",". $_POST['Schoolorcollege'] .",". $_POST['date'] .")"; //$_POST['SQL_query_result'] = 'Success'; if (!mysql_query($sql,$con)) { die("Database Error". mysql_error()); //$_POST['SQL_query_result'] = 'Database Error'; } ?>
  4. Hello All, I am trying to get some data from a MS Access database through ODBC, but don't know why I am failing no matter what I try. my code is given below I run this code and get the following error/output, which I have set to be displayed if no record is selected This means that my query is not affecting/selecting any data/row from the database. Please help WHY? <?php function get_given_number($num){ $conn = odbc_connect(settings('dsn'), settings('user'), settings('pass')) or die(odbc_error()."Cant conect"); $query = "SELECT * FROM pNum WHERE `iNum`='$num' ORDER BY `iSr` DESC"; //$query = "SELECT * FROM pNum"; $result = odbc_exec($conn, $query) or die(odbc_error($conn) . "get_given_number-query error"); $affected_rows = odbc_num_rows($result); //die($affected_rows); if($affected_rows < 1 ) die("get_given_number-no records found"); $output = ''; $entry_list = file_as_var('includes/pdel_entry_list.html'); while(odbc_fetch_row($result)){ $serial = odbc_result($result, 'iSr'); $reference = odbc_result($result, 'iRef'); $party_name = get_party_name($reference); $party_status = get_party_status($reference); if($party_status == 0) continue; $type = odbc_result($result,'iTyp2'); $amounta = odbc_result($result,'iAmnt'); $amountb = odbc_result($result,'iAmnt2'); $output .= format_entry($num, $serial, $party_name, $type, $amounta, $amountb); } $output = str_replace('__ENTRIES__',$output,$entry_list); $output = str_replace('__iNum__',$number,$output); odbc_close_all(); return $output; } echo get_given_number('7139'); ?>
  5. of course you can add whatever you want to add, you text/.txt could be a file with HTML code. or if you like, you can also use a .html file instead of .txt file. and use any of your favorite editor to create/edit this file. just be very careful at the replacement tokens i.e. __COUNTRY__ and replacement commands in PHP <?php $mail_body = str_replace('__COUNTRY__',$country,$mail_body); $mail_body = str_replace('__SCDATE__',$Scdate,$mail_body); $mail_body = str_replace('__COMMENT__',$country,$mail_body); ?> be very careful about these lines, use any number of replacement tokens you would like to, for example if I want to add a new variable into my HTML template file, I would add a line in my HTML code i.e. Your I.P. is __IP__ and add a new line ( at the end of code given below in my PHP code ) to replace __IP__ token with the user IP i.e. $mail_body = str_replace('__IP__',$_SERVER['REMOTE_ADDR'],$mail_body); End word is that: I can just give you the right direction, you have to make it to your destiny yourself
  6. Thanks God, I have got it done just a little addition to my php code, goes as under <?php function mysqlcon(){ $conn = mysql_connect('','root','pass') or die(mysql_error()); $db = mysql_select_db('wordpress') or die(mysql_error()); $unicode = mysql_query("SET NAMES utf8"); return $conn; } function get_wp_news (){ $conn = mysqlcon(); $output = ''; $query = "SELECT * FROM `wp_posts` WHERE `post_category`=0 ORDER BY `post_date` DESC LIMIT 0,1"; $result = mysql_query($query) or die(mysql_error()); $rows = mysql_affected_rows(); if($rows > 0){ while($db_output = mysql_fetch_array($result)){ $output = $db_output['post_content']; } } else $output = "No Records Were Found!"; return $output; } ?> notice the line# 5 in the script $unicode = mysql_query("SET NAMES utf8"); Thanks goes to lorenz pressler @ http://dev.mysql.com/doc/refman/5.1/en/charset-unicode.html
  7. Thanks God, I have got it done just a little addition to my php code, goes as under <?php function mysqlcon(){ $conn = mysql_connect('','root','pass') or die(mysql_error()); $db = mysql_select_db('wordpress') or die(mysql_error()); $unicode = mysql_query("SET NAMES utf8"); return $conn; } function get_wp_news (){ $conn = mysqlcon(); $output = ''; $query = "SELECT * FROM `wp_posts` WHERE `post_category`=0 ORDER BY `post_date` DESC LIMIT 0,1"; $result = mysql_query($query) or die(mysql_error()); $rows = mysql_affected_rows(); if($rows > 0){ while($db_output = mysql_fetch_array($result)){ $output = $db_output['post_content']; } } else $output = "No Records Were Found!"; return $output; } ?> notice the line# 5 in the script $unicode = mysql_query("SET NAMES utf8"); Thanks goes to lorenz pressler @ http://dev.mysql.com/doc/refman/5.1/en/charset-unicode.html
  8. Hello All, I am trying to obtain some uni-code ( uni-code urdu text ) text from MySQL database and show it on my page generated by using PHP. Original text ( that should be displayed or what I want to display ) may be seen here http://fahid.freehostia.com/text.html And this is the PHP code I am using to get the text from data base <?php function mysqlcon(){ $conn = mysql_connect('localhost','root','pass') or die(mysql_error()); $db = mysql_select_db('wordpress') or die(mysql_error()); return $conn; } function get_wp_news (){ $conn = mysqlcon(); $output = ''; $query = "SELECT * FROM `wp_posts` WHERE `post_category`=0 ORDER BY `post_date` DESC LIMIT 0,1"; $result = mysql_query($query) or die(mysql_error()); $rows = mysql_affected_rows(); if($rows > 0){ while($db_output = mysql_fetch_array($result)){ $output = $db_output['post_content']; } } else $output = "No Records Were Found!"; return $output; } ?> The text is stored in database correctly, it is originally stored into data base using Wordpress, a well know PHP blogging engine. Wordpress shows the text absolutely perfectly. but when I try to obtain the uni-code urdu text from MySQL and show it, it show something like ? ? ? ? ? ? ? ? ? ?? symbols instead of the uni-code urdu text. I hope I am using correct HTML encoding type in the html head, that is <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> A working version of my PHP script showing the messed up output is available here http://fahid.freehostia.com/ Please help me do it correctly, I can't understand what's going wrong
  9. How about this <?php function file_as_var ($file, $file_size_kilobytes = 100){ $file_size_bytes = $file_size_kilobytes * 1024; $fp = fopen($file,"r"); $output = fread($fp, $file_size_bytes); // LIMIT 100 KB fclose($fp); return $output; } $mail_body = function file_as_var ("./email_template.txt", 10); $mail_body = str_replace('__COUNTRY__',$country,$mail_body); $mail_body = str_replace('__SCDATE__',$Scdate,$mail_body); $mail_body = str_replace('__COMMENT__',$country,$mail_body); ?> while the email_template.txt should be some thing like this <p>Dear user<br>Your country is __COUNTRY__<br>Your Secure order date is __SCDATE__</p> <p>the comments are __COMMENTS__</p> You can add whatever you like in the text file, I hope this can give you the right idea at least.
  10. Hello All, I am trying to obtain some uni-code ( uni-code urdu text ) text from MySQL database and show it on my page generated by using PHP. Original text ( that should be displayed or what I want to display ) may be seen here http://fahid.freehostia.com/text.html And this is the PHP code I am using to get the text from data bse <?php function mysqlcon(){ $conn = mysql_connect('','root','pass') or die(mysql_error()); $db = mysql_select_db('wordpress') or die(mysql_error()); return $conn; } function get_wp_news (){ $conn = mysqlcon(); $output = ''; $query = "SELECT * FROM `wp_posts` WHERE `post_category`=0 ORDER BY `post_date` DESC LIMIT 0,1"; $result = mysql_query($query) or die(mysql_error()); $rows = mysql_affected_rows(); if($rows > 0){ while($db_output = mysql_fetch_array($result)){ $output = $db_output['post_content']; } } else $output = "No Records Were Found!"; return $output; } ?> The text is stored in database correctly, it is originally stored into data base using Wordpress, a well know PHP blogging engine. Wordpress shows the text absolutely perfectly. but when I try to obtain the uni-code urdu text from MySQL and show it, it show something like ???? ??????? ?? ? symbols instead of the uni-code urdu text. I am using correct encoding type in the html head, that is <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> A working version of my PHP script showing the messed up output is available here http://fahid.freehostia.com/ Please help do it correctly, I can't understand what's going wrong
  11. Sorry, Give it a try now <?php session_start(); $db_host = 'localhost'; //Hostname $db_user = 'root'; //Username $db_pass = ''; //Password $db_db = 'users'; //Database name if (isset($_POST['username'])) { // Mysql Connection $db_link = mysql_connect($db_host, $db_user, $db_pass) or die('MySQl Connection Error:'.mysql_error()); mysql_select_db($db_db) or die('MySQL Error: Cannot select table'); $username = mysql_real_escape_string($_POST['username']); $password = mysql_real_escape_string($_POST['password']); // MySQL Query $result = mysql_query("SELECT * FROM `users` WHERE `username` = '$username' AND `password` = '$password' ") or die ('Error Fetching Username & Pass'. mysql_error()); if(mysql_num_rows($result) > 0) { // Mysql fetch row results $row = mysql_fetch_assoc($result); $_SESSION['userid'] = $row['id']; $_SESSION['username'] = $username; $_SESSION['error'] = 'Login successful!'; } else { $_SESSION['error'] = '<span style="color: red">Login Failed</span>'; } mysql_close($db_link); } header('Location: ./') ?>
  12. I want to get the contents of the file/db_data into a variable, because it has both HTML and some PHP script. I want to save this data into variable so that I can print the data on a specific spot in my page. If I use your method, PHP Script will be executed, but HTML will be sent to browser right away, which I don't want. here are contents of PHP script I want to add through TEXT FILE or MYSQL DATABASE <div id="reporterrorform"> <form method="post" action="report-error.php"> <fieldset> <legend>Report Error...</legend> <table> <tr> <td colspan="2" align="center"><hr /></td> </tr> <tr> <th><label for="PageAddress">Page Address: </label></th> <td><input type="text" name="PageAddress" id="PageAddress" size="60" readonly="readonly" value="<?php isset($PageAddress) ? echo $PageAddress : echo $_SERVER['HTTP_REFERER']; ?>" /></td> </tr> <tr> <th valign="top"><label for="Description">Description of Error: </label></th> <td><textarea rows="6" cols="45" name="Description" id="Description"><?php echo $Description; ?></textarea></td> </tr> <tr> <td colspan="2"><p class="formhelp">Thank You for taking your time to Report the Error.</td> </tr> <tr> <th><label for="Name">Full Name: </label></th> <td><input type="text" name="Name" id="Name" size="60" maxlength="30" value="<?php echo $Name; ?>" /></td> </tr> <tr> <th><label for="Email">Email Address: </label></th> <td><input type="text" name="Email" id="Email" size="60" maxlength="60" maxlength="30" value="<?php echo $Email; ?>" /></td> </tr> <tr> <th><label for="Phone">Phone/FAX/Cell: </label></th> <td><input type="text" name="Phone" id="Phone" size="60" maxlength="60" maxlength="30" value="<?php echo $Phone; ?>" /></td> </tr> <tr> <td align="right"><input type="submit" value="Send" /></td> <td><input type="reset" value="Clear" /></td> </tr> </table> </fieldset> </form> </div>
  13. Try This <?php session_start(); $db_host = 'localhost'; //Hostname $db_user = 'root'; //Username $db_pass = ''; //Password $db_db = 'users'; //Database name if (isset($_POST['username'])) { // Mysql Connection $db_link = mysql_connect($db_host, $db_user, $db_pass) or die('MySQl Connection Error:'.mysql_error()); mysql_select_db($db_db) or die('MySQL Error: Cannot select table'); $username = mysql_real_escape_string($_POST['username']); $password = mysql_real_escape_string($_POST['password']); // MySQL Query $result = mysql_query("SELECT * FROM `users` WHERE `username` = '$username' AND `password` = '$password' ") or die ('Error Fetching Username & Pass', mysql_error()); if(mysql_num_rows($result) > 0) { // Mysql fetch row results $row = mysql_fetch_assoc($result); $_SESSION['userid'] = $row['id']; $_SESSION['username'] = $username; $_SESSION['error'] = 'Login successful!'; } else { $_SESSION['error'] = '<span style="color: red">Login Failed</span>'; } mysql_close($db_link); } header('Location: ./') ?>
  14. I think I have got the solution while visiting this forum, please confirm if you see it. Even if this function is the one I am looking for, still the question is: In which PHP Versions this function is supported? <?php $Name = mysql_real_escape_string($_POST['Name']); $Phone = mysql_real_escape_string($_POST['Phone ']); $query = "INSERT INTO `tablename` VALUES ('$Name', '$Phone' );"; $result = mysql_query($query) or die(mysql_error()); ?>
  15. 1. Can we obtain some text (PHP Script) from a database and execute it? If yes then how? Example-1 - Fetching Data/PHP Script from data base <?php $query = "SELECT `code`, `codename` FROM `tablename` WHERE `codename`='error_from' LIMIT 1;"; $result = mysql_query($query) or die(mysql_error()); if(mysql_num_rows($result) > 0){ while($output = mysql_fetch_array($result)){ $script = $output['code']; } } // now $script has some PHP script in it, // can we some how execute this script, if yes then how? ?> 2. Can we obtain some text (PHP Script) from a text file with fopen/fread and execute it? If yes then how? Example-2 - PHP Code from text file <?php $file = "texts/report-error-form.txt"; $fp = fopen($file,"r"); $script = fread($fp, 4096); fclose($fp); // now $script has some PHP script in it, // can we some how execute this script, if yes then how? ?> Please help !
  16. I created a simple PHP/MySQL GUESTBOOK Script, when user add a SINGLE QUOTE ' in any field, MySQL can't add it to database, I understand that we have to escape (use \ ) in such cases. but can't remember how exactly we should do it, code part-4 shows how I somehow have managed to avoid the error, but I know this is not the most efficient way in the world. Example-1: I have to add a couple of fields to database <?php $Name = $_POST['Name']; $Phone = $_POST['Phone ']; $query = "INSERT INTO `tablename` VALUES ('$Name', '$Phone' );"; $result = mysql_query($query) or die(mysql_error()); ?> in above case if some one adds his name as Myname's Name MySQL will return an error. And that's what I am talking/Asking about. Example-2: I somehow managed to work it out, but am not satisfied with it <?php $Name = str_replace("'","\'",str_replace("\'","\\'",$_POST['Name'])); $Phone = str_replace("'","\'",str_replace("\'","\\'",$_POST['Phone '])); $query = "INSERT INTO `tablename` VALUES ('$Name', '$Phone' );"; $result = mysql_query($query) or die(mysql_error()); ?> Example-2 will not make any problem for MySQL, but I am not satisfied with it, moreover it is expected that this way I can alter the user's submitted data a little. Please help.
  17. Thanks a lot eshta I thoought no one is ever gonna post any reply this thread. Thanks, I am just downloading the file in link above and hope i help me.
  18. Thanks a Lot [b]ryanlwh[/b] Now It's working fine. Thank you very much.
  19. Thanks for response ryan, but I still can't find out, how exactly to do it. this is a sample page which uses the script [code] <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <script type="text/javascript"> /* This funtion helps to make an input-box to only accept integers */ function is_int(Key) { /* 48 is ASCII code for 0 and 57 is for 9 */     /*     ryanlwh's code     Key =  event.keyCode ? event.keyCode : event.which ? event.which : event.charCode;     */     //alert(Key);     if(Key == 13) return true;     for(i=48;i<=57;i++){         if(Key == i) return true;     }     return false; } </script> <title>Numeric Only TextBox</title> </head> <body> <input type="text" onkeypress="return is_int(event.keyCode);" /> </body> </html> [/code] When I use [code]<input type="text" onkeypress="return is_int(event.keyCode);" />[/code] IE and Opera works just as I want, but Firefox doesn't. And When I use [code]<input type="text" onkeypress="return is_int(event.charCode);" />[/code] Firefox works, but neither IE nor Opera OK I changed my javascript to this [code] function is_int(empty) {     // in Firefox navigator.appName returns "Netscape".     if(navigator.appName == "Netscape") Key = event.charCode;     else Key = event.keyCode;     alert(Key);     // removed the rest of code for test     return false; } [/code] Still IE and Opera respond well, but not Firefox.
  20. HI Guys! I wanted to make an input box to accept only numeric (int) values, to do that I wrote following function. [code] function is_int(Key) { /* 48 is ASCII code for 0 and 57 is for 9 */     //alert(Key);     for(i=48;i<=57;i++){         if(Key == i) return true;     }     return false; } [/code] and my input box look like this [code] <input type="text" name="quantity" id="quantity" size="30" maxlength="3" value="1" onkeypress="return is_int(event.keyCode);" /> [/code] Now! when I use IE6 or Opera, everythings just going perfect, But when I use Firefox, I got a problem. Firefox make it impossible to type anything in the input box, not even integers. Infact Firefox return [b]0[/b], not the actuall ASCII code of the key that was pressed. [!--sizeo:6--][span style=\"font-size:24pt;line-height:100%\"][!--/sizeo--]Any Idea how to get it right ?[!--sizec--][/span][!--/sizec--]
  21. Fahid

    MySQL problem

    Thanks Guru ( fenway ) !
  22. Fahid

    MySQL problem

    Hello All ! I have a problem with MySQL. I am not very familiar with MySQL, only use MySQL databases for my PHP scripts. recently I have installed Apache 2.54 PHP 4.4.0 MySQL 4.1.7-nt on my own PC( Windows XP-sp2 ) for faster development process. I configured MySQL's root with no password. I installed phpmyadmin with root user, and It's working OK. Later on I installed MySQL Administrator (mysql server administration software by MySQL). I created a clone of root user with name user and password 0000, through MySQL Administrator. By clone I mean All privileges of root are available to user. only difference is that root has no password, but user does. After restarting MySQL server I executed following script. <?php $link = mysql_connect('localhost', 'user', '0000') or die(mysql_error()); echo 'OK'; ?> and the result was as following: Client does not support authentication protocol requested by server; consider upgrading MySQL client What's wrong ? I am really in trouble. Someone please tell me how to sort it ? How to create new user ? How to set privileges for them ? Why I can't connect to MySQL server, when trying to connect with username, that has a password ?
  23. [div align=\"center\"]Sorry... can't find a better solution than appology, I posted this in MySQL forum instead of PHP forum.[/div]
  24. A pre-written PHP Application require me to enable mod_rewrite to be enabled in my Apache web server. I have Apache 2.0.54 installed on my PC. I checked the module directory in my Apache instalation directory, and I found a filemod_rewrite.so, and I thought I gave mod_rewrite in my Apache, just have to enable it. I opened httpd.conf and removed the # from the front of following line. [!--quoteo--][div class=\'quotetop\']QUOTE[/div][div class=\'quotemain\'][!--quotec--]LoadModule rewrite_module modules/mod_rewrite.so restarted my Apache, but it is still not working. some body tell me how to do it, how to enable mod_rewrite ?
×
×
  • 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.