posting error

Hi all,
I hope someone can help. I have a problem but can’t see what I’m doing wrong. A second opinion would be very useful. My code should post a title, text, intro and link… but the link text ends up in the entry text and the actual link gives a link to the page to edit the link info - I’ve got a bit lost and need some help.

Any would be much appreciated.

Code below.

Thank you for any help.

[php]

$page_title = ‘New Link’;

include (‘includes/header.html’);

// Check if the form has been submitted:

if (isset($_POST[‘submitted’])) {

require_once ('xxxx'); // Connect to the db.

$errors = array(); // Initialise an error array.


// Check for a title:

if (empty($_POST['title'])) {

   $errors[] = 'You forgot to enter the link title.';

} else {

   $title = mysqli_real_escape_string($dbc, trim($_POST['title']));

}



// Check for an intro:

if (empty($_POST['intro'])) {

   $errors[] = 'You forgot to enter the link intro.';

} else {

   $intro = mysqli_real_escape_string($dbc, trim($_POST['intro']));

}



// Check for an entry:

if (empty($_POST['entry'])) {

   $errors[] = 'You forgot to enter the link entry text.';

} else {

   $entry = mysqli_real_escape_string($dbc, trim($_POST['entry']));

}

// Check for an link:

if (empty($_POST['link'])) {

   $errors[] = 'You forgot to enter the link.';

} else {

   $entry = mysqli_real_escape_string($dbc, trim($_POST['link']));

}



if (empty($errors)) { // If everything is ok.



	// Register the user in the database...



	// Make the query:

	$q = "INSERT INTO links (title, intro, entry, link, creation_date) VALUES ('$title', '$intro', '$entry', '$link', NOW() )";

	$r = @mysqli_query ($dbc, $q); // Run the query.

	if ($r) { // If it ran ok.



	   // Print a message:

	   echo '<h1>Thank you!</h1>

	<p>The link is now created. There will be a log in later.</p><p><br /></p>';



	} else { // If it did not run ok.



	   // Public message:

	   echo '<h1>System Error</h1>

	   <p class="error"> The link could not be created due to a system error. We apologise for any inconvenience. </p>';



		// Debugging message:

		echo '<p>' . mysqli_error($dbc) . '<br /><br />Query: ' .$q . '</p>';



	} // End of if ($r) IF. 

	

	



	// Include the footer and quit the script:

	include ('includes/footer.html');

	exit();



} else { // Report the errors.



	echo '<h1>Error!</h1>

	<p class="error">The following error(s) occured:<br />';

	foreach ($errors as $msg) { // Print each error

	   echo " - $msg<br />\n";

	}

	echo '</p><p>Please again.</p><p><br /></p>';



} // End of if (empty($errors)) IF.

mysqli_close($dbc); // Close the database connection

} // End of the main a submit conditional.

?>

New Link

Intro:

Entry:
<?php if (isset($_POST['entry'])) echo $_POST['entry']; ?>

Title:

Link:

[/php]

what does create links have in it

Hi it has a form so the user can post a title, text, intro and link to the corresponding rows in the mysql database. Is that what you mean?

post your code please

Sorry, I understand now.

Cheers…

[php]$page_title = ‘New Link’;

include (‘includes/header.html’);

// Check if the form has been submitted:

