Jump to content

Recommended Posts

Greetings and thanks in advance!

 

I got this script from http://www.phpeasystep.com/mysql/9.html for which I give much thanks.

 

It takes user input and uses it to UPDATE a mysql db, the actual row concerned being chosen by a previous script.

 

The script runs purrfectly unless I add another db field to be updated.

 

After what seems like several years I narrowed it down to the form1 as coded below.

 

This table posts only 3 fields to the script , if for exampleI change the order of the columns, only the first three are enntered into the $_REQUEST array on the next script...I think its something to do with the table layout???

 

so that in this example, $email = $_REQUEST['email'] (in the next script) throws an error. What is the problem please?

 

And another question....this script has

 

// close connection

mysql_close();

 

I read that this is VERY bad practice.....your thoughts are welcomed.

 

 

[pre]CODE

 

############### Code

 

<?php

$host="localhost"; // Host name

$username="root"; // Mysql username

$password=""; // Mysql password

$db_name="soltheatre"; // Database name

$tbl_name="members"; // Table name

 

// Connect to server and select database.

mysql_connect("$host", "$username", "$password")or die("cannot connect");

mysql_select_db("$db_name")or die("cannot select DB");

 

// get value of id that sent from address bar

$id=$_GET['id_user'];

 

 

// Retrieve data from database

$sql="SELECT * FROM $tbl_name WHERE id_user='$id'";

$result=mysql_query($sql);

 

$rows=mysql_fetch_array($result);

?>

<table width="400" border="0" cellspacing="1" cellpadding="0">

<tr>

<form name="form1" method="post" action="update_ac.php">

<td>

<table width="100%" border="0" cellspacing="1" cellpadding="0">

<tr>

<td> </td>

<td colspan="4"><strong>Update data in mysql</strong> </td>

</tr>

 

// ******** somewhere here there are not enough fields or columns defined. **************

<tr>

<td align="center"> </td>

<td align="center"> </td>

<td align="center"> </td>

<td align="center"> </td>

</tr>

<tr>

<td align="center"> </td>

<td align="center"><strong>Name</strong></td>

<td align="center"><strong>Username</strong></td>

<td align="center"><strong>phonenumber</strong></td>

<td align="center"><strong>E-mail</strong></td>

</tr>

<tr>

<td> </td>

<td align="center"><input name="name" type="text" id="name" value="<? echo $rows['name']; ?>"></td>

 

<td align="center"><input name="username" type="text" id="username" value="<?

echo $rows['username']; ?>" size="15"></td>

 

<td align="center"><input name="phonenumber" type="text" id="phonenumber" value="<? echo $rows['phonenumber']; ?>" size="15"></td>

 

<td align="center"><input name="phonenumber" type="text" id="email" value="<? echo $rows['email']; ?>" size="15"></td>

 

</tr>

 

<tr>

<td> </td>

<td><input name="id" type="hidden" id="id" value="<? echo $rows['id_user']; ?>"></td>

<td align="center"><input type="submit" name="Submit" value="Submit"></td>

<td> </td>

</tr>

</table>

</td>

</form>

</tr>

</table>

 

<?

 

// close connection

mysql_close();

 

?>[/pre]

Link to comment
https://forums.phpfreaks.com/topic/257684-variable-not-being-passed/
Share on other sites

the name of the input field is wrong in the email input.

<td align="center"><input name="phonenumber" type="text" id="email" value="<? echo $rows['email']; ?>" size="15"></td>

 

The name "phonenumber" is already used in the field above. Try to call it '... name="email" ...'.

 

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.