Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Unknown Error next page will not show

Status
Not open for further replies.

SeeCharp

Programmer
Nov 15, 2006
12
US
Hello people I have a script that is pulling from a MySQL database and I can't figure out the error on this page can anyone see why the next page is giving me a can't connect error like the url is incorrect so perhaps some of the code being passed is incorrect but I can't find it.

<?php
// Checks for the id value if it doesn't exist send user back to the selection form and exit script.
if (!$_POST[a_id]) {
header("Location: exit;
// if the required field has a value start session or continue one.
} else {
session_start();
}

// check value of session[valid] if answer is not yes then authentication is not valid
if ($_SESSION[valid] != "yes") {

// Send user back to the login form
header("Location: exit;
}

// Create a variable to hold the name of the database on which the table resides.
$db_name = "cayema";

// Create a variable to hold the name of the table you're populating with this script
$table_name = "Articles";

$connection = @mysql_connect("localhost", "cayema", "red27") or die (mysql_error());

// Select the database
$db = @mysql_select_db($db_name, $connection) or die (mysql_error());

// create the sql statement
$sql = "SELECT article_name, image, text FROM $table_name WHERE a_id = '$_POST[a_id]'";

// create a variable to hold the result of the mysql_query() function
$result = @mysql_query($sql, $connection) or die (mysql_error());

// Start the while loop create an array called $row for each record in the result set
while ($row = mysql_fetch_array($result)) {

// Get individual elements of the record and give them good names
$article_name = $row['article_name'];
$image = $row['image'];
$text = $row['text'];




// close the loop and php block
}
?>

<html><head><title>My Website Management System: Delete an Article</title>
</head>
<body>
<h1>My Website Management System</h1>
<h2><em>Delete an Article</em></h2>
<form method="post" action="do_delarticle.php">

<input type="hidden" name="a_id" value="<?php echo '$_POST[a_id]'; ?>">
<input type="hidden" name="article_name" value="<? echo '$article_name'; ?>">



<table cellspacing=3 cellpadding=5>
<tr><th>Article Information</th>
</tr>

<!-- Create rows and cells to hold input fields for items in the record usign value attributes in each input field -->
<tr><td valign=top>
<p><strong>Article Name:</strong><br>
<?php echo "$article_name"; ?></p>

<p><strong>Image:</strong><br>
<?php echo "$image"; ?></p>

<p><strong>Text:</strong><br>
<?php echo "$text"; ?></p>
</td>
</tr>

<tr><td align=center colspan=2><br>
<p><input type = "submit" Name="submit" value="Delete this Article"></p>
<p><a href="contact_menu.php">Return to Main Menu</a></p>
</td></tr></table></form></body></html>
 
get rid of the @ signs and make sure that you have got display_errors switched on and the error reporting set to E_ALL.

make sure that you enquote your array keys

and unless you really want to test against FALSE i'd recommend checking a_id for isset instead.
Code:
if (isset($_POST['a_id'])) {
 
I really appreciate your help jpadie but can you break down your explanations because I don't know PHP very well at all and I'm not sure how to turn on display errors, enquote array keys, set error reporting to e_all ect. Thanks
 
Code:
ini_set('display_errors', 1);
error_reporting(E_ALL);


Code:
$_POST[aid] <--- example of unenquoted array key

$_POST[[red]'[/red]aid[red]'[/red]] <--- example of enquoted array key
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top