812 Posted Topics
Re: The javascript function ConfirmChoice() should should be somehow told the ID of the user to delete. It could be read from the chosen option of the select element. So the select element should be assigned an ID (for accessing with javascript) and the options have to have values: <tr><td><select name="id" … | |
Re: The connect function lacks the connection functionality and lacks a returns statement. You should add a connect function `mysql_connect` which returns a valid link (or an error): private function connect() { $this->link = mysql_connect($this->server, $this->username, $this->password); $result= mysql_select_db($this->db, $this->link) or die('sql error'); return mysql_connect() or die('Could not connect: ' . … | |
Re: Set up a web server, a database, maybe a PHP framework or libraries. Pick a good editor (a lot of people prefer Eclipse). Write a hello world or a phpinfo program and test if everything works together. Now you are ready to start thinking what would be a useful app … | |
Re: Welcome on DW from me too. There is a nice article [here](http://www.daniweb.com/web-development/php/threads/435023/read-this-before-posting-a-question) about how to participate on the forum (this or any other) to get the most out of it. We will be more than glad to help once we get a proper question. | |
Re: This is not strictly a PHP question, maybe it would be better to seek help in [HTML](http://www.daniweb.com/web-development/web-design-html-and-css/threads/444421/custom-mobile-site) forum on DW. But anyway, html code seem to be OK. Check whether the paths in the href attribute are correct. What exactly does happen when you click on particular link? | |
Re: When you use values from forms in your query best practices are: - check for existence of values - validate entered values for correct type/value - escape the values to prevent entering bad characters (like `'`) // check if there is a value in the request if(isset($_REQUEST['tid']) && !empty($_REQUEST['tid'])) { … | |
Re: I am not familiar with Codeigniter but it seems that in the last foreach loop you are overwriting the same element (`$finalarray["row"]`) over and over again: $finalarray["row"]=implode("|",$item); I do not know what the end result should be. If it should be string then you should use concatenation. If on the … | |
Re: Your approach is completely OK, I think most of people do it this way. You start a html table, display a header row and then loop through the resultset from a mysql query and display each row, adding a delete and edit links. The only thing that could be done … | |
Re: Once you query the database you can retrieve a row in either: - an array (associative: using mysql_fetch_assoc or enumerated using mysql_fetch_row or both using mysql_fetch_array) where keys are field names (or filed index) and values are the values you queried: $myArray['username'] = 'broj1'; $myArray['password'] = 'IamNotTellingIt'; or - an … | |
Re: mysqli_fetch_assoc function returns only one row. You use a while loop to go through all the rows (10 in your case) but the way you implemented your function this is not happening. If you want to use this function to return all results, you have to read all the rows … | |
Re: If you want to use this function outside the object make it public. public function getAktiva(){ return $this->aktivaLancar+$this->aktivaTetap; } This is usually the purpose of the get functions (getters): to get the data stored in protected or private variables. | |
Re: One possibility for the cause of the error could be on the return line of the login function (which obviously returns false): return(mysql_result($query, 0) === 1) ? $user_id : false; `mysql_result()` function returns string so you should compare it to `1` (an integer) with `==` operator. If you want to … | |
Re: Please post the insert_validation.php script also since the values should be accessible there (assuming that the queries return expected values). | |
Re: To add a new fibonacci number on each refresh you should store each previous and current value in a session. session_start(); // on the beginning you have 0 and 1 if(!isset($_SESSION['previous']) || !isset($_SESSION['current'])) { $_SESSION['previous'] = 0; $_SESSION['current'] = 1; echo $_SESSION['previous']; echo ' '; echo $_SESSION['current']; } else { … | |
Re: The code on lines 16 to 20 is a bit suspicious: if (!isset($_GET['Page'])) { //Instruction if $_POST['value']doesnt exist $_GET['Page']="%"; } `$_GET['Page']` is supposed to be an integer, isn't it? In some circumstances the `$Page` variable could be assigned a value of `%` and the query would fail since `$Page_Start` and … | |
Re: Try it this way (escaping double quotes for javascript arguments): <?php echo" <button type='submit' onmousedown='func(\"$item_id_g\");'>test</button> "; ?> or this way (escaping double quotes for html attributes): <?php echo" <button type=\"submit\" onmousedown=\"func('$item_id_g');\">test</button> "; ?> | |
Re: You have some errors in your code: - missing $ character at variable names for $i, $qid - if qid is not a variable but rather an associative index it should be always enclosed within quotes - the name of the $_SESSION array is misspelled (it is not $_SEESION) The … | |
Re: Do not despair, I am here to help you out :-) I hope you have corrected the code according to the post by pzuurveen above. Now, what are the action and method attributes of your form? Depending on that you will either check for existence of $_GET / $_POST array … | |
Re: LastMitch, how come you dug up all these 7 years old threads all of a sudden :-) It is actually nice that someone cares to offer help to all the forgotten questions but I think this old stuff should be somehow marked as dead by admins. | |
Re: If you use mysql, see http://php.net/manual/en/mysqli.construct.php. You might want to think about using a conectivity layer that enables you to change backend. The example is MDB2 fro PEAR framework. See http://pear.php.net/package/MDB2/ | |
Re: > it does print eg 2012-12-09 03:34:25. but i cant seem to store in database What is the format of the field you want to store the value into? > You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the … | |
Re: The double quotes are causing trouble since everything betwen the opening and the closing double quote is a string (array elements do not get parsed correctly and also no concatenation takes place). You can do it the way gavinflud suggested. On the other hand if you wish to use double … | |
Re: > I don't even know what PHP is If you are not kidding :-): PHP is a server side scripting language that does a bit of processing before spitting out a html page (with a .php extension). This is how scripting enabled web server can add some logic to the … ![]() | |
Re: Form values get into the $_GET array after submitting the form. So you first check for the value if it exists: if(isset($_GET['test']) { $y=$_GET['test']; } or you might want to check whether the form has been submitted: if(isset($_GET['submit']) && isset($_GET['test']) { $y=$_GET['test']; } | |
Re: The textarea that is used for commenting should have a name attribute that has image ID in it (say image ID is 6, textarea name is comm-6). Then when you check for submition get the ID from the textarea name, something like: if(isset($_POST['submit'])) { // loopthrough $_POSTarray and search for … | |
Re: Or you can do it in one query (provided that $_POST['checkbox'] contains IDs to delete): // if delete was clicked and some checkboxes were checked if( isset($_POST['delete']) && isset($_POST['checkbox']) && !empty($_POST['checkbox']) ){ // string of IDs to be deleted (separated by ,) $id_list = implode(',', $_POST['checkbox']); $sql = "DELETE FROM … | |
Re: foreach ($data1 as $in1 => $h1) { // temporary array for inner loop, needed for sorting $count_arr_temp = array(); foreach ($data2 as $in2 => $h2) { $match = array_unique(array_intersect($h1, $h2)); // put count data in a temporary array $count_arr_temp[] = count($match); } // sort temporary array rsort($count_arr_temp); // didplay sorted … | |
Re: Other way of checking it is placing this code on line 34: die("UPDATE staff SET enabled='$status',name='$name', password='$password', email='$email' , department='$department' WHERE id='$id'"); which will echo your query and halt the sript. Now you can examine the query and/or test it in phpmyadmin. | |
Re: Your code seems to be allright. There are two things that come to my mind. First one is to check whether the first block of the `if` executes at all since maybe you are doing too little of checking of the $_POST values - namely you are not checking for … | |
Re: Variable names can not contain spaces. $fmcg application=mysql_real_escape_string($_POST['fmcg application']); Replace spaces with underscores ($fmcg application -> $fmcg_application) | |
Re: Change the function this way: function display(){ return $this->teamName; } You need to refer to the object->property; `this` refers to the current object. | |
Re: Are you sure that you will get better user experience this way? If you let users delete each post without asking them for confirmation first thea are at risk deleting too many posts to quickly. If you ask them for consfirmation at each post they wish to delete you will … | |
Re: There are many tutorials out there but they might vary in completeness since they often omit some parts to emphasizes others. But your question is spot on. If I got it right you are asking about what to do with the posted values to use them securely. The trim is … | |
Re: The thing is that you have name attributes for your hidden fields the same for every row so the $_POST array contains only teh last row (last assigned name attributes). You should give the name attributes in each row a unique identifier that is linked to the row in a … ![]() | |
Re: Do you have a primary key or unique field in the table and what type it is? This is cruical for some control of which record to access. | |
Re: This is a bit strange. You populate the select element with numbers from vehicle_info table and then store the chosen number into the same table. You should have a source for the select element somewhere else (maybe some other table) otherwise you keep running in circles. Or have I missunderstood … | |
Re: use mysql_real_escape_string() function to escape characters in all input fields. Not just to enable people to enter quotes but also to prevent evil people to enter harmfull code. $title = mysql_real_escape_string($_POST['title']); $content = mysql_real_escape_string($_POST['content']); $creator = mysql_real_escape_string($_POST['creator']); Mind you the connection to mysql has to be established in order to … | |
Re: It is a lot of code to have a look at and a lot of includes which makes it very difficult to test. Also the structure of tables is not shown. And even if it were it is quite a project for someone to help here. In principle I would … | |
Re: In a nutshell: // connect to a database (mysql in this example, using mysqli extension) $link = mysqli_connect('localhost', 'my_user', 'my_password', 'my_db'); // check connection if (mysqli_connect_errno()) { die("Connect failed: " . mysqli_connect_error()); } // a query for selecting age $query = 'SELECT Age FROM tablename WHERE condition=something'; // run the … | |
Re: Assuming that id is an integer and autoincremented by the DB then the id fields probably increase with every new question and you can use this approach: Whenever you read and display the question save the id in the session. If there is no id in the session you are … | |
Re: You have probably sent some HTML output before session_start() line in your code. Make sure that the session_start() function is on the very beginning of the script. Also make sure there is no space that you are unaware of in the beginning before the <?php ?> block. If there are … | |
Re: First check in your generated html code whether checkboxes have intended names (chkDel[] and values (the ID of the customer). You can do that by looking at the source in your browser (right button and `View Page Source` in Firefox). Then check whether the $_POST contains appropriate values in code … | |
Re: Give each textbox a name that has and ID of the record in it (hopefully you have a primary key in the table, you can use it for this purpose). If you have any code yet I can show you what I mean. Or if I put it in a … | |
Re: if(isset($_POST['formImage']) && !empty($_POST['formImage'])) { // do what you like with it } | |
Re: Use [is_numeric](http://php.net/manual/en/function.is-numeric.php) function. if(is_numeric($string)) { $float = (float) $string; } | |
Re: My opinion: making your own database class might be worth only if you are doing it in order to learn about database handling and OOP. If you need a good and verstaile db class there are many arround which have been developed by dedicated people/teams and through considerable amount of … | |
Re: How do you track if user is logged in? It would help if you posted some code. Usually users are tracked in session array so if you use this method, check the values there. something like: // start the session (on the very top of the script) session_start(); // if … | |
Re: What has the action attribute of your form been set to? If form posts to the same page (#) then set the action to the page name without the querystring, something like: $action = parse_url(__FILE__, PHP_URL_PATH); echo "<form action='$action'>"; ... | |
Re: A quick debugging technique is to check the contents of variables at various stages using a combination of echo, die() and print_r() functions: $sql = mysql_query("SELECT * FROM teachersubject WHERE teacherID ='$id'"); while($test = mysql_fetch_array($sql)) { // inspect the contents of returned row echo(print_r($test, 1)) . '<br />'; $subjectid=$test['subjectID']; // … | |
Re: I would do it simple way without regular expressions which are not very efficient: $allowed = array('Indiana', 'Ohio'); if(!in_array(allowed)) { $errors .= "You have entered the wrong state."; } |
The End.