Jump to content

Insert into not working with two variables


jdock1

Recommended Posts

I have no idea and there is no reason why this should not be working.

 

im simply trying to add three variables into a database, and only one works.

 

the other two do not work for any reason i can find.

 

can someone point out my error, if any?

 

code:

<?php
$date = date("Y-m-d"); 
$dbc = mysqli_connect('localhost', 'root', '', 'timer')
or die('Error connecting to DB');
$query = @"INSERT INTO sessions (date, user, sessiontime) VALUES ('$date', '$user', '$sessiontime')";
$user = @$_GET['user'];
$sessiontime = @$_GET['clock'];
if (@$_GET['addDB'] == "Session Complete")
{
	mysqli_query($dbc, $query)
	or die( '<br>Query string: ' . $query . '<br>Produced error: ' . mysqli_error($dbc) );
}
?>

 

Form:

<label for="user"><b><em>Your name:  </b></em></label><br /><input type="text" name="user" value="Admin/User" />
<input id="clock" name="clock" type="text" value="00:00:0" readonly><br> 
<input id="startstopbutton" type="button" value="S t a r t" onClick="startstop();" style="font-weight:bold"><br>  
    <input type="submit" name="addDB" value="Session Complete" />	

 

See, all the variables match up!?

 

I dont get what im doing wrong?

 

You are referencing $user and $sessiontime BEFORE you assign values to them.  Switch those lines around:

$user = $_GET['user'];
$sessiontime = $_GET['clock'];
$query = "INSERT INTO sessions (date, user, sessiontime) VALUES ('$date', '$user', '$sessiontime')";

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.