if (isset($_POST[‘submitted’])) {

require_once ('xxxx'); // Connect to the db.

$errors = array(); // Initialise an error array.


// Check for a title:

if (empty($_POST['title'])) {

   $errors[] = 'You forgot to enter the link title.';

} else {

   $title = mysqli_real_escape_string($dbc, trim($_POST['title']));

}



// Check for an intro:

if (empty($_POST['intro'])) {

   $errors[] = 'You forgot to enter the link intro.';

} else {

   $intro = mysqli_real_escape_string($dbc, trim($_POST['intro']));

}

// Check for an entry:

if (empty($_POST['entry'])) {

   $errors[] = 'You forgot to enter the link entry text.';

} else {

   $entry = mysqli_real_escape_string($dbc, trim($_POST['entry']));

}

// Check for an link:

if (empty($_POST['link'])) {

   $errors[] = 'You forgot to enter the link.';

} else {

   $entry = mysqli_real_escape_string($dbc, trim($_POST['link']));

}



if (empty($errors)) { // If everything is ok.



	// Register the user in the database...



	// Make the query:

	$q = "INSERT INTO links (title, intro, entry, link, creation_date) VALUES ('$title', '$intro', '$entry', '$link', NOW() )";

	$r = @mysqli_query ($dbc, $q); // Run the query.

	if ($r) { // If it ran ok.



	   // Print a message:

	   echo '<h1>Thank you!</h1>

	<p>The link is now created. There will be a log in later.</p><p><br /></p>';



	} else { // If it did not run ok.



	   // Public message:

	   echo '<h1>System Error</h1>

	   <p class="error"> The link could not be created due to a system error. We apologise for any inconvenience. </p>';



		// Debugging message:

		echo '<p>' . mysqli_error($dbc) . '<br /><br />Query: ' .$q . '</p>';



	} // End of if ($r) IF. 

	

	



	// Include the footer and quit the script:

	include ('includes/footer.html');

	exit();



} else { // Report the errors.



	echo '<h1>Error!</h1>

	<p class="error">The following error(s) occured:<br />';

	foreach ($errors as $msg) { // Print each error

	   echo " - $msg<br />\n";

	}

	echo '</p><p>Please again.</p><p><br /></p>';



} // End of if (empty($errors)) IF.

mysqli_close($dbc); // Close the database connection

} // End of the main a submit conditional.

?>

New Link

Intro:

Entry:
<?php if (isset($_POST['entry'])) echo $_POST['entry']; ?>

Title:

Link:

[/php]

eheh

ok i need you to post the code of your create_links.php please

yea please,

post code

The last is infact the create_links.php - just unhelpfully it has $page_title = ‘New Link’; written at the top.

It is called create_links.php on the server

… which has pointed me to an error in my edit_link.php code

<form action="create_links.php" method="POST">

should read

<form action="edit_link.php" method="POST">

which explains an error duplication ;D

Ok, have sorted most of my messed up pages - this has helped to clear my head a bit…

But still the problem - the link is posted as the entry and the link is blank when I create a link and when I edit it and then post the link has the word link in it…

[php]echo ‘

Edit Link

’;

// Check for a valid link ID, throught GET or Post:

if ( (isset($_GET[‘id’])) && (is_numeric ($_GET[‘id’])) ) { // From view_links.php
$id = $_GET[‘id’];
} elseif ( (isset($_POST[‘id’])) && (is_numeric($_POST[‘id’])) ) { // Form submission.
$id = $_POST[‘id’];
} else { // No valid ID, kill the script.
echo ‘

This page has been accessed in error.

’;
include (‘pook_includes/footer.html’);
exit();
}

require_once (‘xxxx’);

