Hello Dear Brothers & Sisters
how are you....?

Well, i am facing a problem while handling a script and database.
actually i am trying to shift some data (user id form database) form one page to another. through $_GET (if you have any other technique also suggest.)

and after transfring i grap that data through $_GET. and now i want to put that id from url to database for future use. and for that purpose i am using poster_id() function. it works fine normally i checked it through echo. but when i put this funtion in INSERT statement of mysql it put always "0" in database. why?
Please guide me. also i am new user of PHP.

<?php
                       require 'connect.php';

                         if(!empty($_GET["id"]) && !empty($_GET{"Summary"})){
                         echo  $id = $_GET["id"].'<br>';
                         echo $summary = $_GET["Summary"].'<hr>';
                         }
                            
                            function poster_id(){
                                 if(!empty($_GET["id"]) && !empty($_GET{"Summary"})){
                                 $id = $_GET["id"];
                                 return $id;
                                 }
                              }

                            //echo $one = poster_id();


                         if(isset($_POST["name"]) && isset($_POST["email"]) && isset($_POST["textArea"])){
                           $name  =    $_POST["name"];
                           $email =    $_POST["email"];
                           $textArea = $_POST["textArea"];
                           if(!empty($name) && !empty($email) && !empty($textArea)){

                                 $id = poster_id();

                             $query = "INSERT INTO coments VALUES('', '$id', '$name','$email','$textArea')";
                             if($query_run = mysql_query($query)){
                               echo $id = poster_id();
                             }
                           }
                         }
?>

HTML CODE HERE

<form action="test.php" method="POST">
                            Your Name:<input type="text" name="name" size="25">
                            E-mail address:<input type="text" name="email" size="30"><br>
                            <textarea cols="69" rows="10" name="textArea"></textarea>
                            <input type="submit" value="Submit">
                      </form>

Recommended Answers

All 5 Replies

Hi

Can you provide your error msg

Hello Dear Brother
How are you......?

And thanks for giving me time
but no error appear on my script when i press submit button.
just tell me how i can use return value of function (poster_id) in my database, i wanna store return value in mysql.
Thanks

Hi

$query = "INSERT INTO coments VALUES('', '$id', '$name','$email','$textArea')";

do you have 5 field in coments table.

$query = "INSERT INTO coments VALUES('', '$id', '$name','$email','$textArea')";

isn't coments suppose to be comments, and i find it always best to name the columns

$query = "INSERT INTO comments ('col1','col2','col3','col4','col5') VALUES ('$var1','$var2','$var3','$var4','$var5')";
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.