Jump to content

[SOLVED] Annoying invisible title


jrws

Recommended Posts

Hey guys me again. Ignore the fact that this is insecure, it is simply for testing purposes. Anyway here are the files first:

<?php
//Edit Data
//edit.php
require_once'config.php';
if (isset($_GET['id']) && is_numeric($_GET['id'])) {
error_reporting(E^ALL);
    $id = $_GET['id'];
    $sql2 = mysql_query("SELECT * FROM `formdata` WHERE id='$id'") or die(mysql_error());
    $row = mysql_fetch_array($sql2);
    $title = $row['title'];
    $data = $row['data'];
    $id = $row['id'];
    if(empty($title)or $title =='') echo 'Its empty...';
    echo ('<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

<html>
<head>
    <meta http-equiv="content-type" content="text/html; charset=us-ascii">
    <meta name="author" content="">

    <title>Database Edit</title>
</head>

<body>
<form action="http://localhost/website/Basic ideas/edit2.php" method = "post">
<input type = "hidden" name = "id" value ="'.$id.'">
Title:<input type="text" name = "title" size="32 value = "'.$title.'"><br>
    <textarea rows="6" cols="40" name = "data">
    ' . $data . '
</textarea>
<br>
<input type = "submit" value = "Submit">
</form>
</body>
</html>'); }else{
echo 'No data selected to edit!';
}
?>

^ The problem code (I think)

 

 

<?php
//display.php
include "config.php";
if (isset($_GET['id'])&& is_numeric($_GET['id'])) {
$id = $_GET['id'];
    $sql2 = mysql_query("SELECT * FROM `formdata` WHERE id='$id'") or die(mysql_error());
    $row = mysql_fetch_array($sql2);
$title = $row['title'];
$data=$row['data'];
echo '<h1>'.$title.'</h1>';
echo '<p>'.$data.'</p>'; 

echo '<a href = "http://localhost/website/Basic ideas/edit.php?id='.$id.'">Edit this</a>';
}else{
header('Location: http://localhost/website/Basic ideas/database.htm');
}


?>

<?php
//Edit 2
require_once('config.php');
$title = $_POST['title'];
$data = $_POST['data'];
$id = $_POST['id'];
$query = "UPDATE formdata SET title='$title', data='$data' WHERE id=$id";
$res =mysql_query($query)or die('Error: '.mysql_error().'<br>Query: '.$query);
if($res){
echo 'Successfully updated!';
}
?>

<?php
require_once ('config.php');
$data = clean($_POST['data']);
$title = clean($_POST['title']);
$query = "INSERT INTO formdata(title,data)VALUES('$title','$data')";
$res = mysql_query($query) or die('Error: ' . mysql_error() . '<br>' . 'Query: ' .
    $query);
if ($res) {
    echo 'Success! Click <a href="http://localhost/website/Basic ideas/database.htm" >here</a> to go back<br>Below are all the recent articles:<br>';
}
$sql = mysql_query("SELECT * FROM `formdata` ORDER BY `id` ASC") or die(mysql_error
    ()); # select the news
echo 'Current posts: ';
while ($row = mysql_fetch_array($sql)) { #create a while loop to echo the news in.
    echo '<br>' . 'Title: ' . $row['title'] . '<br>' . 'Post: ' . $row['data'] .
        '<br>' . '<a href ="http://localhost/website/Basic ideas/display.php?id=' . $row['id'] .
        '"> View full post</a>';
}

?>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

<html>
<head>
    <meta http-equiv="content-type" content="text/html; charset=us-ascii">
    <meta name="author" content="">

    <title>Database Submition test</title>
</head>

<body>
<form action="http://localhost/website/Basic ideas/data.php" method = "post">
Title:<input type="text" name = "title" size="32"><br>
    <textarea rows="6" cols="40" name = "data">
</textarea>
<br>
<input type = "submit" value = "Submit">
</form>
</body>
</html>

 

Okies so that was all the code. Now the problem.

When I enter the edit screen it shows no title. At one point I did a test to see if it was empty (as is still in the code) it returned true. And now it returns false. I can't find where it is having the problem. The edit works, its only the title that doesn't seem to want to. So help is appreciated :)

Link to comment
Share on other sites

I did not test your stuff but could it be a quote problem ...

Your not filtring out the stuff befor inserting it. Does mysql_error() return anything

 

I dont understand your question actualy. What do you mean you dont see the title in the edit page

<input type="text" name = "title" size="32">

 

If you mean in that box it would probably work better if you insert the value

 

Link to comment
Share on other sites

unless I'm cross-eyed, your code looks fine.  Check to make sure that your column is correctly named (including the right case; like, make sure it's 'title' and not 'Title' because it's case-sensitive). 

I thought I was too, it is all correct and yet I still cannot see why it isn't working. It is really peeing me off!

I did not test your stuff but could it be a quote problem ...

Your not filtring out the stuff befor inserting it. Does mysql_error() return anything

 

I dont understand your question actualy. What do you mean you dont see the title in the edit page

<input type="text" name = "title" size="32">

 

 

If you mean in that box it would probably work better if you insert the value

 

I told you I am not doing sercurity at the moment. Because this is staying in a test environment. I don't see the title in the edit page, I mean when you edit a topic here it has your topic name and then the body content. In my file it is missing the topic name (in this example). Do you understand now? And I don't understand what you are doing by saying inserting the value? Its already there

Title:<input type="text" name = "title" size="32 value = "'.$title.'"><br>
Link to comment
Share on other sites

Yeah sorry i am using a weird browser at the moment and i messed the scroller of the code box lol

Can you take a look in your database and confirm the title of the $row['id'] is not empty and show us what it contains and can you take a look at the HTML output code ... sometimes some values can temper with the output since your not filtring it ...

 

Ex: $this = '"hi';

echo "<input type = "hidden" name = "id" value ="'.$this.'">";

 

Would end up being: <input type = "hidden" name = "id" value =""hi">

 

So what's in that table?

Link to comment
Share on other sites

Alright will try your suggestions. I will edit this post in a minute, as soon as I have tried ;)

size="32 value = "

Missing a " on the <input>

 

Also, if that doesn't work,

Find:

<body>

Replace:

<body>
print_r($row);

 

That'll show to make sure you're pulling the right col names + if there is a value or not

You are my hero! Thats what I was missing! I don't know how I kept missing it >_<;

Thanks for all your help.

Man I am glad I have you guys to help ^^

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.