PHP Code returns blank page...

mattjs92

New Member
Messages
4
Reaction score
0
Points
0
<?php
$con = mysql_connect("***","***","***") or die('Could not connect: ' . mysql_error());
$dbconnect = mysql_select_db("***", $con) or die ("could not connect to database: " . mysql_error());
if($_SESSION['username']=="***")
{
if ($_POST['title'] && $_POST['description'])
{
$check = mysql_query("INSERT INTO links (title, description) VALUES ('$_POST[title]', '$_POST[description]')") or die("Could not add content to database: " . mysql_error());
echo "<p>Link Added Successfully.</p>";
}
elseif ($_POST['title'] || $_POST['description'])
{
$title1 = $_POST['title'];
$description1 = $_POST['description'];
}
if ($_GET[successful]==1)
{
echo "<p>Link Edited Successfully.</p>";
}
echo "<form action='links.php' method='post'>
<p><b>Link Title</b><br/>
<input type='text' style='width:690px;' id='title' value='" . $title1 . "'/><br/><br/>
<b>URL: http</b><br/>
<input type='text' style='width:690px;' id='description' value='" . $description1 . "'/></p>
</form>";
$result = mysql_query("SELECT * FROM links") or die("Could not get link data: " . mysql_error());
while($row = mysql_fetch_array($result))
{
echo "<p><a href='" . $row['description'] . "'>" . $row['title'] . "</a></p><a href='edit.php?id=" . $row['id'] . "&page=links&redirect=links.php' onclick='return editEvent();'>Edit</a> | <a href='delete.php?did=" . $row['id'] . "&page=links&redirect=links.php' onclick='return doubleCheck();'>Delete</a>";
}
}
else
{
$result = mysql_query("SELECT * FROM links") or die("Invalid Query: " . mysql_error());
while($row = mysql_fetch_array($result))
{
echo "<p><a href='" . $row['description'] . "'>" . $row['title'] . "</a></p>
}
}
mysql_close($con);
?>
 
Last edited:

Twinkie

Banned
Messages
1,389
Reaction score
12
Points
0
Firstly, is this on your home server or on X10? I had a home server with the same problem, and it turns out PHP has reporting errors disabled by default in the php.ini file. In error, the browser would return a blank page.
 
Last edited:

Twinkie

Banned
Messages
1,389
Reaction score
12
Points
0
Your scripts don't have to be hosted on x10 to get community support, if I understand this correctly?
 

misson

Community Paragon
Community Support
Messages
2,572
Reaction score
72
Points
48
When asking questions about code:
  • Include a description of what you want the code to do and what it actually does in the body of the message.
  • Make sure the code you post is a minimal test case. The code you posted is fairly minimal, but doesn't look complete.
  • format the code to make it readable. This means indent (using a variant of a standard indent style) and (for these forums) encase the code in
    PHP:
    , [HTML] or [CODE] tags to preserve the indentation. If you use an editor designed for coding, it will indent the code for you. Here's the result of indenting your code in emacs (ESC ^\) and putting it in [PHP] tags:
    [php]<?php
    $con = mysql_connect("***","***","***") or die('Could not connect: ' . mysql_error());
    $dbconnect = mysql_select_db("***", $con) or die ("could not connect to database: " . mysql_error());
    if($_SESSION['username']=="***")
    {
    	if ($_POST['title'] && $_POST['description'])
    	{
    		$check = mysql_query("INSERT INTO links (title, description) VALUES ('$_POST[title]', '$_POST[description]')") or die("Could not add content to database: " . mysql_error());
    		echo "<p>Link Added Successfully.</p>";
    	}
    	elseif ($_POST['title'] || $_POST['description'])
    	{
    		$title1 = $_POST['title'];
    		$description1 = $_POST['description'];
    	}
    	if ($_GET[successful]==1)
    	{
    		echo "<p>Link Edited Successfully.</p>";
    	}
    	echo "<form action='links.php' method='post'>
    <p><b>Link Title</b><br/>
    <input type='text' style='width:690px;' id='title' value='" . $title1 . "'/><br/><br/>
    <b>URL: http</b><br/>
    <input type='text' style='width:690px;' id='description' value='" . $description1 . "'/></p>
    </form>";
    	$result = mysql_query("SELECT * FROM links") or die("Could not get link data: " . mysql_error());
    	while($row = mysql_fetch_array($result))
    	{
    		echo "<p><a href='" . $row['description'] . "'>" . $row['title'] . "</a></p><a href='edit.php?id=" . $row['id'] . "&page=links&redirect=links.php' onclick='return editEvent();'>Edit</a> | <a href='delete.php?did=" . $row['id'] . "&page=links&redirect=links.php' onclick='return doubleCheck();'>Delete</a>";
    	}
    }
    else 
    {
    	$result = mysql_query("SELECT * FROM links") or die("Invalid Query: " . mysql_error());
    	while($row = mysql_fetch_array($result))
    	{
    		echo "<p><a href='" . $row['description'] . "'>" . $row['title'] . "</a></p>
    }
    }
    mysql_close($con);
    ?>
    Notice how the closing bracket for the last while loop isn't indented and the code is red? This is a clue that there is a syntax problem before the bracket, something that prevented emacs' auto-indent from working. The red text (here it means the text is in a string) is another clue, one that means you've got an unterminated string. Looking at the line above and you'll see it. Notice the line is also missing its line-ending semicolon. Also, there's no need for string concatenation (the "." operator) with echo as it's variadic (it supports a variable number of arguments). You can separate each string to be printed with a comma. Lastly, if you don't need variable interpolation, try single quoted strings:
    PHP:
    		echo '<p><a href="', $row['description'], '">', $row['title'], '</a></p>';
    Normally, you shouldn't be too concerned with this sort of micro-optimization 2) and shouldn't optimize too early, but the above tips are good when you're writing new code (except perhaps single quoting). The best (ie most readable and not slower in a big-O sense) code is probably:
    PHP:
    		echo "<p><a href='$row[description]'>$row[title]</a></p>";

