PDA

View Full Version : PHP Error Help



Shibby-Shabs
14-09-2010, 08:04 AM
I've been coding a php script and I've used session and I cannot figure out why I'm getting this error, help:


Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at C:\xampp\htdocs\PHP-Testing\FORM\backend\index.php:10) in C:\xampp\htdocs\PHP-Testing\FORM\backend\data.php on line 6

My Code:

<br />
<center>
<?php

// Session Start
session_start();

// If logged in - view data
if ($_SESSION['username'])
{
// Data
include("../require.php");
$connect = @mysql_connect( $host, $user, $pass );

if ( !$connect )
{

die( 'Could not connect: ' . mysql_error() );

}

$select = @mysql_select_db( $database, $connect );

if ( !$select )
{

die( 'Could not choose db: ' . mysql_error() );

}

$result = mysql_query( "SELECT * FROM `questions`" );

echo
'
<table border="1">
<tr>
<th>Name</th>
<th>Email</th>
<th>ID</th>
<th>Question</th>
</tr>
';


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

echo
'
<tr>
<td>' . $row['Name'] . '</td>
<td>' . $row['Email'] . '</td>
<td>' . $row['id'] . '</td>
<td>' . $row['Question'] . '</td>
<td><a href="index.php?page=data&delete=' . $row['id'] . '">Delete</a></td>
</tr>
';

}

echo
'
</table><br /><br />
';

$delete = mysql_real_escape_string( $_GET['delete'] );

if ( $delete )
{

if ( is_numeric( $delete ) )
{


$check = mysql_query( "SELECT * FROM `questions` WHERE `id` = '{$delete}'" );
$num = mysql_num_rows( $check );

if ( $num )
{

mysql_query( "DELETE FROM `questions` WHERE `id` = '{$delete}'" );
echo 'Question ID: ' . $delete . ' has been deleted! Refresh the page.';

}
else
{

echo 'Question ID does not exist!';

}

}
else
{

echo 'Question ID must be a number!';

}

}

mysql_close( $connect );


}
else
die("You must sign in before viewing this page! <br> <a href='index.php'>Sign in now.</a>")
?></center>

emotional
14-09-2010, 08:24 AM
Hi!

session_start() needs to be at the very top. PHP will output this error if there's any characters previous to this function, including white space.

Shibby-Shabs
14-09-2010, 08:38 AM
Changed it so it goes:


<?php
session_start();

It just changes and says "Line 2".

Blob
14-09-2010, 06:11 PM
<?php

// Session Start
session_start();

?>
<br />
<center>
<?php
// If logged in - view data
if ($_SESSION['username'])
{
// Data
include("../require.php");
$connect = @mysql_connect( $host, $user, $pass );

if ( !$connect )
{

die( 'Could not connect: ' . mysql_error() );

}

$select = @mysql_select_db( $database, $connect );

if ( !$select )
{

die( 'Could not choose db: ' . mysql_error() );

}

$result = mysql_query( "SELECT * FROM `questions`" );

echo
'
<table border="1">
<tr>
<th>Name</th>
<th>Email</th>
<th>ID</th>
<th>Question</th>
</tr>
';


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

echo
'
<tr>
<td>' . $row['Name'] . '</td>
<td>' . $row['Email'] . '</td>
<td>' . $row['id'] . '</td>
<td>' . $row['Question'] . '</td>
<td><a href="index.php?page=data&delete=' . $row['id'] . '">Delete</a></td>
</tr>
';

}

echo
'
</table><br /><br />
';

$delete = mysql_real_escape_string( $_GET['delete'] );

if ( $delete )
{

if ( is_numeric( $delete ) )
{


$check = mysql_query( "SELECT * FROM `questions` WHERE `id` = '{$delete}'" );
$num = mysql_num_rows( $check );

if ( $num )
{

mysql_query( "DELETE FROM `questions` WHERE `id` = '{$delete}'" );
echo 'Question ID: ' . $delete . ' has been deleted! Refresh the page.';

}
else
{

echo 'Question ID does not exist!';

}

}
else
{

echo 'Question ID must be a number!';

}

}

mysql_close( $connect );


}
else
die("You must sign in before viewing this page! <br> <a href='index.php'>Sign in now.</a>")
?></center>

Shibby-Shabs
15-09-2010, 12:05 AM
I'll give that a try after school when I'm on my computer that has Xampp

LMS16
15-09-2010, 07:15 AM
I tend to but line breaks (<br />)'s in the echo rather than outside the php tags if its a full PHP page.

