-
Posts
3,404 -
Joined
-
Last visited
-
Days Won
55
Everything posted by Ch0cu3r
-
If you are passing ErrorDocument an absolute url to 404.php, then the user will be redirected to that page ErrorDocument 404 http://sitename.com/path/to/404.php # causes redirect If you don't want the redirect to happen then drop the http://sitename.com part from the path. ErrorDocument 404 /path/to/404.php # does not cause redirect The file paths used in your HTML you must then use an absolute url for serving files, whereas with PHP the file paths will be relative to where 404.php is located on the file system.
-
I think you are getting confused with how PHP and HTML works. PHP uses file paths when requiring files from the file system. Whereas HTML uses http requests (a url) to request for files from the server. PHP has nothing do with the .htaccess (unless you are using the php_flag or php_value directives to alter PHP's config). The .htaccess file is only invoked when responding to a http request.
-
That will generate this query SELECT * FROM DB_PREFIXmediaPost WHERE post_enabled = 1 AND... post_created = <=UNIX_TIMESTAMP(DATE_ADD(CURDATE(),INTERVAL 1 DAY)) ... LIMIT 20 Notice the = <= bit. This is invalid SQL syntax. This caused due to my code hard-coding the comparison operator to a = and the fact you have included a different operator as part of the field value. The function does not have the logic to substitute the = with <=. I think rather than passing in an array of field, value pairs instead just pass in array of combined field, value pairs eg getCatid(array('post_enabled = 1', 'post_featured = 0', 'post_created <= UNIX_TIMESTAMP(DATE_ADD(CURDATE(),INTERVAL 1 DAY))')); So change // generated the where clause if(is_array($params)) { $sql .= 'WHERE '; foreach ($params as $field_value) { $sql .= "$field_value AND "; } $sql = substr($sql, 0, -4); // remove 'AND ' from the end of generated query } To just if(is_array($params)) { $sql .= 'WHERE ' . implode(' AND ', $params); }
-
Are you wanting to display an error message if the query does not return the users avatar? If you so you should code your function like //function that takes username and avatar // pass the username to the function function take_username_avatar($username) { $result = mysql_query("SELECT username, avatar FROM data WHERE username ='$username'")or die(mysql_error()); if($result)) { if(mysql_num_rows($result)) { return mysql_fetch_assoc($query); // return the username and avatar } } return false; // any other case return false } You'd then check the return value of the function to decided whether to display an error $username_avatar = take_username_avatar($_SESSION['username']); // if the take_username_avatar() returned false, display error if($username_avatar === false) { echo $_SESSION['username'] . ' has no avatar'; } // diplay the avatar else { ?> <p><a href='index.php?page=profile& username =<?php echo $username_avatar[' username ']; ?>'> <?php echo $username_avatar[' username '] ?></a></p> <a href='index.php?page=profile&username=<?php echo $username_avatar['username']; ?>'> <img src="avatar/<?php echo $username_avatar['avatar']; ?>" height='100' width='100' alt='avatar'></a> <?php } ?> To force the error so you can take a screenshot of it pass non existing user to the function, eg take_username_avatar('non-existing-user') and the function will return false. Which will force the error message to be displayed
-
You haven't closed the form in the while loop while ( $row = mysqli_fetch_assoc( $dbretrieve_result ) ) { echo $row['id']; echo "<table>"; echo "<form action=\"{$_SERVER['PHP_SELF']}\" name=\"delete_student\" method=\"POST\">"; echo "<tr><td><p><input type=\"submit\" name=\"delete_row\" value=\"Delete Student Number: {$row['id']}\" /></p></td><td><b>Student ID NO.</b> {$row['id']}</td></tr>"; echo "<input type=\"hidden\" name=\"deleteStudent\" value=\"{$row['id']}\">"; echo "<tr><td></td><td><b>Student Name:</b> {$row['username']}</td></tr>"; echo "</from>";// <-- missing closing form tag echo "</table>"; echo "<br>"; }
-
Why are you needing to use a url to include a file? What is it you are trying to do?
-
Are you using the array to construct the where clause, eg array("post_enabled"=>"1", "post_featured"=>"0") should yield the following query to be performed by your function SELECT * FROM ".DB_PREFIX."mediaPost WHERE post_enabled = 1 AND post_featured = 0 ORDER BY p.post_created DESC LIMIT 20 You can accomplish this using function getCatid($params=false) { // start to define the query $sql = 'SELECT * FROM '.DB_PREFIX.'mediaPost '; // generated the where clause if(is_array($params)) { $sql .= 'WHERE '; foreach ($params as $field => $value) { $sql .= "$field = $value AND "; // add the field, value pair to the query } $sql = substr($sql, 0, -4); // remove 'AND ' from the end of generated query } // append the rest of the query $sql .= 'ORDER BY p.post_created DESC LIMIT 20'; // pass the generated query to GetList() if($result = GetList($sql)){ foreach ($result as $data) { echo $data['post_name']."<br>"; } } }
-
The behaviour you have experience is correct. When including a file using a url, only the output from that file is returned, not the raw php source code.
-
im stuck with my code. IF this = that show image code.
Ch0cu3r replied to djzman's topic in PHP Coding Help
You're using the wrong operator for comparing values. You use = (assignment operator) to a assign a value to variable You use == (comparison operator) to compare a value -
$rows['id'] should be $row['id'] Using queries within loops is not recommended. You can delete multiple records from on query by using an IN clause $ids = array_map('intval', $_POST['checkboxes']); $sql = 'DELETE FROM Persons WHERE id IN('. implode(',' $ids) .')'; $result = mysql_query($sql); Also you should be processing the form deletion before constructing the page <?php $con=mysqli_connect("localhost","*****","*****","stradsol_sales"); if (mysqli_connect_errno()) { echo "Failed to connect to MySQL: " . mysqli_connect_error(); } // process the form first if(isset($_POST['delete'])) { $ids = array_map('intval', $_POST['checkboxes']); $sql = 'DELETE FROM Persons WHERE id IN('. implode(',' $ids) .')'; $result = mysqli_query($con, $sql); // if successful redirect if($result) { header('Location: edit_table_del.php'); exit; // kill the page when performing a redirect } } // no construct the page ?> <html> <head> <title>Strad Hosting Limited -Web Hosting</title> <script language="javascript"> function validate() { var chks = document.getElementsByName('checkbox[]'); var hasChecked = false; for (var i = 0; i < chks.length; i++) { if (chks[i].checked) { hasChecked = true; break; } } if (hasChecked == false) { alert("Please select at least one."); return false; } return true; } </script> </head> <body > <?php $result = mysqli_query($con,"SELECT * FROM Persons"); echo "<form name='form1' method='post' action='' onSubmit='return validate();'>"; echo "<table border='1' style=' background-color: white;'> <tr> <th></th> <th>id</th> <th style='padding-left: 11px;'>Lead Generated Date </th> <th>name</th> <th>email</th> <th>contacts</th> <th>requirement</th> <th style='display:none;'>Company name</th> <th style='display:none;'>Address</th> <th>Next Follow-Up date</th> <th>Final_Details</th> <th style='display:none;'>Status</th> <th style='padding-left: 12px; display:none;'>Lead Closed Date</th> <th>EDIT</th> <th>Follow-up History</th> <th>Add Follow-up</th> <th>Delete Record</th> </tr>"; while($row = mysqli_fetch_array($result)) { echo "<tr>"; echo "<td><input name='checkbox[]' type='checkbox' id='checkbox[]' value='".$rows['id']."'></td>"; echo "<td>" . $row['id'] . "</td>"; echo "<td>" . $row['date'] . "</td>"; echo "<td><a href='config_info.php?id=" . $row['id'] . "'>".$row['name']."</a></td>"; echo "<td>" . $row['email'] . "</td>"; echo "<td>" . $row['contacts'] . "</td>"; echo "<td>" . $row['requirement'] . "</td>"; echo "<td style='display:none;'>" . $row['company_name'] . "</td>"; echo "<td style='display:none;'>" . $row['address'] . "</td>"; echo "<td>" . $row['startdate'] . "</td>"; echo "<td>" . $row['final_details'] . "</td>"; echo "<td style='display:none;'>" . $row['status'] . "</td>"; echo "<td style='display:none;'>" . $row['lead_close'] . "</td>"; echo "<td><a href='edit_eg1.php?id=" . $row['id'] . "'>Edit</a></td>"; echo "<td><a href='Follow_history.php?id=" . $row['id'] . "'>Follow_history</a></td>"; echo "<td><a href='add_follow.php?id=" . $row['id'] . "'>Followup</a></td>"; echo "<td><a href='delete.php?id=" . $row['id'] . "'>Delete</a></td>"; echo "</tr>"; } echo "<tr><td><input name='delete' type='submit' id='delete' value='Delete'></td></tr>"; mysqli_close($con); echo "</table>"; echo "</form>"; ?> <br><br> <a href="index2.php">[ Back To Home ]</a> </body> </html>
-
Validating a query string to detect change from user
Ch0cu3r replied to leegodden's topic in PHP Coding Help
How would that work? You can obfuscate the price however you like. You'll still have the same problem the user is still able to modify it. If PHP can receive the value, then you can use sessions. But without seeing code we cant really give your specific instructions. -
This line is responsible for connecting to mysql. //$con=mysqli_connect("localhost", "root", "", "abc"); However it is commented out (meaning it will be ignored) and secondly you need to be connected to mysql before performing any database operations, such as a query. To solve the error, you need to first uncomment it (by deleting the // infront of it), then make sure you give it the correct database credentials (hostname, username, password and database name) and then move it so it is a line before performing a query on the database.
-
Validating a query string to detect change from user
Ch0cu3r replied to leegodden's topic in PHP Coding Help
Why? When dealing with sensitive data such as prices you should not be letting the client (web browser) handle it, the only time you would do this is when listing the price on the webpage. As anything set in then url can easily be altered by the user. Sessions are recommended as you have full control over it. The data stored in the session is stored on the server and not the client. -
Your Country dropdown has this onchange event onchange="javascript:getDivContent('/ch_div_content.php?method=getPriceSets&countryId='+this.value,'divPriceSet','');return true;" On selecting a country from the menu it will pass in the selected options value to ch_div_content.php. This script appears to be controlling the quantity field. For example selecting any country between Israel and United Kingdom from the country menu and a static quantity field is returned. However selecting any other country a dropdown box is returned.
-
try $includeCat = '2,3,4,5,6,7'; if($includeCat) $query .= " AND c.id = IN($includeCat) ";
-
if you want the Country menu to maintain the selected option on form submit the code will be <select name="country" id="country_list" onchange="this.form.submit();" > <?php foreach($countries as $name): $selected = isset($_POST['country']) && $_POST['country'] == $name['country'] ? ' selected="selected"' : ''; ?> <option value="<?php echo $name['country'] ?>"<?php echo $selected; ?>><?php echo $name['country'] ?></option> <?php endforeach; ?> </select>
-
You have left off the ; at the end of line 2 $link = mysql_connect("localhost", "USER", "PASS"); // <-- missing semi-colon at end of line NOTE: If you are starting to lean to use MySQL databases with PHP, then I strongly encourage you to not carry on using the standard mysql_* functions. Instead use MySQLi instead. The mysql_* function are deprecated and could so be removed completely from newer versions of PHP.
-
You have a variable scope issue. Functions have their own variable scope, meaning any variables defined outside of that function is not accessible. The same rule apples to variables defined inside of the function. Have a read of manual on variable scope http://php.net/manual/en/language.variables.scope.php The fix is to pass $DB as an argument to your get_mentor_users function. function get_mentor_users($DB, $fromdate = 0, $todate = 0){ ... } // pass $DB as a function argument $sql2 = get_mentor_users($DB, $fromdate, $todate);
-
Change $row=mysql_fetch_object(mysql_query($query)); $interests_array=split(",",$row->people_interests); to $people_result = mysql_query($query); $interest_array = array(); while($row = mysql_fetch_row($people_result )) { $interests_array[] = $row[0]; }
-
You'd use a modules $i by 2 in a condition to alternate to the text weight. Example using a ternary operator for ($x=0; $x<=10; $x++) { $weight = ($x % 2 == 0) ? 'bold' : 'normal'; // alternate the text boldness echo "<span style=\"font-weight: $weight;\"> $x </span><br />"; }
-
PHP help - Working with Files and Directories
Ch0cu3r replied to dragonscrapper's topic in PHP Coding Help
If the HTML file has PHP code in it then it should end with a .php extension, not a .html extension. -
Struggling with the correct syntax to modify a return value
Ch0cu3r replied to zigojacko's topic in PHP Coding Help
What is the purpose of $noescape? If you want the result of returned from preg_replace to be applied to $this->_queryText then there is no need for $noescape. $this->_queryText = preg_replace("/%u([0-9a-f]{3,4})/i","\\1;",urldecode($this->_queryText)); -
This is could be why <BODY bgcolor="#ffffff" TEXT="#ffffff" LINK="#ffffff" VLINK="#ffffff"><font face="Arial,Helvetica"> TEXT, LINK and VLINK attributes will set the text color to white, which could be overriding the text color defined by your forums css.
-
The only time you'll need to install PHP and MySQL (and Apache) on your computer is if you plan on testing your code locally on your computer, rather than having to download a file, make a change and then reupload the files to your host in order to test any changes made to your code.