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?

 

Link to comment
Share on other sites

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')";

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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