Jump to content

Hydrian

Members
  • Posts

    57
  • Joined

  • Last visited

    Never

Posts posted by Hydrian

  1. Im running a testing forum iv made from scratch, i want the posts to be order by newest, but there going as, order by oldest. How come this happens.

     

    <?php
    
    session_start();
    error_reporting(-1);ini_set('display_errors', 1);
        $myServer = "mysql8.000webhost.com";
        $myUser = "a1761169_chat";
        $myPass = "site123";
        $myDB = "a1761169_chat";
        //Connection to the database
        $dbhandle = mysql_connect($myServer, $myUser, $myPass)
        or die("Couldn't connect to SQL Server on $myServer");
        //Select a database to work with
        $selected = mysql_select_db($myDB, $dbhandle)
        or die("Couldn't open database $myDB");
    $where = "";	
    	if(isset($_GET['id'])){
    	$id = $_GET['id'];
    	$where = " WHERE id = $id";
    }    
    
    
    
    //Declare the SQL statement that will query the database
        $query = "SELECT * FROM `topics` $where ORDER BY topic_date";
        //Execute the SQL query and return records
        $result = mysql_query($query)
        or die('A error occured: ' . mysql_error());
    ?>
    <html>
    <head>
    </head>
    
    <body>
    	<h2>
    		My First Forum
    	</h2>
    		<br>
    		<div style="background-color:#CCCCCC; color:#; border-radius:5px;" align=''>
    			     <a href='index.php'><b>Board Index<b></a>     <a href='create_topic.php'><b>New Topic<b></a>
    		</div>
    		<br>
    		<?php
    
    		while ( $record = mysql_fetch_array($result) )
    		{	
    
    		echo '<div id="content" >' . '<div style="background-color:#CCCCCC; color:#; border-radius:5px;">' . '<a href="index.php">'. $record["topic_username"] .'</a>' . '     |     ' . '<a href="index.php?id=' . $record["id"] . ' ">'. $record["topic_name"] .'</a>' . '</div> ' . "<br>" . '<div style="word-wrap:break-word;div-layout:fixed; background-color:#CCCCCC; color:#; border-radius:5px;" width="500px" border="1">';
    		if(isset($_GET['id'])){echo $record['topic_date']; echo "<br><br>"; echo $record['topic_input']; }
    		else { echo ""; }
    		echo '</div></div>';
    
    		}
    		 echo "<br><br>";
    		while ( $record = mysql_fetch_array($result) )
    		{	
    
    		echo '<div id="content" >' . '<div style="background-color:#CCCCCC; color:#; border-radius:5px;">' . '<a href="index.php">'. $record["reply_username"] .'</a>' . '     |     ' . '<a href="index.php?id=' . $record["id"] . ' ">'. $record["reply_name"] .'</a>' . '</div> ' . "<br>" . '<div style="word-wrap:break-word;div-layout:fixed; background-color:#CCCCCC; color:#; border-radius:5px;" width="500px" border="1">';
    		if(isset($_GET['id'])){echo $record['reply_date']; echo "<br><br>"; echo $record['reply_input']; }
    		else { echo ""; }
    		echo '</div></div>';
    
    		}
    		 echo "<br><br>";
    		?>
    </body>
    </html>
    

     

    Thats the page i want the topics to go order by descending

  2. When i load my page. i get

     

    Warning: mysql_fetch_array(): 9 is not a valid MySQL result resource in /home/a1761169/public_html/a40g/index.php on line 46
    

     

    Here is my script

     

    <?php
    
    session_start();
    error_reporting(-1);ini_set('display_errors', 1);
        $myServer = "";
        $myUser = "";
        $myPass = "";
        $myDB = "";
        //Connection to the database
        $dbhandle = mysql_connect($myServer, $myUser, $myPass)
        or die("Couldn't connect to SQL Server on $myServer");
        //Select a database to work with
        $selected = mysql_select_db($myDB, $dbhandle)
        or die("Couldn't open database $myDB");
    $where = "";	
    	if(isset($_GET['id'])){
    	$id = $_GET['id'];
    	$where = " WHERE id = $id";
    }    
    
    
    
    //Declare the SQL statement that will query the database
        $query = "SELECT * FROM `topics`$where";
        //Execute the SQL query and return records
        $result = mysql_query($query)
        or die('A error occured: ' . mysql_error());
        //Show result
        //Free result set memory
        mysql_free_result($result);
        //Close the connection 
        mysql_close($dbhandle);	
    ?>
    <html>
    <head>
    </head>
    
    <body>
    	<br>
    	<div style="background-color:#CCCCCC; color:#; border-radius:5px;" align=''>
    		     <a href='create_topic.php'><b>New Topic<b></a>
    	</div>
    	<br><br>
    	<?php
    
    	while ( $record = mysql_fetch_array($result) )
    	{	
    
    	echo '<div id="content" >' . '<div style="background-color:#CCCCCC; color:#; border-radius:5px;">' . '<a href="index.php?id=' . $record["id"] . ' ">'. $record["topic_username"] .'</a>' . '       ' . '<a href="index.php?id=' . $record["id"] . ' ">'. $record["topic_name"] .'</a>' . '</div> ' . "<br>" . '<div style="word-wrap:break-word;div-layout:fixed; background-color:#CCCCCC; color:#; border-radius:5px;" width="500px" border="1">';
    	if(isset($_GET['id'])){echo $record['topic_date']; echo "<br><br>"; echo $record['topic_input']; }
    	else { echo ""; }
    	echo '</div></div>';
    
    	}
    
    	?>
    </body>
    </html>
    

     

    What have i done wrong?

  3. Im working on the login stuff

     

    I get an unexpected '=' on line 9

     

    <?php
    
    session_start();
    include_once('connect.php');
    
    if (isset($_POST['username'])) {
    $username = $_POST['username'];
    $password = $_POST['password'];
    $sql = " SELECT * FROM members WHERE username='".$username."'" AND password='".$password." LIMIT 1';
    $res = mysql_query($sql) or die(mysql_error());
    if (mysql_num_rows($res) == 1) {
    	$row = mysql_fetch_assoc($res);
    	$_SESSION['uid'] = $row['id'];
    	$_SESSION['username'] = $row['username'];
    	header ("Location: index.php");
    	exit();
    } else {
    	echo "Invalid login information. Please return to previous page.";
    	exit();
    }
    }
    
    ?>
    

  4. I get 

    mysql_fetch_assoc(): 

    supplied argument is not a valid MySQL result resource. when i load the page

     

    <?php
    
    session_start();
    include 'config.php';
    
    mysql_select_db("my_db");
    
    $result = mysql_query("SELECT * FROM `categorys`, SELECT * FROM `topics` ");	
    
    while ($row = mysql_fetch_assoc($result)) {
    	echo $row["cat_name"];
    }
    
    
    ?>
    

  5. I get Resource id #10 when i load my page

     

     

    Full Script

    <?php
    
    session_start();
    include 'config.php';
    
    mysql_select_db("my_db");
    
    $result = mysql_query(" SELECT * FROM `categorys`, SELECT * FROM `topics` ");	
    
    
    ?>
    <?php include 'header.php'; ?>
    	<div id="nar">
    		 
    	</div>
            <div id="content">
    	<?php print $result; ?>
    	</div>
    	<div id="nar">
    		 
    	</div>
    <?php include 'footer.php'; ?>
    

  6. I get  Resource id #10  when i do 

    <?php print $result; ?>

    when i load my page.

     

    Here is my page code

     

    <?php
    
    session_start();
    include 'config.php';
    
    mysql_select_db("my_db");
    
    $result = mysql_query(" SELECT * FROM `categorys` ");
    $result = mysql_query(" SELECT * FROM `topics` ");
    
    $num = mysql_numrows($result);
    
    
    ?>
    <?php include 'header.php'; ?>
    	<div id="nar">
    		 
    	</div>
            <div id="content">
    	<?php print $result; ?>
    	</div>
    	<div id="nar">
    		 
    	</div>
    <?php include 'footer.php'; ?>
    

     

     

  7. I want to know if you can make a application that allows a user to make a post(topic) and allow other users to reply to that post. Is there any way to do this. If i can do that, i want to try and create a forum with it. And style it how i want it. And then maybe after beta testing upload it to my site. Please i want to know if this is possible, it would be good if this can happen.

     

    Cheers Hydroo

  8. For the file names just have a user having to register before uploading a file. Then set a var that randomises a url and set another function making sure that each url isnt the same. if a post is say like hasent been visited for 5months delete it

  9. Iv got a script. Now it it tells me there is a unexpected { at the end of line 9 which is i dont know why it tells me its unexpected. Please help, im a learning phper

     

    while (($row = mysql_fetch_assoc($result)) !== false{
    	$users[] = $row;
    }
    

     

     

    Full Script

     

    <?php
    
    // fetchs all of the users from the table
    function fetch_users(){
    $result = mysql_query('SELECT `user_id` AS `id`, `user_username` AS `username` FROM `users` ');
    
    $users = array();
    
    while (($row = mysql_fetch_assoc($result)) !== false{
    	$users[] = $row;
    }
    
    return $users;
    }
    
    
    ?>
    

×
×
  • 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.