Jump to content

[SOLVED] Why isn't this working?


ryeman98

Recommended Posts

I don't get any errors or anything so I just don't get why it won't work. I'm connected to the database and the table that I have is there.

 

It's supposed to display each Clothing item by a link...

 

<?php

// Display the list
$query = mysql_query("SELECT * FROM CustomisationClothes ORDER BY name");
$result = mysql_fetch_array($query);

echo "<a href\"";
echo $sPHPSELF;
echo "?edit=";
echo $result['name'];
echo "\">";
echo $result['name'];
echo "</a>";


?>

Link to comment
Share on other sites

You can try this as well.

 

<?php

// Display the list
$query = mysql_query("SELECT * FROM CustomisationClothes ORDER BY name");
$result = mysql_fetch_assoc($query)or die(mysql_error());

echo "<a href='$sPHPSELF?edit={$result['name']}'>{$result['name']}</a>";

?>

 

It's also a possibility that there is an error in your query and it isn't returning anything, so I tacked on the error checking.

Link to comment
Share on other sites

Neither way is working. I'm going to post the entire code. But, there is no errors at all.

 

<?php
$pagetitle = ".........";
include($_ENV['SITE_HTMLROOT']."/header.php");
    require($_ENV['SITE_HTMLROOT']."/include/dbconnect_class.php");
        $db = new DB;
$sPHPSELF = $_SERVER['PHP_SELF'];
?>
<h1>Edit Clothing</h1>

<?php
if ($_GET['edit'] == $name) {

$name = $_POST['name'];
$edit = mysql_query("SELECT * FROM CustomisationClothes WHERE name='$name'");
while($row = mysql_fetch_array($edit)) {

echo "<img src=\"".$row['img_url']."\" alt=\"".$row['name']."\" />
<form name=\"editClothes\" action=\"editClothing.php\" method=\"post\">
<b>Name:</b> <input type=\"text\" name=\"name\" value=\"".$row['name']."\" /><br />
<b>IMG URL:</b> <input type=\"text\" name=\"img_url\" value=\"".$row['img_url']."\" /><br />";

$acara = mysql_query("SELECT * FROM CustomisationClothes WHERE acara");
$aisha = mysql_query("SELECT * FROM CustomisationClothes WHERE aisha");
	if ($acara == "yes") {
			echo "<input type='checkbox' name='acara' value='".$acara."' checked='checked' />";
	} else {
		echo "<input type='checkbox' name='acara' value='".$acara."' />";
	}

	if ($aisha == "yes") {
		echo "<input type='checkbox' name='aisha' value='".$aisha."' checked='checked' />";
	} else {
		echo "<input type='checkbox' name='aisha' value='".$aisha."' />";
	}

?>
<input type="submit" name="submit" value="Edit Clothing" />
</form>

<?php
} // End while
} else {

// Display the list
$query = mysql_query("SELECT * FROM CustomisationClothes ORDER BY name") or die(mysql_error());
$result = mysql_fetch_assoc($query) or die(mysql_error());

echo "<a href\"".$sPHPSELF."?edit=".$result['name']."\">".$result['name']."</a>";

} // End else
?>

<?php
include($_ENV['SITE_HTMLROOT']."/footer.php");
?>

Link to comment
Share on other sites

<?php
   $acara = mysql_query("SELECT * FROM CustomisationClothes WHERE acara");
   $aisha = mysql_query("SELECT * FROM CustomisationClothes WHERE aisha");
?>

 

These two queries have nothing to do with your link not working, but they are both invalid.

 

You need to be more specific on the conditon:

WHERE aisha

 

Where aisha...? Where aishia is what, or equal to what? Those queries will most likely bring up problems later on when your testing your script.

 

 

Link to comment
Share on other sites

The query that is effecting your links looks like this:

$query = mysql_query("SELECT * FROM CustomisationClothes ORDER BY name") or die(mysql_error());

 

You have an ORDER BY in there...so your obviously wanting to display more than one result, correct? To do that you will need a while loop.

 

Just for the sake of testing, try changing your query to this:

$query = mysql_query("SELECT * FROM CustomisationClothes") or die(mysql_error());

Link to comment
Share on other sites

Okay, let me make sure I understand your problem.

 

There is absolutely NO output from this:

echo "<a href\"".$sPHPSELF."?edit=".$result['name']."\">".$result['name']."</a>";

 

It is displaying a total blank screen?

 

See if you get something from replacing that with this:

echo "<a href\"".$sPHPSELF."?edit=".$result['name']."\">TEST</a>";

 

Link to comment
Share on other sites

Try this:

 

<?php
$pagetitle = ".........";
include($_ENV['SITE_HTMLROOT']."/header.php");
require($_ENV['SITE_HTMLROOT']."/include/dbconnect_class.php");
$db = new DB;
$sPHPSELF = $_SERVER['PHP_SELF'];
?>
<h1>Edit Clothing</h1>

<?php
if ($_GET['edit'] == $name) {
    
    $name = $_POST['name'];
    $edit = mysql_query("SELECT * FROM CustomisationClothes WHERE name='$name'");
    
    while ($row = mysql_fetch_array($edit)) {
        
        echo "<img src=\"".$row['img_url']."\" alt=\"".$row['name']."\" />
         <form name=\"editClothes\" action=\"editClothing.php\" method=\"post\">
         <b>Name:</b> <input type=\"text\" name=\"name\" value=\"".$row['name']."\" /><br />
         <b>IMG URL:</b> <input type=\"text\" name=\"img_url\" value=\"".$row['img_url']."\" /><br />";
        
        $acara = mysql_query("SELECT * FROM CustomisationClothes WHERE acara");
        $aisha = mysql_query("SELECT * FROM CustomisationClothes WHERE aisha");

        if ($acara == "yes") {
            echo "<input type='checkbox' name='acara' value='".$acara."' checked='checked' />";
        } else {
            echo "<input type='checkbox' name='acara' value='".$acara."' />";
        }
        
        if ($aisha == "yes") {
            echo "<input type='checkbox' name='aisha' value='".$aisha."' checked='checked' />";
        } else {
            echo "<input type='checkbox' name='aisha' value='".$aisha."' />";
        }
        
        ?>
        <input type="submit" name="submit" value="Edit Clothing" />
        </form>
        
        <?php
    }
    // End while
}

// Display the list
$query = mysql_query("SELECT * FROM CustomisationClothes ORDER BY name") or die(mysql_error());
$result = mysql_fetch_assoc($query) or die(mysql_error());

echo "<a href\"".$sPHPSELF."?edit=".$result['name']."\">".$result['name']."</a>";

?>

<?php
include($_ENV['SITE_HTMLROOT']."/footer.php");
?>

Link to comment
Share on other sites

Ah, I figured out the main problem though.

 

All you have to do is remove change this line:

if ($_GET['edit'] == $name) {

 

To:

if ($_GET['edit']) {

 

The "== $name" part wouldn't even make sense there. You don't have that variable defined anywhere in the script before that line...so it has no idea what $name is.

 

I would personally change the line to this:

if (!empty(trim($_GET['edit']))) {

 

With that change, the code should work.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.