Jump to content

OsirisElKeleni

Members
  • Posts

    29
  • Joined

  • Last visited

Posts posted by OsirisElKeleni

  1. your code contains a fatal php parse/syntax error, because you are missing a closing ?> tag.

     

    you need to have php's error_reporting set to E_ALL and display_errors set to ON in your php.ini so that php will report and display all the errors it detects. you will save a ton of time. for parse errors in your main file, you cannot put these settings into your code, because your code never runs to make use of the settings.

     

    I dont see where I'm missing the closing tag i'm sorry,

    The php.ini file i've uploaded and this is the error:

    Parse error: syntax error, unexpected '$row' (T_VARIABLE), expecting ',' or ';' in /home/osiris1q/public_html/includes/header.php on line 20
    

    This is the line but i dont see whats wrong:

    echo "<li><a href='#'></a>"$row"</li>";
    
  2. Hello again!

     

    I'm here with another PHP/Mysqli related question, I want to output the data i receive from the Query:

    SHOW tables; 

    Into html code, more specific: links.

    This is what i try'd to do:

    <div class="container">
      <div class="header" align="center">
       <nav>
    		<ul>
    			<li><a href="#">Home</a></li>
    			<li><a href="#">Databases</a>
    				<ul>
    <?php
    $mysqli = new mysqli('localhost','*****','*****','*****');
    if ($mysqli->connect_error) {
        die("Connection failed: " . $mysqli->connect_error);
    } 
    $sql = 'show tables from osiris1q_mtg';
    $result = $mysqli->query($sql);
    if(!$result = $mysqli->query($sql)){
        die('There was an error running the query [' . $mysqli->error . ']');
    }
        // output data of each row
        while($row = $result->fetch_assoc()){
        echo "<li><a href='#'></a>"$row"</li>";
    }
    } else {
        echo "<li><a href='#'></a>0 results</li>";
    }				</ul>
    			</li>
    		</ul>
    	</nav>
    </div>    <!-- end .header -->
    ?>
    

    This is the header.php file which is included in the actual index page.

    This doesn't return anything not even the html parts of it.

    Even all the files i have 'included' aren't showing up anymore.

    I hope i explained myself good enough for anyone to understand

     

    How Anyone can help me out!

     

    Thank you in Advance!

  3. If, as I suggested in reply #7, your data is stored in an array the data will not be lost. Only data in any unsaved result sets will be lost when the connection closes.

     

    There is no problem with two connections. I have done it many times when I needed to connect to a development and production server in the same script or when a script required connections to MySql server and an MS SQL server

    Okido!

    I will try it and get back to you with results or errors i can't solve thanks a lot!

  4. The way I see it you have two options:

     

    1. Send a request with the data you want inserted to server2

    2. After getting the data from server1 (your result), you setup another Database connection to the database on server2

     

    Personally I would opt for the second option, if that is available to you. Then you could simply loop over your results. Pardon me if the code example looks a bit iffy, I genuienly don't use mysqli, but I'm sure you'll get the idea.

    $databaseServer2 = mysqli_connect($host, $user, $pass, $db);
    while($row = mysqli_fetch_assoc($result)) {
    $name = $row['username'];
    $databaseServer2->query('INSERT INTO table(name) VALUES($name)');
    }
    

    As long as I understood what you wanted to do correctly, then this should work

    Alright i think you're saying its possible to connect to 2 different servers in one script?

    I've looked up on this and i found this:

    <?php
    // we connect to example.com and port 3307
    $link = mysql_connect('example.com:3307', 'mysql_user', 'mysql_password');
    if (!$link) {
        die('Could not connect: ' . mysql_error());
    }
    echo 'Connected successfully';
    mysql_close($link);
    
    // we connect to localhost at port 3307
    $link = mysql_connect('127.0.0.1:3307', 'mysql_user', 'mysql_password');
    if (!$link) {
        die('Could not connect: ' . mysql_error());
    }
    echo 'Connected successfully';
    mysql_close($link);
    ?>
    

    Do you know for sure its possible to connect to 2 different servers at once?

    If so i'd love to have a confirmation on that because it all seems not possible ;p

  5. Thanks for the quick response guys!

     

    However how will i do this? can i connect to another server in the same script?

    Store the data in an array then connect to the second server and write the data

     

    The second server is a mysql database as well if that is what you mean.

    If you could give me a little start to what functions i should use i can work my way from there i think.

    Depends on the second server, really. Does it have an API? Or some script that can insert the data to that second server's database?

     

    You could just convert the data selected from server1 into an array and send that as the body in a POST(or PUT) request to server2 provided server2 has a script to handle that.

     

    Thanks!

  6. Hello everybody!

     

    I'm here today with a mystery i can't solve...

    The problem i'm having is that i need to be able to transfer mysql data from one server to another one.

    Retrieving data from the one database is easy, but making it transfer to another server is not that easy for me.

    I have it printing out the data ATM

     

    This is how i retrieve data from one server:

    <?php 
    $dbhost = "";
    $dbname = "eg_xenforo";
    $dbuser = "";
    $dbpass = "";
    $conn = mysqli_connect("$dbhost","$dbuser","$dbpass","$dbname") or die("Error " . mysqli_error($conn)); 
    
    $sql=	"SELECT username
    		FROM xf_user
    		WHERE FIND_IN_SET('9',secondary_group_ids)
            UNION
    		SELECT username
    		FROM xf_user
    		WHERE FIND_IN_SET('10',secondary_group_ids)
            UNION
    		SELECT username
    		FROM xf_user
    		WHERE FIND_IN_SET('12',secondary_group_ids)";
    $result = mysqli_query($conn, $sql);
    
    if (mysqli_num_rows($result) > 0) {
        // output data of each row
        while($row = mysqli_fetch_assoc($result)) {
    		$name = $row['username'];
            echo "$name <br>";
        }
    } else {
        echo "0 results";
    }
    
    ?>
    

    This is what i get as result:

    CosmonautBob 
    ooglebrain 
    JamieKG 
    Quinnter16 
    Jordan 
    Zoehamp 
    skynet1123 
    misscupcake1306 
    Sir Crimson
    

    These are usernames that should be added onto another server in a database table.

    Any suggestions?

     

    Thanks in advance!

  7. update

    I'm trying to check mutiple criteria in one row if its already in my database the newly sent record should not be added but instead the stock count should be added to the stock count already saved.

  8. I tryd it but the sql didnt work :(

    Are you looking for something like this?

    SELECT 
        SUM(IF(Name='$name'),1,0) as namecheck
        , SUM(IF(Expansion='$expansion'),1,0) as expcheck
        , SUM(IF(Foil='$foil'),1,0) as foilcheck
    FROM Osiris 
    WHERE (Name='$name')
      OR  (Expansion='$expansion')
      OR  (Foil='$foil')
    

    Or are you looking for those where all 3 match the criteria.

     

    It's impossible to tell what you want from your post and current query

     

    I'm trying to check mutiple criteria in one row if its already in my database the newly sent record should not be added.

     

    I'm going to give you an example of what a record looks like:

    Name         Color       Type	    Sub-Type   Power   Toughness  CMC  Rarity    Expansion Foil Stock
    Kite Shield  Colorless   Artifact   Equipment                      0   Uncommon	    M12	    No	  1
    

    The top row are the names of the colums the bottom row is the data stored.

    The thing is another row could be exactly the same as the one above with the expansion changed or the Foil status changed or the name slightly changed. So i'd have to check atleast these 3 criteria in one row to know for sure its not in there already.

     

    I hope this explains alot more :/ 

    I basicly need to be able to check for 3 different criteria in one row to be sure its not the same.

     

    If you look at the second and 3rd row on the webite you'll see that checking the name for differences is not enough because the Foil row is different.

    If you type in Loxodon Warhammer in the first input box and press enter you'll see that the Expansion and the Rarity is different.

    So i hope now you understand what i'm trying to achieve here.

     

    I hope you understand more now.

    This is my website: http://osiriselkeleni.be

     

    So you can see what setup i have atm.

     

    Thanks for helping me out!

  9. This is a dummy question but i cant get multiple criteria in the count function.

     

    This is what i'm trying to do:

    SELECT COUNT(Name, Expansion, Foil) AS NameCheck FROM Osiris WHERE Name="$name" Expansion="$expansion" Foil="$foil"
    

    I have Colums named:

    `Name` `Color` `Type` `Subtype` `Power` `Toughness` `Manacost` `Rarity` `Expansion` `Foil` `Stock`
    

    I want to check before i enter a new record if its not already there, by checking the Name, Expansion and Foil colum on the same record.

     

    I think i have just messed up that code line but i cant seem to find any solution on the web.

     

    Thanks in advance!

  10. This did do the trick! Thanks alot!

     

    The "duplicates" are likely caused by $cardname (and the other variables) only being updated when $color == 1. Try moving the variables below before the if statement:

    if($color==1){
         $cardname = $row['Name']; 
         $encodedcardname = str_replace(" ","%20",trim($cardname)); 
         $url = "http://mtgimage.com/card/$encodedcardname.jpg";
         //...

     

    I don't fully understand what all this does, so i rather not use it for now i could look into it but its working fine now,

    If you want to explain this piece of code i'd love to learn it but i dont really like to implement things in my web unless i understand it a bit and know how to mess around with it.

    Still you helped me and thanks for that!

     

    Also note that the code could be simplified a bit. The following is untested:

    <?php
    //INITIALIZE COUNT
    $count = 0;
     
     
    while($row = mysqli_fetch_assoc($retval)) { 
        $cardname = $row['Name']; 
        $encodedcardname = str_replace(" ","%20",trim($cardname)); 
        $url = "http://mtgimage.com/card/$encodedcardname.jpg";
     
        //GET ROW COLOR
        $bgcolor = ($count % 2) ? '' : ' bgcolor="#F8F8F8"';
     
        //DISPLAY CURRENT ROW
        echo '<tr' . $bgcolor . '><td>'; 
        echo "<a href=$url>$cardname</a>"; 
        echo "</td><td>"; 
        echo $row['Color']; 
        echo "</td><td>"; 
        echo $row['Type']; 
        echo "</td><td>"; 
        echo $row['Subtype']; 
        echo "</td><td>"; 
        echo $row['Power']; 
        echo "</td><td>"; 
        echo $row['Toughness']; 
        echo "</td><td>"; 
        echo $row['Manacost']; 
        echo "</td><td>"; 
        echo $row['Rarity']; 
        echo "</td><td>"; 
        echo $row['Expansion']; 
        echo "</td><td>"; 
        echo $row['Foil']; 
        echo "</td><td>"; 
        echo $row['Stock']; 
        echo "</td></tr>";
     
        //INCREMENT COUNT
        $count++;
    } 
    echo "</table>"; 
    ?>
  11. hey guys!

    i'm back again with another question :D

     

    I've been messing with the piece of code for a few days now and can't get it to function properly.

    i'm trying to make each row a different color which works... BUT it leaves out some data and prints it double...

    This is the piece of code that will help you find what i've been doing wrong...

        $color="1";
        while($row = mysqli_fetch_array($retval,  MYSQLI_ASSOC)) { 
            if($color==1){
        $cardname = $row['Name']; 
        $encodedcardname = str_replace(" ","%20",trim($cardname)); 
        $url = "http://mtgimage.com/card/$encodedcardname.jpg";
         
                echo "<tr bgcolor=''><td>"; 
                echo "<a href=$url>$cardname</a>"; 
                echo "</td><td>"; 
                echo $row['Color']; 
                echo "</td><td>"; 
                echo $row['Type']; 
                echo "</td><td>"; 
                echo $row['Subtype']; 
                echo "</td><td>"; 
                echo $row['Power']; 
                echo "</td><td>"; 
                echo $row['Toughness']; 
                echo "</td><td>"; 
                echo $row['Manacost']; 
                echo "</td><td>"; 
                echo $row['Rarity']; 
                echo "</td><td>"; 
                echo $row['Expansion']; 
                echo "</td><td>"; 
                echo $row['Foil']; 
                echo "</td><td>"; 
                echo $row['Stock']; 
                echo "</td></tr>";
    
                $color="2";
                }
                else {
                    echo "<tr bgcolor='#F8F8F8'><td>"; 
                    echo "<a href=$url>$cardname</a>"; 
                    echo "</td><td>"; 
                    echo $row['Color']; 
                    echo "</td><td>"; 
                    echo $row['Type']; 
                    echo "</td><td>"; 
                    echo $row['Subtype']; 
                    echo "</td><td>"; 
                    echo $row['Power']; 
                    echo "</td><td>"; 
                    echo $row['Toughness']; 
                    echo "</td><td>"; 
                    echo $row['Manacost']; 
                    echo "</td><td>"; 
                    echo $row['Rarity']; 
                    echo "</td><td>"; 
                    echo $row['Expansion']; 
                    echo "</td><td>"; 
                    echo $row['Foil']; 
                    echo "</td><td>"; 
                    echo $row['Stock']; 
                    echo "</td></tr>";
    
                $color="1";
                }
    
            } 
            echo "</table>"; 
    

    A picture of the result of whats it outputting right now is attached to this thread.

    Thanks in advance!

    post-173017-0-37372900-1412962636_thumb.png

  12. Hello everyone,

     

    I have a card database and everything works perfectly besides one thing..

    I can't store 

    '

     in my database via my form, i however do can store them into the database via PHPMyAdmin.

    I dont know what i've been doing wrong and it really bothers me.

    If any of you guys could help me out.

    Here's all the code you would need to find the issue.

     

    This is the form file

    <!doctype html>
    <html>
    <head>
    <meta charset="utf-8">
    <title>Edit Page</title>
    </head>
    <body>
    <h1 align="center"> Add Cards</h1>
    <form action="insert.php" method="POST">
          <input type="text" name="name" placeholder="Name" />
          <input type="text" name="color" placeholder="Color" />
          <input type="text" name="type" placeholder="Type" />
          <input type="text" name="subtype" placeholder="Sub Type" />
          <input type="text" name="power" placeholder="Power" />
          <input type="text" name="toughness" placeholder="Toughness" />
          <br>
          <input type="text" name="manacost" placeholder="Converted Mana Cost" />
          <input type="text" name="rarity" placeholder="Rarity" />
          <input type="text" name="expansion" placeholder="Expansion" />
          <input type="text" name="foil" placeholder="Foil" />
          <input type="text" name="stock" placeholder="Stock" />
          <input type="submit" value="Save" />
    	  
    </form>
    </body>
    </html> 

    This inserts it into my database.

    <?php 
    
    ($GLOBALS["___mysqli_ston"] = mysqli_connect("",  "",  "", , ))or die("cannot connect");  
    ((bool)mysqli_query($GLOBALS["___mysqli_ston"], "USE e_industries"))or die("cannot select DB"); 
    
    $name = $_POST['name']; 
    $color = $_POST['color']; 
    $type = $_POST['type']; 
    $subtype = $_POST['subtype']; 
    $power = $_POST['power']; 
    $toughness = $_POST['toughness']; 
    $manacost = $_POST['manacost']; 
    $rarity = $_POST['rarity']; 
    $expansion = $_POST['expansion']; 
    $foil = $_POST['foil']; 
    $stock = $_POST['stock']; 
    
    $sql="INSERT INTO Osiris (Name, Color, Type, Subtype, Power, Toughness, Manacost, Rarity, Expansion, Foil, Stock) 
    VALUES ('$name', '$color', '$type', '$subtype', '$power', '$toughness', '$manacost', '$rarity', '$expansion', '$foil', '$stock')"; 
    $result=mysqli_query($GLOBALS["___mysqli_ston"], $sql); 
    
    if($result){ 
    echo "Successful"; 
    echo "<BR>"; 
    echo "<a href='add.html'>Back to main page</a>"; 
    } 
    
    else { 
    echo "ERROR"; 
    } 
    ?>
    

    If anyone could help me out that would be great!

  13. I will do that, its just i'm still a beginner at this and now that i (kinda) understand this code its really not that easy to jump and change everything around :P

    But as you bring up the malicious users, i will try and convert it into MySQLI

     

    Thanks alot guys!

  14. Thanks QuickOldCar,

     

    How ever i have one more question.. :P

     

    It seems that when i use spaces in the card names that the variable doesn't coppy it in the HREF link.

    Is there an easy fix for it? Or should i use _ instead of spaces?

     

    Thanks for all the help Guys!

  15. Okay thanks that works,

    but now all the other data isnt showing anymore...

    Anyone knows what the cause is?

     

    This is a link to the actual website

    <!DOCTYPE html>
    <html>
    <head>
    <title>MTG Card List</title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
    <style type="text/css" media="screen">
    @import "filtergrid.css";
    body{ 
    	margin:15px; padding:15px; border:0px solid #666;
    	font-family:Arial, Helvetica, sans-serif; font-size:88%; 
    }
    h2{ margin-top: 50px; }
    caption{ margin:10px 0 0 5px; padding:10px; text-align:left; }
    pre{ font-size:13px; margin:5px; padding:5px; background-color:#f4f4f4; border:1px solid #ccc;  }
    .mytable{
    	width:100%; font-size:12px;
    	border:1px solid #ccc;
    }
    th{ background-color:#003366; color:#FFF; padding:2px; border:1px solid #ccc; }
    td{ padding:2px; border-bottom:1px solid #ccc; border-right:1px solid #ccc; border-left:1px solid #ccc; border-top:1px solid #ccc; }
    body p {
    	font-size: 50%;
    	color: #000;
    }
    a:link {
    	color: #000;
    }
    a:visited {
    	color: #000;
    }
    </style>
    <script language="javascript" type="text/javascript" src="actb.js"></script>
    <script language="javascript" type="text/javascript" src="tablefilter.js"></script>
    </head>
    <body>
    
    
    <form align="center" action="password.php" method="POST">
    <b>Username:</b> <input type="text" name="username">
    <b>Password:</b> <input type="text" name="password">
    <input type="submit">
    </form>
    <?php
    $dbhost = '';
    $dbuser = '';
    $dbpass = '';
    $conn = mysql_connect($dbhost, $dbuser, $dbpass);
    if(! $conn )
    {
      die('Could not connect: ' . mysql_error());
    }
    mysql_select_db('e_industries');
    $sql = 'SELECT `Name`, `Color`, `Type`, `Subtype`, `Power`, `Toughness`, `Manacost`, `Rarity`, `Expansion`, `Foil`, `Stock` FROM `Osiris`';
    
    
    $retval = mysql_query( $sql, $conn );
    if(! $retval )
    	{
    	die('Could not get data: ' . mysql_error());
    	}
    	echo '<table align="center" id="mytable" cellspacing="0" class="table" >';
    	echo "<tr><th >Name</th><th >Color</th><th >Type</th><th >Sub Type</th><th >Power</th><th >Toughness</th><th >Converted mana cost</th><th >Rarity</th><th >Expansion</th><th >Foil</th><th >Stock</th></tr>";
    	while($row = mysql_fetch_array($retval, MYSQL_ASSOC))
    	$cardname = $row['Name'];
    	$url = "http://mtgimage.com/card/$cardname.jpg";
    		{
    			echo "<tr><td>";
    			echo "<a href=$url>$cardname</a>";
    			echo "</td><td>";
    			echo $row['Color'];
    			echo "</td><td>";
    			echo $row['Type'];
    			echo "</td><td>";
    			echo $row['Subtype'];
    			echo "</td><td>";
    			echo $row['Power'];
    			echo "</td><td>";
    			echo $row['Toughness'];
    			echo "</td><td>";
    			echo $row['Manacost'];
    			echo "</td><td>";
    			echo $row['Rarity'];
    			echo "</td><td>";
    			echo $row['Expansion'];
    			echo "</td><td>";
    			echo $row['Foil'];
    			echo "</td><td>";
    			echo $row['Stock'];
    			echo "</td></tr>";
    		}
    		echo "</table>";
    mysql_close($conn);
    ?>
    
    <script language="javascript" type="text/javascript">
    //<![CDATA[
    	var table2_Props = 	{
    							col_1: "select",
    							col_2: "select",
    							col_3: "select",
    							col_7: "select",
    							col_8: "select", 
    							col_9: "select",
    							col_10: "none",
    							display_all_text: " [ Show all ] ",
    							sort_select: true 
    						};
    	setFilterGrid( "mytable",table2_Props );
    //]]>
    </script>
    </body>
    </html>
    
    
  16. Hello everyone,

    i'm struggeling with posting a link with variables in a table with info i receive from a database.

     

    The variable

    $url = "http://mtgimage.com/card/$cardname.jpg";
    

    works but the variable

    $cardname = $row['Name'];
    

    doesnt. i dont know what i am doing wrong in that line of code.

    my actual goal with this is so when i hover over the card name which i receive from the database it shows the image.

     

    This is the actual full file.

    <!DOCTYPE html>
    <html>
    <head>
    <title>MTG Card List</title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
    <style type="text/css" media="screen">
    @import "filtergrid.css";
    body{ 
    	margin:15px; padding:15px; border:0px solid #666;
    	font-family:Arial, Helvetica, sans-serif; font-size:88%; 
    }
    h2{ margin-top: 50px; }
    caption{ margin:10px 0 0 5px; padding:10px; text-align:left; }
    pre{ font-size:13px; margin:5px; padding:5px; background-color:#f4f4f4; border:1px solid #ccc;  }
    .mytable{
    	width:100%; font-size:12px;
    	border:1px solid #ccc;
    }
    th{ background-color:#003366; color:#FFF; padding:2px; border:1px solid #ccc; }
    td{ padding:2px; border-bottom:1px solid #ccc; border-right:1px solid #ccc; border-left:1px solid #ccc; border-top:1px solid #ccc; }
    body p {
    	font-size: 50%;
    	color: #000;
    }
    a:link {
    	color: #000;
    }
    a:visited {
    	color: #000;
    }
    </style>
    <script language="javascript" type="text/javascript" src="actb.js"></script>
    <script language="javascript" type="text/javascript" src="tablefilter.js"></script>
    </head>
    <body>
    
    
    <form align="center" action="password.php" method="POST">
    <b>Username:</b> <input type="text" name="username">
    <b>Password:</b> <input type="text" name="password">
    <input type="submit">
    </form>
    <?php
    $dbhost = 'hostname';
    $dbuser = 'user';
    $dbpass = 'pw';
    $cardname = $row['Name'];
    $url = "http://mtgimage.com/card/$cardname.jpg";
    $conn = mysql_connect($dbhost, $dbuser, $dbpass);
    if(! $conn )
    {
      die('Could not connect: ' . mysql_error());
    }
    mysql_select_db('e_industries');
    $sql = 'SELECT `Name`, `Color`, `Type`, `Subtype`, `Power`, `Toughness`, `Manacost`, `Rarity`, `Expansion`, `Foil`, `Stock` FROM `Osiris`';
    
    
    $retval = mysql_query( $sql, $conn );
    if(! $retval )
    	{
    	die('Could not get data: ' . mysql_error());
    	}
    	echo '<table align="center" id="mytable" cellspacing="0" class="table" >';
    	echo "<tr><th >Name</th><th >Color</th><th >Type</th><th >Sub Type</th><th >Power</th><th >Toughness</th><th >Converted mana cost</th><th >Rarity</th><th >Expansion</th><th >Foil</th><th >Stock</th></tr>";
    	while($row = mysql_fetch_array($retval, MYSQL_ASSOC))
    		{
    			echo "<tr><td>";
    			echo "<a href=$url>. $cardname .</a>";
    			echo "</td><td>";
    			echo $row['Color'];
    			echo "</td><td>";
    			echo $row['Type'];
    			echo "</td><td>";
    			echo $row['Subtype'];
    			echo "</td><td>";
    			echo $row['Power'];
    			echo "</td><td>";
    			echo $row['Toughness'];
    			echo "</td><td>";
    			echo $row['Manacost'];
    			echo "</td><td>";
    			echo $row['Rarity'];
    			echo "</td><td>";
    			echo $row['Expansion'];
    			echo "</td><td>";
    			echo $row['Foil'];
    			echo "</td><td>";
    			echo $row['Stock'];
    			echo "</td></tr>";
    		}
    		echo "</table>";
    mysql_close($conn);
    ?>
    
    <script language="javascript" type="text/javascript">
    //<![CDATA[
    	var table2_Props = 	{
    							col_1: "select",
    							col_2: "select",
    							col_3: "select",
    							col_7: "select",
    							col_8: "select", 
    							col_9: "select",
    							col_10: "none",
    							display_all_text: " [ Show all ] ",
    							sort_select: true 
    						};
    	setFilterGrid( "mytable",table2_Props );
    //]]>
    </script>
    </body>
    </html>
    
    

     Thanks 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.