The one that Blob posted should work.

Lew.

Shibby-Shabs
15-09-2010, 09:14 AM
It's being gayy.


Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at C:\xampp\htdocs\PHP-Testing\FORM\backend\index.php:10) in C:\xampp\htdocs\PHP-Testing\FORM\backend\data.php on line 4

Shibby-Shabs
15-09-2010, 10:25 AM
I fixed that issue but now I'm trying to upload a demo and I keep getting this error.


Parse error: syntax error, unexpected T_STRING, expecting T_CONSTANT_ENCAPSED_STRING or '(' in /home/*USERNAME*1/public_html/scripts/jps/demo/insert.php on line 5


Here's my code:


<?php
include("require.php");
$connect = mysql_connect($host,$user,$pass) or die("<center><br />Couldn't connect to MySQL!</center><br />");
mysql_select_db($database) or die("Couldn't connect to Database!");
use the_database_name

$sql="INSERT INTO questions (name, email, question)
VALUES
('$_POST[name]','$_POST[email]','$_POST[question]')";

if (!mysql_query($sql,$con))
{
die('Error: ' . mysql_error());
}
echo "<center><br />Question submitted!</center><br />";

mysql_close($con)
?>
<br />

Johno
15-09-2010, 12:25 PM
<?php
include("require.php");
$connect = mysql_connect($host,$user,$pass) or die("<center><br />Couldn't connect to MySQL!</center><br />");
mysql_select_db($database) or die("Couldn't connect to Database!");
use the_database_name

$sql="INSERT INTO questions (name, email, question)
VALUES
('$_POST[name]','$_POST[email]','$_POST[question]')";

if (!mysql_query($sql,$con))
{
die('Error: ' . mysql_error());
}
echo "<center><br />Question submitted!</center><br />";

mysql_close($con);
?>

never even looked at the error properly, all I could see was the missing semi-colon on "mysql_close" - someone else will probably see whats actually up, been a while since I did PHP :P

Shibby-Shabs
16-09-2010, 08:04 AM
Sorry. I pasted wrong error..

Warning: mysql_connect() [function.mysql-connect]: Host '*HOST-REMOVED*' is not allowed to connect to this MySQL server in /home/*USER*/public_html/scripts/jps/demo/insert.php on line 3

Johno
16-09-2010, 03:39 PM
<?php
include("require.php");
$con = mysql_connect($host,$user,$pass) or die("<center><br />Couldn't connect to MySQL!</center><br />");
$select = mysql_select_db($database, $con) or die("Couldn't connect to Database!");
use the_database_name

$sql="INSERT INTO questions (name, email, question)
VALUES
('$_POST[name]','$_POST[email]','$_POST[question]')";

if (!mysql_query($sql, $con)) {
die('Error: ' . mysql_error());
}
echo "<center><br />Question submitted!</center><br />";

mysql_close($con);
?>

Give that a go, not entirely sure if it will work once again but possibly :P

Shibby-Shabs
16-09-2010, 11:58 PM
More errors :O


Parse error: syntax error, unexpected T_STRING, expecting T_CONSTANT_ENCAPSED_STRING in /home/a4030461/public_html/scripts/jps/demo/insert.php on line 5

Recursion
17-09-2010, 06:37 AM
Warning: mysql_connect() [function.mysql-connect]: Host '*HOST-REMOVED*' is not allowed to connect to this MySQL server in /home/*USER*/public_html/scripts/jps/demo/insert.php on line 3

Does this one not mean that the server which hosts the files isn't allowed to connect to the server that is hosting the MySQL...?

Dentafrice
19-09-2010, 04:35 AM
You had a comment on line 5 not closing.



<?php
include "require.php";
$connect = mysql_connect($host, $user, $pass) or die("<center><br />Couldn't connect to MySQL!</center><br />");
mysql_select_db($database) or die("Couldn't connect to Database!");

$sql = "INSERT INTO `questions` (`name`, `email`, `question`) VALUES('{$_POST["name"]}', '{$_POST["email"]}', '{$_POST["question"]}')";

if(!mysql_query($sql, $connect)) {
exit("ERROR: " . mysql_error());
}

echo "<center><br/>Question submitted!</center><br />";

mysql_close($connect);
?>

Shibby-Shabs
19-09-2010, 07:36 AM
Sorry if I hadn't posted. This has all been solved ;)

Want to hide these adverts? Register an account for free!