Jump to content

[SOLVED] Problem with update link/form


patheticsam

Recommended Posts

Hi everyone!

 

I have a page that displays some data from mySQL database and I want to add the possibility to modify that information through an HTML form.

 

 

Here's the code that I have wich will display the mySQL data (link to update form is in red) :

<?php

 

$db = mysql_connect('localhost', 'user', 'pass');

 

mysql_select_db('table', $db);

 

$sql = "SELECT `id`, `username`, `firstname`, `lastname`, `email`, `movedate`, `adress1`, `adress2`, `app1`, `app2` FROM moving WHERE id='$_POST[id]'";

 

$req = mysql_query($sql) or die('Erreur SQL !<br>'.$sql.'<br>'.mysql_error());

 

while($data = mysql_fetch_assoc($req))

 

    {

 

echo "

<center>

<h2>Confirmation</h2>

<table border=0 bgcolor=FFFFFF STYLE=\"border: 1px solid #000000\" width=70% cellpadding=0 cellspacing=0 >

<tr>

<td colspan=2>$data[firstname] $data[lastname]</td>

</tr>

<tr>

<td colspan=2>$data</td>

</tr>

<tr>

<td colspan=2>Date du déménagement : $data[movedate] </td>

</tr>

<tr>

<td width=50%><br><b>Ancienne adresse :</b><br><br></td>

<td width=50%><br><b>Nouvelle adresse :</b><br><br></td>

</tr>

<tr>

<td>$data[adress1] #$data[app1]</td>

<td>$data[adress2] #$data[app2]</td>

<td colspan=2 align=right><a href=\"modif_adress.php?cmd=view&id=$_POST[id]\" class=2>Modifier/Corriger</a></td>

</tr>

</center>

        ";

  }

?>

 

 

And here's the update form code :

 

$db = mysql_connect('localhost', 'user', 'pass');

 

mysql_select_db('table', $db);

 

$sql = "SELECT `id`, `username`, `firstname`, `lastname`, `email` FROM moving WHERE id='$id'";

 

$req = mysql_query($sql) or die('Erreur SQL !<br>'.$sql.'<br>'.mysql_error());

 

while($data = mysql_fetch_assoc($req))

 

if($cmd=="view")

    {

      {

 

echo "

 

<h2>Changement d'adresse</h2>

<form name=moving action=\"insert_step1.php\" method=\"post\">

<table border=0>

<tr>

<td>Prénom :</td><td><input type=text class=texta name=firstname size=40 value=$data[firstname]></td>

</tr>

<tr>

<td>Nom :</td><td><input type=text class=texta name=lastname size=40 value=$data[lastname]></td>

</tr>

<tr>

<td>Courriel :</td><td><input type=text class=texta name=\"email\" size=40 value=$data></td>

</tr>

</tr>

</table>

</center>

<p class=border2></p>

<div align=right><input type=submit value=\"Suivant\"></div>

</form>

 

        ";

      }

  }

?>

 

 

Is anyone sees what I'm doing wrong? any help would be greatly appreciated!

Link to comment
https://forums.phpfreaks.com/topic/149159-solved-problem-with-update-linkform/
Share on other sites

when posting for help, always use the code tags so you can see properly formatted code, its much easier to spot problems.  If you look at this formatted code, you will see that your PHP variables in the echo statements are being "echo'd" as is, instead of being used as PHP variables.  Fix this and then see if it will work for you.  Also, what exactly is the problem you are having.  with this.  Is it a problem, or are you asking how to add functionality to it

 

<?php

$db = mysql_connect('localhost', 'user', 'pass');

mysql_select_db('table', $db);

$sql = "SELECT `id`, `username`, `firstname`, `lastname`, `email`, `movedate`, `adress1`, `adress2`, `app1`, `app2` FROM moving WHERE id='$_POST[id]'";

$req = mysql_query($sql) or die('Erreur SQL !<br>'.$sql.'<br>'.mysql_error());

while($data = mysql_fetch_assoc($req))

    {

echo "
<center>
<h2>Confirmation</h2>
<table border=0 bgcolor=FFFFFF STYLE=\"border: 1px solid #000000\" width=70% cellpadding=0 cellspacing=0 >
<tr>
<td colspan=2>$data[firstname] $data[lastname]</td>
</tr>
<tr>
<td colspan=2>$data[email]</td>
</tr>
<tr>
<td colspan=2>Date du déménagement : $data[movedate] </td>
</tr>
<tr>
<td width=50%><br><b>Ancienne adresse :</b><br><br></td>
<td width=50%><br><b>Nouvelle adresse :</b><br><br></td>
</tr>
<tr>
<td>$data[adress1] #$data[app1]</td>
<td>$data[adress2] #$data[app2]</td>
<td colspan=2 align=right><a href=\"modif_adress.php?cmd=view&id=$_POST[id]\" class=2>Modifier/Corriger</a></td>
</tr>
</center>
        ";
   }
