I am trying to implement a customer records page, where you can modify and save the changes on one page. What I am trying to do is, post a action using a link (or better button) and then execute a function depending on the action posted.

My code is as follow.

$action = $_GET["action"];
switch ($action){
case "addnew";

case "apply":
mysql_query("UPDATE users SET ........... ") or die(mysql_error());

case "delete":
mysql_query(not done yet) or die(mysql_error());

my problem is........ if you haven't already guessed is that, how to I grab the values from my form and pass them to my switch statement. I grab the value from my action, but I have no way to extract the text from the fields of the form.

my form looks like

<form name="main_form" method="post" action="">

<table border="0">
<td width="90">User ID</td>
<td width="300"><input name="userid" type="text" disabled="disabled" id="userid" value="<?=$user_id?>" /></td>
<td width="90">Address</td>
<td width="250" rowspan="4"><textarea name="address" rows="5" id="address"><?=$address?>
<td width="300"><input name="name" type="text" id="name" value="<?=$fullname?>" maxlength="30" width="200"/></td>
<td>User Level</td>
<td width="300">
<td width="300">&nbsp;</td>
<td height="10">Tel</td>
<td width="300" height="10">
<input name="tel" type="text" id="tel value=" value="<?=$contact_no?>" maxlength="20" /></td>
<td height="10">Post Code</td>
 <td width="250" height="10"><input name="post_code" type="text" id="post_code" value="<?=$postcode?>" /></td>
<td width="90" height="10">Mobile</td>
<td width="300" height="10"><input name="mobile" type="text" id="mobile" value="<?=$mobile_no?>" maxlength="20" /></td>
<td width="90" height="10">&nbsp;</td>
<td width="250" height="10">&nbsp;</td>
<td width="90">&nbsp;</td>
<td width="300">&nbsp;</td>
<td width="90">Login Name</td>
<td width="250"><input name="user_login" type="text" id="user_login" value="<?php echo $user_login;?>" /></td>
<td width="90">Email</td>
<td width="300"><input name="email" type="text" id="email" value="<?=$email?>" maxlength="50" width="200"/></td>
<td width="90">Password</td>
<td width="250"><input name="password" type="text" id="password" value="<?php echo $password;?>" /></td>

and my links are also in the form

<table width="50" border="0" align="right">
<tr align="center">
<td><a href="?action=addnew">Add</a></td>
<td><a href="?uid=<?=$uid?>&action=apply">Apply</a></td>
<tr align="center">
<td><input type="reset" name="cancel" id="cancel" value="Cancel" /></td>
<td><input type="submit" name="back" id="back" value="Back" onClick="history.go(-1)"/></td>

any help would be appriciated. im really stuck and i need to get this done asap.

thanks in advance, but i will also thank again.


6 Years
Discussion Span
Last Post by TechySafi

You are posting the input values so you have to use $_POST[name of the input field]. i.e.

//in your form
<input name="mobile" type="text" id="mobile" value="<?=$mobile_no?>"
//in your php script, to get the value from this input field
$value = $_POST['mobile']; //$_POST['mobile'] because <input name="mobile" ..>

Also, you need to add an action to your form. It seems that you are trying to use the same file for displaying as well as processing the form. I suggest you go through this tutorial before proceeding with your coding.

Edited by kekkaishi: n/a


Pretty simple, grab the values with $_POST syntax.Here is a example

//if you have a field like this:
<input name="userid" type="text" .....
//you should write following php code
//grab other values exactly in the same way and make now u can make a query with //those variables.
UPDATE table_name SET column1=$a_variable,.....


Edited by TechySafi: n/a

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.