Question

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. I would like a little help to this issue. it effects all the add pages.

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

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

<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.

Was it helpful?

Solution 2

The $id variable is not declared. If PRIMARY_KEY and AUTO_INCREMENT, remove the variable.

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

OTHER TIPS

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top