2017-07-06 7 views
-1

Ich bin neu Stackoverflow. Ich möchte dieses Formular erstellen, das Informationen in die Datenbank hochlädt. Wenn ich auf "Senden" klicke, wird es nicht hochgeladen. Ich habe meine Verbindungsdatei überprüft und das ist korrekt. Code unten. Bitte helfen Sie.php register zur datenbank

<?php 
include("/connections/db_conx.php"); 

if (isset($_POST['submit'])) { 


$title = mysqli_real_escape_string($_POST['title']); 
$text = mysqli_real_escape_string($_POST['text']); 
    $picture = mysqli_real_escape_string($_POST['picture']); 


    $sql = "INSERT INTO news (title, text, picture) VALUES('$title','$text','$picture', now(),now(),now())"; 

    $query = mysqli_query ($db_conx, $sql); 


    echo 'Entered into the news table'; 
    } 
    ?> 


    <html> 


    <head> 



</head> 


<body> 

    <table border="0"> 
    <tr> 
    <form method="post" action="index.php" id="tech"> 
    <td>Title</td><td> <input type="text" name="title"></td> </tr> 
    <tr> <td>Text</td><td> <textarea rows="4" name="text" cols="50"  name="comment"  form="tech"> </textarea> 
     </td> </tr> 

<tr> <td>Picture</td><td> <input type="varchar" name="picture"></td> </tr> 

<tr> <td><input id="button" type="submit" name="submit" value="Submit"></td> 

</tr> 
</form> 


</table> 



</body> 




</html> 
+0

[Little Bobby] (http://bobby-tables.com/) sagt *** [Ihr Skript ist für SQL Injection Attacks gefährdet.] (Http://stackoverflow.com/questions/60174/how- can-i-prevent-sql-injection-in-php *** Erfahren Sie mehr über [vorbereitete] (http://en.wikipedia.org/wiki/Prepared_statement) Anweisungen für [MySQLi] (http://php.net /manual/de/mysqli.quickstart.prepared-statements.php). Sogar [die Zeichenfolge zu entkommen] (http://stackoverflow.com/questions/5741187/sql-injection-that-gets-around-mysql-real-escape-string) ist nicht sicher! –

+3

Die Anzahl der Felder und die Anzahl der Werte stimmen nicht überein. – lkdhruw

+0

Erhalten Sie einen Fehlercode? – GrumpyCrouton

Antwort

0

Dieses Versuchen:

$title = mysqli_real_escape_string($db_conx, $_POST['title']); 
$text = mysqli_real_escape_string($db_conx, $_POST['text']); 
$picture = mysqli_real_escape_string($db_conx, $_POST['picture']); 

$sql = "INSERT INTO news (title, text, picture) VALUES('$title','$text','$picture')"; 

Fehler zu erhalten, fügen Sie diese nach if Aussage:

else { 
    echo mysqli_error($db_conx); 
} 
1

Hier ist der Code, den Sie verwenden müssen:

<?php 
    include("/connections/db_conx.php"); 
    if(isset($_POST['submit'])) { 
     $title = mysqli_real_escape_string($db_conx, $_POST['title']); 
     $text = mysqli_real_escape_string($db_conx, $_POST['text']); 
     $picture = mysqli_real_escape_string($db_conx, $_POST['picture']); 
     $sql  = "INSERT INTO news (`title`, `text`, `picture`) VALUES('$title','$text','$picture');"; 
     if(!$result = $db_conx->query($sql)){ 
      die('There was an error running the query [' . $db_conx->error . ']'); 
     } 
     echo 'Entered into the news table'; 
    } 
?> 


<html> 
    <head> 
    </head> 
    <body> 
     <form method="post" action="index.php" id="tech"> 
      <table border="0"> 
       <tr> 
        <td>Title</td> 
        <td> <input type="text" name="title"></td> 
       </tr> 
       <tr> 
        <td>Text</td> 
        <td><textarea rows="4" name="text" cols="50" name="comment" form="tech"> </textarea></td> 
       </tr> 
       <tr> 
        <td>Picture</td> 
        <td> <input type="varchar" name="picture"></td> 
       </tr> 
       <tr> 
        <td><input id="button" type="submit" name="submit" value="Submit"></td> 
       </tr> 
      </table> 
     </form> 
    </body> 
</html> 

Dein Problem ist, dass die mysqli_real_escape_string() Funktion erfordert 2 Parameter: die Datenbankverbindung und die Zeichenfolge zu entkommen.

Ich habe auch komplett neu formatierten Code und Fehlerprüfung enthalten.

Verwandte Themen