Jump to content

87dave87

Members
  • Posts

    86
  • Joined

  • Last visited

Posts posted by 87dave87

  1. Trying to show results of address details from my database.

     

    But the if statement for 'if there is no result' isnt working... its just displaying 'no recordno recordno record '

     

    I want this to skip if there is no result (using the 'no record' as test text)

     

    Also how can I skip showing a detail, such as 'echo "$addressline2<br>";' if there is nothing in that field on the database?

     

    Mailshots from
    <?
    $query = "SELECT * FROM userfield";
    $result = mysql_query($query);
    $num = mysql_numrows($result);
    print $num
    ?>
    Members
    
    </b>
    
    <p>
    
    <?
    $i=0;
    while ($i < $num) {
    
    $firstnames=mysql_result($result,$i,"field5");
    $surname=mysql_result($result,$i,"field6");
    $housenamenumber=mysql_result($result,$i,"field7");
    $addressline1=mysql_result($result,$i,"field8");
    $addressline2=mysql_result($result,$i,"field9");
    $addressline3=mysql_result($result,$i,"field10");
    $citycounty=mysql_result($result,$i,"field11");
    $postcode=mysql_result($result,$i,"field12");
    $country=mysql_result($result,$i,"field13");
    
    if($result="")
    {
    echo "no record";
    }
    
    else
    {
    echo "-- TEST --<br>";
    echo "$firstnames $surname<br>";
    echo "$housenamenumber $addressline1<br>";
    echo "$addressline2<br>";
    echo "$addressline3<br>";
    echo "$citycounty<br>";
    echo "$postcode<br>";
    echo "$country<br>";
    echo "-- TESTEND --<br>";
    echo "<br>";
    }
    $i++;
    }
    ?>
    
    </p>
    
    <?
    mysql_close($conn);
    ?>
    

     

    For the page click here

  2. I am having a problem validating my stylesheet.

     

    See: http://jigsaw.w3.org/css-validator/validator?uri=http%3A%2F%2Fwww.emulators.cc%2F&warning=1&profile=css21&usermedium=all

     

    When I change this to what it says in the valid css section the table height obviously reduces, how can I get around this and stay valid?  If i can't change this in the stylesheet Im going to need to change the height on each page... which is over a hundred!

     

    Thanks,

     

    David.

  3. Hi,

     

    As quite a few of you may have noticed, I have been developing www.emulators.cc over the last 6 months with help along the way from users of this forum.

     

    I am coming to the end of the development and as I am no expert in securing my website's mysql databases I need some of you to help me with checking the website for security glitches, e.g. users running queries through my input form... the search box at the top of the page.

     

    Any advice would be appreciated.

     

    Thanks,

     

    David  ;D

  4. I have double checked and it works fine, although if I type in 2 records it shows this: -

     

    "Error

    Column 'version' in field list is ambiguous

    select version, os, platform, details from windows_genesis, mac_atari2600 where emulator LIKE '%gens%' OR platform LIKE '%gens%' order by platform asc, emulator asc"

     

    How would I get around that? Surely searching through multiple tables is a regular thing to do when making a search script?

  5. Hi, I have been trying to search multiple tables in my database (I have 60+ tables in one database) for records that are LIKE what the user has typed into a search box.

     

    I have generated a table list using SHOW TABLES, I am struggling on the last part to display the results, the area that I need help with is the PHP code which starts with 'if (isset($_POST['emusearch']) && strlen(trim($_POST['emusearch'])) > 0)'

     

    I am trying to use 'show tables' in the row[0] 'select emulator, version, os, platform, details from ".$row[0]." in $search_query, see the third RED php section in the code below.

     

    The error which occurs in the browser when trying to run is:

     

    Error

    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 'where emulator LIKE '%stella%' OR platform LIKE '%stella%' order by platform asc' at line 1

    select emulator, version, os, platform, details from where emulator LIKE '%stella%' OR platform LIKE '%stella%' order by platform asc, emulator asc

     

     

    Full page code is: -

     

    <?
    include($_SERVER['DOCUMENT_ROOT'] . '/includes/head.php'); 
    include($_SERVER['DOCUMENT_ROOT'] . '/includes/dbconnect.php'); 
    if (empty($_POST['emusearch'])) 
       { 
       echo "<meta http-equiv='refresh' content='0; URL=/noresults.php'>";  
       exit(); 
       } 
    else 
       { 
        $query = mysql_query('show tables');     
        $result = $query or die(mysql_error()); 
        $searchresults = array(); 
        while($row = mysql_fetch_array($result)){ 
            $search_query = "select emulator, version, os, platform, details from ".$row[0]." where emulator LIKE '%".mysql_real_escape_string($_POST["emusearch"])."%' OR platform LIKE '%".mysql_real_escape_string($_POST["emusearch"])."%' order by platform asc, emulator asc";  
    
            $search = mysql_query($search_query); 
             
            while ($row2 = mysql_fetch_assoc($search)) { // new 
                 $searchresults[] = $row2; // new 
            } // new 
        }   
         
        if(count($searchresults) < 1)  
        {  
        echo "<meta http-equiv='refresh' content='0; URL=/noresults.php'>";  
        exit(); 
        } else { 
        } 
    }  
    ?> 
    
    <table width="600" border="0"> 
      <tr> 
        <td> 
        <table width=600 border=0 cellpadding=0 cellspacing=0> 
        <tr> 
            <td> 
                <img src="/images/searchresults.jpg" width=300 height=30 alt="Search Results"></td> 
            <td> 
                <table border="0" cellpadding="0" cellspacing="0" width="290" height="30" background="/images/barmid.jpg"> 
                  <tr> 
                    <td> 
                    <div align="right"> 
    <? 
    echo "<span class='footer'>"; 
    echo $num_rows; 
    echo " ";
    echo $_POST['emusearch'];
    if ($num_rows == "1") 
    { 
    echo " emulator found</span>";
    } 
    else
    { 
    echo " emulators found</span>";
    } 
    ?> 
                    </div></td> 
                  </tr> 
                </table> 
            </td> 
            <td> 
                <img src="/images/barend.jpg" width=10 height=30 alt="Search Results"></td> 
        </tr> 
    </table> 
        </td> 
      </tr> 
      <tr> 
        <td><table width="100%" border="0" cellpadding="0" cellspacing="0"> 
            <tr class="tablehead"> 
              <td width="240">Emulator</td> 
              <td width="120">Version</td> 
              <td width="120">OS</td> 
              <td width="120">Platform</td> 
              <td width="120">Details</td> 
            </tr> 
    <? 
    if (isset($_POST['emusearch']) && strlen(trim($_POST['emusearch'])) > 0)
    { 
    $search_query = "select emulator, version, os, platform, details from ".$row[0]." where emulator LIKE '%".mysql_real_escape_string($_POST["emusearch"])."%' OR platform LIKE '%".mysql_real_escape_string($_POST["emusearch"])."%' order by platform asc, emulator asc"; 
    
    if(!$rs = mysql_query($search_query))
    	{ 
    	echo "Error<br>".mysql_error()."<br>".$search_query; 
    	exit(); 
    	} 
    else
    	{ 
    	$num_rows = mysql_num_rows($rs); 
    	while ($emulators = mysql_fetch_row($rs)) 
    		{ 
    		echo "<tr>"; 
    		foreach ($emulators as $field)
    		{ 
           		echo "<td>$field</td>\n"; 
            	} 
                echo "</tr>\n"; 
          		} 
       		} 
    } 
    ?>
          </table> 
    </table> 
    
    <? 
    require_once('includes/search.php'); 
    require_once('includes/foot.php'); 
    ?>
    

  6. thanks! this maybe the wrong place to ask but does anyone have any idea on how i could implement that code into the following code where the from ".$query1."  part is? im trying to do this to search all tables in my database: -

     

    <?

    include($_SERVER['DOCUMENT_ROOT'] . '/includes/head.php');

    include($_SERVER['DOCUMENT_ROOT'] . '/includes/dbconnect.php');

    $query1 = mysql_query('show tables');

    $search_query = "select emulator, version, os, platform, details from ".$query1." where emulator LIKE '%".mysql_real_escape_string($_POST["emusearch"])."%' OR platform LIKE '%".mysql_real_escape_string($_POST["emusearch"])."%' order by platform asc, emulator asc";

     

    if (empty($_POST['emusearch']))

    {

    echo "<meta http-equiv='refresh' content='0; URL=/noresults.php'>";

    exit();

    }

    else

    {

    $search = mysql_query($search_query);

    $num_rows = mysql_num_rows($search);

     

    if($num_rows < 1)

    {

      echo "<meta http-equiv='refresh' content='0; URL=/noresults.php'>";

    exit();

    }

    }

    ?>

  7. I have the following code which displays all of the tables in my database with a comma in between each, e.g. "table1, table2, " the problem is that the last comma needs to be removed, I have looked into this and have been told about rtrim or implode functions, although ive tried both in my code with no joy, the following is my code using rtrim which still displays the last comma...

     

    <?php

    include($_SERVER['DOCUMENT_ROOT'] . '/includes/dbconnect.php');

    $query = mysql_query('show tables');

    $result = $query or die(mysql_error());

     

    while($row = mysql_fetch_array($result)){

    echo $row[0],", ";

    $row[0] = rtrim( $row[0],", ");

    }

    ?>

  8. toonmariner ive tried to do that, then i get this error: -

     

    Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/irrm3a/public_html/search.php on line 15

     

    This is the full code: -

     

    <?
    include($_SERVER['DOCUMENT_ROOT'] . '/includes/head.php'); 
    include($_SERVER['DOCUMENT_ROOT'] . '/includes/dbconnect.php'); 
    $query1 = mysql_query('show tables'); 
    $search_query = "select emulator, version, os, platform, details from '$query1' where emulator LIKE '%".mysql_real_escape_string($_POST["emusearch"])."%' OR platform LIKE '%".mysql_real_escape_string($_POST["emusearch"])."%' order by platform asc, emulator asc"; 
    
    if (empty($_POST['emusearch']))
    {
    echo "<meta http-equiv='refresh' content='0; URL=/noresults.php'>"; 
    exit();
    }
    else
    {
    $search = mysql_query($search_query);
    $num_rows = mysql_num_rows($search); 
    
    	if($num_rows < 1) 
    	{ 
       		echo "<meta http-equiv='refresh' content='0; URL=/noresults.php'>"; 
    	exit();
    	}
    }
    ?>
    

  9. $query1 = mysql_query('show tables');

    $search_query = "select emulator, version, os, platform, details from "$query1" where emulator LIKE '%".mysql_real_escape_string($_POST["emusearch"])."%' OR platform LIKE '%".mysql_real_escape_string($_POST["emusearch"])."%' order by platform asc, emulator asc";

     

    Im trying to show all tables in 'query1': -

     

    Parse error: syntax error, unexpected T_VARIABLE in /home/irrm3a/public_html/search.php on line 5

     

  10. <input name="emusearch" type="text" value="e.g. Stella or Atari 2600" onblur="if(this.value=='') this.value='e.g. Stella or Atari 2600';">
    

     

    I search 'stella' and it returned a result the result of your search will be an issue with the search script - this js for controlling the default value won't affetc it...

     

    How do i make it so that when I click into the box all the default text disappears? at the moment you have to delete it yourself.

  11. Hi,

     

    I have a text box which contains a default value which disappears when a user clicks into it to type something: -

     

    <form method="post" action="/search.php" onsubmit="return dis(this)">
              <a href="/"><strong>Home</strong></a><strong> | <a href="/about.php#bookmark">Bookmark 
              Us</a> | Find Emulator:</strong> 
              <input name="emusearch" type="text" value="e.g. Stella or Atari 2600" onfocus="if(this.value==this.defaultValue) this.value='';">
              <input type="submit" value="Go">
        </form>
    

     

    What code do I need to use to make it so that if the user clicks out of the box it displays the 'e.g. Stella' again?

     

    I know its something to do with default value... but can'tfind the code to use.

     

    Thanks.  :)

  12. [code]
    <?
    include($_SERVER['DOCUMENT_ROOT'] . '/includes/head.php');
    include($_SERVER['DOCUMENT_ROOT'] . '/includes/dbconnect.php');
    $search_query = "select emulator, version, os, platform, details from windows_atari2600 where emulator LIKE '%".mysql_real_escape_string($_POST["emusearch"])."%' OR platform LIKE '%".mysql_real_escape_string($_POST["emusearch"])."%' order by platform asc, emulator asc";

    if (empty($_POST['emusearch']))
    {
    echo "<meta http-equiv='refresh' content='0; URL=/noresults.php'>";
    exit();
    }
    else
    {
    $search = mysql_query($search_query);
    $num_rows = mysql_num_rows($search);

    if($num_rows < 1)
    {
      echo "<meta http-equiv='refresh' content='0; URL=/noresults.php'>";
    exit();
    }
    }
    ?>
    [/code]

    Do I need to use an else statement after the ' if($num_rows < 1) '  in the else call for if (empty($_POST['emusearch']))
  13. What am I doing wrong with this code?  When the if statement is used it still displays the else <title> too.

    [code]
    <? 
    $url = $_SERVER['REQUEST_URI'];

    if($url == '/')
    {
    echo "<title>emulators.cc - ";
    echo $num_rows;
    echo " console and handheld emulators for Windows, Mac and Linux computers";
    echo "</title>";
    }
    if(strpos($url, "about")!== false) 
    {
    echo "<title>emulators.cc > About Us</title>";
    }
    if(strpos($url, "search")!== false) 
    {
    echo "<title>emulators.cc > Search results for ";
    echo $_POST['emusearch'];
    echo " (";
    echo $num_rows;
    echo ")";
    echo "</title>";
    }
    if(strpos($url, "windows")!== false) 
    {
    echo "<title>emulators.cc > Windows Emulators > ";
    echo $platform['platform'];
    echo " (";
    echo $num_rows;
    echo ")";
    echo "</title>";
    }
    if(strpos($url, "mac")!== false)
    {
    echo "<title>emulators.cc > Mac Emulators > ";
    echo $platform['platform'];
    echo " (";
    echo $num_rows;
    echo ")";
    echo "</title>";
    }
    if(strpos($url, "linux")!== false)
    {
    echo "<title>emulators.cc > Linux Emulators > ";
    echo $platform['platform'];
    echo " (";
    echo $num_rows;
    echo ")";
    echo "</title>";
    }
    else
    {
    echo "<title>emulators.cc -  console and handheld emulators for Windows, Mac and Linux computers</title>";
    }
    ?>
    [/code]
×
×
  • 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.