Fatal error: Uncaught Error: Call to a member function


#43

For that specific problem, don’t close the database connection if you didn’t open it - so put the close() inside the if() clause as well. Or don’t call close() at all, when your script ends it will automatically be closed.

For the $_POST issue, as I said earlier, get rid of that <a href> part and put the destination in your form tags, in the action parameter. Then see if you get data in the $_POST array.

You can ignore the error about closing the database connection for now, because I think that’s only happening because your $_POST data isn’t coming through from the form.


#44

i got rid of it of an errors but cant go next page,
code is

<button id="submit" name="submit" action="http://localhost/carbooking3/16%20y/korak22.php?id=" class="sear-btn" type="submit">Search</button>


#45
  <form action="<?php echo $editFormAction; ?>" name="form" class="form-horizontal" style="width: 95%; margin:0 2.5% 2.5%" method="POST">
                        <div class="control-group">
                            <label class="control-label" for="checkInDate">Start date:</label>
                          <div class="controls">
                            <input name="start_date" type="text" class="tt" id="dpd1" value="" size="16" readonly width="150px" data-date-format="yyyy-mm-dd">
                          </div>
                        </div>
                        <div class="control-group">
                            <label class="control-label" for="End date">End date :</label>
                            <div class="controls">
                            	
                                    <input class="sa" type="text" readonly size="16" id="dpd2" name="end_date" value="" data-date-format="yyyy-mm-dd">
                                  
                            </div>
                        </div>
                        <div class="control-group">
                          <label class="control-label" for="cars">Kind of car:</label>
                            <div class="controls"><select class="s" id="cars" name="cars">
                           	  <option value="Select">Select</option>
                           	  <option value="1 ">Skoda manual gas</option>
                           	  <option value="2">Passat</option>
                           	  <option value="3">Kia</option>
                           	  <option value="4">Volvo</option>
                              <option value="5 ">Skoda automatic disel</option>
                         
                          </select></div>
                        </div>
                        <div class="control-group">
                            <label class="control-label" for="Location_of_renting">Location of renting:</label>
                            <div class="controls">
                            	<select class="input-medium" id="Location_of_renting" name="Location_of_renting">
                            	  <option value="Select">Select</option>
                            	  <option value="Santa Barbara">Santa Barbara</option>
                            	  <option value="Los Angeles">Los Angeles</option>
                            	  <option value="San Diego">San Diego</option>
                          </select>
                            	<select class="input-medium" id="vr_uzi" name="vr_uzi">
                            	  <option value="8:00">8:00</option>
                            	  <option value="9:00 ">9:00 </option>
                            	  <option value="10:00">10:00</option>
                            	  <option value="11:00">11:00</option>
                          	   <option value="12:00">12:00</option>
                            	  <option value="13:00 ">13:00 </option>
                            	  <option value="13:00">13:00</option>
                            	  <option value="14:00">14:00</option>
                               <option value="15:00">15:00</option>
                            	  <option value="16:00 ">16:00 </option>
                            	  <option value="17:00">17:00</option>
                            	  <option value="18:00">18:00</option>
                              
                              
                              
                              
                              </select>
                          </div></div>                       
                       <div class="control-group">
                            <label class="control-label" for="Location_of_returning">Location of returning:</label>		
                            <div class="controls">
                            	<select class="input-medium" id="Location_of_returning"			 name="Location_of_returning">			
                            	  <option value="Select">Select</option>
                            	  <option value="Santa Barbara">Santa Barbara</option>
                            	  <option value="Los Angeles">Los Angeles</option>
                            	  <option value="San Diego">San Diego</option>
                         </select>
                            <select class="input-medium" id="vr_vraca" name="vr_vraca">
                            	  <option value="8:00">8:00</option>
                            	  <option value="9:00 ">9:00 </option>
                            	  <option value="10:00">10:00</option>
                            	  <option value="11:00">11:00</option>
                          	   <option value="12:00">12:00</option>
                            	  <option value="13:00 ">13:00 </option>
                            	  <option value="13:00">13:00</option>
                            	  <option value="14:00">14:00</option>
                               <option value="15:00">15:00</option>
                            	  <option value="16:00 ">16:00 </option>
                            	  <option value="17:00">17:00</option>
                            	  <option value="18:00">18:00</option>
                          	  </select>
                        </div></div>
                       <button id="submit"   name="submit"  action="http://localhost/carbooking3/16%20y/korak22.php?id="  class="sear-btn" type="submit">Search</button>
                       <div align="right">
                         <input type="hidden" name="MM_insert" value="form">
                 </form>    

