Jump to content

narjis

Members
  • Posts

    107
  • Joined

  • Last visited

Everything posted by narjis

  1. narjis

    Help me

    Here is simple program which should return atrimmed string by using trim.I can't find why is it not working. $tr="Hira Mallick"; var_dump($tr); $new= trim($tr," lic"); var_dump ($new); Also this program is not runnig correctly $hello = "Hello World"; $trimmed = trim($hello, "HdWr"); echo($trimmed);
  2. how can I read a url coming from another site by header('Location:') command
  3. I want to show one select box in which selecting any option would show another select box of sub fields here's the code. <html> <head> <title>Drop down list usage in AJAX</title> <script type="text/javascript"> function show_second(choice){ var xmlhttp; if(window.XMLHttpRequest){ //for firefox xmlhttp = new XMLHttpRequest(); } else{ xmlhttp = new ActiveXObject("Microsoft.XMLHTTP"); } xmlhttp.onreadystatechange = function(){ if(xmlhttp.readyState == 4 && xmlhttp.status == 200) { document.getElementById("first").innerHtml = xmlhttp.responseText; } } xmlhttp.open("GET","getSecond.php?q="+choice,true); xmlhttp.send(); } </script> </head> <body> <form> <select name ="first" onchange=show_second(this.value)> <option value="karachi">Karachi</option> <option value="lahore">Lahore</option> <option value="islamabad">Islamabad</option> </select> <p id="second"> </p> </form> </body> </html> php code is as follows <?php $arrKarachi = array("Nazimabad","Gulshan","F.BArea"); $arrIslamabad = array("Defence","kinhgt"); $arrLahore = array("Abc","Def","Ghi"); $val = $_GET["q"]; echo "$val"; switch($val){ case 'karachi': { echo "<select name = 'second'>"; $cnt = count($arrKarachi); for($i=0;$i<$cnt;$i++){ echo "<option value='".$arrKarachi[$i]."'>".$arrKarachi[$i]."</option>"; } echo "</select>"; break; } case 'lahore' : { echo "<select name='second'>"; $cnt = count($arrLahore); for($i=0;$i<$cnt;$i++){ echo "<option value='".$arrLahore[$i]."'>".$arrLahore[$i]."</option>"; } echo "</select>"; break; } case 'islamabad': { echo "<select name='second'>"; $cnt = count($arrIslamabad); for($i=0;$i<$cnt;$i++){ echo "<option value='".$arrIslamabad[$i]."'>".$arrIslamabad[$i]."</option>"; } echo "</select>"; break; } } //case ?>
  4. In the given code below I am getting this error Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in C:\xampp\htdocs\samples\getcustomers.php on line 20 WHY? <?php $value = $_GET["q"]; $con = mysql_connect('localhost', 'root', ''); //db_connect(); if (!$con) { die('Could not connect: ' . mysql_error()); } $db_selected = mysql_select_db("ajaxDb",$con); $sql = "SELECT * FROM 'cutomers' WHERE Name = '".$value."'"; // echo $sql; $result = mysql_query($sql); echo "<table border='1'> <tr> <th>Name</th> <th>Address</th> <th>Country</th> </tr>"; while($row = mysql_fetch_array($result)) { echo "<tr>"; echo "<td>" . $row['Name'] . "</td>"; echo "<td>" . $row['Address'] . "</td>"; echo "<td>" . $row['Country'] . "</td>"; echo "</tr>"; } echo "</table>"; mysql_close($con); ?>
  5. Problem resolved. It's working now.
  6. I'm working on localhost where can I find firebug. Thanks for helping.
  7. I've copied this exmaple form w3school website as it is but my browser does not display tghe correct result. Here's the code <html> <head> <script type="text/javascript"> function showHint(str) { var xmlhttp; if (str.length==0) { document.getElementById("txtHint").innerHTML=""; return; } if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari xmlhttp=new XMLHttpRequest(); } else {// code for IE6, IE5 xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); } xmlhttp.onreadystatechange=function() { if (xmlhttp.readyState==4 && xmlhttp.status==200) { document.getElementById("txtHint").innerHTML=xmlhttp.responseText; } } xmlhttp.open("GET","gethint.asp?q="+str,true); xmlhttp.send(); } </script> </head> <body> <h3>Start typing a name in the input field below:</h3> <form action=""> First name: <input type="text" id="txt1" onkeyup="showHint(this.value)" /> </form> <p>Suggestions: <span id="txtHint"></span></p> </body> </html> Php code is as follows <?php $a[]="Anna"; $a[]="Brittany"; $a[]="Cinderella"; $a[]="Diana"; $a[]="Eva"; $a[]="Fiona"; $a[]="Gunda"; $a[]="Hege"; $a[]="Inga"; $a[]="Johanna"; $a[]="Kitty"; $a[]="Linda"; $a[]="Nina"; $a[]="Ophelia"; $a[]="Petunia"; $a[]="Amanda"; $a[]="Raquel"; $a[]="Cindy"; $a[]="Doris"; $a[]="Eve"; $a[]="Evita"; $a[]="Sunniva"; $a[]="Tove"; $a[]="Unni"; $a[]="Violet"; $a[]="Liza"; $a[]="Elizabeth"; $a[]="Ellen"; $a[]="Wenche"; $a[]="Vicky"; //get the q parameter from URL $q=$_GET["q"]; //lookup all hints from array if length of q>0 if (strlen($q) > 0) { $hint=""; for($i=0; $i<count($a); $i++) { if (strtolower($q)==strtolower(substr($a[$i],0,strlen($q)))) { if ($hint=="") { $hint=$a[$i]; } else { $hint=$hint." , ".$a[$i]; } } } } // Set output to "no suggestion" if no hint were found // or to the correct values if ($hint == "") { $response="no suggestion"; } else { $response=$hint; } //output the response echo $response; ?>
  8. I am having probelm in saving Session variables ALthough I'm writing session_start(); in the header of my php script and saving the values of Session array in the next page. It does not print the values or show right results. session_start(); require_once ("functions.php"); $token=$_GET['t']; if(!isset($token)){ $name = stripslashes($_POST['username']); $email = stripslashes($_POST['email']); check_validate_input($name, $email); } if($token=='register') { show_registration_form(); } $my_model = new model(); $arr_info = $my_model->check_members($name,$email); if (($arr_info==NULL)&&($token!='register')) { echo '<p> Hello Guest</p><br />'; show_mailing_form(); } else if (($arr_info['role']=='user')||($arr_info['role'] == 'admin')) { $_SESSION['userId']=$arr_info['id']; $_SESSION['user_role']=$arr_info['role']; $_SESSION['user_name']=$arr_info['name']; print_r ($_SESSION);} here it does not print session array.
  9. I am passing astriung value 'user' in one of the as the following code. ($stmt->bindParam(':username', $user_info['username'], PDO::PARAM_STR) && $stmt->bindParam(':userpass', $user_info['password'], PDO::PARAM_STR) && $stmt->bindParam(':email', $user_info['email'], PDO::PARAM_STR) && $stmt->bindParam(':role', 'user', PDO::PARAM_STR) && $stmt->bindParam(':location', $user_info['location'], PDO::PARAM_STR) && $stmt->bindParam(':interests', $user_info['interests'], PDO::PARAM_STR) && $stmt->bindParam(':homepage', $user_info['homepage'], PDO::PARAM_STR)) it is giving this error: Cannot pass parameter 2 by reference in C:\xampp\htdocs\EduProject\model.php on line 110
  10. I am passing an array in the following function and want my data to be added in the table .Here is the statement public function insert_data($user_info) { try{ $dbh = new PDO("mysql:host=localhost;dbname=phpfaqproject",'root',''); //echo "connected"; } catch(PDOException $e){ echo $e-> getMessage(); } $sql ="INSERT INTO account (username, userpassword, email, role, location, interest, homepage) VALUES ('" .$user_info['username']."','".$user_info['password'] ."','".$user_info['email']."', 'user','".$user_info['location']."','".$user_info['interests'] ."','".$user_info['homepage']."')"; echo $query."<br />"; $stmt = $dbh->prepare($query); $stmt->execute(); } I don't know why it is not updating the tble although echo $query gives correct results.
  11. narjis

    Text Area format

    How can we add text formatting tools in our website in order to post some text from it . Just like in the forum of PHP Freaks. B for bold, I for italics and so on... Hope someone understands what I am trying to say. Where should I post this question.
  12. I am calling an object from another class in the constructor of first class but when I call it in another function it does not access it's object. Here is the code. <?php /* This is controller.php used to control the flow of data between view.php and model.php. This file cotains all the controlling mechanism of the data It was created on 11th Feb 2011 By Narjis Fatima for an Open Source Project and contains all the includes to the database etc. */ include ("view.php"); include ("functions.php"); $name = stripslashes($_GET['username']); $email = stripslashes($_GET['email']); //echo "in controller.php"; check_validate_input($name, $email); $newUser = new controller($name, $email); $action=$_GET['t']; $newUser->display_view($action); class controller { public $my_model; //is an object of model class public $user_info;//=array('id' , 'username' ,'role','email','interests','location', 'homepage'); function __construct($name,$email) { $my_model = new model(); $user_info = $my_model->check_members($name,$email); echo "<pre>"; print_r ($user_info); } function __destruct() { } function display_view($token) { echo "In display function"; echo "<pre>"; print_r ($user_info); if ($this->user_info == NULL) { if (($token=="register")) { show_registration_form(); } else{ show_mailing_form(); } } if ($this->user_info['role'] == "admin") { $myView = new view(); $myView->view_admin_menu(); } if ($this->user_info['role'] == "user") { $myView = new view(); $myView->view_user_menu() ; } }//close of function display_view() } /* name and email cominfg from index.php would be checked by the controoler class to be checked if it a vaild name and email. The database would be connected n the model.php*/ ?> The code for model.php is as follows <?php //This is model.php created on 10th Feb 2011 .It deals with daytabase connection // //By NArjis Fatima //For the project of EDUForge an Open Source Software //include ("register.php"); class model{ public $dbh; public $user_arr=array('username','password','email','location','interest','homepage'); //cunstructor of model class //function to connect to database function __construct(){ try{ $this->dbh = new PDO("mysql:host=localhost;dbname=phpfaqproject",'root',''); //echo "connected"; } catch(PDOException $e){ echo $e-> getMessage(); } } public function check_members($username,$email) { //get_connected(); $sql = "SELECT * FROM account WHERE (username='" .$username ."' AND email='" .$email."')"; $sth = $this->dbh->prepare($sql); $sth->execute(); $result = $sth->fetch(); /* echo('<pre>'); print_r($result);*/ return ($result); } public function insert_data($user_info) { //$user_info = $user_in; //$dbh; try{ $dbh = new PDO("mysql:host=localhost;dbname=phpfaqproject",'root',''); //echo "connected"; } catch(PDOException $e){ echo $e-> getMessage(); } $dbh->exec("INSERT INTO account (username, userpassword, email, role, location, interest, homepage) VALUES ('" .$user_info['username']."','".$user_info['password'] ."','".$user_info['email']."', 'user','".$user_info['location']."','".$user_info['interests'] ."','".$user_info['homepage']."')"); } } ?> Please somebody help me. I am really stuck. I am also sending my attachment. [attachment deleted by admin]
  13. I am making a project by designing my own MVC model. In this the user accesses controller class which further calls model class which accesses the database by $dbh attiribute defined public. My View is a script which calls different pages. In the constructor of model I'm establishing connection with the database. Firstly I construct the model object when the user accesses i.e. in the controller class to check in the databse then if the username is not present in the dtaabse I want to insert his info in the database for that I again calla model class but this time I again have to establish connection. Is the $dbh firstly constructed is lost like dangling pointers in C++. Do I have to worry about it. If yes how can I solve this problem.
  14. I want to save class property values and want to write these in the database after being called from another function. class model{ public $dbh; public $user_arr=array('username','password','email','location','interest','homepage'); public function insert_data() { $sql = "INSERT INTO account VALUES ('" .$user_info['username']."','".$user_info['password'] ."','".$user_info['email']."', 'user','".$user_info['location']."','".$user_info['interests'] ."','".$user_info['homepage']."')"; //if(isset($data)) echo $sql; } public function data_approoved($user){ //$user_info = new array(); $user_arr['username'] = $user['username']; $user_arr['password'] = $user['password']; $user_arr['email'] = $user['email']; $user_arr['location'] = $user['location']; $user_info['interests'] = $user['interests']; $user_info['homepage'] = $user['homepage']; Model::insert_data(); } } }//class ended The approoved_data function is supposed to set the values of $user_info array which should be later on stored in database. Please somebody help me.
  15. Here's my code of function sending email. In the $urtext I am sendinding a hyperlink and want the $token to return in another function in register.php. Can I call a function from register.php? How? function send_mail($name,$email,$location,$interests) { $token = rand(); $urtext = "Please click on the following link for your registration to be complete <a href=http://localhost/PHPFAQProject/register.php?t=$token>Click Here </a>"; if ((!isset($name))||(!isset($email))) { //checking for blank input echo "<b> Please check you have not enetered the name or the email address</b>"; } $user = '[a-zA-Z0-9_\-\.\+\^!#\$%&*+\/\=\?\`\|\{\}~\']+'; $domain = '(??:[a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9\-]*[a-zA-Z0-9])\.?)+'; $ipv4 = '[0-9]{1,3}(\.[0-9]{1,3}){3}'; $ipv6 = '[0-9a-fA-F]{1,4}(\:[0-9a-fA-F]{1,4}){7}'; //checking for e-mauil validity if (preg_match("/^$user@($domain|(\[($ipv4|$ipv6)\]))$/", $email)) { mail('narjisfatima@yahoo.com','feed back',$urtext); echo " <html> <head><title>Email example</title> </head> <body> <p>Your text has ben sent. Check your mail</p> </body> </html>";} else{ echo "$name<br>"; echo "$email" ; echo "Please input valid email" ;} }
  16. How can I insert a url in the body of an mail such that when the user clicks on it return the url string
  17. I am calling my class constructor with the following code class controller{ function _construct($name,$pass){ session_start(); get_model_class($name, $pass); echo "I\'m in controller"; } } function get_model_class($username, $password){ $my_model = new model(); $my_model->check_users($username,$password); } $username = $_POST['username']; $password = $_POST['password']; echo "in controller.php"; $newUser = new controller($username,$password); but it is not entering the constructor
  18. for a project I'm developing I want to design my own MVC model for that can I call model class from inside a constructor of controller class.
  19. thanx alot man so clumsy of me. Bless ya
  20. I am accessing my datbase bookorama with the follwoiung code @ $db= new mysqli('localhost','bookorama', 'bookorama123','bookorama'); $query = "select * from books where ". $searchtype." like '%".$searchterm."%'"; $results =$db->query($query); $num_results = $result->num_rows; the last line is being echoed but it does not give the number of rows in it. Please help me. I'm stuck
  21. I am using mysqli to open the database table and execute query. The qery is running successfully, but the number of rows count is not giving correct results. $username=$_POST['username']; $pass=$_POST['password']; $mysql = mysqli_connect("localhost","root","","auth"); $sql="SELECT * FROM 'authorized_users' WHERE name = '".$username ."' AND password = '" . $pass. "'"; // print "$username $password"; if(!$mysql){echo "cannot connect to databse" ; } else { echo "Connected"; $result = $mysql->query($sql); $row = $result->num_rows; echo "Found \$rows ". $row; for($i=0;$i<$row;$i++){ echo "found a record at ".$i; } $result->close(); } $mysql->close(); This should return 3 rows but it gives 1 only.
  22. Thanks it was a great help. I've seperated my header in header.php. In the div tags if <div class="header">blahbhjka </div> is defined and header is css class here i'm putting <?php echo "<div class='".header."'">blahblah balkj</div>"; It gives an error unexpected T_STRING, expecting ',' or ';' where am I doing wrong
  23. I have an index.html with tables and div tags, headers defined in css too. How can I convert them to header.php and footer.php.If there is any guiding book for converting Html to PHP please guide me to it. Thanks
×
×
  • 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.