// Check if the form has been submitted:
if (isset($_POST[‘submitted’])) {

$errors = array();

// Check for a title:
if (empty($_POST[‘title’])) {
$errors[] = ‘You forgot to enter the link title.’;
} else {
$title = mysqli_real_escape_string($dbc, trim($_POST[‘title’]));
}

// Check for an intro:
if (empty($_POST[‘intro’])) {
$errors[] = ‘You forgot to enter the link intro.’;
} else {
$intro = mysqli_real_escape_string($dbc, trim($_POST[‘intro’]));
}

// Check for an entry:
if (empty($_POST[‘entry’])) {
$errors[] = ‘You forgot to enter the link entry text.’;
} else {
$entry = mysqli_real_escape_string($dbc, trim($_POST[‘entry’]));
}

// Check for an link:
if (empty($_POST[‘link’])) {
$errors[] = ‘You forgot to enter the link.’;
} else {
$entry = mysqli_real_escape_string($dbc, trim($_POST[‘link’]));
}

if (empty($errors)) { // If everything's ok.

	// Make the query
	$q = "UPDATE links SET title='$title', intro='$intro', entry='$entry', link='link' WHERE id=$id LIMIT 1";
	$r = mysqli_query ($dbc, $q);
	if (mysqli_affected_rows($dbc) == 1) { // If it ran ok
	
	// Print a messagr
	echo '<p>The page has been edited.</p>';
	
	} else { // If it did not run ok
	echo '<p class="error">The page could not be edited due to a system error. We appologise for any inconvenience.</p>'; // Public message.
	
	}

} else { // Report the errors.

echo '<p class="error">The following errors occurred:<br />';
foreach ($errors as $msg) { // Print each error.
	echo " - $msg<br />\n";
	}
	echo '</p><p>Please try again.</p>';
	
	} // End of if (empty($errors)) IF.
	
} // End of submit conditional.

// Always show the form...

// Retrieve the page's information:
$q = "SELECT title, intro, entry, link FROM links WHERE id=$id";
$r = mysqli_query ($dbc, $q);

