• There is NO official Otland's Discord server and NO official Otland's server list. The Otland's Staff does not manage any Discord server or server list. Moderators or administrator of any Discord server or server lists have NO connection to the Otland's Staff. Do not get scammed!

PHP files and header

Raggaer

Godly Member
Joined
Jul 25, 2012
Messages
1,557
Solutions
8
Reaction score
957
Location
Spain
Hi, I have a big problem

PHP:
<form action="index.php" method="post">
Using this , this code executes
PHP:
if ($_POST['submit']) {
					
					$rules = $_POST['rules'];
					$title = $_POST['title'];
					$body = $_POST['body'];
					$date = date("Y-m-d");	
					
					
					if ($title && $body) {
						
						
						if ($rules == 'on') {
							
							$filename = 'w'.$title.'.txt';
							$handle = fopen('pastes/'.$filename, 'w');
							fwrite($handle, $body);
							fclose($handle);
							$query = mysql_query("INSERT INTO codes VALUES ('','$title','$body','$date')");
							
							
							
						
							
						} else {
							
							echo '<b>Accept our rules</b>';
						}
				
					} else {
						
						echo '<b>Fill all fields</b>';
					}
				}

But I need that when u click submit you get to new page so I use this

PHP:
<form action="see.php" method="post">

but then the code doestn execute ;S dont know why

Thanks
 
Last edited:
Use this below the MySQL query, but make sure no HTML was printed prior to it.
PHP:
header('Location: see.php');
exit;
 
Thats imposible for the code Im using, full code..

PHP:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>ShareWorld</title>
<link rel="stylesheet" type="text/css" href="sw.css" />
</head>
<body>
<div id="content">
<div id="logo"></div>
<div id="main">
	<div id="main2">
    	<div id="main3">
        	<div id="main4"><a href="#">Login</a>  |  <a href="#">Register</a>  | <a href="#">About</a>  |  Rules  </div>
            <form action="index.php" method="post">
            <div id="main6">New share title : <input type="text" name="title" maxlength="19" /><br />
            <input type="checkbox" name="rules" /> I accept to ShareWorld rules<br />
            <input type="submit" name="submit" value="Share this"/>
            <?PHP
			
				mysql_connect('localhost','root','');
				mysql_select_db('sworld');
			
				if ($_POST['submit']) {
					
					$rules = $_POST['rules'];
					$title = $_POST['title'];
					$body = $_POST['body'];
					$date = date("Y-m-d");	
					
					
					if ($title && $body) {
						
						
						if ($rules == 'on') {
							
							$filename = 'w'.$title.'.txt';
							$handle = fopen('pastes/'.$filename, 'w');
							fwrite($handle, $body);
							fclose($handle);
							$query = mysql_query("INSERT INTO codes VALUES ('','$title','$body','$date')");
							
							header('Location: see.php');
							exit;  
							
						
							
						} else {
							
							echo '<b>Accept our rules</b>';
						}
				
					} else {
						
						echo '<b>Fill all fields</b>';
					}
				}
            ?>
            </div>
        	<div id="main5">
            
            <center>Lastest code shared</center>
            <?PHP
			
				mysql_connect('localhost','root','');
				mysql_select_db('sworld');
				
				$querty = mysql_query("SELECT * FROM codes ORDER BY id DESC LIMIT 3");
				
				while ($row = mysql_fetch_assoc($querty)) {
					
				$titlee = $row['title'];
				$date = $row['date'];
				
				echo "<hr>
				<b>$titlee</b> posted on $date<br> 
				";	
				}
			
			?>
            </div>
            
        </div>
    	 <div id="main7">
         New share full text :<br />
         <textarea name="body" style="resize:none" rows="30" cols="77"></textarea>
         </form>
         </div>
    </div>
</div>
</div>
</body>
</html>
 
Just place that specific piece of php code above the html.
 
Dont work in see.php I should have this

PHP:
 <?PHP
			
$title = $_POST['title'];
echo '<b>'.$title.'</b>';
?>

But the code doesnt get the $_POST vars :S
 
Ah, you want to be able to use the values in see.php as well? Well, you have a few options...

1) Pass the values by the url, e.g. header("Location: see.php?title={$title}");

2) Store the values in a session and then destroy that session after you've used it in see.php

3) Move the php code (mysql query etc.) to see.php
 
That worked(sessions) now, last question, why Im getting array in this echo,

PHP:
$id = mysql_query("SELECT * FROM codes ORDER BY id DESC LIMIT 1");
							
while($roww = mysql_fetch_assoc($id)) {
							
$_SESSION['id'] = $roww;	
								
}

Then I display it here

PHP:
echo '<b>'.$_SESSION['id'].'</b>';

Thanks
 
PHP:
$_SESSION['id']['fieldname_from_db_here'];
 
Worked, thanks but why for the other values didnt need to use it?
 
Where you echo it (id is the name of the session, which in turn contains an array of all the database fields from the query).
PHP:
echo '<b>' . $_SESSION['id']['column_field_from_db'] . '</b>';
 
Back
Top