1

im trying to send my variables to table but i get error for $title and $body:

Undefined variable: title in C:\wamp\www\source\pishnahad.php on line 237

Notice: Undefined variable: body in C:\wamp\www\source\pishnahad.php on line 237

<div class='container' dir="rtl" >
<label for='name'>نام: </label>
<input type='text' name='name' id='name' value='<?=  $fgmembersite->UserFullName() ?>' maxlength="50"  disabled="disabled"/><br/>

</div>


<div class='container' dir="rtl" >
<label for='email'>ایمیل: </label>
<input type='text' name='email' id='email' value='<?= $fgmembersite->UserEmail() ?>' disabled="disabled"/><br/>

</div>

<form name="form2" method="post" action="submit_shekayat" accept-charset='UTF-8'>
<div class='container' dir="rtl" >
<label for='title'>موضوع: </label>
<input type='text' name='title' id='title'/><br/>

</div>

<div class='container' dir="rtl" >
<label for='body'>توضیحات: </label> <br />
<textarea name="body" id="body" cols="" rows="" style="width:300 ;height:300"></textarea>

</div>

            <?php

$user_id =$fgmembersite->UserID();

$db_host = 'localhost';
$db_name= 'site';
$db_table= 'shekayat';
$db_user = 'root';
$db_pass = '';




$con = mysql_connect($db_host,$db_user,$db_pass) or die("خطا در اتصال به پايگاه داده");

mysql_query("SET NAMES 'utf8'", $con);
mysql_query("SET CHARACTER SET 'utf8'", $con);
mysql_query("SET character_set_connection = 'utf8'", $con);

$selected=mysql_select_db($db_name, $con) or die("خطا در انتخاب پايگاه داده");
mysql_query("SET CHARACTER SET  utf8");
$ins="INSERT INTO $db_table (user_id,title,body) VALUES('$user_id','$title','$body')";
$saved=mysql_query($ins );
mysql_close($con); 
?>


<div class='container'>
<input type='submit'  name='Submit' value='ارسال اطلاعات' />


</div>
1
  • You have no such values as $title and $body ?!? Commented Nov 1, 2015 at 14:48

2 Answers 2

1

I solved my problem, myself.

We should use of two pages:

  1. Sending input boxes via form to another page.
  2. Insert input boxes via these codes:

    $ins="INSERT INTO $db_table (user_id,title,body) VALUES('$user_id','" . mysql_escape_string($_POST['title']) . "','" .
    mysql_escape_string($_POST['body']) . "')";

Sign up to request clarification or add additional context in comments.

Comments

0

You have the

 $user_id = $fgmembersite->UserID();

But where

 $title

and

 $body 

come from ? If you want to assign $body a value of the textarea with the ID body you have to use JS Ajax call for example or simply hardcoding it (which is not recommended).

2 Comments

here is title and body: <div class='container' dir="rtl" > <label for='title'>موضوع: </label> <input type='text' name='title' id='title'/><br/> </div> <div class='container' dir="rtl" > <label for='body'>توضیحات: </label> <br />
They are HTML elements. You can't simply that say $body. I suppose you have some missunderstanding between html php and ...

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.