PHP:
<?php
$con = mysql_connect("***","***","***") or die('Could not connect: ' . mysql_error());
die() can be OK for test code, but not production code (2). Also, printing MySQL error information can disclose too much information. Moreover, the information will likely be useless and unintelligible for most users of your site (the ones who can understand and use it are the ones you need to worry about).

PHP:
if($_SESSION['username']=="***")
You need to call session_start() before you can access $_SESSION

PHP:
{
	if ($_POST['title'] && $_POST['description'])
	{
		$check = mysql_query("INSERT INTO links (title, description) VALUES ('$_POST[title]', '$_POST[description]')") or die("Could not add content to database: " . mysql_error());
Placing user input directly into a query opens your script to SQL injection (2). Never do this. Instead, filter the data using PHP's filter functions or the DB driver's escape function (e.g. mysql_escape_string, mysqli_real_escape_string, pg_escape_string). Even better is to use prepared statements, if the driver supports them (e.g. mysqli_prepare, PDO::prepare).

PHP:
	if ($_GET[successful]==1)
This looks wrong for two reasons: if "successful" is a string index, it should be quoted (it should remain unquoted only if it's a constant). The second comes mostly from intuition and is harder to put into words, but it involves the fact that $_GET is filled from the query string for the current page.

HTML:
<form action='links.php' method='post'>
<p><b>Link Title</b><br/>
<input type='text' style='width:690px;' id='title' value='" . $title1 . "'/><br/><br/>
<b>URL: http</b><br/>
<input type='text' style='width:690px;' id='description' value='" . $description1 . "'/></p>
</form>
Use inline style sparingly. Also, avoid using <br /> for layout. px units are mostly appropriate for images; use ems with text & text widgets. Try the following structure:
HTML:
<form action='links.php' id="linkEdit" method='post'>
<label for="title">Link Title</label>
<input type='text' id='title' value='" . $title1 . "'/>
<label for="description">URL: http</label>
<input type='text' id='description' value='" . $description1 . "'/>
</form>
with the following style:
Code:
form#linkEdit input {
  width: 40em;
  display: block;
  margin-bottom: 1em;
}
form#linkEdit label {
  display: block;
}
form#linkEdit input:last-child {
  margin-bottom: 0;
}
 
Last edited:

taha116

Member
Messages
505
Reaction score
0
Points
16
I am having the same blank page problem on lotus and it was always working, i made no modifications? Is this also due to the changes on the servers?
 

xav0989

Community Public Relation
Community Support
Messages
4,467
Reaction score
95
Points
0
Well, in mattjs92 case, it was because of poorly built code. Since you are on lotus, this could be due to the server moves... However, since lotus is supposed to be fully transferred, you should and are entitled to posting a support ticket.
 

taha116

Member
Messages
505
Reaction score
0
Points
16
Yay I just submitted one even though i was afraid of getting banned, now i feel more secure about my ticket
 

xav0989

Community Public Relation
Community Support
Messages
4,467
Reaction score
95
Points
0
I just went over the announcements (this should be the first thing every member does when accessing the forum), and Corey clearly states that Lotus is supposed to be completely transferred. http://forums.x10hosting.com/news-announcements/98693-latest-updates-6-18-09-a.html and http://forums.x10hosting.com/news-announcements/98555-latest-updates-6-14-09-a.html is were he states it. Mainly, the problem is from starka users. I've been moved from stoli to chopin during the move, and it's behaving like a charm, so I'm kinda happy!
 
Last edited:
Top