简体   繁体   English

php mysql 插入语句

[英]php mysql insert into statement

When running this code in the web page I do not get a confirmation that it is complete.在网页中运行此代码时,我没有得到它已完成的确认。 I took the sql code directly from phpmyadmin sql query window.我直接从 phpmyadmin sql 查询窗口中获取了 sql 代码。 I would like a little help to this issue.我想对这个问题有一点帮助。 it effects all the add pages.它影响所有添加页面。

id ID

$results=mysqli_query($con, "select * from Users where `userName` ='$userName'");
$row = mysqli_fetch_array($results);
$id = $row['id_cust'];

that is before this statement那是在这个声明之前

php php

if(isset($_POST['insert'])){
$artist = $_POST['artist'];
$place = $_POST['place'];
$hour = $_POST['hour'];
$minute = $_POST['min'];
$year = $_POST['year'];
$month = $_POST['month'];
$day = $_POST['day'];
$price = $_POST['price'];
$open = $_POST['open'];
$time = $hour.':'.$minute;
$date = $year.'-'.$month.'-'.$day;
$result=mysqli_query($con,"insert into Concert values('$id','$artist','$date','$time','$place','$price','$open')");
    if($result)
    {
    echo 'Values updated successfully';
    }
}

html html

<form name="addconcerts" method="post" action="addconcert.php" id="form">
<p>Please Fill out all information</p>
Artist:<input type="text" name="artist" /> <br />
Place:<input type="text" name="place" /><br />
Approximant start time<select name="hour">
<option value="">Hour</option>
<option value="01">01</option>
 """"""""
<option value="24">24</option>
</select>
<select name="min">
<option value="">Minute</option>
<option value="00">00</option>
<option value="15">15</option>
<option value="30">30</option>
<option value="45">35</option>
</select><br />
<select name="month">
<option value="">Month</option>
<option value = "01">January</option>
 """"""""""""""""
<option value = "12">December</option> 
 </select>
<select name="day">
<option value="">Day</option>
<option value="01">01</option>
""""""""""""""""""
<option value="31">31</option>
</select>
<select name="year">
<option value="">Year</option>
<option value="2014">2014</option>
<option value="2015">2015</option> 
</select><br />
Price:<input type="text" name="price"><br />
Opening Act:<input type="text" name="open"><br><br>
<input type="reset" name="reset" value="Reset">
<input type="submit" name="insert" value="insert">
</form>

any help would be greatly appreciated.任何帮助将不胜感激。

Check Your Insert Query.检查您的插入查询。

This is your Insert Query :这是您的插入查询

$result=mysqli_query($con,"insert into Concert values('$id','$artist','$date','$time','$place','$price','$open')");

And your Insert Query should look like this:您的插入查询应如下所示:

$result=mysqli_query($con,"insert into Concert (id, artist, date, time, place, price, open) values('$id','$artist','$date','$time','$place','$price','$open')");

Of course, you should REPLACE the necessary column names on the above provided code.当然,您应该在上面提供的代码中替换必要的列名

The $id variable is not declared.未声明$id变量。 If PRIMARY_KEY and AUTO_INCREMENT , remove the variable.如果PRIMARY_KEYAUTO_INCREMENT ,删除变量。

$result = mysqli_query($con,"insert into Concert (id, artist, date, time, place, price, open) VALUES('$id','$artist','$date','$time','$place','$price','$open')");

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

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