douhuang5331 2019-05-15 17:44
浏览 50

未定义的变量:X行中的yourName? [重复]

So i always get this error and i don't know what the cause of this is, ive been trying allday

Array ( [inputName] => [inputEmail] => [inputNumber] => 43235432532 [inputTitle] => [inputText] => sadasdas [submit] => Postavi besplatan Oglas ) Notice: Undefined variable: yourName in C:\xampp\htdocs\oglasi\add_script.php on line 56

Notice: Undefined variable: yourEmail in C:\xampp\htdocs\oglasi\add_script.php on line 56

Notice: Undefined variable: yourTitle in C:\xampp\htdocs\oglasi\add_script.php on line 56

Warning: mysqli_error() expects exactly 1 parameter, 0 given in C:\xampp\htdocs\oglasi\add_script.php on line 59 nije mogucce postaviti dadoteke u db:

add.html

                <form  method="post" action="add_script.php">

                    <h2 ></h2> <!-- ueberschrift -->

                    Ime (vaše Ime neće pisati u Oglasu):
                    <input type="text" name="inputName"  placeholder="Ime"><!--class="form-control"-->
                    <br>

                    E-Mail (neće biti objavljena, za eventualna Pitanja):
                    <input type="text" name="inputEmail"  placeholder="E-Mail"><!--class="form-control"-->
                    <br>

                    *Broj Telefona (Na primer 0631110000, kako bih vas zainteresovani ljudi kontaktirali):
                    <input type="number" name="inputNumber"  placeholder="Broj telefona" size="20"required><!--class="form-control"-->
                    <br>

                    Naslov Oglasa (Maksimalno 50 reči):
                    <input type="text" name="inputTitle"  placeholder="Naslov Oglasa" width="48" height="48"><!--class="form-control"-->


                    *Tekst Oglasa (Maksimalno 200 reči, opišite šta kupujete, prodajete, menjate, tražite, ...):
                    <input type="text" name="inputText"  placeholder="Tekst Oglasa" width="48" height="48"required> <!--class="form-control"-->


                            <div class="checkbox">
                                <label>
                                    <input type="checkbox" value="remember-me" required>*Pročitao sam <a href="legal.html">prava koriščenja</a>, razumeo sam sve i prihvatam sve.
                                </label>
                                <!-- kontakt button -->
                                <div class="pull-right">
                                    <a href="kontakt.html"></a>
                                </div>
                            </div>
                        *Markirana polja se moraju ispuniti
                    <br>

                    <input type="submit" name="submit" value="Postavi besplatan Oglas">
                </form>

add_script.php

<?php
// Datenbank-Verbindung herstellen
require_once ('conf.php');

 $sql = "SELECT * FROM oglasi";
// MySQL-Befehl der Variablen $sql zuweisen     ..... OGLASI bzw. ADRESSEN 
//$sql = "
//    CREATE TABLE `oglasi` ( 
//    `id` INT( 10 ) NOT NULL AUTO_INCREMENT PRIMARY KEY ,
//   `name` VARCHAR( 150 ) NOT NULL ,
//    `email` VARCHAR( 150 ) NOT NULL ,
//    `number` INT( 20 ) NOT NULL ,
//    `text` VARCHAR( 1500 ) NOT NULL ,
//    ) ENGINE = MYISAM ;
//    ";

// MySQL-Anweisung ausführen lassen
$db_erg = mysqli_query($db_link, $sql) 
  or die("nije moguce postaviti vezu sa scriptadd: " . mysqli_error());



    if (isset($_POST['yourName'])){
        $inputName = $_POST['inputName'];
    }

    if (isset($_POST['yourEmail'])){
        $inputEmail = $_POST['inputEmail'];
    }

    if (isset($_POST['yourName'])){
        $inputTitle = $_POST['inputTitle'];
    }

    $inputNumber = $_POST['inputNumber'];
    $inputText = $_POST['inputText'];

    print_r($_POST); // zeigt alles an was in der FORM drinnen ist von add.html !!!

if ( !empty($inputNumber) ){

} else {
        echo "Morate napisati svoj broj telefona";
        die();
}

if ( !empty($inputText) ){

} else {
        echo "Morate napisati tekst svog oglasa";
        die();
}

  $sql = "
  INSERT INTO oglasi(name , email , number, title , text) 
  VALUES(inputName, inputEmail, inputNumber, inputTitle, inputText) 
";
$db_erg = mysqli_query($db_link, $sql) 
   or die("nije mogucce postaviti dadoteke u db:  " . mysqli_error($mysqli));

   mysqli_close($db_link);
?>

<!--  

INSERT INTO oglasi(date , name , email , number, title , text) 
VALUES(curdate(), $yourName, $yourEmail, $yourNumber, $yourTitle, $yourText)

  -->

conf.php

<?php
// die Konstanten auslagern in eigene Datei
// die dann per require_once ('konfiguration.php'); 
// geladen wird.

// Damit alle Fehler angezeigt werden
error_reporting(E_ALL);

// Zum Aufbau der Verbindung zur Datenbank
// die Daten erhalten Sie von Ihrem Provider
define ( 'MYSQL_HOST', 'localhost' );

// bei XAMPP ist der MYSQL_Benutzer: root
define ( 'MYSQL_BENUTZER',  'root' );
define ( 'MYSQL_KENNWORT',  '' );

define ( 'MYSQL_DATENBANK', 'oglasi' );         // für unser Bsp. nennen wir die DB oglasi

$db_link = mysqli_connect (MYSQL_HOST, 
                           MYSQL_BENUTZER, 
                           MYSQL_KENNWORT, 
                           MYSQL_DATENBANK);
if ( $db_link )
{
    //echo 'Veza uspesno postavljena sa Serverom: ';
    //print_r( $db_link);

}
else
{
    // hier sollte dann später dem Programmierer eine
    // E-Mail mit dem Problem zukommen gelassen werden
    die('nije mogucce postaviti vezu sa Serverom: ' . mysqli_error());
}

//damit sprska slova nicht vorkommen 
mysqli_set_charset($db_link, 'utf8');
?>

i expected it to insert the texts into my Database but it says this instead:

Array ( [inputName] => [inputEmail] => [inputNumber] => 43235432532 [inputTitle] => [inputText] => sadasdas [submit] => Postavi besplatan Oglas ) Notice: Undefined variable: yourName in C:\xampp\htdocs\oglasi\add_script.php on line 56

Notice: Undefined variable: yourEmail in C:\xampp\htdocs\oglasi\add_script.php on line 56

Notice: Undefined variable: yourTitle in C:\xampp\htdocs\oglasi\add_script.php on line 56

Warning: mysqli_error() expects exactly 1 parameter, 0 given in C:\xampp\htdocs\oglasi\add_script.php on line 59 nije mogucce postaviti dadoteke u db:

</div>
  • 写回答

1条回答 默认 最新

  • dsfliu1129 2019-05-15 17:51
    关注

    This section of code is looking for elements that don't exist:

    if (isset($_POST['yourName'])){
        $yourName = $_POST['inputName'];
    }
    
    if (isset($_POST['yourEmail'])){
        $yourEmail = $_POST['inputEmail'];
    }
    
    if (isset($_POST['yourName'])){
        $yourTitle = $_POST['inputTitle'];
    }
    

    You're probably wanting to change $_POST['yourName'] to $_POST['inputName'] and similar change to the others that follow.

    评论

报告相同问题?

悬赏问题

  • ¥15 无线电能传输系统MATLAB仿真问题
  • ¥50 如何用脚本实现输入法的热键设置
  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀
  • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100
  • ¥15 关于#hadoop#的问题