PHP - A Simple Select....
Hey Again;
trying to have the code select the top 5 players bases on exper field in the DB 'SELECT * from players WHERE exper = ''; Similar TutorialsHi, I've been trying to get a simple select statement to work in my code, and I just don't know why it returns an error. Quote Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /adoptnow.php on line 13 And the code is: Code: [Select] <?php $con = mysql_connect("localhost","***","***"); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("a8784hos_pets2", $con) or die ("Couldn't select database because: ".mysql_error()); $query = "SELECT * FROM species WHERE available = 1"; $petcrap = mysql_query($query) or die ("Error in number one query: $query. ".mysql_error()); $petinfo = mysql_fetch_array($petcrap); while ($row = mysql_fetch_array($petinfo)){ echo $row['petid']; } ?> I've read that this is usually because you haven't selected the database or it can't find the table, but I've run the sql query in phpmyadmin, and it comes back perfectly. I honestly have no idea what I'm doing wrong right now and would appreciate some help. Thanks. Not really sure what to ask because I don't know what the problem is. Maybe just need a fresh set of eyes to find out whats wrong. I am trying selecting content from a database table but its not working. I am not getting any errors just a blank screen where the content should be displayed. html Code: [Select] <table> <tbody> <tr> <th>Topic</th> <th>Name</th> <th>Date</th> </tr> <?php include 'server/forum.php'; ?> </tbody> </table> php Code: [Select] <?php require_once('load_data.php'); $con = mysql_connect($db_host, $db_user, $db_pwd); if (!$con) { die('Could not connect to database: ' . mysql_error()); } $dbcon = mysql_select_db($database); if (!$dbcon) { die('Could not select database: ' . mysql_error()); } $sql = "SELECT * FROM $table ORDER BY id"; $result = mysql_query($sql) or die("Error ". mysql_error(). " with query ". $sql); if (!$result) { die("Query to show fields from table failed:".mysql_error()); } $row = mysql_fetch_array($result) while($row) { echo '<tr>'; echo '<td class="forumtd"><b>'; echo '<a href="topic.php?id='.$row['id'].'">'.stripslashes(htmlspecialchars($row['topic'])).'</a>'; echo "</b></td>"; echo '<td class="forumtd"><em>'; echo stripslashes(htmlspecialchars($row['name'])); echo "</em></td>"; echo '<td class="forumtd">'; echo date("l M dS, Y", $row['date']); echo "</td>"; echo "</tr>"; } mysql_close($con); ?> This topic has been moved to MySQL Help. http://www.phpfreaks.com/forums/index.php?topic=322930.0 hirealimo.com.au/code1.php this works as i want it: Quote SELECT * FROM price INNER JOIN vehicle USING (vehicleID) WHERE vehicle.passengers >= 1 AND price.townID = 1 AND price.eventID = 1 but apparelty selecting * is not a good thing???? but if I do this: Quote SELECT priceID, price FROM price INNER JOIN vehicle....etc it works but i lose the info from the vehicle table. but how do i make this work: Quote SELECT priceID, price, type, description, passengers FROM price INNER JOIN vehicle....etc so that i am specifiying which colums from which tables to query?? thanks I have 2 queries that I want to join together to make one row
Hi everyone, I'm trying to select either a class or an id using PHP Simple HTML DOM Parser with absolutely no luck. My example is very simple and seems to comply to the examples given in the manual(http://simplehtmldom.sourceforge.net/manual.htm) but it just wont work, it's driving me up the wall. Here is my example: http://schulnetz.nibis.de/db/schulen/schule.php?schulnr=94468&lschb= I think the HTML is invalid: i cannot parse it. Well i need more examples - probly i have overseen something! If anybody has a working example of Simple-html-dom-parser...i would be happy. The examples on the developersite are not very helpful. your dilbertone Hello, im very green to php and I am having trouble creating a simple log in script. Not sure why this is not working, maybe a mysql_query mistake? I am not receiving any errors but nothing gets updated in the members table and my error message to the user displays. any help is appreciated! here is my php: <?php session_start(); $errorMsg = ''; $email = ''; $pass = ''; if (isset($_POST['email'])) { $email = ($_POST['email']); $pass = ($_POST['password']); $email = stripslashes($email); $pass = stripslashes($pass); $email = strip_tags($email); $pass = strip_tags($pass); if ((!$email) || (!$pass)) { $errorMsg = '<font color="#FF0000">Please fill in both fields</font>'; }else { include 'scripts/connect_db.php'; $email = mysql_real_escape_string ($email); $pass = md5($pass); $sql = mysql_query("SELECT * FROM members WHERE email='$email' AND password='$pass'"); $log_check = mysql_num_rows($sql); if ($log_check > 0) { while($row = mysql_fetch_array($sql)) { $id = $row["id"]; $_SESSION['id']; $email = $row["email"]; $_SESSION['email']; $username = $row["username"]; $_session['username']; mysql_query("UPDATE members SET last_logged=now() WHERE id='$id' LIMIT 1"); }//Close while loop echo "You are logged in"; exit(); } else { $errorMsg = '<font color="#FF0000">Incorrect login data, please try again</font>'; } } } ?> and the form: <?php echo $errorMsg; ?> <form action="log_in.php" method="post"> Email:<br /> <input name="email" type="text" /><br /><br /> Password:<br /> <input name="password" type="password" /><br /><br /> <input name="myBtn" type="submit" value="Log In" /> </form> Dear All, I wish to have 2 drop down boxes, Country Select Box and Locality Select Box. The locality select box will be affected by the value chosen in the country select box. All is working fine except that the locality select box is not being populated. I know that the problem is in the sql statement WHERE country_id='$co' because i am having an error that $co is an undefined variable. All the rest works fine because i have replaced the $co variable directly with a number (say 98) for a particular country id and it worked fine. In what way can i define this variable $co so that it is accepted by my sql statement? Thank you for your help in advance. MySQL Tables indicated below: CREATE TABLE countries( country_id INT(3) UNSIGNED NOT NULL AUTO_INCREMENT, country_name VARCHAR(30) NOT NULL, PRIMARY KEY(country_id), UNIQUE KEY(country_name), INDEX(country_id), INDEX(country_name)) ENGINE=MyISAM; CREATE TABLE localities( locality_id INT(10) UNSIGNED NOT NULL AUTO_INCREMENT, country_id INT(3) UNSIGNED NOT NULL, locality_name VARCHAR(50), PRIMARY KEY (locality_id), INDEX (country_id), INDEX (locality_name)) ENGINE=MyISAM; Extract PHP script included below: // connect to database require_once(MYSQL); if(isset($_POST['submitted'])) { // trim the incoming data /* this line runs every element in $_POST through the trim() function, and assigns the returned result to the new $trimmed array */ $trimmed=array_map('trim',$_POST); // clean the data $co=mysqli_real_escape_string($dbc,$trimmed['country']); $lc=mysqli_real_escape_string($dbc,$trimmed['locality']); } ?> <form action="form.php" method="post"> <p>Country <select name="country"> <option>Select Country</option> <?php $q="SELECT country_id, country_name FROM countries"; $r=mysqli_query($dbc,$q) or trigger_error("Query: $q\n<br />MySQL Error: " . mysqli_error($dbc)); while($row=mysqli_fetch_array($r)) { $country_id=$row[0]; $country_name=$row[1]; echo '<option value="' . $country_id . '"'; if(isset($trimmed['country']) && ($trimmed['country']==$country_id)) echo 'selected="selected"'; echo '>' . $country_name . '</option>\n'; } ?> </select> </p> <p>Locality <select name="locality"> <option>Select Locality</option> <?php $ql="SELECT locality_id, country_id, locality_name FROM localities WHERE country_id='$co' ORDER BY locality_name"; $rl=mysqli_query($dbc,$ql) or trigger_error("Query: $q\n<br />MySQL Error: " . mysqli_error($dbc)); while($row=mysqli_fetch_array($rl)) { $locality_id=$row[0]; $country_id=$row[1]; $locality_name=$row[2]; echo '<option value="' . $locality_id . '"'; if(isset($trimmed['locality']) && ($trimmed['locality']==$locality_id)) echo 'selected="selected"'; echo '>' . $locality_name . '</option>\n'; } // close database connection mysqli_close($dbc); ?> </select> </p> <p><input type="submit" name="submit" value="Submit" /></p> <input type="hidden" name="submitted" value="TRUE" /> </form> Hi can someone pls help, im tryin a tutorial but keep getting errors, this is the first one i get after registering. You Are Registered And Can Now Login Warning: Cannot modify header information - headers already sent by (output started at /home/aretheyh/public_html/nealeweb.com/regcheck.php:43) in /home/aretheyh/public_html/nealeweb.com/regcheck.php on line 46 Hi, I'm not quite sure how to do this, so i thought i'd ask you guys from some assistance. Basically i am inserting Author's into a table successfully using an array. The reason for this is that i have multiple authors being added and there is no limit as to how many. An example of what i mean can be seen he http://www.prima.cse.salford.ac.uk:8080/~ibrarhussain/test.html You can click on "Add author" to add however many necessary.. Anyway, i have got the insert working, however when i edit i want to be able to see all the authors that have been added but obviously i don't know how many there are.. Typically i would like to see something like this: http://www.prima.cse.salford.ac.uk:8080/~ibrarhussain/edit.jpg So i would click on an edit link and it would pre populate the text boxes. I don't have a problem with doing this, but how can i show the correct amount of input textboxes based on how many authors exist for that specific record? Can someone offer some advice please? The input elements are like so: Quote <input type="text" name="author[]" id="author1"/> <input type="text" name="author[]" id="author2"/> <input type="text" name="author[]" id="author3"/> ... ... ... <input type="text" name="author[]" id="author10"/> Some records may have 1 author some may have 10, so how can i do this? Thanks again.. Hi, I'm trying to make a 3 page registration form. On the 3rd page I want it to echo back all the options they have selected. I can get the input type to work but having problems with the selects. First Page Code: [Select] <form action="choose.password.php" method="post"> eMail: <input type="text" name="eMail" /><br /> Forename: <input type="text" name="fname" /><br /> Surname: <input type="text" name="lname" /><br /> Date of Birth: <input type="text" name="dob" /><br /> Gender: <select name="gender"> <option value="male">Male</option> <option value="female">Female</option> </select> <br /> I am not a lawyer: <input type="checkbox" name="lawyer" value="lawyer"> <br /> <br /> <input type="submit" value="Next" /> </form> Second Page Code: [Select] <form action="confirm.details.php" method="post"> <p>email address: <?php echo $_POST["eMail"]; ?></p> <p>password: <input type="password" name="eMail" /></p> <p>Confirm Password: <input type="password" name="eMail" /></p> <p>Hint: <input type="text" name="hint" /></p> <p>My email is correct, I am happy to be sent occassional emails, and i am not a family lawyer. <input type="checkbox" name="lawyer" value="lawyer"></p> <input type="hidden" name="fname" value="<?php echo ($_POST["fname"]); ?>" /> <input type="hidden" name="eMail" value="<?php echo ($_POST["eMail"]); ?>" /> <input type="hidden" name="lname" value="<?php echo ($_POST["lname"]); ?>" /> <input type="hidden" name="dob" value="<?php echo ($_POST["dob"]); ?>" /> <select style="display:none;" name="gender" <?php echo ($_POST["gender"]); ?> /> <p><input type="submit" value="Next" /></p> Third page Code: [Select] <p>Please confirm your details are correct to register.</p> <p>Email Address: <?php echo $_POST["eMail"]; ?> <p>Forename: <?php echo $_POST["fname"]; ?></p> <p>Surname: <?php echo $_POST["lname"]; ?></p> <p>Date of Birth: <?php echo $_POST["dob"]; ?></p> <p>Gender: <?php echo $_POST["gender"]; ?></p> How can I make the select work and echo it back on the third page? Thanks I'm trying to run a readout of a db which runs fine as an individual script. When I embed it in PHP inside an html div container, it bails when it encounters the first ">" and simply outputs the PHP characters from there through the "?>". The rest of the html runs fine before and after. For example, this line echo "<select>"; would output "; and any other php script up to the ?> end, after which it renders html fine. If I run the script as a separate php file, it runs as expected. Any help would be appreciated. Thanks. Code: [Select] id player_id nat nt_caps 13740 28664 97 24 13741 28664 68 0 13742 28664 79 0 16252 42904 15 40 16253 42904 68 0 16254 42904 241 0 That's how my table looks. I want to select the player_id's that have either nt_caps = "0" for every nat OR player_id's that have nt_caps != "0" only for nat = "68". The SQL query I try to use is: SELECT player_id FROM x WHERE nat = '68' AND (nat != '68' AND nt_caps = '0') But then I get player_id '42904' and '28664' because they both have 1 entry that matches the query but I don't want them because they have nt_caps for another nat than nat "68". I hope you understand what I try to achieve. Hi all, Im trying to get the requested genre and compare it with the <SELECT> list to add the word SELECTED on the option. So if the requested genre is the same as the option name them make that the SELECTED option. Cheers. Here's a bit of code I made that does not work Code: [Select] <? function selected(){ if ($_REQUEST['genre'] = $name){ echo"SELECTED"; }} ?> Gen <SELECT class="sort" align="right" onChange="window.location.href=this.options[this.selectedIndex].value;"> <option value="<?=$_SERVER['PHP_SELF'];?>" <?$name = ''; selected(); ?>>Any</option> <option value="<?=$_SERVER['PHP_SELF'];?>?genre=Action" <?$name = 'Action'; selected(); ?>>Action</option> <option value="<?=$_SERVER['PHP_SELF'];?>?genre=Adventure" <?$name = 'Adventure'; selected(); ?>>Adventure</option> <option value="<?=$_SERVER['PHP_SELF'];?>?genre=Animation" <?$name = 'Animation'; selected(); ?>>Animation</option> </SELECT> hi guys ive just finished this task after hours of head scratching since svg is only really supported good in firefox and opera ive chosen firefox as my browser to view this url www.deansignori.com/phpsvgpie/index.php i do need more help with this task but a different problem (creating select box to call different stylesheet and to change from 2d - 3d i have the code set out so that i can explode any segment or change size of slices or change from 2d-3d but i have to do this manually in the code to render different piecharts im wanting to use 1 but change it using a select box and echo my variable into it basically im unsure of the syntax for this problem psuedo code for style maybe something like if select box value isset onchange stylecolour echo stylecolour if select box value isset onchange stylegrey echo stylegrey and for 3d-2d if select box value isset onchnage format3 echo format3 if select box value isset onchange format2 echo format2 this would be on my index page can anyone advise me please regards Dean Hi, what I want to figure out is for instance a person has registered with their country e.g. England. Now if I echo the country in a select box giving the person an option to change their country and Showing the person which currently they have selected already. The select box shows two England`s to select from. Could some one tell me how can I have one of each country and echo their already selected country from the database. I don't know how to explain any better what I am after but just basically there are two Englands showing one which is already selected (echoing from the mysql database) and one is already in the select box. Any help is much appreciated thank you. I'm using a PHP helpdesk script, but when a customer submits a ticket, they are able to assign a category. I want to be able to have the category function so I can move tickets around, but only allow customers to assign to one. (Basically I want to hide the Select Box on the new ticket page) This is the code which displays the select box: Quote <td style="text-align:right" width="150"><?php echo $hesklang['category']; ?>: <font class="important">*</font></td> <td width="80%"><select name="category"> Can you tell me what I can do to "hide" the category select box without getting rid of it? (The page requires a variable for category) Thanks Hi everyone! I need to know how to write two $what_services variables in so it looks for both "R" AND "B".. R and B are values within my db table, here's the code: Code: [Select] <?php $what_services = "R"; $query = "SELECT * FROM companies WHERE what_services = '$what_services' ORDER BY approved DESC, company_name ASC"; $result = mysql_query($query); ?> iv'e tried the following but have gotten undesired results: two what services like so; $what_services = "R"; $what_services = "B"; separating with comma's; $what_services = "R, B"; Using AND; $what_services = "R AND B"; None of which works, what is the correct way to write this? Thanks Hi guys, I'm trying to do make this code so that IF a user owns a property (in this code a bulletfactory) then the BF CP Shows up... Here's the code so far..... Code: [Select] <?php session_start(); include_once"includes/db_connect.php"; include_once"includes/functions.php"; logincheck(); $username=$_SESSION['username']; $query=mysql_query("SELECT * FROM users WHERE username='$username'"); $fetch=mysql_fetch_object($query); $query_bf=mysql_query("SELECT * FROM bf WHERE location='England, Japan, Colombia, USA, Russia, Italy, Turkey'"); $fetch_bf=mysql_fetch_object($query_bf); if (strtolower($fetch_bf->owner) == (strtolower($fetch->username))){ require_once"bulletCP.php"; exit(); } ?> |