812 Posted Topics
Re: Your function is not returning the number of comments but the resource (a special PHP type) for the query. And also the query has to be changed to: $sql = "SELECT COUNT(*) FROM `comments` WHERE `post_id`= {$pid}"; The function should be something like: function gather_comments ($pid){ $pid = (int)$pid; $sql … | |
Re: Line 22: mysqli_fetch_assoc($ChangeDownloadSQL){ You should terminate it with ; | |
Re: It would help if you posted the code you already have and table structures so we can build from there. Basicaly what you do is: 1. read the database to get the list of countries 2. build the first drop down (html select element ) with options containing countries 3. … ![]() | |
Re: The form data is being sent to the database only when you execute a query. So after collecting the data first check the dates and only if within the range, connect to the database and execute the query. if($sDate < $enDate && $sDate > $exDate) { // connect to the … | |
Re: There seem to be no syntax errors but this does not guarantee your code works. So make sure you have your php.ini set to display errors and post the errors that you get. Other tips: * Use meaningful names for variables; `$x`, `$y` etc do not tell much but are … | |
Re: $_COOKIE is associative array. If you want to turn it to numerically indexed you can use [array_values()](http://php.net/manual/en/function.array-values.php) function. But you are loosing valuable information. You can list values this way: foreach($_COOKIE as $value) { echo $value; } ![]() | |
Re: The `<textarea>` tag should be be ended with `</textarea>` end tag. Anything between these two tags gets displayed, but as a plain text. I believe the html code (the table in your case) will be displayed just as plain text and not formatted as a table. | |
Re: Have you taken into account the fact that the same visitor will have different session ID on each visit (on each session)? | |
Re: I don't see any submit button. How do you submit the form? You can change the hidden input into submit button. Change this code: <input type="hidden" name="submitted" value="true" /> into this code: <input type="submit" name="submitted" value="Submit" /> ![]() | |
Re: If you need to know only whether email exists or not, use COUNT(*) in your query and use fetchColumn() to get the number of rows found: foreach($email as $em) { $sql = "SELECT COUNT(*) from sf_guard_user sf,personal pi where pi.user_id = sf.id and sf.email_address = '$em' "; $query = $db->prepare($sql); … | |
Re: You can do multiple insertion with one query: if (isset($_POST['submit'])){ // start the query $query = 'INSERT INTO links VALUES '; // get number of elements in the array containing links $linksCount = count($_POST['alink']); // step through the array containing links for($i = 0; $i < $linksCount; $i++) { // … | |
Re: I am not sure whether I got exactly what you want but I can suggest you use a function that will return the ID formed as a string. Something like: function getCustomID($id) { // check if ID is within the limits (you can go from a01 to z99 only) if($id … | |
Re: Your responsibility is to format the data read from the database, using PHP and HTML, into something that looks useful and appealing to the user. You can use tables, lists and other HTML elements and CSS. Regarding CSS you can use [media rules](http://www.w3schools.com/css/css_mediatypes.asp): @screen for onscreen display in the browser … | |
Re: Use a rich text editor. I use [TinyMCE](http://www.tinymce.com/) and it is one of the best in my opinion. But you have to be aware that there is some learning curve. | |
Re: You first have to insert new user data into tbl_user table, somehow creating fields (id could be autoincrement). Then use this user ID and add it to the query for the tbl_userprofile table. | |
Re: On line 12 you assign a filename to $filename variable: $filename = stripslashes($_FILES['file']['name']); which is good. But then you do not use that variable on line 62: $filename = "../../../../../../../../bloggbilder/". $_FILES['file']['name']; which is strange since it defeats the purpose of the code on line 12. I think you should create … | |
Re: What do you mean by offline? Are database and webserver accessible when you are offline (localhost) or are they somewhere else (accessible through internet)? Do you have php.ini set up to display errors? Do you have a ob_end_flush() command at the end? | |
Re: As AHarrisGsy says you did not assign values from $_POST to variables you use in your query. So check for the existence of each of $_POST element, escape the values and assign them to variables. If any of the $_POST elements is missing then display an error message. if(isset($_POST['warranty']) && … | |
Re: To add a row at the end of the HTML table you can use Javascript and insertRow() and insertCell() methods. Create a function that will insert a row and four cells in that new row. Then make a link with an onclick event that will trigger inserting of the row. … | |
Re: On line 22 you are missing a semicolon on the end of the statement. In the query all the field names should be enclosed in backticks and not in single quotes (a mysql syntax requirement). | |
Re: You are missing a semicolon at the end of line 5, hence the T_IF error (if statement is not expected there if no semicolon): session_start() Same on line 17: mysql_error($handle) | |
Re: In PHP code use session_start() on the beginning to use a session. <?php session_start(); if($_POST) { $_SESSION['array']=array(); array_push($_SESSION['array'],($_POST)); print_r($_SESSION['array']); } ?> | |
Re: I tested your code on my server and it works OK. Clicking on Back button always brings me to index.php. Make sure you have no html before the code you posted (not even a space). If you have any html before a header() function, the function will not work. | |
Re: `mysql_num_rows()` function returns a number of found rows (an integer), not an array of rows. You should use a `mysql_fetch_assoc()` in a while loop function instead. Something like: while(mysql_fetch_assoc($rs_k8goodsin)) { echo '<tr>'; echo '<td class="labelcell">' . $count . '</td>'; echo '<td>' . $reck8goodsin['goodsDesc'] . '</td>'; echo '<td>' . $reck8goodsin['k8goodsQty'] . … | |
Re: The solution for your requirement seems to be OK. But in some circumstances the result in line 5 returns FALSE which indicates an error when querying. You should change the code in line 5 to: $result=mysql_query($statement) or die(mysql_error()); This way if there is an error when querying the error will … | |
Re: Also the ultimate checklist for web app security is [[OWASP's to 10]](https://www.owasp.org/index.php/OWASP_Top_Ten_Cheat_Sheet). It is comprehensive but it is worth taking some time to get to grips with it. | |
Re: <?php $name=?> This piece of code will generate an error since it is not complete. To pas a JS function value to PHP the JS function should return the value first. Then the value could either be 1. set into a form element (maybe a hidden input) and the form … | |
Re: public function getLastInsertId() { // you can do checks first (has the query been successful etc) return $this->mysqli->insert_id; } It would be good idea to initialize the properties: protected $mysqli = null; protected $result = null; I would also use more descriptive names. The connection class is not only doing … | |
| |
Re: Variables $title and $entry haven't been defined anywhere in the script. Did you forget to add these two lines: $title = $_POST['title']; $entry = $_POST['entry']; | |
Re: The problem is probably in this line: $start =mysql_real_escape_string($_POST['start']); $_POST['start'] is set if user selects one of the radio buttons (booking time). If user does not select any button you have to display an error message, but you have to test for it first: if(isset($_POST['start'])) { $start =mysql_real_escape_string($_POST['start']); } else … | |
Re: As NardCake said put session_start() function on top of the script so you can use a session. Then do not use session_register() function since it has been [deprecated](http://php.net/manual/en/function.session-register.php) and removed after PHP 5.4. Just assign the values to the $_SESSION array (see NardCake's post). Then before using $_POST array values … | |
Re: I would presume that the query: $query_recTenantuser = "SELECT * FROM md_storage WHERE tenantID='".$tenantID."'"; will return just one row ($tenantID is probably unique), so in the select element (drop down) you will have only one option. That does not make senese. Correct me if I am wrong. | |
Re: You could add this code somewhere at the end of the snippet above: die('<pre>' . print_r($send_params, 1) . '</pre>'); This will display array of the final version of all parameters needed for sending. Now you can go through each element and check it. Carefuly look at the `$send_params['headers']` if it … | |
Re: What is the error message? Does `$_SESSION['clubsId'][0]` have any value? Have you tried to display the query and test it in phpmyadmin: die("SELECT * FROM cards2 WHERE cardid NOT LIKE '{$_SESSION['clubsId'][0]}'"); It is usually a good practice to test for variable values before using them in queries: if(isset($_SESSION['clubsId'][0])) { mysql_query("SELECT … | |
![]() | Re: Quote the field names with backtick (assumming that you use mysql): $qry = "insert into users (`name`, `surname`, `email`, `password`, `date`) values ('$name', '$surname', '$email', '$password', '$date')"; This is how you make sure column names do not clash with any keywords. Not sure if this is the right solution for … |
Re: You pass the selected values to modellist.php by ajax for some processing, using `$_POST` array, if I got the code correctly. So the modellist.php script would be good candidate to save values to the session. IN modellist.php just assign the values to the `$_SESSION` array using their names for associative … | |
Re: You can also insert multiple sets of values in one query: INSERT INTO table_name (column1, column2, column3) VALUES (value1, value2, value3), (value4, value5, value6), (value7, value8, value9) | |
Re: Also [phpacademy](https://phpacademy.org/) if you prefer watching videos. ![]() | |
Re: Is it only that you do not want to to have a submit button or do you not want to reload the page? In first case you can use onchange event of the select (dropdown). echo '<select name="room" id ="rooms" onChange="this.submit()">'; The form wil get submitted once you select an … | |
Re: And info on cookies and session from PHP's point of view: http://php.net/manual/en/features.cookies.php http://www.php.net/manual/en/book.session.php | |
Re: You should have defined action attribute in the <form> tag which is the name of the script that will process the data. The script should go something like this: <?php // if submited the value will be in the $_POST['expenses'] element of the $_POST array // (provided that the method … | |
Re: Add a value attribute to each option tag: echo '<option value="' . $rows[1] . '">'.$rows[1].'</option>'; And make sure you enclose the select element in <form> </form> tags? | |
Re: You use mysqldump program to export database into a SQL file, something like: mysqldump -u USER -p DATABASE > FILENAME.sql then use mysql client to import SQL file into another database: mysql -u USER -p DATABASE < FILENAME.sql This was taken from [this link](http://www.ghacks.net/2009/12/29/how-to-import-and-export-a-database-in-mysql/). EDIT: I just noticed that you … | |
Re: I think the `$nomineeid => $voted, $p_vote` part in line 10 is not valid syntax. foreach (array_combine($cLists, $Votes, $Votes_p) as $nomineeid => $voted, $p_vote){ The [foreach](http://php.net/manual/en/control-structures.foreach.php) construct is defined as foreach (array_expression as $key => $value) so in your case PHP expects a `)` instead of a `,` after $voted. … | |
Re: WHere do you keep the list of URL's? If it is a file or an array then do a while or foreach or for loop reading the urls, getting the value and add values to the insert query: // your URLs (in an array in this example) $url_list = array( … | |
Re: My opinion: if you develop a complex site start using it soon since it will help you keep your code organized and under control. But it might take some time to learn it and it is probably not a good idea to learn on a real project. Well, I am … | |
Re: Check also your setting for the display_errors directive, as szabizs suggested. If it is set to false (prior to php 5.2.4) the errors won't get displayed. | |
Re: When user clicks on logout link it takes him to the logout script that has the code that Webville312 suggested in his post. The script does not do anything visual. It just destroys the session and redirects to the index page. We are assuming here that you keep the login … |
The End.