0

I am trying to create a 'submit' input type button that when clicked will call up a switch case action that I've defined in PHP. When the 'submit' button is clicked, I want the form action to essentially create a link and display in the URL form action so that it is called properly by the PHP file.

However when I click on the submit button, the URL does not properly display the desired link and action.

PHP:

$getuserid_result = mysql_query($getuseridsql, $conn);
$userid_array = mysql_fetch_array($getuserid_result);

$userid = $userid_array['uid']; 

// Above code works fine and retrieves the current user's ID

// PHP Form code is below

// Variables used for creating the id of the input since the submit button is displayed
// in an HTML table with multiple rows.  These variables are working fine.
$time_cell_row = 1;
$time_cell_column = 1;

echo "<form action='enter_time.php?uid='" . $userid . "?action=timesubmit method='get'>";  

       echo "<td><input name=submit_time type=submit id=submit_time" . $time_cell_row . $time_cell_column . "></input></td>";
       echo  "</form></tr>";

// PHP Action code

/* This is currently commented out and will eventually be filled with code to handle 
   the 'timesubmit' action 

      if (isset($_GET['action'])) { 
    switch (strtolower($_GET['action'])) {
      case 'timesubmit':



    }
   } 
      */

The problem now is when I click on the 'submit' button, the URL displayed enter_time.php?submit_time=Submit" instead of "enter_time.php?uid=3?action=timesubmit

2
  • 1
    try change your form method from GET to POST Commented Aug 21, 2014 at 2:55
  • You should consider getting away from mysql_* functions and move to PDO. When you do, use prepared/parameterized queries to avoid SQL injection and related problems. Also in your HTML, use htmlspecialchars() around any arbitrary data. Finally, your HTML is a bit of a mess... make sure you properly close your quotes. And, even though it isn't strictly required in HTML5, you will have an easier time by actually using quotes around attribute values consistently. Commented Aug 21, 2014 at 2:58

4 Answers 4

1

You might want to add in the final apostrophe after timesubmit

echo "<form action='enter_time.php?uid=" . $userid . "?action=timesubmit' method='post'>";

Sign up to request clarification or add additional context in comments.

2 Comments

I figured out the answer. It was actually a combination of the missing single apostrophe after 'timesubmit' and changing my method from 'get' to 'post'. The 'submit' click works fine now. Thank you all!
@JeffP. Don't put GET variables in your action attribute like that, you should be hiding all of your variables inside form input elements.
1

You have a quote after uid that should not be there:

"<form action='enter_time.php?uid=" . $userid . "?action=timesubmit method='get'>"; 

Comments

1

If you are using a form to submit GET variables into a url you could do something like

<a id="submit_time<?= $time_cell_row . $time_cell_column ?>" href="enter_time.php?uid=<?= $userid ?>">Submit Time</a>

If you prefer to use a form, writing it this way looks clearer to me

PHP

<?php

$getuserid_result = mysql_query($getuseridsql, $conn);
$userid_array = mysql_fetch_array($getuserid_result);

$userid = $userid_array['uid']; 

// Above code works fine and retrieves the current user's ID

// PHP Form code is below

// Variables used for creating the id of the input since the submit button is displayed
// in an HTML table with multiple rows.  These variables are working fine.
$time_cell_row = 1;
$time_cell_column = 1;

?>

<form action='enter_time.php' method='get'>
    <input type="hidden" name="action" value="<?= $timesubmit ?>">
    <input type="hidden" name="uid" value="<?= userid ?>">
    <input name="submit_time" type="submit" id="submit_time<?= $time_cell_row . $time_cell_column ?>" />
</form>

<?php 
// PHP Action code

/* This is currently commented out and will eventually be filled with code to handle 
     the 'timesubmit' action 

            if (isset($_GET['action'])) { 
        switch (strtolower($_GET['action'])) {
            case 'timesubmit':



        }
     } 
            */

?>

Comments

1

Just off top of my head it should be:

echo "<form action='enter_time.php?uid=" . $userid . "?action=timesubmit' method='get'>";

Single quote after "uid=" was in the wrong place. Shouldn't be until after "timesubmit".

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.