wildteen88
Staff Alumni-
Posts
10,480 -
Joined
-
Last visited
Never
Everything posted by wildteen88
-
<?php if(isset($_GET['setcookie']) && $_GET['setcookie'] == '1') { setcookie('cookie_name', 'cookie_value', time()+3600); } ?> <h1>Link</h1> <a href="?setcookie=1">Set Cookie</a> <h1>Image</h1> <a href="?setcookie=1"><img src="image.jpg" title="Set Cookie" /></a>
-
You'd use another if statement, get.php <?php if (isset($_COOKIE["cs_hpage"])) { $cookie = $_COOKIE["cs_hpage"]; if($cookie == '1') { print("Received a cookie: ".$cookie."\n"); } else { print("Fail"); } } else { print("Fail!.\n"); } ?> Or better yet merge the two together <?php if (isset($_COOKIE["cs_hpage"]) && $_COOKIE["cs_hpage"] == '1') { $cookie = $_COOKIE["cs_hpage"]; print("Received a cookie: ".$cookie."\n"); } else { print("Fail!.\n"); } ?> Like so <?php if(isset($_GET['submit'])) { setcookie('button_cookie', '2', time()+3600); } ?> <form action="" method="post"> <input type="submit" name="submit" value="Create Cookie" /> </form>
-
It is adding an empty array item to the $items array.
-
Well the variable $images appearers to be a multi-dimensional array. How is this array formatted? To display an image from the array, aslong as you know how it is formatted you can do <img src="<?php echo $images['some_key_here']['url']; ?>">" /> <img src="<?php echo $image['some_key_here']['thumb_url']; ?>" />
-
Check that multiple variables aren't empty?
wildteen88 replied to rockstarrem's topic in PHP Coding Help
Oops sorry. I was referring to the modifications I made to kens code. Your code should be like <?php require_once("mysqli.connect.php"); $album = $mysqli->real_escape_string($_POST["cd_album"]); $artist = $mysqli->real_escape_string($_POST["cd_artist"]); $year = $mysqli->real_escape_string($_POST["cd_year"]); $genre = $mysqli->real_escape_string($_POST["cd_genre"]); $vars = array( 'album' => 'CD Album', 'artist' => 'CD Artist', 'year' => 'CD Year', 'genre' => 'CD Genre' ); $errors = array(); foreach ($vars as $var => $label) { if (isset($$var) && strlen($$var) == 0) { $errors[$var] = $label . 'is empty'; } } if(is_array($errors) && count($errors) > 0) { echo 'Please fix the following errors: '; echo '<ul><li>' . implode('</li><li>', $errors) . '</li></ul>'; } else { $query = "INSERT INTO cd (album, artist, year, genre) VALUES ('$album', '$artist', '$year', '$genre')"; $mysqli->query($query, MYSQLI_STORE_RESULT); printf("Added: (%s) %s - %s GENRE: %s", $year, $album, $artist, $genre); } ?> -
Pretty much most well known forums come with some form of API for integrating your site with the forum. Here is a list of popular forums you can checkout SimpleMachines Forum (what this site uses) PHPBB3 MyBB IPB (not free) Vbulletin (not free)
-
$target_path should be a local file path, not a url $target_path = "http://adiscountsignco.com/admin/uploads/"; For example it should be $target_path = $_SERVER['DOCUMENT_ROOT'] . "/admin/uploads/";
-
Check that multiple variables aren't empty?
wildteen88 replied to rockstarrem's topic in PHP Coding Help
This is what ken's code does. Add the full variable name but without the dollar sign eg do $vars = array( "_POST['cd_name']" => 'CD Name', 'var1' => 'Variable 1', 'var2' => 'Variable 2', 'var3' => 'Variable 3'); You can add any variable to the array, just ommit the dollar sign. -
Do you mean the forms action attribute? <form action="server.php?view=vote&id<?php ?>" method="post" id="registration_form"> What are you doing inside the PHP tags there? Also you forgot the equals sign ( = ) after id. Maybe you'll be better off using a hidden input field for passing the vote id, eg <input type="hidden" name="vote_id" value="<?php echo $vote_id_variable; ?>" />
-
Check that multiple variables aren't empty?
wildteen88 replied to rockstarrem's topic in PHP Coding Help
If you're using kens code then modify the array to be // variable => label $vars = array( 'var1' => 'Variable 1', 'var2' => 'Variable 2', 'var3' => 'Variable 3'); Basically you're setting the variable as the key, then assigning the label as the value. Now change the loop to $errors =array(); foreach ($vars as $var => $label) { if (isset($$var) && strlen($$var) == 0) { $errors[$var] = $label . 'is empty'; } } When displaying the errors you can either display them individually , for example next to the form field if(isset($error['variable_here'])) echo $error['variable_here']; Or display them in one go if(is_array($errors) && count($errors) > 0) { echo 'Please fix the following errors: '; echo '<ul><li>' . implode('</li><li>', $errors) . '</li></ul>'; } -
You wont be able to list the contents of a directory with HTML. You're going to need to use a server side language like PHP for this. PHP has many functions for iterating through a directories contents, for example DirectoryIterator class.
-
It doesn't work. $status["status"][0] = "Waiting for support..."; $status["status"][1] = "Waiting for user..."; $status["status"][2] = "Ticket Closed..."; $status["status"][3] = "Ticket Opened..."; Get rid of ["status"]
-
You wouldn't need another counter for that, just define the max number of results you want returned from your query. So if you want to display 30 games (5 x 6 grid) then use $sql = 'SELECT game_id, game_name, game_thumbnail_image FROM games ORDER BY game_id DESC LIMIT 30';
-
The following will help you http://www.phpfreaks.com/forums/index.php/topic,95426.0.html
-
Because I need to check if and see if the users position (rank) is higher than 1, or equal to it. And I wanted to use it all in one query. It can all be within one query. An example (untested) query would be SELECT t.id, t.status, t.date, t.question, t.title, u.position FROM tickets t LEFT JOIN users u ON t.id = u.ticket_id WHERE (t.id='$existing' OR u.username='$username') AND u.position > 1
-
Divs and (un)ordered lists (<ol> or <ul>). Are all block level elements so applying display: block will have no affect on these tags. If you're displaying a menu or list of items then it is best to use a (unordered) list, then use CSS to style the menu to your liking. You'd use divs for each part of your layout. For example <div id="container"> <div id="header"> Heading here <div id="navigation"> Site menu here </div> </div> <div id="main"> main content here </div> <div id="footer"> footer here </div> </div> Do not use text-align. text-align is for aligning text not elements on your page. Provided the parent container has a width defined you can use auto margins (margin: 0 auto;) You can apply padding to any element.
-
Ok, what is your table structure like? Make sure your username field is set to atleast VARCHAR(32). md5() returns a 32 character hash string.
-
$query = "SELECT names FROM table WHERE type='$type'"; $result = mysql_query($query) or die(mysql_error()); while($row = mysql_fetch_array($result)) { $names = array_unique( unserialize($row['names']) ); foreach($names as $key => $value){ echo $value . '<br />'; } }
-
Ahh, its the quote after Test that is causing the issue. You'll want to use mysql_real_escape_string $query1 = "SELECT number FROM testing WHERE name = '" . mysql_real_escape_string($tname) . "'";
-
As you're passing a string to mysql you'll need to wrap it within quotes. Which is what you have already done. $query1 = "SELECT number FROM testing WHERE name = '" . $tname . "'"; Notice the single quotes before/after the double quotes. That should work regardless of the spaces. How are your defining $tname? And what is its value?
-
Where are you echoing out the individual variables? The code you posted above is not contained within a function is it? If it is then you may have a variable scope issue. But without seeing more code we wont know for sure.
-
You should compare the password within your MySQL Query, eg if(isset($_POST['submit3'])) { $email = mysql_real_escape_string($_POST['email3']); $password = md5($_POST['password3']); $sql = "SELECT username, password FROM Members WHERE email='$email' AND password='$password'"; $result = mysql_query($sql); // check that only one result has been returned, indicating a match with the username/password if($result && mysql_num_rows($result) == 1) { // user has provided correct login details // continue to login user } else { // User has provided invalid login details // display an error messsage } } This is why it is best to type the code out yourself. That way you should understand your code and work out how to debug it if things go wrong.
-
Both codes are correct, except in your second code block this line $row1 = mysqli_query($data1); Should be $row1 = mysqli_fetch_array($data1); Note, You call mysqli_query to execute the query you defined. To get the data returned from the query you use mysqli_fetch_array
-
Add echo '<pre>'.print_r($row, true).'</pre>'; After $row = mysqli_fetch_array($result); Post the output here.
-
Retrieve results from mysql as array and echo it out
wildteen88 replied to Danbannan's topic in PHP Coding Help
To add items to an array, do $var[] = 'new item here'; Adding [] after a variable will add the value on the right to the array ($var). Rather than use mysql_result it is much cleaner to use mysql_fetch_assoc, eg $data = array(); while($row = mysql_fetch_assoc($result)) { $data[] = $row; }