that is form i fixed couples mistake can you see any


#46
if($stmt->execute()){
    print 'Successfully inserted and Last inserted ID is : ' .$stmt->insert_id .'<br />'; 
}else{
    die('Error : ('. $db->errno .') '. $db->error);
}

i tried this no messages


#47

something is wrong with html form i dont know what is it.


#48

I suggest you run it through the W3C Validator, which will indicate the HTML errors.


#49

i run another html form with another php works perfect


#50

If you’re not getting anything in the $_POST array as you said earlier, then this bit won’t be executing because you said you’d added a check to see if $_POST['submit'] is set.


#51

what i gonna do


#52
                    <form action="" method="post">
<label>Student Name :</label>
<input type="text" name="start_date" id="start_date" required="required" placeholder="Please Enter Name"/><br /><br />

<input type="submit" value=" Submit " name="submit"/><br />
</form>
                      
                      



<?php
if(isset($_POST["submit"])){
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "cars123";

// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}

$sql = "INSERT INTO cars321(start_date)
VALUES ('".$_POST["start_date"]."')";

if ($conn->query($sql) === TRUE) {
{
    header("Location: https://stackoverflow.com/questions/4643697/how-do-i-navigate-to-another-page-when-php-script-is-done");
    exit;
}
} else {
echo "<script type= 'text/javascript'>alert('Error: " . $sql . "<br>" . $conn->error."');</script>";
}

$conn->close();

This go in db but wont go on next page if i put in html action redirect page wont go in db


#53

If all that is in one file, the header redirect won’t work because you’ve already sent the html form to the browser. You should put the PHP code before the html code if you want to do a redirect. You should be getting “headers already sent” error messages.


#54

I put HP code before the html code wont work


#55

What does that mean? What happens, or doesn’t happen? Can’t help with so little information.


#56

same thing,nothing happen


#57

Hmmm, I very often write preliminary files with PHP before HTML and they work.


#58

The most recent code posted probably won’t insert a row into the database because there are so many missing columns. The database definition prevents some of them from being null, but as the query does not provide values, and they have no defaults, the query is bound to fail. This seems to be something that has been mentioned several times before - you either have to allow nulls, provide default values in the table scheme, or insert values in all the fields.


#59

What confuses me is the “nothing happens”. Obviously, something happens. But what??

BTW in addition to the fields being defined as NOT NULL, “s” stands for “string”.


#60

@capljina2 Consider making a github repository containing your actual code and posting a link to it. It can be challenging to figure out why individual bits and pieces fail to work. Sometime you need a complete view to see what it going on.


#61

allowed nulls, default values in mysql nothing happened.
in insert i put all null they went thru but all null.


#62

ooooooooooooo111
Warning : mysqli_stmt::bind_param(): Number of elements in type definition string doesn’t match number of bind variables
stmt->bind_param("ssssssssssss", _POST[‘id’], _POST['start_date'],_POST[‘end_date’],_POST['cars'],_POST[‘Location_of_renting’],_POST['Location_of_returning'], _POST[‘vr_uzi’], _POST['vr_vraca'], _POST[‘paid’], _POST['price'], _POST[‘numberdays’], $_POST[‘Numbers_of_cars’]);
anybody see Number of variables doesn’t match number of parameters in prepared statement