-
Posts
3,404 -
Joined
-
Last visited
-
Days Won
55
Everything posted by Ch0cu3r
-
There should be a { after the while loop statement on line 6 while($aGame = mysql_fetch_assoc($rQuery)) { // <--- this is missing
-
On way would be to use counter // initiate counter $i = 0; while($aGame = mysql_fetch_assoc($rQuery) { if($aGame['cijfer'] != 0 AND $aGame['stemmen'] != 0) { $cijfer = floor($aGame['cijfer'] / $aGame['stemmen']); } else { $cijfer = 0; } $sSpelNaam = str_replace(" ", "-",$aGame['name']); // increment counter by one $i++; // output counter echo "$i. <font color='#333333'>• <a href=\"http://www.crocgame.com/games.php/" . $sSpelNaam . ".html\" target='blank' onmouseover=\"ddrivetip('<img src=\'" . $aGame['screenshoturl'] . "\' width=\'170\' height=\'140\' alt=\'" . $aGame['name'] . "\'><br /><b>" . $aGame['name'] . "</b>');\" onmouseout='hideddrivetip();'>" . $aGame['name'] . " " . $aGame['extra'] . "</a></font><br />" . PHP_EOL; } The code will increment $i by one each time a row is outputted in the while loop Or you could output the results in a HTML ordered list Yes, depending on how have named your images, I assume you have named like 1.png, 2.png etc, you can change echo "$i. in my example code above to to be echo "<img src=\"$i.png\" />
-
Asumming get_comments is a wordpress function, then ;ooking at the wordpress documentation for the get_comments, you set the order clause in the argument string $comments = get_comments('status=approve&post_id=' .$post->ID.'&orderby=comment_date&order=DESC'); // alternatively can be written as $args = array( 'status' => 'approve', 'post_id' => $post->ID, 'orderby' => 'comment_date', 'order' => 'DESC' ); $comments = get_comments($args);
-
mysqli_real_escape_string alternative for decimal ?
Ch0cu3r replied to bambinou1980's topic in PHP Coding Help
To validate that it is a float. // validate price is a numeric value if(is_numeric($_POST['price'])) { //typecast to a float $price = (float) $_POST['price']; else { // price is not numeric, fails validation } If the user provides a non numeric value, then it will fail validation. mysqli_real_escape_string should only be used on string values (such as a persons name, contents to a blog post etc), that why it has string in its name, . It should not be used for non string values, such as numbers, floats etc. For those data types you should validate the data you are receiving is of that type/format you are expecting. However if you are using mysqli, then do not use mysqli_real_escape_string instead use prepared statements. -
It is better if you code it as you will learn more from doing it yourself than copy and pasting someone elses code. I have simplified the pseudo code <?php if (isset $_GET['url']) // check url exists - documentation http://php.net/isset { if(filter_input $_GET['url'] filter PHP_URL_HOST) // check url is valid - documentation http://php.net/filter_input using PHP_URL_HOST as the filter { $hostname = parse_url $_GET['url'] component PHP_URL_HOST; // get hostname and assign to variable - documentation http://php.net/parse_url $dns_records = dns_get_record $hostname type DNS_A; // use dns_get_record for hostname - documentation http://php.net/dns_get_record } else { echo url is not valid // echo an error message, url is not valid } } ?> your html form here <form ...>...</form> <?php if (isset $dns_records) // documentation http://php.net/isset { //output dns records here foreach($dns_records as $record) { // output dns $record here } } I have provided 90% of the code for you. If you read the documentation I have referenced in the code you should be able to fill in the missing pieces with ease.
-
It is processing the form regardless because you have not instructed PHP not to do that. PHP only does what you explicitly instruct it to do. You should only retrieve/show the dns records for the url if a) a url has been submitted and b) the url passes your validation. But your next problem is dns_get_record() does not take a url. It requires only a hostname (the domain). If you want to get the hostname from a url you will first want to call parse_url and grab the hostname segment, using PHP_URL_HOST flag. Also if you want to validate a url use filter_input using FILTER_VALIDATE_URL as the filter Pseudo code for how to layout your code <?php if ($_GET['url'] exists) { if(url is valid) { get hostname from url get dns record for hostname and save to a variable } else { output error, url is not valid } } ?> show form <?php if (have dns records) { output dns records here } ?>
-
Locked. See your topic from yesterday Please do not post duplicate topics.
-
Did you not see my reply?
-
It is showing that line 5 times because dns_get_record( "example.com", DNS_ALL); returns a multidimensional array of each type of dns record for that domain. In your case $site is a multidimensional array, which contains 5 sub-arrays. In each of these sub-arrays there is a "host" key. Your foreach loop is looping through each of these sub-arrays and outputting the "host" key. This is why line "the name of the host is example.com" is outputted five times. If you only want to host to be outputted once, you need add logic to your foreach loop example $putput_host = false; foreach( $site as $anyvariable) { // check if the host has been outputted if(!$output_host) { echo "the name of the host is" .$anyvariable['host']. "." ; echo "<br>"; // set $output_host to true, we have outputted the host $putput_host = true; } } If you are doing is outputting the host, then have dns_get_record return only one dns record, such as DNA_A $site = dns_get_record( "example.com", DNS_A); echo $site['host'] . ' ip address is ' . $site['ip'] . '<br />';
-
No, fputcsv only writes the data to the file. If you want file to automatically download you need to use headers to force the csv file to be download.
-
If you want to populate your csv file with the results from your query then use fputcsv. Example (I'm guessing your table column names) // path to csv file to write data to $data_file = 'myfile.csv'; $result = $mysqli->query('SELECT number, surname, forename, email, message, id, address, city, state, country, unit FROM table'); // open/create the csv file $handle = fopen($data_file, 'w'); // loop over results from query while($row = $result->fetch_row()) { // write row contents to csv file fputcsv($handle, $row); } fclose($handle); Documentation http://php.net/fputcsv Alternatively if your mysql user has file privileges, you can have the actual query dump the data into the csv file using a SELECT INTO query
-
Calling glob on its own wont do any thing. You need the foreach loop like you had in post #3
-
First append the your folder name with a forward slash, $source_folder = "archive/"; Second use the concatenation operator (period . ) not a comma between $source_folder and "*.html" glob($source_folder. "*.html");
-
Can you post the full error message.
-
It mentions it in the first sentence The filepath is the pattern.
-
PHP Script That Creates Text File for Download
Ch0cu3r replied to mike102t's topic in PHP Coding Help
Maybe stop blindly copying random code found on the internet and actually take the time to study what you it is you are trying to do. -
Check is results exist or not / MySQLi Prepared statement
Ch0cu3r replied to aHMAD_SQaLli's topic in MySQL Help
mysqli_num_rows expects a mysqli_result object not a mysqli_stmt object (returned by mysqli_prepare). If are going to use mysqli_num_rows then you need to call mysqli_stmt_get_result before hand. Example if ($stmt = mysqli_prepare($link, "SELECT id, username FROM users WHERE id=? ")) { mysqli_stmt_bind_param($stmt, "s", $tid); mysqli_stmt_execute($stmt); // get result set from prepared query $result = mysqli_stmt_get_result($stmt); // pass result to mysqli_num_rows if(mysqli_num_rows($result) !== 0) { // fetch row using mysqli_fetch_assoc $row = mysqli_fetch_assoc($result); echo "id: <b>[" . $row['id'] . "]</b> username: <b>[" . $row['username']. "]</b><br> "; } else { echo "Not Found"; } } else { // prepared query failed trigger_error('Unable query users table: ' . mysqli_error($link)); } But as mac_gyver said there is no need to do the above you can just use mysqli_stmt_fetch as the condition in a if statement to know if the prepared query returned a row if ($stmt = mysqli_prepare($link, "SELECT id, username FROM users WHERE id=? ")) { mysqli_stmt_bind_param($stmt, "s", $tid); mysqli_stmt_execute($stmt); // the columns returned in the query will be bound to these variables when calling mysqli_stmt_fetch mysqli_stmt_bind_result($stmt, $id, $username); // mysqli_stmt_fetch returns FALSE if no rows where returned if(mysqli_stmt_fetch($stmt)) { echo "id: <b>[" . $id . "]</b> username: <b>[" . $username. "]</b><br> "; } else { echo "Not Found"; } } else { // prepared query failed trigger_error('Unable query users table: ' . mysqli_error($link)); } -
Can you also show the javascript code for the playpause() function Also when posting code please wrap it within tags or click <> button in the editor
-
You need to do as mac_gyver suggested for 2) in his reply. If you do not give names to the fields used in your form no data will be submitted to PHP. PHP no longer automatically defines variables based on the names of the fields used in your form, ie if you had a field in your form called name (older versions of) php would of defined a variable called $name which would contain the value for the name form field. This is no longer the case instead you must use the $_POST or $_GET superglobal array (depending on your form submit method) to get that fields value, which will be $_POST['name'] to get the value for field named name See the following documentation http://php.net/manual/en/tutorial.forms.php http://php.net/manual/en/language.variables.external.php http://php.net/manual/en/language.variables.superglobals.php
-
Your login code is still broken. Anyone can login using any username or password that does or does not exist. That is because your code only checks to see if the query executed. mysqli_query only returns TRUE when the query executed and FALSE if a MySQL error occured. You need to check the query did return a row in order to authenticate the user $result = mysqli_query($conn, $sql); // check mysqli_query return TRUE, meaning query executed without error (returns FALSE otherwise) if($result) { // check the query did return a row, where the username and password hash used matched if(mysqli_num_rows($result) !== 0) { // can now authenticate the user $_SESSION['username'] = $username; header('Location: panel.php'); exit; // use exit/die to terminate the script after using header redirect to prevent remaining PHP code from being executed } // the query did not return a row, incorrect login credentials used else { echo 'Wrong username or password!'; } } // mysqli_query returned FALSE, else { // query did not execute due to an error. Lets find out trigger_error('Login Query Error: ' . mysqli_error($conn)); } Why? If you are going to use bcrypt when the project is finished then use it at the beginning.
-
You do not use PHP tag syntax within a PHP echo statement to output variables. You use the variable inside the string. A few examples // with strings defined with double quotes variables are expanded echo "Your card is: $card<br />"; echo "Have ordered: $qty"; // with strings defined with single quotes variables are NOT expanded, you must use concatenation echo 'Your card is: '.$card.'<br />'; echo 'Have ordered: '.$qty; // or as separate echo statements echo 'Your card is: '; echo $card; echo '<br />'; echo 'Have ordered: '; echo $qty; PHP documentaion on strings and echo http://php.net/manual/en/language.types.string.php http://php.net/manual/en/function.echo.php The only time you would use PHP tags would be when you go in and out of PHP mode, example <?php $card = 'black lotus'; $qty = 4; ?> Your card is: <?php echo $card; ?><br /> Have ordered: <?php echo $qty; ?>
-
PHP cannot do any operation on a variable within a string, it can only output the value of the variable. You must do the operation before using the variable in the string or use concatenation to perform the operation (like your first code snippet). <input type=\"radio\" name=\"action".(++$number3)."\" value=\"".(++$price2)."\" id=\"{$id_2}\" /> € ".(++$price2)." NOTE: Why is $price2 being incremented twice? This will result in two completely different (price) values $price2 = 2.50; echo " <input type=\"radio\" name=\"action".(++$number3)."\" value=\"".(++$price2)."\" id=\"{$id_2}\" /> € ".(++$price2) . ""; // output <input type="radio" name="action2" value="3.5" id="1" /> € 4.5 ^ ^ | | +--- different --+ values Also you should not name fields like action1, action2, action3 etc. You should use square brackets in the name as demonstrated in your other topic by cyberRobot/Barand
-
Does the free host you are going to be using support PHP? If they do not then this is not possible.
-
You getting that output because most likely your "newer system" does not have a setting call short_open_tags enabled for your php config. Either enable that setting or covert the short php tags such as <? ?> to be the full php tag syntax <?php ?>
-
Yes and no. If you are using PHP version 5.4 or newer then that short hand php echo tag should work. For older older versions of PHP you can enabled a setting short_open_tag in the php.ini (or via ini_set during runtime) to allow you to use short hand php syntax.