Welcome to Dream.In.Code
Become a PHP Expert!

Join 137,424 PHP Programmers for FREE! Get instant access to thousands of PHP experts, tutorials, code snippets, and more! There are 1,964 people online right now. Registration is fast and FREE... Join Now!




Cant pass myvalue

 
Reply to this topicStart new topic

Cant pass myvalue

cimpercee
9 Jan, 2008 - 07:07 PM
Post #1

D.I.C Head
**

Joined: 10 Aug, 2006
Posts: 127


My Contributions
CODE

<?php
require_once('db_login.php');
require_once('connect.php');
$postID = $_POST[postID];
$title = htmlentities($_POST['title']);
$body = htmlentities($_POST['body']);
$action = htmlentities($_POST['action']);
$categoryID = htmlentities($_POST['categoryID']);
if ($_GET['action']=='delete' and !$stop)
{
$postID = $_GET["postID"];
$query = "Delete From posts Where postID = $postID";
$result = mysql_query($query);
if(!$result)
{
die("Could not execute query: <br/>" . mysql_error());
}
echo ("Deleted Successfully.<br/>");
$stop = "TRUE";
}
if ($_GET[postID] AND !$stop){
$query = "SELECT * FROM users NATURAL JOIN posts NATURAL JOIN categories WHERE postID = $_GET[postID]";
$result = mysql_query($query);
if(!$result)
{
die("Could not execute query: <br/>" . mysql_error());
}
//fetching data to be edited
while ($result_row = mysql_fetch_array($result, MYSQL_ASSOC))
{
$a = $result_row["title"];
$b = $result_row["body"];
$c = $result_row["postID"];
$e = $result_row["categoryID"];
$f = $result_row["userID"];
}
echo '<form action="modify_post.php?" method="POST">';
echo '<label><b>Title</b> : <input type="text" name="title" value="'.$a.'"></label>';
echo '<br />'.'<br />';
echo '<label><b>Body</b> : <textarea name="body" cols="40" rows="4"4>'.$b.'</textarea></label>';
echo '<input type="hidden" name="action" value="edit">';
echo '<input type="hidden" name="postID" value="'.$c.'"</label>';
echo '<input type="hidden" name="userID" value="'.$f.'"';
echo '<input type="hidden" name="categoryID" value="'.$e.'"'.'<br>';
//echo $userID . $catID;    

echo '<p><b>Category</b> : <select name="categ">';
$query = "Select categoryID, category From categories";
$result = mysql_query($query);
if(!$result){
die("Could not query: </b>" . mysql_error());
}
while($result_row = mysql_fetch_array($result, MYSQL_ASSOC))
{
$id = $result_row["categoryID"];
echo '<option';
//echo $cat;
echo ">$result_row[category]";
echo '</option>';}
echo '</select>';
echo '<br/>';

echo '<br/>';
echo '<input type="submit" name="t" value="Post" />';
echo '</form>';
$stop="TRUE";
}
// Form submitted validate fields
if ($_POST["t"] AND !$stop){
if($title == ""){
echo ("Title must not be null.<br>");
$found_error="TRUE";
$stop="TRUE";
}
if($body == ""){
echo ("Body must not be null.<br>");
$found_error="TRUE";
$stop="TRUE";
}
//validated now hitting database
if($_POST['action']=="edit" AND !$stop){
//use update query
echo $userID;
echo $categoryID;
//echo $postID;
//$query = "Insert into Posts values (NULL,'$categoryID','$userID','$title','$body','NULL')";
//$result = mysql_query($query);
//if(!$result) {
//die("Could not execute query: <br/>" . mysql_error());}
//echo ("Updated Successfully.<br>");
$stop="TRUE";
}
}
?>


i have problem after entries being validated, I can't pass my $userID and my $categoryID. if i remove the comment from the query, categoryID and UserID doesn't have a value.

I appreciate your help.

Thanks in advance!
User is offlineProfile CardPM
+Quote Post

WXY
RE: Cant Pass Myvalue
9 Jan, 2008 - 09:07 PM
Post #2

D.I.C Head
Group Icon

Joined: 2 Jan, 2008
Posts: 85


Dream Kudos: 50
My Contributions
Things I find strange:
$postID = $_POST[postID]
postID ?? do you mean $postID? or is it a constant defined in one of the include files? or were you after $_POST['postID']??

$stop = "TRUE"
uhh Ii think your looking for "$stop = true" there. Also you never initialized that value to false, so just to be on the safe side, add $stop = false at the begining of your code

