PHP - Moved: Prefer Content By Random
This topic has been moved to MySQL Help.
http://www.phpfreaks.com/forums/index.php?topic=319085.0 Similar TutorialsHey, I'm getting an undefined index in my final test and would like to know that this is fixed and I don't have to worry about any troubles.. here is what's going on Notice: Undefined index: register in C:\wamp\www\unitedsticks\insert.php on line 6 Registered! Return Notice: Undefined index: class in C:\wamp\www\unitedsticks\insert.php on line 58 1 record added Now...It Registers and does everything it's meant to, I just want the undefined index gone...here's my coding: THIS IS insert.php Code: [Select] <?php session_start(); mysql_connect("localhost", "root", ""); // Server connection mysql_select_db("myfirstdatabase"); // Database selection $page = $_POST['register']; // Setting the page value $user = $_POST['username']; // Setting the user value $pass = $_POST['password']; // Setting the pass value if($page == 1) { //This means that the page is the register form so the register form code goes here $query = mysql_query("select * FROM userdata WHERE username = '$user'"); // Queries the Database to check if the user already exists if(mysql_num_rows($query) !== 0) // Checks if there is any rows with that user { echo "THIS USER IS ALREADY TAKEN!"; // Stops there } else { mysql_query("INSERT INTO userdata (username, password) VALUES('$user', '$pass')"); // Inserts into the database. echo "REGISTERED! <BR> <a href='index.php'>Go to the login page</a>"; //Link and text to go to the login } } ?> <?php if($page == 0) { //This means that the page is the login form so the register form code goes here $query = mysql_query("SELECT username FROM userdata WHERE username = '$user'"); // Queries the Database to check if the user doesn't exist if(mysql_num_rows($query) == 0) // Checks if there is any rows with that user { echo "User doesn't exist"; // Stops there } $query = mysql_query("SELECT username FROM userdata WHERE username = '$user' AND password = '$pass'"); if(mysql_num_rows($query) !== 0) // Checks if there is any rows with that user and pass { echo "Registered!<BR> <a href='index.php'>Return</a>"; //Link and text to go to the login $_SESSION['LOGGEDIN'] = 1; } } ?> <?php $con = mysql_connect("localhost","root",""); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("database", $con); $sql="INSERT INTO register (username, password, class) VALUES ('$_POST[username]','$_POST[password]','$_POST[class]')"; if (!mysql_query($sql,$con)) { die('Error: ' . mysql_error()); } echo "1 record added"; mysql_close($con) ?> And my other coding: Code: [Select] <html> <body> <center><p><p><!-- Main Table(You can define padding accordingly) --> <table width="50%" border="0" cellspacing="0" cellpadding="5"> <td width="50%"> <!-- Table on left side --> <table width="90%" height="100%" border="1" cel1pacing="0" cellpadding="0" BORDERCOLOR="#007FFF"> <body style="background-color:;"> <td><h3><center><h3 style="background: blue; color: white;">Create Account Here<br></font></center></h2><p> <h4><p>Login Information</h4></p> <form action="insert.php" method="post"> Username: <input type="text" name="username" /><br> Password: <input type="password" name="password" /> <h3>Choose your Class</h2> <table width="100%" border="1"> <tr> <p> <label> <input type="radio" name="class" value="Clubber" id="SC" /> Clubber</label> <br /> <label> <input type="radio" name="class" value="Pastamancer" id="PM" /> Pastamancer</label> <br /> <label> <input type="radio" name="class" value="" id="" /><br> <center><input type="submit" /></center> </label> <br /> </p></td> </tr> </table> </form> </body> </html> Thanks for any help... Brent. Hi I'm wondering how I would go by making some sort of scrip for my website that loads random content from different files on my web server. Preferably php coding and maybe some mysql coding for an example I would like to have different folders on my web server lets say I have ( File 1 ) and in file 1 I have files named "cover.jpg" and "description.txt" and maybe some other files too and the same thing in other files on the web server So how would I go by making some thing that can load up these different files on the web server, like I said that will load up the content in each of the files every time the page refreshes or press of a button. Thanks Hi to everyone , I have used PHP for some basic things in my previous website design but am now venturing into another website for which I have a more complex use for PHP. I plan on making business directory for my local area. People will click on the area of their choice followed by the business type that they require. Then on the results page, they will have a list of all the business types in that particular area. What I would like to be able to do is rather than have the results displayed on the page like this : A Plumber xxxxx xxxxxx Tel: xxxxx xxxxxx Web: xxxxx xxxxxx E-Mail: xxxxx xxxxxx Best Plumber xxxxx xxxxxx Tel: xxxxx xxxxxx Web: xxxxx xxxxxx E-Mail: xxxxx xxxxxx Top Plumber xxxxx xxxxxx Tel: xxxxx xxxxxx Web: xxxxx xxxxxx E-Mail: xxxxx xxxxxx I would like it so that the same businesses are displayed on the page but either: 1) In a random order each time someone loads the page or 2) In a random order changed every hour The aim is so the businesses all have a shot at appearing nearer the top and aren't penalised for the 1st letter of their company name. Any help on this would be much appreciated, Thank You This topic has been moved to Miscellaneous. http://www.phpfreaks.com/forums/index.php?topic=315227.0 This topic has been moved to Miscellaneous. http://www.phpfreaks.com/forums/index.php?topic=314527.0 This topic has been moved to Miscellaneous. http://www.phpfreaks.com/forums/index.php?topic=310934.0 Stop posting non-PHP questions in the PHP Coding Help section. We have many sub-forums, including both a JavaScript forum and one dedicated entirely to Ajax. This topic has been moved to Ajax Help. http://www.phpfreaks.com/forums/index.php?topic=327454.0 This topic has been moved to HTML Help. http://www.phpfreaks.com/forums/index.php?topic=319610.0 This topic has been moved to Website Critique. http://www.phpfreaks.com/forums/index.php?topic=346717.0 This topic has been moved to mod_rewrite. http://www.phpfreaks.com/forums/index.php?topic=357949.0 This topic has been moved to CSS Help. http://www.phpfreaks.com/forums/index.php?topic=315351.0 This topic has been moved to JavaScript Help. http://www.phpfreaks.com/forums/index.php?topic=319719.0 This topic has been moved to Ajax Help. http://www.phpfreaks.com/forums/index.php?topic=314750.0 This topic has been moved to PHP Applications. http://www.phpfreaks.com/forums/index.php?topic=318539.0 As above, I have a lottery style site that picks a random number between 1-8 but my users complain for some reason that this is not enough. So i was told to look into using fopen and random.org to generate a random number. Anyone have experience of this and perhaps a code snippet for me to look at and possibly use? help will be appreciated. Hi
I try to echo out random lines of a html file and want after submit password to whole content of the same html file. I have two Problems.
1st Problem When I echo out the random lines of the html file I don't get just the text but the code of the html file as well. I don't want that. I just want the text. How to do that?
for($x = 1;$x<=40;$x++) { $lines = file("$filename.html"); echo $lines[rand(0, count($lines)-1)]."<br>"; }I tried instead of "file("$filename.html");" "readfile("$filename.html");" But then I get the random lines plus the whole content. Is there anything else I can use instead of file so that I get the random lines of text without the html code?P.S file_get_contents doesn't work either have tried that one. 2nd Problem: As you could see in my first problem I have a file called $filename.html. After I submit the value of a password I want the whole content. But it is like the program did forget what $filename.html is. How can I make the program remember what $filename.html is? Or with other words how to get the whole content of the html file? My code: if($_POST['submitPasswordIT']){ if ($_POST['passIT']== $password ){ $my_file = file_get_contents("$filename.html"); echo $my_file; } else{ echo "You entered wrong password"; } }If the password isn't correct I get: You entered wrong password. If the password is correct I get nothing. I probably need to create a path to the file "$filename.html", but I don't know exactly how to do that. Hi, I will start off trying to explain what I am trying to make the best I can. What I want to create is a script that gets the gold value from this website: http://www.lbma.org.uk/pages/index.cfm?page_id=46&title=current_statistics and then save it to a variable which I will use to calculate values of different gold karats. Here is the content in bold I need on the website I linked: Quote LONDON GOLD FIXING USD GBP EUR AM 1588.00 1005.127 1251.083 PM 1589.50 1004.741 1249.803 So what help do I need? Well, I don't expect you to figure out the calculating part for me but some help how to get that content pointed out above and save it to a variable is what I would appreciate getting some help with. I don't know much PHP, only some and I have been trying to figure this out for a day now without any success. I suppose php get contents and/or curl should be used here but I don't know how really. I would very much appreciate the help I can get on this. Thank you! This is the Code i am using. This is show error: Fatal error: Call to a member function item() on a non-object in /home/domain/public_html/forum/file/Test.php on line 35 Code: [Select] <?php $xml=("http://www.vn-zoom.com/external.php?type=RSS2&forumids=77"); $xmlDoc = new DOMDocument(); $xmlDoc->load($xml); //get elements from "<channel>" $channel=$xmlDoc->getElementsByTagName('channel')->item(0); $channel_title = $channel->getElementsByTagName('title') ->item(0)->childNodes->item(0)->nodeValue; $channel_link = $channel->getElementsByTagName('link') ->item(0)->childNodes->item(0)->nodeValue; $channel_desc = $channel->getElementsByTagName('description') ->item(0)->childNodes->item(0)->nodeValue; //output elements from "<channel>" echo("<p><a href='" . $channel_link . "'>" . $channel_title . "</a>"); echo("<br />"); echo($channel_desc . "</p>"); //get and output "<item>" elements $x=$xmlDoc->getElementsByTagName('item'); $i=1; // $i = 1 to n (I use For here). { $item_title=$x->item($i)->getElementsByTagName('title') ->item(0)->childNodes->item(0)->nodeValue; $item_link=$x->item($i)->getElementsByTagName('link') ->item(0)->childNodes->item(0)->nodeValue; $item_desc=$x->item($i)->getElementsByTagName('description') ->item(0)->childNodes->item(0)->nodeValue; // If i remove this, it will work....//////////// $item_content=$x->item($i)->getElementsByTagName('content') ->item(0)->childNodes->item(0)->nodeValue; ///////////////////////////////////////////////////// echo ("<p><a href='" . $item_link . "'>" . $item_title . "</a>"); echo ("<br />"); echo ($item_desc . "</p>"); echo ("<br />"); echo ($item_content . "</p>"); } ?> Please help me Fix this Code to Get content of Tag Name <content:encoded> Thanks I know this is not coding.. However... How tolerant is PHP from generating a random output from 1000s of entry columns in a mysql database. I would like to make a script that would potentially pick one of a 1000 results at random. is this a problem with being ran multiple times? Wow, I have no clue what I'm doing.. I'm trying to make a random game and if you roll a 6, you will win 500 rp and I'm trying to insert the 500 rp into the user who is logged in ($_SESSION['username'). But I... just don't know where to begin. Here is my crappy coding that I just.. am stumped on: <p><?php $dice = rand(1,6); if($dice == 1){ echo "You rolled a <br><b>1</b>"; }if($dice == 2){ echo "You rolled a <br><b>2</b>"; }if($dice == 3){ echo "You rolled a <br><b>3</b>"; }if($dice == 4){ echo "You rolled a <br><b>4</b>"; }if($dice == 5){ echo "You rolled a <br><b>5</b>"; }if($dice == 6){ echo "You rolled a <br><b>6</b>"; } $winner = "500"; if($dice == 6); { include("haha.php"); $cxn = mysqli_connect($dbhost,$dbuser,$dbpassword,$dbdatabase); $sql = "INSERT INTO Member (rp) VALUES ('$winner')"; mysqli_query($cxn,$sql); } ?> |