Jump to content

Solar

Members
  • Posts

    145
  • Joined

  • Last visited

Everything posted by Solar

  1. Say I have a forum with tables that look like this in the mysql database; fidforumdesccat 1GeneralTalk About Anythinggeneral 2HobbiesTalk About Hobbiesgeneral 3HTML HelpGet help on HTMLhelp How can I use this; $sql="SELECT * FROM $tbl_name ORDER BY fid"; By grabbing just the one column for example general? Thanks.
  2. Ahh Stupid me! So my answer is; date("Y-m-d H:i:s"); I added Year, Month, and Date as well. Thanks for your help!
  3. Using $_SERVER['REQUEST_TIME'] How could I make it so it just echo's HOUR:MINUTE:SECOND ?? www.php.net doesn't give enough information for that.
  4. I would love to create a simple coding that will allow users on my website to post their videos and allready be embed with an output source Form: <h2 class="title">Submit Youtube Video</h2> <p><form action="insert.php" method="post"> Channel Name: <span class="style1">(Channel name of the video you are posting, this will keep submitted videos more organized) </span><br /> <input name="channel" type="text" size="50" /> <br /> Title of Video: <br /> <input name="title" type="text" size="50" /> <br /> URL:<br /> <input name="url" type="text" size="50" /> <br /> Category: <span class="style1">(Please insert the type of category well suited) </span><br /> <select size="1" input name="categories"> <option>Autos Vehicles</option> <option>Comedy</option> <option>Education</option> <option>Entertainment</option> <option>Film Animation</option> <option>Gaming</option> <option>Howto Style</option> <option>Music</option> <option>News Politics</option> <option>People Blogs</option> <option>Pets Animals</option> <option>Science Technology</option> <option>Sports</option> <option>Travel Events</option> <option>Shows</option> <option>Movies</option> <option>Contests</option> <option>Events</option> </select> <input name="name" type="hidden" size="50" value="<?php echo "$session"; ?>"/> <br /> <input type="submit" value="Submit Video" /> </form> Output: $sql = "SELECT * FROM info WHERE channel = '" . htmlspecialchars($_GET["name"]) . "' LIMIT $offset, $rowsperpage"; $result = mysql_query($sql, $conn) or trigger_error("SQL", E_USER_ERROR); // while there are rows to be fetched... while ($list = mysql_fetch_assoc($result)) { // echo data echo $list[''] . "<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\" style=\"border-collapse: collapse\" bordercolor=\"#111111\" width=\"100%\"> <tr> <td width=\"50%\"> <table border=\"0\" cellpadding=\"0\" cellspacing=\"0\" style=\"border-collapse: collapse\" bordercolor=\"#111111\" width=\"100%\"> <tr> <td width=\"100%\"><a href=\"watch.php?name=" . $list['title'] . "\">" . $list['title'] . "</a><br>Channel: <a href=\"channel.php?name=" . $list['channel'] . "\">" . $list['channel'] . "<br></a>Submitted By: <a href=\"userinfo.php?user=" . $list['name'] . "\">" . $list['name'] . "</a></td> <td width=\"70\" align=\"right\"><img border=\"0\" src=\"http://i1.ytimg.com/vi/" . $list['url2'] . "/1.jpg\"></a></td> </tr> </table> </td> </tr> </table><hr color=\"#C0C0C0\" size=\"1\">"; } This is what I would love to do. While a user submits a URL video for example; To the database row URL. Is is possible to when the user submits the link in the INPUT Code to take uImk2RgCq_U From the URL and copy it to database row URL2. So end results idnamechanneltitleurlurl2categories 1SubmittedByMyWebsite'sUsername1nterwebsThe 20 oldest Videos ever on Youtube uImk2RgCq_UEntertainment Thanks for your help!
  5. I will make a new topic with a different way then. Thanks.
  6. Thanks for the replies and I was working on it and it is what I am looking for, somewhat. The database URL would be; 'http://phpfreaks.com/profile?photo=php' When it echo's I would like it to transform to; 'php' So pretty much take out (Is what I meant); 'http://phpfreaks.com/profile?photo=' Thanks for the replies so far, its just great to learn!!, and the codes you've been posting I have an idea for those for my site as well!
  7. Exactly what I am looking for the182guy! Thanks a lot for all of your help everyone who has posted! One very last Question for future refrence. id name url 1 phpfreaks http://phpfreaks.com/profile?photo=php Using; $url = "http://phpfreaks.com/profile?photo="; $filename = basename($url); How would I cut out /profile?photo= ?
  8. Sorry I modified my post to make more sense out of it.
  9. Thanks for the fast replies! I really appreciate it. Answer to Question 1 works like a charm, I even used WHERE gender = '" . htmlspecialchars($_GET["name"]) . "' and works like a charm. I want to go more in depth with Question # 2. Say I have a script like this; <?php echo $list[''] . "<img border=\"0\" src=\"http://google.com/" . $list['url'] . "\">"; ?> And what comes out is; http://google.com/http://phpfreaks.com/logo.png Using; $url = 'http://phpfreaks.com/logo.png'; $filename = basename($url);// $filename is logo.png How would I import that into my code? Better explination; So when a user submits a form It asks for URL Instead of trimming it to logo.png on the spot, I would like to trim the URL when the list shows. So the end results turn into; http://google.com/logo.png
  10. Question #1: Lets say if I have a database that looks like this; id username gender 1 Steven Male 2 Emily Female 3 Jason Male Is it possible to SELECT gender and just list the column that has male? How would I go by doing so? Question #2 Lets say I have a database like this; idnameurl 1phpfreakshttp://phpfreaks.com/logo.png Is it possible; After Selecting the database, To when you list the row "URL" to trim http://phpfreaks.com/ to just show logo.png? How would I go by doing so? Thanks a lot for your time and thankyou for replying below in this topic.
  11. My fault, I made a mistake in the database wise. I've re-edit the code to my likings and it works like a charm. Thanks for your help and time.
  12. Thankyou for your reply. That Bracket was never there until I added to try it out and I kept it in the script sorry. But there is still the same error.. This one is a tough one. I can't even see it.
  13. <?php $dbHost = 'localhost'; // localhost will be used in most cases // set these to your mysql database username and password. $dbUser = 'root'; $dbPass = 'passwordhere'; $dbDatabase = 'login'; // the database you put the table into. $con = mysql_connect($dbHost, $dbUser, $dbPass) or trigger_error("Failed to connect to MySQL Server. Error: " . mysql_error()); mysql_select_db($dbDatabase) or trigger_error("Failed to connect to database {$dbDatabase}. Error: " . mysql_error()); ?> <html> <title>My Simple Search Form</title> <style type="text/css"> #error { color: red; } </style> <?php echo (count($error) > 0)?"The following had errors:<br /><span id=\"error\">" . implode("<br />", $error) . "</span><br /><br />":""; ?> <form method="GET" action="<?php echo $_SERVER['PHP_SELF'];?>" name="searchForm"> Search For: <input type="text" name="search" value="<?php echo isset($searchTerms)?htmlspecialchars($searchTerms):''; ?>" /><br /> Search In:<br /> Body: <input type="checkbox" name="id" value="on" <?php echo isset($_GET['id'])?"checked":''; ?> /> | Title: <input type="checkbox" name="username" value="on" <?php echo isset($_GET['username'])?"checked":''; ?> /> | Description: <input type="checkbox" name="gender" value="on" <?php echo isset($_GET['gender'])?"checked":''; ?> /><br /> Match All Selected Fields? <input type="checkbox" name="matchall" value="on" <?php echo isset($_GET['matchall'])?"checked":''; ?><br /><br /> <input type="submit" name="submit" value="Search!" /> </form> <?php echo (count($results) > 0)?"Your search term: {$searchTerms} returned:<br /><br />" . implode("", $results):""; ?> <?php // Set up our error check and result check array $error = array(); $results = array(); // First check if a form was submitted. // Since this is a search we will use $_GET if (isset($_GET['search'])) { $searchTerms = trim($_GET['search']); $searchTerms = strip_tags($searchTerms); // remove any html/javascript. } if (strlen($searchTerms) < 3) { $error[] = "Search terms must be longer than 3 characters."; }else { $searchTermDB = mysql_real_escape_string($searchTerms); // prevent sql injection. } // If there are no errors, lets get the search going. if (count($error) < 1) { $searchSQL = "SELECT id, username, gender FROM users WHERE "; // grab the search types. $types = array(); $types[] = isset($_GET['id'])?"`id` LIKE '%{$searchTermDB}%'":''; $types[] = isset($_GET['username'])?"`username` LIKE '%{$searchTermDB}%'":''; $types[] = isset($_GET['gender'])?"`gender` LIKE '%{$searchTermDB}%'":''; $types = array_filter($types, "removeEmpty"); // removes any item that was empty (not checked) if (count($types) < 1) $types[] = "`gender` LIKE '%{$searchTermDB}%'"; // use the body as a default search if none are checked $andOr = isset($_GET['matchall'])?'AND':'OR'; $searchSQL .= implode(" {$andOr} ", $types) . " ORDER BY `id`"; // order by title. $searchResult = mysql_query($searchSQL) or trigger_error("There was an error.<br/>" . mysql_error() . "<br />SQL Was: {$searchSQL}"); if (mysql_num_rows($searchResult) < 1) { $error[] = "The search term provided {$searchTerms} yielded no results."; }else { $results = array(); // the result array $i = 1; while ($row = mysql_fetch_assoc($searchResult)) { $results[] = "{$i}: {$row['id']}<br />{$row['username']}<br />{$row['gender']}<br /><br />"; $i++; } } } } function removeEmpty($var) { return (!empty($var)); } ?>
  14. One of the search tutorials listed on phpfreaks homepage left me with an error. Parse error: syntax error, unexpected T_STRING in C:\xampp\htdocs\searchuser.php on line 46 I read that this error could lead into missing quotation marks, brackets, and semi-colons. Highlighted in red is line 46. Highlighted in yellow is what I added but still same error on line 46. // Set up our error check and result check array $error = array(); $results = array(); // First check if a form was submitted. // Since this is a search we will use $_GET if (isset($_GET['search'])) { $searchTerms = trim($_GET['search']); $searchTerms = strip_tags($searchTerms); // remove any html/javascript. } if (strlen($searchTerms) < 3) { $error[] = "Search terms must be longer than 3 characters."; }else { $searchTermDB = mysql_real_escape_string($searchTerms); // prevent sql injection. } // If there are no errors, lets get the search going. if (count($error) < 1) { $searchSQL = "SELECT id, username, gender FROM users WHERE "; // grab the search types. $types = array(); $types[] = isset($_GET['id'])?"`id` LIKE '%{$searchTermDB}%'":''; $types[] = isset($_GET['username'])?"`username` LIKE '%{$searchTermDB}%'":''; $types[] = isset($_GET['gender'])?"`gender` LIKE '%{$searchTermDB}%'":''; $types = array_filter($types, "removeEmpty"); // removes any item that was empty (not checked) if (count($types) < 1) $types[] = "`gender` LIKE '%{$searchTermDB}%'"; // use the body as a default search if none are checked $andOr = isset($_GET['matchall'])?'AND':'OR'; $searchSQL .= implode(" {$andOr} ", $types) . " ORDER BY `id`"; // order by title. $searchResult = mysql_query($searchSQL) or trigger_error("There was an error.<br/>" . mysql_error() . "<br />SQL Was: {$searchSQL}"); if (mysql_num_rows($searchResult) < 1) { $error[] = "The search term provided {$searchTerms} yielded no results."; }else { $results = array(); // the result array $i = 1; while ($row = mysql_fetch_assoc($searchResult)) { $results[] = "{$i}: {$row['id']}<br />{$row['username']}<br />{$row['gender']}<br /><br />"; $i++; } } } } function removeEmpty($var) { return (!empty($var)); } IN PHP MODE: <?php // Set up our error check and result check array $error = array(); $results = array(); // First check if a form was submitted. // Since this is a search we will use $_GET if (isset($_GET['search'])) { $searchTerms = trim($_GET['search']); $searchTerms = strip_tags($searchTerms); // remove any html/javascript. } if (strlen($searchTerms) < 3) { $error[] = "Search terms must be longer than 3 characters."; }else { $searchTermDB = mysql_real_escape_string($searchTerms); // prevent sql injection. } // If there are no errors, lets get the search going. if (count($error) < 1) { $searchSQL = "SELECT id, username, gender FROM users WHERE "; // grab the search types. $types = array(); $types[] = isset($_GET['id'])?"`id` LIKE '%{$searchTermDB}%'":''; $types[] = isset($_GET['username'])?"`username` LIKE '%{$searchTermDB}%'":''; $types[] = isset($_GET['gender'])?"`gender` LIKE '%{$searchTermDB}%'":''; $types = array_filter($types, "removeEmpty"); // removes any item that was empty (not checked) if (count($types) < 1) $types[] = "`gender` LIKE '%{$searchTermDB}%'"; // use the body as a default search if none are checked $andOr = isset($_GET['matchall'])?'AND':'OR'; $searchSQL .= implode(" {$andOr} ", $types) . " ORDER BY `id`"; // order by title. $searchResult = mysql_query($searchSQL) or trigger_error("There was an error.<br/>" . mysql_error() . "<br />SQL Was: {$searchSQL}"); if (mysql_num_rows($searchResult) < 1) { $error[] = "The search term provided {$searchTerms} yielded no results."; }else { $results = array(); // the result array $i = 1; while ($row = mysql_fetch_assoc($searchResult)) { $results[] = "{$i}: {$row['id']}<br />{$row['username']}<br />{$row['gender']}<br /><br />"; $i++; } } } } function removeEmpty($var) { return (!empty($var)); } ?> Thanks.
  15. Solar

    UserID

    Thankyou for all your help! It's been really appreciated, as silly as my question was, I hope more people have found there solution by looking at mine. Thanks abunch.
  16. Solar

    UserID

    Thanks for all the replies. CREATE TABLE users2 (id int(5), userid varchar(32), username varchar(30), PRIMARY KEY (id));INSERT INTO users2 (userid, username) SELECT userid, username FROM users Works, but it seems to me like it doesn't want to. It only does the first row and then finds the error: #1062 - Duplicate entry '0' for key 1 So does this mean that once it hits the second row in table users, it wants to put the ID for username Emily as 0? When I username Steven is the first row allready at 0? Thanks for the troubles.
  17. Solar

    UserID

    I'm sorry maybe I didn't clarify myself as well enough. All 200 of my members have userid's like; For example; Username: Steven Userid: fa98c641369c6d9798314c97df52f1be Username: Emily Userid: 6a5cf112a6e83fac907d0b45a53bba91 Username: tyman Userid: f874f5ca582697f25465e521e79ea903 So what I would like to have is still Userid, But have a new table; id int(5) Username: Steven Id: 1 Userid: fa98c641369c6d9798314c97df52f1be Username: Emily Id: 2 Userid: 6a5cf112a6e83fac907d0b45a53bba91 Username: tyman Id: 3 Userid: f874f5ca582697f25465e521e79ea903 What I am trying to ask is, is there a query that will allow itself to go through every username and give it an ID Number for example like above. Or does it need to be done manually?
  18. Solar

    UserID

    Thanks for your help. The two first mysql queries worked but this last one isn't. I can't see why it doesn't :/ UPDATE TABLE usertest SET (id=CONVERT(userid, UNSIGNED)) SQL query: UPDATE TABLE usertest SET( id = CONVERT( userid, UNSIGNED ) ) MySQL said: #1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'TABLE usertest SET (id=CONVERT(userid, UNSIGNED))' at line 1
  19. Solar

    UserID

    Hello and Thankyou for your time; I would love to change; userid varchar(32) utf8_swedish_ci Yes NULL to; id int(5) But my database keeps messing up and I am not able to log into my website when this is changed. I have close to 200 registered members. Is there a way to change userid to id int(5) and have all 200 members automatically counted inside the table? Like for example; ID: 1 USERNAME: Steven ID: 2 USERNAME: Solar etc. If this cannot work, is it possible to add table id int(5) and have it auto counted like above? Thanks!
  20. Solar

    Echo SQL.

    Works Perfectly, thankyou for your help!
  21. Hello and before I say anything, thankyou for your time. I have many different things on my user's profile page but I would like to expand it. The user profile displays there username, a quick bio, a profile picture, and so on... I would like to display something like the following; echo "<a href=\"".$req_user_info['facebook']."\"><img src=\"facebook.png\"></a>"; My question is; Is it possible for a person who hasn't edit there profile for the facebook field to hide on their actual profile page until they fill it out? And how would I go by doing so?
  22. Doh I'm an idiot.. I kinda said my questions in the wrong way. I didn't mean that but I think the "Where Clause" is the answer I am looking for! Thanks!
  23. This will be a hard one to explain, or maybe I am going over board for nothing. $session = $_SESSION['username']; I have the session as username, Thats fine. $sql = "SELECT id, members, friendwith userlevel FROM friends ORDER BY id DESC,id LIMIT $offset, $rowsperpage"; Using the Pagenation script provided by PHP Freaks, works perfectly. I want to change the "Members" to the variable to $session but it's not working properly. What I want to do is list a simple friendlist using; echo $list[''] . "<a href=\"userinfo.php?user=" . $list['$session'] . "\">" . $list['$session'] . " <br />"; So when the session = Username, change that with Members for the SQL Database which for example; $session=Steven. I really confused myself, Once again I may be going over then what I need to. I'm guess my Question is, Is it possible to change the SQL statement from Members to show a specific name for eg. $session->Username? Thanks.
  24. Hello I want to use this forum tutorial from; http://www.phpeasystep.com/phptu/12.html I would rather change; <input name="name" type="text" id="name" size="50" /> <input name="email" type="text" id="email" size="50" /> into; <input name="name" type="[i]hidden[/i]" id="name" size="50" value="[i]echo username[/i]"/> <input name="email" type="[i]hidden[/i]" id="email" size="50" value="[i]echo email[/i]" /> But my username and email are in a different mysql table, How can I echo the username and e-mail from a different mysql table to submit into this form? Thanks, Steven
  25. Works like a charm, I added a Exclamation mark because it wasn't working and re-arranged some wording; Soultion: <?php $req_user_info = $database->getUserInfo($req_user); if(!$req_user){ echo "<img src=\"http://URLHERE/photo/".$req_user_info['username']."\"\width=\"400\" height=\"300\" >"; }else{ echo "no pic"; } ?> Thanks again bro. I didn't like to do with mysql, thats why I needed coding like this.. Perfect.
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.