Hi,

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";
func_add_new_record();
break;

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

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

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">
<tr>
<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?>
</textarea></td>
</tr>
<tr>
 <td>Name</td>
<td width="300"><input name="name" type="text" id="name" value="<?=$fullname?>" maxlength="30" width="200"/></td>
<td>&nbsp;</td>
</tr>
<tr>
<td>User Level</td>
<td width="300">
</td>
<td>&nbsp;</td>
</tr>
<tr>
<td>&nbsp;</td>
<td width="300">&nbsp;</td>
<td>&nbsp;</td>
 </tr>
<tr>
<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>
</tr>
<tr>
<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>
</tr>
<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>
</tr>
<tr>
<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>
</tr>
</table>

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>               
<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>
</tr>
</table>/form>

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.

gaf.

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.

Member Avatar for TechySafi

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
$a_variable=$_POST['userid'];
//grab other values exactly in the same way and make now u can make a query with //those variables.
//like 
UPDATE table_name SET column1=$a_variable,.....

Cheers!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.