if (mysqli_num_rows($r) == 1) { // Valid link ID, show the form.

// Get the link's information:
$row = mysqli_fetch_array ($r, MYSQLI_NUM);

// Create the form:
echo '<form action="edit_link.php" method="post">

Intro:

Entry: ' . stripslashes($row[2]) . '

Title:

Link:

';[/php]

I really am at a complete loss now :S

[php]// Check if the form has been submitted:
if (isset($_POST[‘submitted’])) {

$errors = array();

// Check for a title:
if (empty($_POST[‘title’])) {
$errors[] = ‘You forgot to enter the link title.’;
} else {
$title = mysqli_real_escape_string($dbc, trim($_POST[‘title’]));
}

// Check for an intro:
if (empty($_POST[‘intro’])) {
$errors[] = ‘You forgot to enter the link intro.’;
} else {
$intro = mysqli_real_escape_string($dbc, trim($_POST[‘intro’]));
}

// Check for an entry:
if (empty($_POST[‘entry’])) {
$errors[] = ‘You forgot to enter the link entry text.’;
} else {
$entry = mysqli_real_escape_string($dbc, trim($_POST[‘entry’]));
}

// Check for an link:
if (empty($_POST[‘link’])) {
$errors[] = ‘You forgot to enter the link.’;
} else {
$entry = mysqli_real_escape_string($dbc, trim($_POST[‘link’]));
}

if (empty($errors)) { // If everything's ok.

	// Make the query
	$q = "UPDATE links SET title='$title', intro='$intro', entry='$entry', link='$link' WHERE id=$id LIMIT 1";
	$r = mysqli_query ($dbc, $q);
	if (mysqli_affected_rows($dbc) == 1) { // If it ran ok
	
	// Print a messagr
	echo '<p>The page has been edited.</p>';
	
	} else { // If it did not run ok
	echo '<p class="error">The page could not be edited due to a system error. We appologise for any inconvenience.</p>'; // Public message.
	
	}

} else { // Report the errors.

echo '<p class="error">The following errors occurred:<br />';
foreach ($errors as $msg) { // Print each error.
	echo " - $msg<br />\n";
	}
	echo '</p><p>Please try again.</p>';
	
	} // End of if (empty($errors)) IF.
	
} // End of submit conditional.

// Always show the form...

// Retrieve the page's information:
$q = "SELECT title, intro, entry, link FROM links WHERE id=$id";
$r = mysqli_query ($dbc, $q);

if (mysqli_num_rows($r) == 1) { // Valid link ID, show the form.

// Get the link's information:
$row = mysqli_fetch_array ($r, MYSQLI_NUM);

// Create the form:
echo '<form action="edit_link.php" method="post">

Title:

Intro:

Entry: ' . stripslashes($row[2]) . '

Link:

';[/php]

I mean, even this way still has a problem :o

[php] echo ’

Title:

Intro:

Entry: ' . stripslashes($entry) . '

Link:

[/php]

Same error in the Create Link page? I just can’t see it :S

[php] // Check for a title:

if (empty($_POST['title'])) {

   $errors[] = 'You forgot to enter the link title.';

} else {

   $title = mysqli_real_escape_string($dbc, trim($_POST['title']));

}



// Check for an intro:

if (empty($_POST['intro'])) {

   $errors[] = 'You forgot to enter the link intro.';

} else {

   $intro = mysqli_real_escape_string($dbc, trim($_POST['intro']));

}



// Check for an entry:

if (empty($_POST['entry'])) {

   $errors[] = 'You forgot to enter the link entry text.';

} else {

   $entry = mysqli_real_escape_string($dbc, trim($_POST['entry']));

}

// Check for an link:

if (empty($_POST['link'])) {

   $errors[] = 'You forgot to enter the link.';

} else {

   $entry = mysqli_real_escape_string($dbc, trim($_POST['link']));

}



if (empty($errors)) { // If everything is ok.



	// Register the user in the database...



	// Make the query:

	$q = "INSERT INTO links (title, intro, entry, link, creation_date) VALUES ('$title', '$intro', '$entry', '$link', NOW() )";

	$r = @mysqli_query ($dbc, $q); // Run the query.

	if ($r) { // If it ran ok.



	   // Print a message:

	   echo '<h1>Thank you!</h1>

	<p>The link is now created. There will be a log in later.</p><p><br /></p>';



	} else { // If it did not run ok.



	   // Public message:

	   echo '<h1>System Error</h1>

	   <p class="error"> The link could not be created due to a system error. We apologise for any inconvenience. </p>';



		// Debugging message:

		echo '<p>' . mysqli_error($dbc) . '<br /><br />Query: ' .$q . '</p>';



	} // End of if ($r) IF. 

	

	



	// Include the footer and quit the script:

	include ('pook_includes/footer.html');

	exit();



} else { // Report the errors.



	echo '<h1>Error!</h1>

	<p class="error">The following error(s) occured:<br />';

	foreach ($errors as $msg) { // Print each error

	   echo " - $msg<br />\n";

	}

	echo '</p><p>Please again.</p><p><br /></p>';



} // End of if (empty($errors)) IF.

mysqli_close($dbc); // Close the database connection

} // End of the main a submit conditional.

?>

New Link

Intro:

Entry:
<?php if (isset($_POST['entry'])) echo $_POST['entry']; ?>

Title:

Link:

[/php]

Problem solved!

[php]// Check for an link:
if (empty($_POST[‘link’])) {
$errors[] = ‘You forgot to enter the link.’;
} else {
$entry = mysqli_real_escape_string($dbc, trim($_POST[‘link’]));
}[/php]

should read:

[php]// Check for an link:
if (empty($_POST[‘link’])) {
$errors[] = ‘You forgot to enter the link.’;
} else {
$link = mysqli_real_escape_string($dbc, trim($_POST[‘link’]));
}[/php]

of course.

Cheers!

ok something in your code is sending the information to the wrong place

meaning create links thoroughly check that file please or if your mysql is what is storing the links then you are querying it to be sent to the wrong place this has happened to all of us all that needs to be done is fully check where what part of the code is sending the info to the html

edit sorry i forgot to refresh
yes i see it now sorry we couldnt help you to many things going on
good you found the problem

That’s ok. I knew it was a simple problem and I just needed the space and another pair of eyes. I managed to find someone who could help and posted the result here. Don’t worry about not helping - having the space did help.

Cheers,
Colin

Sponsor our Newsletter | Privacy Policy | Terms of Service