Jump to content

blank page coming....


abeer

Recommended Posts

here is my code. it grabs id number from url then post data to mysql. everything is working fine.. the is also updating by this codes..

 

but the problem is after clicking the change button it goes to a blank page.

 

check out

http://www.platformsociety.org/update3.php/?id=2

 

<?php
$hostname = "local";
$username = "lash";
$password = "lash";

$db = mysql_connect($hostname, $username, $password) or die ("not able to connected to mysql");
// connect to database

mysql_select_db("lash")or die("Connection Failed");

$id = $_GET['id'];
if(isset($_POST['id'])) {
$sql="UPDATE page SET dtl='".$_POST['content']."' WHERE id = ".$_POST['id'];
mysql_query($sql) or die(mysql_error());
}


$result = mysql_query("select * from page where id = $id");
$row = mysql_fetch_assoc($result);
mysql_close($db);
?>

<html>
<head></head>
<body>

<form name="change_content" method="POST" action="update3.php">
<input type="hidden" name="id" value="<?php echo $row["id"]; ?>">
<textarea name="content"><?php echo $row["dtl"]; ?></textarea>
<input type="submit" value="change">
</form>

</body>
</html>

 

is it possible that after clicking the button CHANGE . it wil  show that " the data sucessfully saved"

Link to comment
Share on other sites

Well, I get the following error when submitting the form (i.e. not a blank page)

PHP Warning:  mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in D:\USERS\platform soc\platformsociety.org\wwwroot\update3.php on line 19

Link to comment
Share on other sites

I do see your problem though. The form has an action set as

 action="update3.php">

 

So, when the form is POSTed there is no GET value for the id, therefore the query you have at the end (to get the current values to populate the form) has no $id with which to use for the query. Here is a modification of your code that should work. If the ID was sent in the POST data it will use that, otherwise it will use the GET value (if available), if neither are set it will display an error.

<?php
$hostname = "local";
$username = "lash";
$password = "lash";

//Connect to database
$db = mysql_connect($hostname, $username, $password) or die ("not able to connected to mysql");
mysql_select_db("lash")or die("Connection Failed");

//Check if form was POSTed
if(isset($_POST['id']))
{
    //Update record if POST data submitted
    $id = (int) $_POST['id'];
    $content = mysql_real_escape_string($_POST['content']);
    $sql="UPDATE page SET dtl='$content' WHERE id = $id";
    mysql_query($sql) or die(mysql_error());
    if(mysql_affected_rows()>0)
    {
        $message = "<span style=\"\">The data was sucessfully saved</span>";
    }
    else
    {
        $message = "<span style=\"color:red;\">There was a problem saving the data.</span>";
    }
}
elseif(isset($_GET['id']))
{
    //Get ID from query string
    $id = (int) $_GET['id'];
}
else
{
    $message = "<span style=\"color:red;\">No record ID available.</span>";
}

if(isset($id))
{
    //Get current value for selected record
    $sql = "SELECT `id`, `dtl` FROM `page` WHERE `id` = $id"
    $result = mysql_query($sql) or die(mysql_error());
    $row = mysql_fetch_assoc($result);
}

mysql_close($db);
?>
<html>
<head></head>
<body>
<?php echo $message; ?></span>
<form name="change_content" method="POST" action="update3.php">
<input type="hidden" name="id" value="<?php echo $row["id"]; ?>">
<textarea name="content"><?php echo $row["dtl"]; ?></textarea>
<input type="submit" value="change">
</form>

</body>
</html>

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.