-
Posts
3,404 -
Joined
-
Last visited
-
Days Won
55
Everything posted by Ch0cu3r
-
Assigning wrong session variable to link.
Ch0cu3r replied to CloudBreaker's topic in PHP Coding Help
The line below is defining the link for each project, the project id is being passed in the query string. (Anything after the ? in a url is referred to as a query string, query strings are made up of key/value pairs, each key/value pairs are separated by an &. PHP will automatically populate the $_GET superglobal with the values in the query string) <td><a href="project.php?id=<?php echo $projNumber; ?>"> <?php echo $projName;?></a></td> So if our query returns two projects, lets say their project ids are 1 and 2 we'll have two links that look like this being produced <td><a href="project.php?id=1">Project 1</a></td> <td><a href="project.php?id=2">Project 2</a></td> When the user clicks Project 1 link then the product id value of 1 is passed to project.php, if the user clicks the second link then the product id of 2 will be passed. $_GET['id'] is used to retrieve the value of the id being passed in the query string. It displays the projects name by querying the projects table to return the row where the project id matches $_GET['id']. To do this I am using a prepared statement, which is the correct way for using user input within queries If you are new prepared statements I recommend you read http://php.net/manual/en/mysqli.quickstart.prepared-statements.php to understand whats going on. The reason a prepared statement is used is to protect against SQL Injection. -
Its perfectly fine to use a constant in your includes. The problem is you are including your files using urls. Including files using urls results in different behaviour, as I said it only returns the output of the script you are including, meaning if you are going to use variables, functions etc defined from your parent script in the script you are going to include they will not be available. For my projects I always use dirname(__FILE__) in my main file to get the root directory for my application, I usually define the constant like define('ROOT', dirname(__FILE__)); Then prepend ROOT constant to my file paths. This way no matter where my application is located on the server it will always find the files I am trying to include
-
When using urls to include files, PHP will only include output of the script, not the actual source code. You should use file system paths for including/requiring files.
-
If you select the Remember Me checkbox on login, then it should not be logging you out. The only time its done that to me is if I have cleared my cookie/history Which is? If you can send use proof of ownership (via PM) of that account we can reset the password for you. If you have not received the reset password email, then I guess our mail servers are down again.
-
This is not achieved with PHP. How elements appear/positioned on your webpage is down to your HTML/CSS. Your navigation links can be aligned to the right, by applying text-align: right; I presume to the .navigation selector in your stylesheet To have the image title appear to the side of the image, first swap the imge and post tile lines around, so its <h6 class="post-title"><?php the_title(); ?></h6> <?php echo wp_get_attachment_image( get_the_ID(), 'large' ); ?> Then add the following selector to your stylesheet h6.post-title { float: right; margin-top: 15px; }
-
The problem is caused because you have two many } for closing your constructor. This is results in the class definition closing prematurely and so this is why you are getting the error. public function __construct(){ // Set DSN $dsn = 'mysql:host=' . $this->host . ';dbname=' . $this->dbname; ... code omitted .. catch(PDOException $e){ $this->error = $e->getMessage(); } } } // <--- remove this line
-
Assigning wrong session variable to link.
Ch0cu3r replied to CloudBreaker's topic in PHP Coding Help
Sorry, left of the closing php tag after $projNumber, that line should be <td><a href="project.php?id=<?php echo $projNumber; ?>"> <?php echo $projName;?></a></td> -
Generate the qty field using a function. Example function genQtyList($name, $qtyMax = 10, $qtyMin = 1) { $html = "\n<select name=\"$name\">\n"; for($i = $qtyMin; $i <= $qtyMax; $i++) $html .= "\t<option>$i</option>\n"; $html .= "</select>\n"; return $html; } // by default generates options 1 to 10 echo 'Qty: ' . genQtyList('qty1'); echo '<br />'; // pass maximum qty as second argument, generates options 1 to 4 echo 'Items sold: ' . genQtyList('item_sold', 4); You pass the name of the field as the first argument. The second argument sets the maximum qty. Optionally set the minimum qty as the third argument
-
Assigning wrong session variable to link.
Ch0cu3r replied to CloudBreaker's topic in PHP Coding Help
You dont want to use session variable for that purpose. You need to pass the project id to the next page, as a url query string parameter. Example code <td><a href="project.php?id=<?php echo $projNumber"> <?php echo $projName;?></a></td> In the next page you grab the probject id from the url using $_GET['id']. To get retrieve the project from the database, you apply a where clause to your query, eg SELECT * FROM projects WHERE project_id = $id. Example code for project.php <?php // connect to db $conn = new mysqli( ... ); // retrieve the project id from url, and make sure its a numeric value if(isset($_GET['id']) && is_numeric($_GET['id')) { // prepare query, the project id is bound as a value $stmt = $conn->prepare("SELECT projectId, projectName, etc.. FROM projects WHERE project_id = ?"); // bind project id value to query $stmt->bind_param('i', intval($_GET['id'])); // check the stmt did execute if($stmt->execute()) { // fetch the result from the query $result = $stmt->get_result(); // fetch the row if($row = $result->fetch_assoc()) { // output the project details here echo "Project Name: " . $row['projectName']; } // no row was returned for the project id supplied, display error else { echo 'Project id ' . intval($_GET['id']) . ' does not exist'; } } // statement did not execute, trigger an errror else { trigger_error('MySQL error, unable to fetch project: ' . $conn->error); } } -
See reply #2, above
-
If you still do not get any errors after doing as fastcol suggested, then one thing that could prevent the code from working is the use of short open tags <? ?> throughout the code rather then the full php tag <?php ?> tags. You maybe able to enable a setting call short_open_tags in the php.ini, but this is deprecated never version of php will complain. I would recommend converting all short tags to the full php syntax.
-
That to me seems like your code is stuck in a loop or something is taking a long time to process. The code you posted is fine and will redirect the user, provided you are not outputting anything before the use of header If the only purpose of the continue shopping button is to redirect the user back to your store, then why not just use a link which links back to your stores homepage. If you want the link to appear as a button you can style it using css.
-
Hard to tell from that snippet of text you posted but it looks like that is part of a json encoded string? In which case you do not need to use regex. First decode the json buy using json_decode, then pass the urls to pathinfo and use the PATHINFO_FILENAME flag.
-
You need to output the table row within the while loop while($row=mysqli_fetch_assoc($run)) { $projName =$row['name']; $projNumber = $row["project_id"]; $i++; ?> <tr align="center"> <td><?php echo $projName;?></td> <td><?php echo $projNumber;?></td> </tr> <?php } // end while loop ?>
-
Sorry, had to pop out earlier. Would of replied sooner. You would need to loop over your day indexes (1 through to 7, which I guess means Monday through to Sunday?) and setting the open/closing times for each row. Example code $resturant_id = ...; // restaurant id value // converts the user entered times into 24 hour time, eg 9am gets converted to 09:00 $open_time = date('H', strtotime($_POST['open_time'])); $close_time = date('H', strtotime($_POST['close_time'])); // loop over dayindex, and set the open and close time $values = array(); for($dayInex = 1; $dayIndex <= 7; $dayIndex++) { // sets values for each day index $values = "($restaurant_id, $dayIndex, '$open_time', '$close_time')"; } // insert open/closing times foreach day index using one insert query $sql = 'INSERT INTO business_hours VALUES ' . implode(', ', $values); Problem is if there is a particular day that is closed, your form makes it hard for the code to know what day that is. Currently it will set the open/close time for every day. This is why your need to either change your form so either each day has its own open/close time value or change your to/from dropdown menu to be either check boxes or make it a multiple select menu. The code can then loop over the days the user has chosen and insert the open/close times for those days only.
-
You cannot use a url as the target. It must be a local file system path, eg /home/user/uploads/candidatescvs/ if you are still getting the error with a full file system path, then double check you have named the folder correctly. Files and folders are case sensitive
-
You are getting that error because the PHP code is not outputting the json object, this results in an empty value being passed to JSON.parse and so you are getting the unexpected end of data error. Are you sure $coords is defined and values are being set?
-
The error is saying it is unable to move the file to the candidatescvs folder. Are you sure a) this is folder exists and b) you have set sufficient file permissions to allow for PHP to write to this directory?
-
You don't want to store the openning hours as am/pm. You should store the times in 24 hour format (HH:MM:SS), eg 09:00:00 and 23:00:00 You can convert the hours to 9am and 11pm using PHP's date function or within the query using MySQL's date/time_format function when you get the hours from the database.
-
You need to pass the PHP json value to JSON.parse in your javascript code var coords = JSON.parse('<?php echo json_encode($coords, true) ?>'); // coords will no be a JSON object
-
In the code you posted you are calling session_start() after the opening <DOCTYPE html> tag. This is wrong, it needs to be called before that line. Anything that is outside of the php tags is classed as output. This is what scootstah meant by his post. You should rearrange your code in your scripts so all processing is done before you begin to output any HTML. Eg your code should be layout like Eg <?php session_start(); // process the login here ?> then you output your html here
-
Or why not contact the author of the script for support?
-
The next error you will probably get is your query $sql = "<<<sql SELECT * FROM `UserName` WHERE userName = '" . $_SERVER['PHP_AUTH_USER'] . "' AND pass ='" . $_SERVER['PHP_AUTH_PW'] . "' SQL;"; This is because you appear to have PHP herodoc syntax within the string that defines your query, this will produce an error. You should remove the herdoc demileters <<<sql and SQL; from your query. If you are going to use PHP heredoc for defining the query then it will be $sql = <<<SQL SELECT * FROM `UserName` WHERE userName = '{$_SERVER['PHP_AUTH_USER']}' AND pass ='{$_SERVER['PHP_AUTH_PW']}' SQL; // do not indent or adding thing else on the line above Next you should not be using user input (the users username/password) within your query without first sanitizing the username, see mysqli_real_escape_string or use prepared statements. Also password should not be stored as plain text in the database you should being storing the hash of the password, I recommend you use PHP password_hash function or use the backwards compatible password library
-
extensions located in ext not loading
Ch0cu3r replied to Ginnnga's topic in PHP Installation and Configuration
When enabling any extensions on Windows I recommend you first add your PHP installation folder to the Windows Path Environment Variable. Then configure the the extension_dir directive to be an absolute file path to your PHP extension folder, eg extension_dir = C:/PHP/ext (if your path contains spaces then wrap the path in double quotes) Now go ahead an enable the extensions you require. If they still do enable then trying enabling a setting called display_startup_errors, if PHP is having issues loading extensions it should popup with an error message. -
You can get the difference using PHP's DateTime diff function. Example code $mysqlDate = new DateTime($row['lastupdate']); // pass the variable that contains the lastupdate value from your query $todaysDate = new DateTime(); // leave blank for todays date $interval = $todaysDate->diff($mysqlDate); // calculates the difference between the two dates echo 'Difference is ' . $interval->format('%i Minutes'); // outputs the difference in minutes