/    Sign up×
Community /Pin to ProfileBookmark

Add Links not working

Has anyone got any ideas why this doesnt display the links, after someone has entered them in the form?

addlinks/index.php:

[code=php]
<?php

//** Include library
include(“library.inc.php”);

//** Shorten names
$name = $website_name;
$url = $website_url;

//** If confirmed from confirm.php then write to file
if ($confirm)
{

//** Create website link
$website_link = ” <a href=”” . $confirm_website_url . “”>” . $confirm_website_name . “</a> “;

//** Append link to file
$file_pointer = fopen(DATA_FILE, “a”);
fwrite($file_pointer, $website_link . “<br>n”);
fclose($file_pointer);

}

//** Both variables are empty so show main page
if ($name == “” && $url == “”)
{
include(“form.tpl”);

//** Display links and exit
$file_pointer = fopen(DATA_FILE, “r”);
$file_contents = fread($file_pointer, filesize(DATA_FILE));
fclose($file_pointer);
link_table($file_contents);
exit;

}

//** If name field not filled out
elseif ($name == “” && $url !== “”)

error(“You must enter a website name.”);

//** If url field not filled out
elseif ($url == “” && $name !== “”)

error(“You enter a website URL.”);

//** If < or > found in name
elseif (check_for_html($name))

error(“Invalid character < or > in website name.”);

//** If < or > found in url
elseif (check_for_html($name))

error(“Invalid character < or > in website URL.”);

