search

Home  >  Q&A  >  body text

Regarding the problem of adding data to mysql using php

<?php

include("config.php");

$From=$_POST['Kname'];

$User=$_POST ['Qtime'];

$Skind=$_POST['Ytime'];

$Belong=$_POST['Xname'];


if($From!=""){

$sql="INSERT INTO server(id,From,User,Skind,Belong ) VALUES ('','$From','$User','$Skind','$Belong')";

if(mysql_query($sql)){

echo"<script>alert('Added successfully!'); javascript:window.location.href=document.referrer;</script>";

}

else{

echo "Upload failed!";

}

}else

{

echo "The data is empty";

}

?>

The above cannot be solved by adding data to the database

董先生董先生2413 days ago1096

reply all(6)I'll reply

  • 无忌哥哥

    无忌哥哥2018-06-20 14:07:28

    First check to see if the form value has been passed. If so, print the SQL statement to see if there are any syntax errors.

    reply
    0
  • 董先生

    Worthy

    董先生 · 2018-06-20 14:12:47
    董先生

    INSERT INTO server(From,User,Skind,Belong) VALUES (i','6','7','4') upload failed!

    董先生 · 2018-06-20 14:15:08
    董先生

    The data comes over but cannot be uploaded.

    董先生 · 2018-06-20 14:15:29
    无忌哥哥

    Are the database fields correct?

    无忌哥哥 · 2018-06-20 15:36:35
    寻常人家道不常

    Wrap your variable fields in braces, for example: $sql = "insert into mes_info values ​​('','{$title}','{$content}','{$addtime}')"; Try this There may be a problem that complex variables are not recognized. Is your database connection statement actually in config.php?

    寻常人家道不常 · 2018-06-20 18:10:17
  • Cancelreply