-
Posts
3,404 -
Joined
-
Last visited
-
Days Won
55
Everything posted by Ch0cu3r
-
Website not displaying products after migration
Ch0cu3r replied to mlungisi's topic in PHP Coding Help
Something some where else is already started the session and this line is trying to start it too. You should be able to safely delete that from line 27 from products.php. Replace lines 74 and 75 to the following if(isset($Firstname) && isset($Surname)) { $_SESSION['uFirstName'] = $Firstname[0]; $_SESSION['uSurName'] = $Surname[0]; } It is hard to recommend what to do for the solving the above error as I do not know how/where those variables are being defined, this the problem when variables are defined as global. You could try changing $iAUID to $_SESSION['uAUID'] however I do not know if this will break the GetAU function. If your site is running as it should then edit your servers php config so displayer_errors directive is set to Off. -
Durp. I meant ini_set() <?php error_reporting(E_ALL); ini_set('display_errors', 1); ?>
-
On line 36 need to be checking to see if $row['user_level'] variable is equal to 2, not $user_level.
-
As I said earlier if you are getting a blank page then there is most probably an error. To see what the error is you need to turn error reporting on or check your servers error log. To enable error reporting add these lines at the top of editform_func <?php error_reporting(E_ALL); display_errors(TRUE); ?> Are any errors displayed?
-
Your trying to call a function here. if ($rows_affected() === false) The variable $rows_affected contains the number of rows the query updated. Not a function It should be if ($rows_affected !== false)
-
What you have posted is nothing to do with PHP. That is some form of template code for third party PHP script. What is this script your are using?
-
You need make the function return the value of $input if you want to echo it function getAnswers($input) { $input = implode(";", $_POST[$input]); return $input; } echo getAnswers('breakfast_cereal');
-
Newbie Alert - Getting 500 Error on Php table creation
Ch0cu3r replied to gbarnes27's topic in PHP Coding Help
is that your full code? You have only posted 32 lines of code, yet the error states there is 63 lines. As mentalist said you most likely don't have matching { and } (these denote code blocks). If you do not know how to fix this error post your code for processform.php in full here within tags. -
PDO errors in SELECT query using WHERE clause
Ch0cu3r replied to rghollenbeck's topic in PHP Coding Help
The problem is you are trying to invoke a prepared query. But the variable $sql doesn't exist. Then trying to pass it to pdo query. To query the database with a standard pdo query your code will be $cat = $_POST['category']; $db = new PDO('mysql:host=localhost;dbname=' . $dbname , $dbusername, $pass); $db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); $sql = "SELECT * FROM QuestionsAnswers WHERE category = " . $cat; foreach ($db->query($sql) as $row) { print '<p>' . $row['question'] .' <br /> '. $row['displaystring'] . '</p>'; } If you want to use prepared statements then the code would be $cat = $_POST['category']; $db = new PDO('mysql:host=localhost;dbname=' . $dbname , $dbusername, $pass); $db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); $stmt = $db->prepare('SELECT * FROM QuestionsAnswers WHERE category = ?'); // Values used in the query are marked with the ? placeholder $stmt->execute(array($cat)); // execute the query. Pass in the an array listing the values to be used in the query $results = $stmt->fetchAll(); // Get the results foreach ($results as $row) { print '<p>' . $row['question'] .' <br /> '. $row['displaystring'] . '</p>'; } Full documentation (and examples) on PDO can be found at http://php.net/pdo -
@BrodaNoel is my posts not in english? I have linked to phpmailer twice
-
It is checking to see if $_FILES super global array contains something. When files are uploaded from a form this superglobal array will contain information about the uploaded file(s). If no files are uploaded it'll be empty. Read the following to see what possible information is contained within this variable http://www.php.net/manual/en/features.file-upload.post-method.php
-
On line 20 in register.php you should be assigning the username to $username not $password $password = mysqli_real_escape_string($dbc, $trimmed['username']); In login.php you are not using sessions properly echo "success"; session_start(); $_SESSION['username'] = mysqli_fetch_array($r, MYSQLI_ASSOC); sesssion_start() should be called before you ouput anything to the browser. I recommend putting it on line 1 of header.php To set the username data to the session you need to do $row = mysqli_fetch_array($r, MYSQLI_ASSOC); $_SESSION['username'] = $row['username']; $_SESSION['user_id'] = $row['user_id']; $_SESSION['user_level'] = $row['user_level'];
-
My code is a fully working example, you do not need to modify it. Your screenshot are from something else. What have you changed?
-
Please do not post this in multiple places. Your original thread http://forums.phpfreaks.com/topic/283274-simple-math-problem/
-
This code will do what you are trying to do. I have modified ignace's example. <?php $expression = 'a + b + c - d'; // default expression $input = array( 'a' => 1, 'b' => 7, 'c' => 3, 'd' => 14); // default input values $total = 0; $sum = ''; // when form has been submitted. // Override default expression and input values if(isset($_POST['Calculate'])) { $input = $_POST['input']; $expression = $_POST['expression']; } // make sure the users expression is safe to use if(preg_match('#^[a-z+-\s]+$#i', $expression)) { $sum = $expression; foreach ($input as $char => $value) { // replace the variables in $expression with their values $sum = str_replace($char, $value, $sum); } eval('?><?php $total = ' . $sum . ';'); // perform the calculation } else { // display this message if the entered expression is invalid echo '<b>Expression invalid can only contain letters and math operators (+ or -)</b>'; } ?> <form action="" method="post"> Number A: <input type="text" name="input[a]" value="<?php echo $input['a']; ?>" size=3> <br/> Number B: <input type="text" name="input[b]" value="<?php echo $input['b']; ?>" size=3> <br> Number C: <input type="text" name="input[c]" value="<?php echo $input['c']; ?>" size=3> <br> Number D: <input type="text" name="input[d]" value="<?php echo $input['d']; ?>" size=3> <br> <br> Expression: <input type = "text" name = "expression" value="<?php echo $expression ?>"> = <?php echo $total; ?><br> Sum: <?php echo $sum; ?><br> <input type="submit" name="Calculate" /> </form>
-
In order for the email to be sent the smtp server requires authentication. In other words before you can send the email, the smtp sever requires a username/password that is authorised to send the email. The standard mail() does not have this capability. There is no PHP setting for this either. You will need to use the PHPMailer script I linked to. Look at the example code for sending an email using authentication here http://phpmailer.worxware.com/index.php?pg=examplebsmtp
-
What does my code output when you run it? Just because the query appears to be formatted correctly when you echo it does not mean there is nothing wrong with it. When executing query's you need to check that it executed and that it returned any results. You cannot always assume a query will execute OK.
-
The builtin php mail() function does not support smtp authentication. If your smpt server requires authentication for sending emails then use PHPMailer
-
Nothing to do with Apache. it is just that phpacademy has coded the login/register script poorly. This is why you are getting so many errors. You need to check that the query has returned a result before you call mysql_result(). Change the function to the following to see what could be wrong function user_exists($username) { $username = sanitize($username); if($result = mysql_query("SELECT COUNT(`user_id`) FROM `users` WHERE `username` = '$username'")) { if(mysql_num_rows($result)) return (mysql_result($result, 0) == 1) ? true : false; else echo 'user_exists() query returned no results!'; } else echo 'user_exists() query return: ' . mysql_error(); }
-
If you're using an image as the submit button some browsers only send the X,Y coords for where the user clicked the button. So you'll want to check for this too <?php if(isset($_POST['abuse']) || isset($_POST['abuse_x'])) { echo "Submit here"; } if(isset($_POST['del']) || isset($_POST['del_x'])) { echo "del here"; } if(isset($_POST['add']) || isset($_POST['add_x'])) { echo "add here"; } ?>
-
Maybe use strip_tags instead
-
Have you tried changing 'value' => $sDefaultTitle, to 'value' => getUsername(),
-
The same code you have but place a ! infront of preg_match // if user agent does not match a mobile if(!preg_match('/android|avantgo|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(hone|od)|iris|kindle|lge |maemo|midp|mmp|opera m(ob|in)i|palm( os)?|phone|p(ixi|re)\/|plucker|pocket|psp|symbian|treo|up\.(browser|link)|vodafone|wap|windows (ce|phone)|xda|xiino/i',$useragent)||!preg_match('/1207|6310|6590|3gso|4thp|50[1-6]i|770s|802s|a wa|abac|ac(er|oo|s\-)|ai(ko|rn)|al(av|ca|co)|amoi|an(ex|ny|yw)|aptu|ar(ch|go)|as(te|us)|attw|au(di|\-m|r |s )|avan|be(ck|ll|nq)|bi(lb|rd)|bl(ac|az)|br(e|v)w|bumb|bw\-(n|u)|c55\/|capi|ccwa|cdm\-|cell|chtm|cldc|cmd\-|co(mp|nd)|craw|da(it|ll|ng)|dbte|dc\-s|devi|dica|dmob|do(c|p)o|ds(12|\-d)|el(49|ai)|em(l2|ul)|er(ic|k0)|esl8|ez([4-7]0|os|wa|ze)|fetc|fly(\-|_)|g1 u|g560|gene|gf\-5|g\-mo|go(\.w|od)|gr(ad|un)|haie|hcit|hd\-(m|p|t)|hei\-|hi(pt|ta)|hp( i|ip)|hs\-c|ht(c(\-| |_|a|g|p|s|t)|tp)|hu(aw|tc)|i\-(20|go|ma)|i230|iac( |\-|\/)|ibro|idea|ig01|ikom|im1k|inno|ipaq|iris|ja(t|v)a|jbro|jemu|jigs|kddi|keji|kgt( |\/)|klon|kpt |kwc\-|kyo(c|k)|le(no|xi)|lg( g|\/(k|l|u)|50|54|e\-|e\/|\-[a-w])|libw|lynx|m1\-w|m3ga|m50\/|ma(te|ui|xo)|mc(01|21|ca)|m\-cr|me(di|rc|ri)|mi(o8|oa|ts)|mmef|mo(01|02|bi|de|do|t(\-| |o|v)|zz)|mt(50|p1|v )|mwbp|mywa|n10[0-2]|n20[2-3]|n30(0|2)|n50(0|2|5)|n7(0(0|1)|10)|ne((c|m)\-|on|tf|wf|wg|wt)|nok(6|i)|nzph|o2im|op(ti|wv)|oran|owg1|p800|pan(a|d|t)|pdxg|pg(13|\-([1-8]|c))|phil|pire|pl(ay|uc)|pn\-2|po(ck|rt|se)|prox|psio|pt\-g|qa\-a|qc(07|12|21|32|60|\-[2-7]|i\-)|qtek|r380|r600|raks|rim9|ro(ve|zo)|s55\/|sa(ge|ma|mm|ms|ny|va)|sc(01|h\-|oo|p\-)|sdk\/|se(c(\-|0|1)|47|mc|nd|ri)|sgh\-|shar|sie(\-|m)|sk\-0|sl(45|id)|sm(al|ar|b3|it|t5)|so(ft|ny)|sp(01|h\-|v\-|v )|sy(01|mb)|t2(18|50)|t6(00|10|18)|ta(gt|lk)|tcl\-|tdg\-|tel(i|m)|tim\-|t\-mo|to(pl|sh)|ts(70|m\-|m3|m5)|tx\-9|up(\.b|g1|si)|utst|v400|v750|veri|vi(rg|te)|vk(40|5[0-3]|\-v)|vm40|voda|vulc|vx(52|53|60|61|70|80|81|83|85|98)|w3c(\-| )|webc|whit|wi(g |nc|nw)|wmlb|wonu|x700|xda(\-|2|g)|yas\-|your|zeto|zte\-/i',substr($useragent,0,4))) header('Location: http://domain.com'); // redirect to desktop version