简体   繁体   English

sql查询错过了数据库内的两列

[英]sql query misses out two columns within the database

Ok Hi I have a slightly weird problem that I cannot figure out mysql query posts the uniq_id in the title column instead of its own and the title, blurb and uniq_id end up empty. 好的,您好,我有一个奇怪的问题,我无法弄清mysql查询将在标题栏中显示uniq_id而不是它自己的标题,并且标题,blurb和uniq_id最终为空。

to start off with i create a uniq_id in php and then assign this to be a value within a hidden field within a form this is the code: 首先,我在php中创建一个uniq_id,然后将其分配为以下形式的隐藏字段内的值:

  $uid = uniqid();
  /*echo $uid;*/

  echo " <input type=\"hidden\" value=\"$uid\" name=\"Uniq_id\"/>";

this is then posted using the form submit button, 然后使用表单提交按钮将其发布

then on the next page $_POST catches all of the values and turns them into variables this is the code for that: 然后在下一页$ _POST捕获所有值并将它们转换为变量,这是该代码:

$Title = $_POST['Title'];
$Blurb = $_POST['Blurb'];
$Subject = $_POST['cat'];
$Section = $_POST['typ'];
$Principle = $_POST['princ'];
$Verify = $_POST['verification'];
$Career = $_POST['career'];
$Job = $_POST['job'];
$Uniq_id = $_POST['Uniq_id'];

the variables are then used within this page within the sql query bellow which is ment to post these values into the database the function below is the one that is run when you click the submit button 然后在sql查询对话框中的此页面内使用这些变量,以将这些值发布到数据库中,下面的函数是单击“提交”按钮时运行的函数

    public function addNewRecord($Subject, $Section, $Principle, $Job, $Career, $Title, $Blurb, $Uniq_id)
            { 
                $sql = "INSERT INTO `careersintheclassroom`.`media` (`media_id`, `subject_id`, `section_id`, `principle_id`, `title`, `blurb`, `verified`, `media_uniqid`) 
                       VALUES (NULL, '".$Subject."', '".$Section."', '".$Principle."', '".$Title."', '".$Blurb."', '0', '".$Uniq_id."')"; // sql query 

                 return mysql_query($sql, $this->conn); // connection to database and also getting the results from query

  }

when it posts the values to the page with this function it prints the values on a page showing me all the values this is one of them. 当使用此功能将值发布到页面时,它将在页面上显示这些值,向我显示所有这些值之一。

INSERT INTO `careersintheclassroom`.`media` (`media_id`, `subject_id`, `section_id`, `principle_id`, `jobrole_id`, `career_id`, `title`, `blurb`, `verified`, `media_uniqid`) 
    VALUES (NULL, '1', '1', '1', '2', '2', 'Title1', 'Blurb1', '0', '532061df6b80d');File is valid, and was successfully uploaded. 

Now in the database it does something strange it posts in the first 4 values correctly then it inserts the Uniq_id into the title doesn't insert anything into blurb then put the correct value into verified and then leave the last column blank to, 现在在数据库中,它做了一些奇怪的事情,正确地在前4个值中发布,然后将Uniq_id插入标题中,没有在blurb中插入任何内容,然后将正确的值放入了verify中,然后将最后一列留为空白,

What is the type of the verified field? 验证字段的类型是什么?

Try this, notice the quotes around 0 : 试试这个,注意引号在0附近:

VALUES (NULL, '".$Subject."', '".$Section."', '".$Principle."', '".$Title."', '".$Blurb."', '"0"', '".$Uniq_id."')"; // sql query 

Hi Guys thanks for all of the answers I have figured out what the problem is I have figured out that my syntax for the mysql query was wrong I used phpmyadmin to create the php code and then altered it to fit the functions but this was wrong the code i was using was: 嗨,大家好,谢谢您提供的所有答案。我已经弄清楚了问题所在。我已经发现我对mysql查询的语法是错误的,我使用phpmyadmin创建了php代码,然后对其进行了更改以适应功能,但这是错误的。我使用的代码是:

 $sql = "INSERT INTO `careersintheclassroom`.`media` (`media_id`, `subject_id`, `section_id`, `principle_id`, `title`, `blurb`, `verified`, `media_uniqid`) 
 VALUES (NULL, '".$SUBJECT."', '".$SECTION."', '".$Principle."', '".$Title."', '".$Blurb."', '0', '".$Uniq_id."')"; 

instead the correct code that it should be is 相反,它应该是正确的代码

$sql = "INSERT INTO media (media_id, subject_id, section_id, principle_id, title, blurb, verified, media_uniqid)
VALUES ('NULL', '".$Subject."', '".$Section."', '".$Principle."', '".$Title."', '".$Blurb."', '0', '".$Uniq_id."')"; 

As you can see the columns have got `` around them this is wrong so removing them inserts the details correctly into the columns 如您所见,列周围有``这是错误的,因此删除它们会将详细信息正确插入列中

Thanks for everything guys you have helped a lot. 谢谢大家的帮助。

Is it possible that the "title" column is configured to insert a guid for every row insert. 是否有可能将“标题”列配置为为每行插入插入一个GUID。 Check the column definition for title. 检查列定义的标题。 Also did you verify that the Blurb and media_uniqueid columns values passed on to the function to be inserted are not null/blank for some reason.. Just checking.. 您是否还验证了由于某种原因传递给要插入的函数的Blurb和media_uniqueid列值不是null / blank。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM