jdock1 Posted October 14, 2010 Share Posted October 14, 2010 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 https://forums.phpfreaks.com/topic/215836-insert-into-not-working-with-two-variables/ Share on other sites More sharing options...
DavidAM Posted October 14, 2010 Share Posted October 14, 2010 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 https://forums.phpfreaks.com/topic/215836-insert-into-not-working-with-two-variables/#findComment-1122028 Share on other sites More sharing options...
Pikachu2000 Posted October 14, 2010 Share Posted October 14, 2010 Using @ to suppress errors it doesn't make them cease to exist. Link to comment https://forums.phpfreaks.com/topic/215836-insert-into-not-working-with-two-variables/#findComment-1122030 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.