patheticsam Posted March 12, 2009 Share Posted March 12, 2009 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 More sharing options...
lonewolf217 Posted March 12, 2009 Share Posted March 12, 2009 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> "; } } ?> Link to comment https://forums.phpfreaks.com/topic/149159-solved-problem-with-update-linkform/#findComment-783197 Share on other sites More sharing options...
redarrow Posted March 12, 2009 Share Posted March 12, 2009 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> "; } ?> Link to comment https://forums.phpfreaks.com/topic/149159-solved-problem-with-update-linkform/#findComment-783212 Share on other sites More sharing options...
patheticsam Posted March 12, 2009 Author Share Posted March 12, 2009 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!! Link to comment https://forums.phpfreaks.com/topic/149159-solved-problem-with-update-linkform/#findComment-783222 Share on other sites More sharing options...
lonewolf217 Posted March 12, 2009 Share Posted March 12, 2009 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); Link to comment https://forums.phpfreaks.com/topic/149159-solved-problem-with-update-linkform/#findComment-783254 Share on other sites More sharing options...
redarrow Posted March 12, 2009 Share Posted March 12, 2009 try the link this way , tell me if you see the id in the link? <?php echo"<a href=\"modif_adress.php?cmd=view&id=$id\" class=2>Modifier/Corriger</a>"; ?> Link to comment https://forums.phpfreaks.com/topic/149159-solved-problem-with-update-linkform/#findComment-783260 Share on other sites More sharing options...
patheticsam Posted March 12, 2009 Author Share Posted March 12, 2009 it looks like it still dosen't work. I really don't understand cause I've already used a script liked that and it worked perfectly.... Link to comment https://forums.phpfreaks.com/topic/149159-solved-problem-with-update-linkform/#findComment-783292 Share on other sites More sharing options...
patheticsam Posted March 12, 2009 Author Share Posted March 12, 2009 Hi! With this code : <a href=\"modif_adress.php?cmd=view&id=$_POST[id]\" class=2> I see the correct ID when mouse is over the link cause the Id has been posted from a form in the precedent page. Link to comment https://forums.phpfreaks.com/topic/149159-solved-problem-with-update-linkform/#findComment-783295 Share on other sites More sharing options...
patheticsam Posted March 12, 2009 Author Share Posted March 12, 2009 But if I use modif_adress.php?cmd=view&id=$id\ the id won't appear cuz the the variable hasn't been defined... Link to comment https://forums.phpfreaks.com/topic/149159-solved-problem-with-update-linkform/#findComment-783298 Share on other sites More sharing options...
patheticsam Posted March 12, 2009 Author Share Posted March 12, 2009 also even with error_reporting(E_ALL); I get e blank page Link to comment https://forums.phpfreaks.com/topic/149159-solved-problem-with-update-linkform/#findComment-783300 Share on other sites More sharing options...
redarrow Posted March 12, 2009 Share Posted March 12, 2009 post the id before the link then. try. Link to comment https://forums.phpfreaks.com/topic/149159-solved-problem-with-update-linkform/#findComment-783302 Share on other sites More sharing options...
patheticsam Posted March 12, 2009 Author Share Posted March 12, 2009 ? 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.... Link to comment https://forums.phpfreaks.com/topic/149159-solved-problem-with-update-linkform/#findComment-783307 Share on other sites More sharing options...
patheticsam Posted March 12, 2009 Author Share Posted March 12, 2009 Nevermind I've found the way! Thank you all!!! Link to comment https://forums.phpfreaks.com/topic/149159-solved-problem-with-update-linkform/#findComment-783312 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.