Jump to content

_DarkLink_

Members
  • Posts

    45
  • Joined

  • Last visited

    Never

Everything posted by _DarkLink_

  1. What I am trying to do here is: The user inputs in two text areas, the first one is named "list" and the user inputs things like so: field1,field2,field3... field1,field2,field3... and it keeps going on until the user is satisfied of the number of rows of data added into the table. The second one is named "comment" and the user inputs a line of comment for each of the rows that were inserted using the first text area. The rows in the table are then fetched on the page that I need it in the form of a table. But that is already done and works perfectly. Hope I explained it thoroughly, Thanks.
  2. Hello everyone and I would like you guys to have a look at this piece of code. <?php if(isset($_POST['add'])) { $self = $_SERVER['PHP_SELF']; //the $self variable equals this file $ipaddress = ("$_SERVER[REMOTE_ADDR]"); //the $ipaddress var equals users IP //connect $connect = mysql_connect($host,$username,$password) or die('<p class="error">Unable to connect to the database server at this time.</p>'); mysql_select_db($database,$connect) or die('<p class="error">Unable to connect to the database at this time.</p>'); //fetch data $data = htmlspecialchars($_POST['list']); $comment = mysql_real_escape_string($_POST['comment']); $data_lines = explode( "\r\n", $data ); $comment_lines = explode( "\r\n", $comment ); for($i=0;$i<count($data_lines);$i++) { $data_fields = explode( ",", $data_lines[$i]); $time = time(); $queryb = "INSERT INTO coords SET tag='$data_fields[0]', guild='$data_fields[1]', name='$data_fields[2]', base='$data_fields[3]', econ='$data_fields[5]', maxecon='$data_fields[6]', location='$data_fields[4]', comment='$comment_lines[$i]', ipaddress='$ipaddress' ,date='$time';"; // if it succeeds, display message if (@mysql_query($queryb)) { echo('<p class="success">Successful posting of ['.$data_fields[3].']!</p>'); } else { echo('<p class="error">Error could not post ['.$data_fields[3].'] to database!</p>'); } }//end for loop }//end if $_POST['add'] statement ?> As you can see, it gets data received from a form's submission and explodes them into lines. For $data, it explodes it again for each comma. It then inserts everything for each comma, in a new column and for each line, on a new row. Now for $comment, it should be inserting it on a new row for each line, which isn't doing it. Been looking and testing at it for a few days now. The comment column is a varchar of 100 of length. So basically, it does everything i need it to do except inserting $comment on a new row for every line. Any help is appreciated. Thank you in advance.
  3. Hmm, maybe this one could be interesting. http://www.webcheatsheet.com/PHP/file_upload.php "Googled" it out. =P Hope it helps.
  4. You seem to have missed a semi-colon after your SQL query. Try replacing: $sql="INSERT INTO form_data (your_team, opp_team, m_dat, m_tim, g_name, result, writeup) VALUES ('$your_team','$opp_team','$m_dat','$m_tim','$g_name','$result','$writeup') "; With: $sql="INSERT INTO form_data (your_team, opp_team, m_dat, m_tim, g_name, result, writeup) VALUES ('$your_team','$opp_team','$m_dat','$m_tim','$g_name','$result','$writeup'); "; Hope it helps.
  5. Using a simple log-in script should do the trick. Please consider looking at: http://evolt.org/PHP-Login-System-with-Admin-Features?from=800&comments_per_page=50 Hope it helps.
  6. Hmm, I made a search engine that pretty much looks the same for the url. Try: http://usfthetatau.org/index.php?personsname=TysonHuntsman&class=Alpha&name=Alumni Hope it helps.
  7. A syntax error is like writing a word, if you are missing a letter, it is not that word anymore. You seem to be missing a semi-colon at the end of your SQL query. (';') Try replacing: // Add the next batch of values to the query string $query .= "({$final[$i]}, '{$final[$i + 1]}', '{$final[$i + 2]}')"; With: // Add the next batch of values to the query string $query .= "({$final[$i]}, '{$final[$i + 1]}', '{$final[$i + 2]}');"; Hope it helps.
  8. Yes, Now there are a few more problems, The data, when submitted, seems to add another line of void to the database. And the comments are still not added for a new row for each line... I wonder what is wrong. Here is a quick refresh of my script for now. <?php if(isset($_POST['add'])) { $self = $_SERVER['PHP_SELF']; //the $self variable equals this file $ipaddress = ("$_SERVER[REMOTE_ADDR]"); //the $ipaddress var equals users IP //connect $connect = mysql_connect($host,$username,$password) or die('<p class="error">Unable to connect to the database server at this time.</p>'); mysql_select_db($database,$connect) or die('<p class="error">Unable to connect to the database at this time.</p>'); //fetch data $data = htmlspecialchars($_POST['list']); $comment = mysql_real_escape_string($_POST['comment']); $data_lines = explode( "\r\n", $data ); $comment_lines = explode( "\r\n", $comment ); for($i=0;$i<=count($data_lines);$i++) { $data_fields = explode( ",", $data_lines[$i]); $time = time(); $queryb = "INSERT INTO coords SET tag='$data_fields[0]', guild='$data_fields[1]', name='$data_fields[2]', base='$data_fields[3]', econ='$data_fields[5]', maxecon='$data_fields[6]', location='$data_fields[4]', comment='$comment_lines[$i]', ipaddress='$ipaddress' ,date='$time';"; // if it succeeds, display message if (@mysql_query($queryb)) { echo('<p class="success">Successful posting of ['.$data_fields[3].']!</p>'); } else { echo('<p class="error">Error could not post ['.$data_fields[3].'] to database!</p>'); } }//end for loop }//end if $_POST['add'] statement ?> Thanks in advance, Even more help is appreciated.
  9. Oh my, I see to have forgotten to finish close up with a (") and a few of those ('). Please replace: //After that, we insert those variables we defined. $query = "INSERT INTO `categories` (`name`, `parent`) VALUES ($name, $parent); @mysql_query("$query") or die('There was an unexpected error adding the info into the database.'); mysql_close(); With this: //After that, we insert those variables we defined. $query = "INSERT INTO `categories` (`name`,`parent`) VALUES ('$name','$parent');"; @mysql_query("$query") or die('There was an unexpected error adding the info into the database.'); mysql_close();
  10. Getting data from an SQL table is fairly easy,but you must first tell me how is yuor SQL table is arranged. For the excel sheet, it is not that easy, the only current PHP excel sheet writer and reader that I know of and that I have not tested yet is at: http://pear.php.net/package/Spreadsheet_Excel_Writer I recommend downloading it and try to make it to your desires.
  11. Oh never mind, it was me, I seem to have added two 'if' statements. Anyway, how are you counting $lines if it has no value?
  12. After making the form receiving code, you will need the processing code. Such as: <?php if ($POST['submit']) {//if you receive the form submission for the submit button //You do not need to submit an id, since it is auto-increment. $name = $_POST['name'];//if yes then make variable $name as the value of the text area //named name $parent = $_POST['parent'];//and so on //after defining the variables, you will need to connect to your database. //Let's define your database details. $host = 'localhost'; //The host for your database. $username = 'username'; //your username assigned to your database $password = 'password'; //your password assigned to your user & database $database = 'database'; //your database name //After that, we connect to it. $connect = mysql_connect($host,$username,$password) or die('<p class="error">Unable to connect to the database server at this time.</p>'); mysql_select_db($database,$connect) or die('<p class="error">Unable to connect to the database at this time.</p>'); //After that, we insert those variables we defined. $query = "INSERT INTO `categories` (`name`, `parent`) VALUES ($name, $parent); @mysql_query("$query") or die('There was an unexpected error adding the info into the database.'); mysql_close(); } ?>
  13. This is but a simple SQL query. You will need to make a submit form using HTML. example: <form action="whatever.php" method="POST"> <input type="text" name="blah"> <input type="submit" name="submit" value="Submit"> </form> And then make a PHP file to process the submitted data, example: <?php if ($POST['blah']) {//if you receive the form submission for the text area name, blah //if yes then do whatver you need it to do. } ?> Hope it helps
  14. Hello there, well, just went some 'googling' and found a little piece of code that could be interesting. you could modify it so that it will fit your situation. This code for now, reads your page with the table in it and does some processing. After doing so, it writes the data in a text file with a comma as separator for each new line. This is for a simple table form only and is not recommended for sending documents of great value. <?php $remote_url = 'http://example.com/page.html'; $local_file = 'whatever.txt'; $ch = curl_init($remote_url); curl_setopt($ch, CURLOPT_HEADER, 0); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); $str = curl_exec($ch); curl_close($ch); $table_start = strpos($str, '<table>'); $table_end = strpos($str, '</table>') + strlen('</table>'); $table_len = $table_end - $table_start; $table = substr($str, $table_start, $table_len); $data = str_replace('</td>', ',', $table); $data = str_replace(',</tr>', "\n", $data); $data = strip_tags($data); $fp = fopen($local_file, 'w'); fwrite($fp, $data); fclose($fp); ?> Hope this helps.
  15. Hello again, and thanks for replying. But it seems that there is still an error in it, maybe a syntax error or something? The page is returning blank with no error codes, hmmm, I'm still trying to see what's wrong. Anyway, you missed a parenthesis here. =P $data = htmlspecialchars$_POST['list']); Thanks again for replying, More help is appreciated.
  16. Hello there, anyway, this is my first time trying to help someone, so I'll try as best as I can. If I get you correctly, you are wanting the iframe source to change dependently to the url that is in the address bar. So you would need to first make an "if" statement or a "switch" case every possible cases. We will be using both. //Put this anywhere before your "echo" and don't forget to remove the php tags <?php if ($_GET['name']) {//if the url has "?name" after the file. $name = $_GET['name'];//if yes then "$name" = value of "?name" switch ($_GET['class']){//switch = if case 'founding': $class = 'founding'; break; case 'alpha': $class = 'alpha'; break; case 'Beta': $class = 'Beta'; break; case 'Gamma': $class = 'Gamma'; break; }//end switch }//end if ?> Then after making those conditional statements, we need to apply them to your iframe source. <iframe src="<?php echo"http://usfthetatau.org/modules/Alumni/".$class."/".$name.".html";?>" name="form" height="2000" width="440" scrolling="auto" frameborder="no" allowtransparency="true"> Finally, after doing everything, you just need to change the links to the member profiles on the page accordingly: http://usfthetatau.org/modules/Alumni/Alpha/TysonHuntsman.html to http://usfthetatau.org/index.php?name=TysonHuntsman&class=Alpha So all in one, the code should be like so, don't forget to change the links on it, I'm not changing them for you. =P <?php // protect against direct access if (!defined('CPG_NUKE')) { exit; } // initiate the page title $pagetitle .= ''; if ($_GET['name']) {//if the url has "?name" after the file. $name = $_GET['name'];//if yes then "$name" = value of "?name" switch ($_GET['class']){//switch = if case 'founding': $class = 'founding'; break; case 'alpha': $class = 'alpha'; break; case 'Beta': $class = 'Beta'; break; case 'Gamma': $class = 'Gamma'; break; }//end switch }//end if // include the header in the page generation require_once('header.php'); // start a new table in which we will show some text OpenTable(); // show the text on the page echo ' <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en"> <head> <style type="text/css"> body { font-family: Palatino Linotype; } #nav, #nav ul { /* all lists */ padding: 0; margin: 0; list-style: none; float : left; width : 11em; } #nav li { /* all list items */ position : relative; float : left; line-height : 1.25em; margin-bottom : 0px; width: 11em; } #nav li ul { /* second-level lists */ position : absolute; left: -999em; margin-left : 12em; /*Outset of sub menu box (Should match nav li a w\idth vaule PLUS 1 so if this value is 9 w\idth will be */ margin-top : -1.25em; } #nav li ul ul { /* third-and-above-level lists */ left: -999em; } #nav li a { width: 9em; w\idth : 11em; /*Link box width*/ display : block; color : black; font-weight : bold; text-decoration : none; background-color : #454545; border : 0px solid black; padding : 0 0.5em; } #nav li a:hover { color : black; background-color : #747474; border : 0px solid black; } #nav li:hover ul ul, #nav li:hover ul ul ul, #nav li.sfhover ul ul, #nav li.sfhover ul ul ul { left: -999em; } #nav li:hover ul, #nav li li:hover ul, #nav li li li:hover ul, #nav li.sfhover ul, #nav li li.sfhover ul, #nav li li li.sfhover ul { /* lists nested under hovered list items */ left: auto; } #content { margin-left : 12em; } </style> <script type="text/javascript"><!--//--><![CDATA[//><!-- sfHover = function() { var sfEls = document.getElementById("nav").getElementsByTagName("LI"); for (var i=0; i<sfEls.length; i++) { sfEls[i].onmouseover=function() { this.className+=" sfhover"; } sfEls[i].onmouseout=function() { this.className=this.className.replace(new RegExp(" sfhover\\b"), ""); } } } if (window.attachEvent) window.attachEvent("onload", sfHover); //--><!]]></script> </head> <center><h1>Alumni</h1></center> <table align="center" valign="top"> <tr> <td valign="top" style="padding-top : 9px"> <ul id="nav"> <li><a href="#">Founding Class</a> <ul> <li><a href="http://usfthetatau.org/modules/Alumni/Founding/RoyDaniels.html" target="form">1 Roy Daniels</a></li> <li><a href="http://usfthetatau.org/modules/Alumni/Founding/ElijahKlay.html" target="form">2 Elijah Klay</a></li> <li><a href="http://usfthetatau.org/modules/Alumni/Founding/ValerieTait.html" target="form">3 Valerie Tait</a></li> <li><a href="http://usfthetatau.org/modules/Alumni/Founding/AndrewMcEwen.html" target="form">4 Andrew McEwen</a></li> <li><a href="http://usfthetatau.org/modules/Alumni/Founding/DavidLong.html" target="form">5 David Long</a></li> <li><a href="http://usfthetatau.org/modules/Alumni/Founding/SteveLiparulo.html" target="form">6 Steve Liparulo</a></li> <li><a href="http://usfthetatau.org/modules/Alumni/Founding/SheilaMoghadam.html" target="form">7 Sheila Moghadam</a></li> <li><a href="http://usfthetatau.org/modules/Alumni/Founding/CamiloCortes.html" target="form">9 Camilo Cortes</a></li> <li><a href="http://usfthetatau.org/modules/Alumni/Founding/DarenGoldin.html" target="form">11 Daren Goldin</a></li> <li><a href="http://usfthetatau.org/modules/Alumni/Founding/MatthewCrosby.html" target="form">12 Matthew Crosby</a></li> <li><a href="http://usfthetatau.org/modules/Alumni/Founding/ScottEvarts.html" target="form">13 Scott Evarts</a></li> <li><a href="http://usfthetatau.org/modules/Alumni/Founding/DerekKunkle.html" target="form">14 Derek Kunkle</a></li> </ul> </li> <li><a href="#">Alpha Class</a> <ul> <li><a href="http://usfthetatau.org/modules/Alumni/Alpha/TysonHuntsman.html" target="form">15 Tyson Huntsman</a></li> <li><a href="http://usfthetatau.org/modules/Alumni/Alpha/StephenAskew.html" target="form">16 Stephen Askew</a></li> <li><a href="http://usfthetatau.org/modules/Alumni/Alpha/KevinHolmes.html" target="form">20 Kevin Holmes</a></li> <li><a href="http://usfthetatau.org/modules/Alumni/Alpha/ElizabethJones.html" target="form">22 Elizabeth Jones</a></li> <li><a href="http://usfthetatau.org/modules/Alumni/Alpha/AndrewOrtoski.html" target="form">23 Andrew Ortoski</a></li> </ul> </li> <li><a href="#">Beta Class</a> <ul> <li><a href="http://usfthetatau.org/modules/Alumni/Beta/MoeKhawaja.html" target="form">26 Moe Khawaja</a></li> </ul> </li> <li><a href="#">Gamma Class</a> <ul> <li><a href="http://usfthetatau.org/modules/Alumni/Gamma/PatrickTynan.html" target="form">33 Patrick Tynan</a></li> <li><a href="http://usfthetatau.org/modules/Alumni/Gamma/JonathanTodd.html" target="form">35 Jonathan Todd</a></li> <li><a href="http://usfthetatau.org/modules/Alumni/Gamma/JoeJohnson.html" target="form">36 Joe Johnson</a></li> </ul> </li> </ul> </td> <td width="200" valign="top"> </td>'; ?> <td valign="top" style="padding-left : 20px"> <iframe src="<?php echo"http://usfthetatau.org/modules/Alumni/".$class."/".$name.".html";?>" name="form" height="2000" width="440" scrolling="auto" frameborder="no" allowtransparency="true"></td> <?php </tr> </table> </body> </html> // close the table that we have created CloseTable(); // there isn't any need to include the footer, as the index page handles this already // require('footer.php'); Also, you do not need to echo the whole HTML and JavaScript code when you are using PHP, you can just end the PHP script and continue it after the HTML or JavaScript code. Anyway, that's about it, hope I didn't make any mistakes and helped you.
  17. Hello, I am continuing on with my project and here is my problem: I have text areas, the user inputs information in them and after submitting, I would like PHP to get the submitted data and insert them like so: For each new line, insert the data as a new row and for each comma (','), insert them as a new column. SQL structure # # Data for table `coords` # DROP TABLE IF EXISTS coords; CREATE TABLE coords ( id int(10) NOT NULL auto_increment, tag varchar(5) NOT NULL, guild varchar(27) NOT NULL, name varchar(45) NOT NULL, base varchar(16) NOT NULL, econ int(6) NOT NULL, maxecon int(6) NOT NULL, location varchar(12) NOT NULL, comment varchar(100) NOT NULL, ipaddress varchar(45) NOT NULL, date int(12) NOT NULL, PRIMARY KEY (id), UNIQUE id (id), UNIQUE location (location), UNIQUE location_2 (location) ); The structure would resemble this: id tag guild name base econ maxecon location comment ipaddress date 1 tag1 guild1 name1 base1 econ1 maxecon1 location1 comment1 ipaddress1 date1 2 tag2 guild2 name2 base2 econ2 maxecon2 location2 comment2 ipaddress2 date2 Right now, I have tried working up a piece of code with some success. The adding Form database.php <form action="<?php $self ?>" method="post"> <textarea name="list" rows="10" cols="50"></textarea> </textarea> <textarea name="comment" rows="10" cols="50"> </textarea> <input name="add" type="hidden" /> <input type="submit" value="Add" /> Data processing code after form submission. <?php if(isset($_POST['add'])) { $self = $_SERVER['PHP_SELF']; //the $self variable equals this file $ipaddress = ("$_SERVER[REMOTE_ADDR]"); //the $ipaddress var equals users IP //connect $connect = mysql_connect($host,$username,$password) or die('<p class="error">Unable to connect to the database server at this time.</p>'); mysql_select_db($database,$connect) or die('<p class="error">Unable to connect to the database at this time.</p>'); //fetch data $data = htmlspecialchars(mysql_real_escape_string($_POST['list'])); $comment = htmlspecialchars(mysql_real_escape_string($_POST['comment'])); $lines = explode( "\r\n", $data ); $linesa = explode( "\r\n", $comment ); foreach( $lines as $line ) { $bycomma = preg_split('/,/', $line, -1, PREG_SPLIT_DELIM_CAPTURE); $line_words_by_comma=array(); foreach($bycomma as $word) $line_words_by_comma[] = $word; $time = time(); $queryb = "INSERT INTO coords SET tag='$line_words_by_comma[0]', guild='$line_words_by_comma[1]', name='$line_words_by_comma[2]', base='$line_words_by_comma[3]', econ='$line_words_by_comma[5]', maxecon='$line_words_by_comma[6]', location='$line_words_by_comma[4]', comment='$comment', ipaddress='$ipaddress' ,date='$time';"; // if it succeeds, display message if (@mysql_query($queryb)) { echo('<p class="success">Successful posting of ['.$line_words_by_comma[3].']!</p>'); } else { echo('<p class="error">Error could not post ['.$line_words_by_comma[3].'] to database!</p>'); } }//end foreach loop }//end if $_POST['add'] statement ?> The code is adding the data correctly in the database, however, it is not adding like I wanted it to, it is not adding the data for a new line on a new row, it simply doesn't think it exists. And for the comments part, it will add the whole text area inside the same column, which i don't want it to, but a new row for every line of comment. Okay, so that's about it. Any help is appreciated, Thank you in advance.
  18. Well it seems that I have successfully found the problem in my search engine. Here is the solution: I should have replaced this: if ($_GET['search']){ $search = stripslashes($_GET['search']); $types = "types of search"; switch ($_GET['name']) { case 'on': $types = "name"; break; default: $types = " "; break; } switch ($_GET['tag']) { case 'on': $types = "tag"; break; default: $types = " "; break; } switch ($_GET['guild']) { case 'on': $types = "guild"; break; default: $types = " "; break; } ... Search For: <input type="text" name="search"> Player <input type="radio" name="name" value="on"> | Guild Tag <input type="radio" name="tag" value="on"> | Guild Name <input type="radio" name="guild" value="on"> <input type="submit" name="submit" value="Search"> With: if ($_GET['search'] == "do"){ $search = stripslashes($_GET['searchterm']); $types = "types of search"; if ($_GET['name'] == "on"){ $types = "name"; } else if ($_GET['tag'] == "on"){ $types = "tag"; } else if ($_GET['guild'] == "on"){ $types = "guild"; } else { $types = ' '; } ... Search For: <input type="text" name="searchterm"> Player <input type="radio" name="name" value="on"> | Guild Tag <input type="radio" name="tag" value="on"> | Guild Name <input type="radio" name="guild" value="on"> <input type="hidden" name="search" value="do"> <input type="submit" value="Search"> But anyway, this topic is solved, thank you for those that have read this, took interest in this and tried to help me.
  19. Good day, My first post at this forum and I'm asking away already. Anyway, I'm experiencing some problems a project of mine: I have made an SQL database for storing info and I am using PHP to extract what is in it and display the info on a page. After displaying everything, I have also included a search engine on the page, it's fairly simple of what I need it to do: - User enters a search term and selects a choice in one of the three radio buttons, - The processing code looks up the search term under the column that the user picked out with the radio buttons, - And finally it extracts the results and displays them on the page. Okay so, here is my SQL code: # # Data for table `coords` # DROP TABLE IF EXISTS coords; CREATE TABLE coords ( id int(10) NOT NULL auto_increment, tag varchar(5) NOT NULL, guild varchar(27) NOT NULL, name varchar(45) NOT NULL, base varchar(16) NOT NULL, econ int(6) NOT NULL, maxecon int(6) NOT NULL, location varchar(12) NOT NULL, comment varchar(100) NOT NULL, ipaddress varchar(45) NOT NULL, date int(12) NOT NULL, PRIMARY KEY (id), UNIQUE id (id), UNIQUE location (location), UNIQUE location_2 (location) ); After creating the database tables and columns, I have made the PHP page with HTML included in it. database.php A self updating system. <? include ('db.php'); // for db details $self = $_SERVER['PHP_SELF']; //the $self variable equals this file $ipaddress = ("$_SERVER[REMOTE_ADDR]"); //the $ipaddress var equals users IP $connect = mysql_connect($host,$username,$password) or die('<p class="error">Unable to connect to the database server at this time.</p>'); mysql_select_db($database,$connect) or die('<p class="error">Unable to connect to the database at this time.</p>'); //delete any of same address $time = time(); $point = ($time - 604800); $query = "DELETE FROM coords WHERE date < ".$point; //run the query. if it fails, display error $result = @mysql_query("$query"); //End ... (HTML tags and head tags.) ... The default display of the page when you enter it, the search form and the data is being displayed (inside the body tags). <!--start inputbox--> <table width="83%"> <tr> <td style="background: url(http://www.teamdelta.byethost12.com/barbg.jpg) repeat-x top;"> <center><b><font color="#F3EC84">»Search«</font></b></center> </td> </tr> <tr> <td style="background: #222222;"><!-- at the bottom of the page, we display our comment form --> <form method="GET" action="<?php echo $_SERVER['PHP_SELF'];?>" name="searchForm"> <table border ="0" width="100%"> <tr> <td><center> Search For: <input type="text" name="search"> Player <input type="radio" name="name" value="on"> | Guild Tag <input type="radio" name="tag" value="on"> | Guild Name <input type="radio" name="guild" value="on"> <input type="submit" name="submit" value="Search"> </tr> </center> </td> </tr> </form> </td> </tr> </table> <!--end input box--> <center> <table> <table width="83%" border="1"> <tr> <td ><b>Tag</b></td> <td ><b>Guild</b></td> <td ><b>Player</b></td> <td ><b>Base</b></td> <td ><b>Location</b></td> <td ><b>Econ</b></td> <td ><b>Comments</b></td> </tr> <? $query = "SELECT * FROM coords ORDER BY `id` DESC;"; $result = @mysql_query("$query") or die('<p class="error">There was an unexpected error grabbing routes from the database.</p>'); // while we still have rows from the db, display them while ($row = mysql_fetch_array($result)) { $tag = stripslashes($row['tag']); $guild = stripslashes($row['guild']); $name = stripslashes($row['name']); $base = stripslashes($row['base']); $location = stripslashes($row['location']); $comment = stripslashes($row['comment']); $id = stripslashes($row['id']); $econ = stripslashes($row['econ']); $maxecon = stripslashes($row['maxecon']); echo('<tr><center><td>['.$tag.']</td><td>'.$guild.'</td><td>'.$name.'</td><td>'.$base.'</td><td><a href="http://delta.astroempires.com/map.aspx?loc='.$location.'">'.$location.'</a></td><td>'.$econ.'/'.$maxecon.'</td><td>'.$comment.'</td></center></tr>'); } ?> </table> </table> <? } ?> </center> </body> </html> The search processing code when the search form has been submitted. <? include ('db.php'); // for db details $con = mysql_connect($host, $username, $password) or die("Failed to connect to MySQL Server. Error: " . mysql_error()); mysql_select_db($database, $con) or die("Failed to connect to database {$database}. Error: " . mysql_error()); if ($_GET['search']){ $search = stripslashes($_GET['search']); $types = "types of search"; switch ($_GET['name']) { case 'on': $types = "name"; break; default: $types = " "; break; } switch ($_GET['tag']) { case 'on': $types = "tag"; break; default: $types = " "; break; } switch ($_GET['guild']) { case 'on': $types = "guild"; break; default: $types = " "; break; } $connect = mysql_connect($host,$username,$password) or die('<p class="error">Unable to connect to the database server at this time.</p>'); mysql_select_db($database,$connect) or die('<p class="error">Unable to connect to the database at this time.</p>'); $querya = "SELECT * FROM coords WHERE `{$types}` LIKE '%{$search}%' ORDER BY `{$types}`;"; $result = @mysql_query("$querya") or die("There was an error.<br/>" . mysql_error() . "<br />SQL Was: {$searchSQL}"); ?> After processing, display the results on the page. <center> <table> <table width="83%" border="1"> <tr> <td ><b>Tag</b></td> <td ><b>Guild</b></td> <td ><b>Player</b></td> <td ><b>Base</b></td> <td ><b>Location</b></td> <td ><b>Econ</b></td> <td ><b>Comments</b></td> </tr> <? while ($row = mysql_fetch_array($result)) { $tag = stripslashes($row['tag']); $guild = stripslashes($row['guild']); $name = stripslashes($row['name']); $base = stripslashes($row['base']); $location = stripslashes($row['location']); $comment = stripslashes($row['comment']); $id = stripslashes($row['id']); $econ = stripslashes($row['econ']); $maxecon = stripslashes($row['maxecon']); echo('<tr><center><td>['.$tag.']</td><td>'.$guild.'</td><td>'.$name.'</td><td>'.$base.'</td><td><a href="http://delta.astroempires.com/map.aspx?loc='.$location.'">'.$location.'</a></td><td>'.$econ.'/'.$maxecon.'</td><td>'.$comment.'</td></center></tr>'); } echo "<a href=\"database.php\">New Search</a>"; ?> </table> </table> <?} else{ ?> </center> The whole thing put together would be. <? include ('db.php'); // for db details $self = $_SERVER['PHP_SELF']; //the $self variable equals this file $ipaddress = ("$_SERVER[REMOTE_ADDR]"); //the $ipaddress var equals users IP $connect = mysql_connect($host,$username,$password) or die('<p class="error">Unable to connect to the database server at this time.</p>'); mysql_select_db($database,$connect) or die('<p class="error">Unable to connect to the database at this time.</p>'); //delete any of same address $time = time(); $point = ($time - 604800); $query = "DELETE FROM coords WHERE date < ".$point; //run the query. if it fails, display error $result = @mysql_query("$query"); //End ?> ... (HTML tags and head tags.) ... <body> <? include ('db.php'); // for db details $con = mysql_connect($host, $username, $password) or die("Failed to connect to MySQL Server. Error: " . mysql_error()); mysql_select_db($database, $con) or die("Failed to connect to database {$database}. Error: " . mysql_error()); if ($_GET['search']){ $search = stripslashes($_GET['search']); $types = "types of search"; switch ($_GET['name']) { case 'on': $types = "name"; break; default: $types = " "; break; } switch ($_GET['tag']) { case 'on': $types = "tag"; break; default: $types = " "; break; } switch ($_GET['guild']) { case 'on': $types = "guild"; break; default: $types = " "; break; } $connect = mysql_connect($host,$username,$password) or die('<p class="error">Unable to connect to the database server at this time.</p>'); mysql_select_db($database,$connect) or die('<p class="error">Unable to connect to the database at this time.</p>'); $querya = "SELECT * FROM coords WHERE `{$types}` LIKE '%{$search}%' ORDER BY `{$types}`;"; $result = @mysql_query("$querya") or die("There was an error.<br/>" . mysql_error() . "<br />SQL Was: {$searchSQL}"); ?> <center> <table> <table width="83%" border="1"> <tr> <td ><b>Tag</b></td> <td ><b>Guild</b></td> <td ><b>Player</b></td> <td ><b>Base</b></td> <td ><b>Location</b></td> <td ><b>Econ</b></td> <td ><b>Comments</b></td> </tr> <? while ($row = mysql_fetch_array($result)) { $tag = stripslashes($row['tag']); $guild = stripslashes($row['guild']); $name = stripslashes($row['name']); $base = stripslashes($row['base']); $location = stripslashes($row['location']); $comment = stripslashes($row['comment']); $id = stripslashes($row['id']); $econ = stripslashes($row['econ']); $maxecon = stripslashes($row['maxecon']); echo('<tr><center><td>['.$tag.']</td><td>'.$guild.'</td><td>'.$name.'</td><td>'.$base.'</td><td><a href="http://delta.astroempires.com/map.aspx?loc='.$location.'">'.$location.'</a></td><td>'.$econ.'/'.$maxecon.'</td><td>'.$comment.'</td></center></tr>'); } echo "<a href=\"database.php\">New Search</a>"; ?> </table> </table> <?} else{ ?> </center> <!--start inputbox--> <table width="83%"> <tr> <td style="background: url(http://www.teamdelta.byethost12.com/barbg.jpg) repeat-x top;"> <center><b><font color="#F3EC84">»Search«</font></b></center> </td> </tr> <tr> <td style="background: #222222;"><!-- at the bottom of the page, we display our comment form --> <form method="GET" action="<?php echo $_SERVER['PHP_SELF'];?>" name="searchForm"> <table border ="0" width="100%"> <tr> <td><center> Search For: <input type="text" name="search"> Player <input type="radio" name="name" value="on"> | Guild Tag <input type="radio" name="tag" value="on"> | Guild Name <input type="radio" name="guild" value="on"> <input type="submit" name="submit" value="Search"> </tr> </center> </td> </tr> </form> </td> </tr> </table> <!--end input box--> <center> <table> <table width="83%" border="1"> <tr> <td ><b>Tag</b></td> <td ><b>Guild</b></td> <td ><b>Player</b></td> <td ><b>Base</b></td> <td ><b>Location</b></td> <td ><b>Econ</b></td> <td ><b>Comments</b></td> </tr> <? $query = "SELECT * FROM coords ORDER BY `id` DESC;"; $result = @mysql_query("$query") or die('<p class="error">There was an unexpected error grabbing routes from the database.</p>'); // while we still have rows from the db, display them while ($row = mysql_fetch_array($result)) { $tag = stripslashes($row['tag']); $guild = stripslashes($row['guild']); $name = stripslashes($row['name']); $base = stripslashes($row['base']); $location = stripslashes($row['location']); $comment = stripslashes($row['comment']); $id = stripslashes($row['id']); $econ = stripslashes($row['econ']); $maxecon = stripslashes($row['maxecon']); echo('<tr><center><td>['.$tag.']</td><td>'.$guild.'</td><td>'.$name.'</td><td>'.$base.'</td><td><a href="http://delta.astroempires.com/map.aspx?loc='.$location.'">'.$location.'</a></td><td>'.$econ.'/'.$maxecon.'</td><td>'.$comment.'</td></center></tr>'); } ?> </table> </table> <? } ?> </center> </body> </html> The problem is that it is searching for a space string in the columns of the table. (' ') [EDIT] I have sorted out the code a little bit, hope it helps.[EDIT] Any help is appreciated, Thank you in advance.
  20. Good day, My first post at this forum and I'm asking away already. Anyway, I'm experiencing some problems a project of mine: I have made an SQL database for storing info and I am using PHP to extract what is in it and display the info on a page. After displaying everything, I have also included a search engine on the page, it's fairly simple of what I need it to do: - User enters a search term and selects a choice in one of the three radio buttons, - The processing code looks up the search term under the column that the user picked out with the radio buttons, - And finally it extracts the results and displays them on the page. Okay so, here is my SQL code: # # Data for table `coords` # DROP TABLE IF EXISTS coords; CREATE TABLE coords ( id int(10) NOT NULL auto_increment, tag varchar(5) NOT NULL, guild varchar(27) NOT NULL, name varchar(45) NOT NULL, base varchar(16) NOT NULL, econ int(6) NOT NULL, maxecon int(6) NOT NULL, location varchar(12) NOT NULL, comment varchar(100) NOT NULL, ipaddress varchar(45) NOT NULL, date int(12) NOT NULL, PRIMARY KEY (id), UNIQUE id (id), UNIQUE location (location), UNIQUE location_2 (location) ); After creating the database tables and columns, I have made the PHP and HTML page. database.php <? include ('db.php'); // for db details $self = $_SERVER['PHP_SELF']; //the $self variable equals this file $ipaddress = ("$_SERVER[REMOTE_ADDR]"); //the $ipaddress var equals users IP $connect = mysql_connect($host,$username,$password) or die('<p class="error">Unable to connect to the database server at this time.</p>'); mysql_select_db($database,$connect) or die('<p class="error">Unable to connect to the database at this time.</p>'); //delete any of same address $time = time(); $point = ($time - 604800); $query = "DELETE FROM coords WHERE date < ".$point; //run the query. if it fails, display error $result = @mysql_query("$query"); //End ... (head tags and html tags.) ... <body> <? include ('db.php'); // for db details $con = mysql_connect($host, $username, $password) or die("Failed to connect to MySQL Server. Error: " . mysql_error()); mysql_select_db($database, $con) or die("Failed to connect to database {$database}. Error: " . mysql_error()); if ($_GET['search']){ $search = stripslashes($_GET['search']); $types = "types of search"; switch ($_GET['name']) { case 'on': $types = "name"; break; default: $types = " "; break; } switch ($_GET['tag']) { case 'on': $types = "tag"; break; default: $types = " "; break; } switch ($_GET['guild']) { case 'on': $types = "guild"; break; default: $types = " "; break; } $connect = mysql_connect($host,$username,$password) or die('<p class="error">Unable to connect to the database server at this time.</p>'); mysql_select_db($database,$connect) or die('<p class="error">Unable to connect to the database at this time.</p>'); $querya = "SELECT * FROM coords WHERE `{$types}` LIKE '%{$search}%' ORDER BY `{$types}`;"; $result = @mysql_query("$querya") or die("There was an error.<br/>" . mysql_error() . "<br />SQL Was: {$searchSQL}"); ?> <center> <table> <table width="83%" border="1"> <tr> <td ><b>Tag</b></td> <td ><b>Guild</b></td> <td ><b>Player</b></td> <td ><b>Base</b></td> <td ><b>Location</b></td> <td ><b>Econ</b></td> <td ><b>Comments</b></td> </tr> <? while ($row = mysql_fetch_array($result)) { $tag = stripslashes($row['tag']); $guild = stripslashes($row['guild']); $name = stripslashes($row['name']); $base = stripslashes($row['base']); $location = stripslashes($row['location']); $comment = stripslashes($row['comment']); $id = stripslashes($row['id']); $econ = stripslashes($row['econ']); $maxecon = stripslashes($row['maxecon']); echo('<tr><center><td>['.$tag.']</td><td>'.$guild.'</td><td>'.$name.'</td><td>'.$base.'</td><td><a href="http://delta.astroempires.com/map.aspx?loc='.$location.'">'.$location.'</a></td><td>'.$econ.'/'.$maxecon.'</td><td>'.$comment.'</td></center></tr>'); } echo "<a href=\"database.php\">New Search</a>"; ?> </table> </table> <?} else{ ?> </center> <!--start inputbox--> <table width="83%"> <tr> <td style="background: url(http://www.teamdelta.byethost12.com/barbg.jpg) repeat-x top;"> <center><b><font color="#F3EC84">»Search«</font></b></center> </td> </tr> <tr> <td style="background: #222222;"><!-- at the bottom of the page, we display our comment form --> <form method="GET" action="<?php echo $_SERVER['PHP_SELF'];?>" name="searchForm"> <table border ="0" width="100%"> <tr> <td><center> Search For: <input type="text" name="search"> Player <input type="radio" name="name" value="on"> | Guild Tag <input type="radio" name="tag" value="on"> | Guild Name <input type="radio" name="guild" value="on"> <input type="submit" name="submit" value="Search"> </tr> </center> </td> </tr> </form> </td> </tr> </table> <!--end input box--> <center> <table> <table width="83%" border="1"> <tr> <td ><b>Tag</b></td> <td ><b>Guild</b></td> <td ><b>Player</b></td> <td ><b>Base</b></td> <td ><b>Location</b></td> <td ><b>Econ</b></td> <td ><b>Comments</b></td> </tr> <? $query = "SELECT * FROM coords ORDER BY `id` DESC;"; $result = @mysql_query("$query") or die('<p class="error">There was an unexpected error grabbing routes from the database.</p>'); // while we still have rows from the db, display them while ($row = mysql_fetch_array($result)) { $tag = stripslashes($row['tag']); $guild = stripslashes($row['guild']); $name = stripslashes($row['name']); $base = stripslashes($row['base']); $location = stripslashes($row['location']); $comment = stripslashes($row['comment']); $id = stripslashes($row['id']); $econ = stripslashes($row['econ']); $maxecon = stripslashes($row['maxecon']); echo('<tr><center><td>['.$tag.']</td><td>'.$guild.'</td><td>'.$name.'</td><td>'.$base.'</td><td><a href="http://delta.astroempires.com/map.aspx?loc='.$location.'">'.$location.'</a></td><td>'.$econ.'/'.$maxecon.'</td><td>'.$comment.'</td></center></tr>'); } ?> </table> </table> <? } ?> </center> </body> </html> ?> The problem now is that when I enter a search term, it seems to be searching a space string for the column. (' ') Any help is appreciated, Thank you in advance.
×
×
  • 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.