//** If invalid url
elseif (strrpos($url, “http://”) !== 0 || !strstr($url, “.”))

error(“Invalid website URL”);

//** Check for long url
elseif (strlen($url) > 100)

error(“Website Url contains too many characters. 99 characters max.”);

//** Check for long name
elseif (strlen($name) > 35)

error(“Website name contains too many characters. 35 characters max.”);

//** If show confirm from form.tpl
elseif($show_confirm)
{

//** Check for existance of link in data file if so give error
$file_pointer = fopen(DATA_FILE, “r”);
$file_contents = fread($file_pointer, DATA_FILE);
fclose($file_pointer);

if (strrpos($file_contents, $url) > 0 || strrpos($file_contents, $name) > 0)
{

error(“That link already in the data file”);
exit;

}
include (“confirm.php”);
exit;

}

?>
[/code]

Library.inc.php:

[code=php]<?php

define(ADMIN_VALIDATE, FALSE);
define(DATA_FILE, “links.dat”);

//** Displays error
function error($error_message)
{
echo “<table width=”100%” height=”100%” cellpadding=”0″>
<tr>
<td width=”100%” height=”100%” align=”center” valign=”top”>
$error_message
</td>
</tr>
</table>”;
}

//** Creates the table to put the links in
function link_table($link_string)
{
echo “<table>
<tr>
<td width=”290″>
$link_string
</td>
</tr>
</table>”;
}

//** Checks for < or >
function check_for_html($text)
{
if (strstr($text, “<“) || strstr($text, “>”))
return true;
else
return false;
}
?>[/code]

confirm.php

[code=php]<table class=”tableRows” width=”200″ cellpadding=”0″ cellspacing=”0″>
<tr>
<td>
<table class=”option” cellpadding=”0″ cellspacing=”0″><tr><td width=”28″>&nbsp;<img src=”<?=$snippet_theme?>/img/links.gif” alt=”+”></td><td>Confirm-A-Link…</td></tr></table>
</td>
</tr>
</table><br />
<strong>Name: </strong><?php echo $name ?><br />
<strong>URL: </strong><?php echo $url ?><br />
<form action=”” method=”post”>
<input type=”hidden” name=”confirm” value=”TRUE”>
<input type=”hidden” name=”confirm_website_name” value=”<?php echo $name ?>”>
<input type=”hidden” name=”confirm_website_url” value=”<?php echo $url ?>”><br />
<input type=”submit” value=”Confirm Link” class=”submit”>
</form>
[/code]

snippets/index.php

[code=php]
} elseif(isset($_GET[‘resources’])) {
include ‘resources.php’;
//** Display links and exit
$file_pointer = fopen(DATA_FILE, “r”);
$file_contents = fread($file_pointer, filesize(DATA_FILE));
fclose($file_pointer);
link_table($file_contents);
exit;

[/code]

resources.php

[code=php]include ‘addlinks/library.inc.php’; //for add a link menu[/code]

to post a comment
PHP

2 Comments(s)

Copy linkTweet thisAlerts:
@NewZealandDec 07.2005 — So where is the form inputting this "$name = $website_name;" and "$website_url;"?

I am guessing it is on another page?

So if your form method is POST you would do this
[code=php]
//from this

$name = $website_name;
$url = $website_url;

// if post, to this
$name = $_POST['website_name'];
$url = $_POST['website_url'];

//else if get, to this
$name = $_GET['website_name'];
$url = $_GET['website_url'];

[/code]
Copy linkTweet thisAlerts:
@solidaritiauthorDec 07.2005 — Sorry about that didnt send it: here is the form:

[code=php] <?php
if(isset($_GET['resources']))
{
/*********************************** add-a-link ************************************/
//** Shorten names
$name = $website_name;
$url = $website_url;

//** If confirmed from confirm.php then write to file
if ($confirm)
{
$website_link = " <a href="" . $confirm_website_url . "">" . $confirm_website_name . "</a> "; //** Create website link
//** Append link to file
$file_pointer = fopen(DATA_FILE, "a");
fwrite($file_pointer, $website_link . "<br>n");
fclose($file_pointer);
}

// Both variables are empty so show main page
if ($name == "" && $url == "")
{
?>
<table class="tableRows" width="200" cellpadding="0" cellspacing="0">
<tr>
<td>
<table class="option" cellpadding="0" cellspacing="0"><tr><td width="28">&nbsp;<img src="<?=$snippet_theme?>/img/links.gif" alt="+"></td><td>Add-A-Link...</td></tr></table>
</td>
</tr>
</table>
<form class="addLinksForm" action="" method="post">
<strong>Website Name:</strong>&nbsp;<input type="text" name="website_name" size="20" maxlength="30" class="text">
<strong>Website URL:</strong>&nbsp; <input type="text" name="website_url" size="20" maxlength="99" class="text" value="http://">
<input type="hidden" name="show_confirm" value="TRUE"><br /><br />
<input type="submit" value="Submit Link" class="submit">
</form>

<?php

}
elseif ($name == "" && $url !== "") // If name field not filled out
error("You must enter a website name.");
elseif ($url == "" && $name !== "") // If url field not filled out
error("You enter a website URL.");
elseif (check_for_html($name)) //** If < or > found in name
error("Invalid character < or > in website name.");
elseif (check_for_html($name)) //** If < or > found in url
error("Invalid character < or > in website URL.");
elseif (strrpos($url, "http://") !== 0 || !strstr($url, ".")) //** If invalid url
error("Invalid website URL");
elseif (strlen($url) > 100) //** Check for long url
error("Website Url contains too many characters. 99 characters max.");
elseif (strlen($name) > 35) //** Check for long name
error("Website name contains too many characters. 35 characters max.");
elseif($show_confirm) //** If the addlinks for has been submitted value="showconfirm"
{
//** Check for existance of link in data file if so give error
$file_pointer = fopen(DATA_FILE, "r");
$file_contents = fread($file_pointer, DATA_FILE);
fclose($file_pointer);

if (strrpos($file_contents, $url) > 0 || strrpos($file_contents, $name) > 0)
{
error("That link already exists");
exit;
}

include ("addlinks/confirm.php");
exit;
}
}
?>[/code]



So where is the form inputting this "$name = $website_name;" and "$website_url;"?

I am guessing it is on another page?

So if your form method is POST you would do this
[code=php]
//from this

$name = $website_name;
$url = $website_url;

// if post, to this
$name = $_POST['website_name'];
$url = $_POST['website_url'];

//else if get, to this
$name = $_GET['website_name'];
$url = $_GET['website_url'];

[/code]
[/QUOTE]
×

Success!

Help @solidariti spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.18,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...