$result_row = mysql_fetch_array( ..... $a = $result_row["title"]
You're looking for mysql_fetch_assoc there, not fetch_array

if ($_GET[postID]
This is not a really reliable form of testing, when the input is of a mixed type you really would want to do some kind of more presiced testing than that

Most of your MySQL queries
you would want ` quotes around column & table names to imply they're literals and not commands of the query language

All of those echo lines
You can make things faster by getting rid of those extra echos, the below is perfectly valid and can be expanded to any arbitary lines:
CODE
echo('something '.$somevar.' more stuff '.
'other stuff);


About $userID
Where did you define it? cause its certainly not on the code you've pasted. So from a logical perspective, if its not defined in one of those 2 included files, then it shouldn't have a value...

About $categoryID
I am not exactally sure about this one. But logically if it's not setting to what you've expected, it is that something with your form screwed up. Try using print_r() on the $_POST variable to see what is actually passed and if you've misspelled anything
User is offlineProfile CardPM
+Quote Post

cimpercee
RE: Cant Pass Myvalue
9 Jan, 2008 - 09:08 PM
Post #3

D.I.C Head
**

Joined: 10 Aug, 2006
Posts: 127


My Contributions
I think i got wrong from getting the value on hidden tag. im not so sure if i made it right on writing the code..

echo '<input type="hidden" name="userID" value=

wanted to set the value from my database stored in the variable $f.

im not really sure if i got it right and if Im am wrong, i would like to retrieve the value i have put on the hidden named userID and be using the value on inserting and updating.
i will be using the value stored on it after i have validated the values.

User is offlineProfile CardPM
+Quote Post

cimpercee
RE: Cant Pass Myvalue
9 Jan, 2008 - 09:15 PM
Post #4

D.I.C Head
**

Joined: 10 Aug, 2006
Posts: 127


My Contributions
hey thanks... im not done yet with my code on setting stop to false and other with boolean values there.

thank you for the advice. I will retouch my codes. postID is from a different php file.

thank you for the tips.

the only thing i would like to have is after validating the fields,
i would like to retrieve from one of my hidden fields the value i have stored. im not sure by now if i have write the code correctly.

Thank you for your time.
User is offlineProfile CardPM
+Quote Post

cimpercee
RE: Cant Pass Myvalue
9 Jan, 2008 - 09:35 PM
Post #5

D.I.C Head
**

Joined: 10 Aug, 2006
Posts: 127


My Contributions
[quote]
About $userID
Where did you define it? cause its certainly not on the code you've pasted. So from a logical perspective, if its not defined in one of those 2 included files, then it shouldn't have a value...

About $categoryID
I am not exactally sure about this one. But logically if it's not setting to what you've expected, it is that something with your form screwed up. Try using print_r() on the $_POST variable to see what is actually passed and if you've misspelled anything
[quote]

about the userID and categoryID, its fresh from the database.

CODE

//fetching data to be edited.
while ($result_row = mysql_fetch_array($result, MYSQL_ASSOC))
{
$a = $result_row["title"];
$b = $result_row["body"];
$c = $result_row["postID"];
$e = $result_row["categoryID"];
$f = $result_row["userID"];
}
echo '<form action="modify_post.php?" method="POST">';
echo '<label><b>Title</b> : <input type="text" name="title" value="'.$a.'"></label>';
echo '<br />'.'<br />';
echo '<label><b>Body</b> : <textarea name="body" cols="40" rows="4"4>'.$b.'</textarea></label>';
echo '<input type="hidden" name="action" value="edit">';
echo '<input type="hidden" name="postID" value="'.$c.'"</label>';
echo '<input type="hidden" name="userID" value="'.$f.'"';
echo '<input type="hidden" name="categoryID" value="'.$e.'"'.


set on the variable $e and $f respectively.

im not really sure if i wrote the line
CODE

echo '<input type="hidden" name="userID" value="'.$f.'"';
echo '<input type="hidden" name="categoryID" value="'.$e.'"'.

correctly.

i want to retrieve the values from my input. i find it difficult. I also slight knowledge of HTML but i hope you won't mind now coz I would like to set the values and retrieve it there as well.

tried to retrieve data like
$thevar = $_POST['postID'];
echo $thevar;

output is correct.

but once i do it this way
$thevar = $_POST['categoryID'];
echo $thevar;

i got empty string.

This post has been edited by cimpercee: 9 Jan, 2008 - 10:51 PM
User is offlineProfile CardPM
+Quote Post

cimpercee
RE: Cant Pass Myvalue
10 Jan, 2008 - 08:13 PM
Post #6

D.I.C Head
**

Joined: 10 Aug, 2006
Posts: 127


My Contributions
Got it done..

Thanks for your time
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 12/5/08 04:38AM

Live PHP Help!

PHP Tutorials

Reference Sheets

PHP Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month