?>

 

And here's the update form code :

<?php
$db = mysql_connect('localhost', 'user', 'pass');

mysql_select_db('table', $db);

$sql = "SELECT `id`, `username`, `firstname`, `lastname`, `email` FROM moving WHERE id='$id'";

$req = mysql_query($sql) or die('Erreur SQL !<br>'.$sql.'<br>'.mysql_error());

while($data = mysql_fetch_assoc($req))

if($cmd=="view")
     {
      {

echo "

<h2>Changement d'adresse</h2>
<form name=moving action=\"insert_step1.php\" method=\"post\">
<table border=0>
<tr>
<td>Prénom :</td><td><input type=text class=texta name=firstname size=40 value=$data[firstname]></td>
</tr>
<tr>
<td>Nom :</td><td><input type=text class=texta name=lastname size=40 value=$data[lastname]></td>
</tr>
<tr>
<td>Courriel :</td><td><input type=text class=texta name=\"email\" size=40 value=$data[email]></td>
</tr>
</tr>
</table>
</center>
<p class=border2></p>
<div align=right><input type=submit value=\"Suivant\"></div>
</form>

        ";
      }
   }
?>

Dont no in fact, if you need to use $_POST[''] in the link not sure Theo.

 

tell me if it works any way m8.

 

 

<?php
$db = mysql_connect('localhost', 'user', 'pass');

mysql_select_db('table', $db);

if( ($_GET['cmd']=="view") && (is_numeric($_GET['id'])) )
     {

$id=$_GET['id'];

$sql = "SELECT `id`, `username`, `firstname`, `lastname`, `email` FROM moving WHERE id='$id'";

$req = mysql_query($sql) or die('Erreur SQL !<br>'.$sql.'<br>'.mysql_error());

while($data = mysql_fetch_assoc($req))


      {

echo "

<h2>Changement d'adresse</h2>

<form name=moving action=\"insert_step1.php\" method=\"POST\">
<table border=0>
<tr>
<td>Prénom :</td><td><input type=text class=texta name=firstname size=40 value=\"{$data['firstname']}\"></td>
</tr>
<tr>
<td>Nom :</td><td><input type=text class=texta name=lastname size=40 value=\"{$data['lastname']}\"></td>
</tr>
<tr>
<td>Courriel :</td><td><input type=text class=texta name=\"email\" size=40 value=\"{$data['email']}\"></td>
</tr>
</tr>
</table>
</center>
<p class=border2></p>
<div align=right><input type=\"submit\" name=\"submit\" value=\"Suivant\"></div>
</form>

        ";
      }
   }
?>

 

<?php

$db = mysql_connect('localhost', 'user', 'pass');

mysql_select_db('table', $db);

$sql = "SELECT `id`, `username`, `firstname`, `lastname`, `email`, `movedate`, `adress1`, `adress2`, `app1`, `app2` FROM moving WHERE id='$_POST[id]'";

$req = mysql_query($sql) or die('Erreur SQL !<br>'.$sql.'<br>'.mysql_error());

while($data = mysql_fetch_assoc($req)) {

echo "
<center>
<h2>Confirmation</h2>
<table border=0 bgcolor=FFFFFF STYLE=\"border: 1px solid #000000\" width=70% cellpadding=0 cellspacing=0 >
<tr>
<td colspan=2>{$data['firstname']}\n {$data['lastname']}</td>
</tr>
<tr>
<td colspan=2>$data[email]</td>
</tr>
<tr>
<td colspan=2>Date du déménagement :\n {$data['movedate']} </td>
</tr>
<tr>
<td width=50%><br><b>Ancienne adresse :</b><br><br></td>
<td width=50%><br><b>Nouvelle adresse :</b><br><br></td>
</tr>
<tr>
<td>{$data['adress1']} #{$data['app1']}</td>
<td>$data[adress2] #$data[app2]</td>
<td colspan=2 align=right><a href=\"modif_adress.php?cmd=view&id={$_POST['id']}\" class=2>Modifier/Corriger</a></td>
</tr>
</center>
        ";
   }
?>

Hi! No problem I next i'll put it into code tags.

 

What I am trying to do is when I'm on the confirmation page and I click on the modify link(a href=\"modif_adress.php?cmd=view&id=$_POST[id]\" class=2>Modifier/Corriger</a>).....I get a form already filled out with the mySQL data. But for the moment when I click on the link I get a blank page with no errors.

 

 

Thanks!!

if you are getting a blank page, there's errors.  check your php.ini to make sure error reporting is turned on.  if you dont have access to the php.ini on your host then I think this will work if you put it at the top of your page right after the <?php tag

 

error_reporting(E_ALL);

?

 

I don't think it's possible since this a confirmation page that user may or not wnats to modify his infos. If he wants the he clicks on the link to go back to the registration form wich is already filled out with the data he entered in step 1. don't know if you understand what I mean....

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.