Jump to content

This is weird, a logic error perhaps?


elite_prodigy

Recommended Posts

Um, you guys can mob me later. Like I said, I have far too many problems with PHP, and I shouldn't!

 

Okay, so no error is being generated, but one of my tables is not being updated. I checked the form names, they are ok, I checked the table names, they seem fine, I checked the code against both and that seems in order.

 

So, here is the table:

 

pgContent

-id

-topBar

-content

-pgId

 

And here be the code that creates the form:

 

<?php

include 'config.php';

mysql_select_db('exembar_site');

$query = "SELECT * FROM `navigation` WHERE `id`=".$_GET['id'];

$result = mysql_query($query);

while($info = mysql_fetch_array($result)){

$editing = $info['display'];

}

$query = "SELECT * FROM `pages` WHERE `id`=".$_GET['id'];

$result = mysql_query($query);

while($info = mysql_fetch_array($result)){

$title = $info['title'];

}

$query = "SELECT * FROM `pgContent` WHERE `id`=".$_GET['id'];

$result = mysql_query($query);

while($info = mysql_fetch_array($result)){

$top = $info['topBar'];
$content = $info['content'];

}

$topbar = "Editing: ".$editing;
$body ='
<form name="edit" action="php/edit.php?id='.$_GET['id'].'" method="post">
Page Title: <input type="text" name="title" value="'.$title.'" /> <br />
Nav Text: <input type="text" name="display" value="'.$editing.'" /> <br />
Top Bar Text: <input type="text" name="topbar" value="'.$top.'" /> <br />
Page Content:<br />
<textarea rows="30" cols="50" name="content">'.$content.'</textarea><br />
<input type="submit" value="Save" />

</form>

';

?>

 

And here is the code that updates the table:

 

<?php

include 'config.php';

mysql_select_db('exembar_site');

$title = $_POST['title'];
$display = $_POST['display'];
$top = $_POST['topbar'];
$content = $_POST['content'];
$id = $_GET['id'];

$sql = "UPDATE `navigation` SET `display`='{$display}' WHERE id='{$id}'";
mysql_query($sql) or die(mysql_error());

$sql = "UPDATE `pages` SET `title`='{$title}' WHERE `navId`='{$id}'";
mysql_query($sql) or die(mysql_error());

$SQL = "UPDATE `pgContent` SET `topBar`='{$top} `content`='{$content} WHERE `pageId`='{$id}'";
mysql_query($sql) or die(mysql_error());


?>

 

I can't figure out the problem, though I' sure I've overlooked something.

 

Your help is always appreciated(and I can't say how much).

 

*grovels*

 

-David

Link to comment
Share on other sites

Although I see many things I would change, your problem is on line 11 of the 2nd script you posted

$id = $_GET['id'];

 

You are POSTing data to that page, not sending it on the URL. Change that to

$id = $_POST['id'];

and create a hidden field on the form with the ID. I don't think you can POST and GET data at the same time.

 

I would recommend adding an on die() handler to all of your db calls. I typically have the error echo the full query to the page when it fails. In this case you would have seen that the value for the id was empty.

Link to comment
Share on other sites

I've appended the I'd to the php/edit.php?id= action in the script that generates the form. If that were the case, none of the tables would have changed because I'm relying on that $id variable to select which row I'm editing, the I'd is the primary key to navigation and the pageId and navId to the others, which I should have named the same, but didn't but they are acting as my foreign keys if you will. I need each row in each of the three tables responsible for page generation to reference the other two.

 

It's not my use of $_GET, I thought about this but if that were the case the other two tables would never be updated. But they are, so the problem lies withing all of the code for the third table pgContent, which is not receiving the information from the form.

 

Good idea, but I don't think that's the problem though.

 

Thanks

Link to comment
Share on other sites

I knew it was something stupid. I am doing this on my blackberry, so, the screen size makes it a little hard to notice things, but I do this all the time. And, normally, it continues to happen, I just end up not seeing what is not there.

 

Thanks!

 

(I'll probably be back in about 3 minutes with something else though, God I feel so amature sometimes :( )

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.