cjbeck71081 Posted August 31, 2006 Share Posted August 31, 2006 I have learned how to pass values from PHP to HTML and then back, and now i cannot stop!Here is what i am trying to do. I have a Survey form that restaurant owners in West Warwick have to fill out. My goal is to assign them a userID and allow them to view and update thier survey online once a year. I have setup the page that passes the USERID to the survey.php page and i generated an HTML page using the variables that are in my sql database for that USERID. With the help of a couple nice guys from this forum that all went well.....However, today i would like to include a "UPDATE" button and use form action "POST" to pass the user ID from that HTML page, to the new insert.php page, where users can update thier information. That will then get passed to a update.php page, where the information will be processed and sent back to the database as updated data.Perhaps this is far too complicated and there is an easier way to do this. I am open to new ideas any help will be appreciated... i will post the codes below, hopefully i have been clear enough.[b]CODES[/b]Here is the userid.html page, where a user enters his/her userID and it passes to the survey.php page:[color=red]<form method="post" action="http://epicri.com/survey.php"><p align="center"> </p><p align="center"> </p><p align="center"> </p><form id="form1" name="form1" method="post" action=""> <label> <div align="center"><span class="style1">Please Enter User ID: </span><br /> <br /> <input name="userid" type="text" size="10" maxlength="5" /> <br /> <br /> <input type="submit" name="Go" value="Submit" /> </div> </label></form>[/color]This code seems to work fine...here is the code for the survey.php page, where it then passes the USERID to the update.php page[color=green]<?php$hostname = "mysql.epicri.com"; // The Thinkhost DB server. $username = "epicr001"; // The username you created for this database. $password = "xxxxx"; // The password you created for the username. $usertable = "persontab"; // The name of the table you made. $dbName = "epicr001"; // This is the name of the database you made.$word = $_POST["userid"]?><?php$con = mysql_connect($hostname,$username,$password);if (!$con) { die('Could not connect: ' . mysql_error()); }mysql_select_db($dbName, $con);$result = mysql_query("SELECT userID, owner, operation, location, permit, streetaddress,email,companyname FROM $usertableWHERE userid='$word'");$row = mysql_fetch_array($result);$owner = $row['owner']?><div align="center"> <!-- ImageReady Slices (Untitled-1) --> <TABLE WIDTH=1024 BORDER=0 CELLPADDING=0 CELLSPACING=0> <TR> <TD ROWSPAN=14> </TD> <TD ROWSPAN=14> <IMG SRC="images/survey_02.gif" WIDTH=15 HEIGHT=1650 ALT=""></TD> <TD COLSPAN=13 bgcolor="#ECECED"> </TD> <TD ROWSPAN=14> <IMG SRC="images/survey_04.gif" WIDTH=15 HEIGHT=1650 ALT=""></TD> <TD ROWSPAN=14> </TD> <TD> <IMG SRC="images/spacer.gif" WIDTH=1 HEIGHT=32 ALT=""></TD> </TR> <TR> <TD ROWSPAN=4 bgcolor="#ECECED"> </TD> <TD COLSPAN=2> <IMG SRC="images/survey_07.gif" WIDTH=107 HEIGHT=89 ALT=""></TD> <TD ROWSPAN=4 bgcolor="#ECECED"> </TD> <TD COLSPAN=5> <IMG SRC="images/survey_09.gif" WIDTH=396 HEIGHT=89 ALT=""></TD> <TD ROWSPAN=4 bgcolor="#ECECED"> </TD> <TD COLSPAN=2 ROWSPAN=2> <IMG SRC="images/survey_11.gif" WIDTH=101 HEIGHT=101 ALT=""></TD> <TD ROWSPAN=4 bgcolor="#ECECED"> </TD> <TD> <IMG SRC="images/spacer.gif" WIDTH=1 HEIGHT=89 ALT=""></TD> </TR> <TR> <TD COLSPAN=2 ROWSPAN=3 bgcolor="#ECECED"> </TD> <TD ROWSPAN=3 bgcolor="#ECECED"> </TD> <TD COLSPAN=2 ROWSPAN=2> <IMG SRC="images/survey_15.gif" WIDTH=134 HEIGHT=46 ALT=""></TD> <TD COLSPAN=2 ROWSPAN=3 bgcolor="#ECECED"> </TD> <TD> <IMG SRC="images/spacer.gif" WIDTH=1 HEIGHT=12 ALT=""></TD> </TR> <TR> <TD COLSPAN=2 ROWSPAN=2 bgcolor="#ECECED"> </TD> <TD> <IMG SRC="images/spacer.gif" WIDTH=1 HEIGHT=34 ALT=""></TD> </TR> <TR> <TD COLSPAN=2> <IMG SRC="images/survey_18.gif" WIDTH=134 HEIGHT=45 ALT=""></TD> <TD> <IMG SRC="images/spacer.gif" WIDTH=1 HEIGHT=45 ALT=""></TD> </TR> <TR> <TD COLSPAN=13 bgcolor="#ECECED"><div align="center"><span class="style1"><?=$row['companyname']?></span></div></TD> <TD> <IMG SRC="images/spacer.gif" WIDTH=1 HEIGHT=33 ALT=""></TD> </TR> <TR> <TD COLSPAN=13 align="center" valign="top" bgcolor="#ECECED"><span class="style4">Permit no.:</span></TD> <TD> <IMG SRC="images/spacer.gif" WIDTH=1 HEIGHT=53 ALT=""></TD> </TR> <TR> <TD COLSPAN=2 ROWSPAN=6> <IMG SRC="images/survey_21.gif" WIDTH=47 HEIGHT=254 ALT=""></TD> <TD height="62" COLSPAN=4 align="left" valign="baseline" bgcolor="#ECECED" class="style2"><span class="style2"><?=$row['companyname']?></span></TD> <TD COLSPAN=2 ROWSPAN=6> <IMG SRC="images/survey_23.gif" WIDTH=134 HEIGHT=254 ALT=""></TD> <TD COLSPAN=3 align="left" valign="baseline" bgcolor="#ECECED" class="style2"><span class="style2"><?=$owner?></span></TD> <TD COLSPAN=2 ROWSPAN=6> <IMG SRC="images/survey_25.gif" WIDTH=50 HEIGHT=254 ALT=""></TD> <TD rowspan="3"> <IMG SRC="images/spacer.gif" WIDTH=1 HEIGHT=127 ALT=""></TD> </TR> <TR> <TD height="30" COLSPAN=4 bgcolor="#ECECED"><span class="style2"> <?=$row['location']?> </span></TD> <TD COLSPAN=3 bgcolor="#ECECED"><span class="style2"><?=$row['streetaddress']?></span></TD> </TR> <TR> <TD COLSPAN=4 bgcolor="#ECECED" class="style2"><span class="style2">West Warwick RI, 02886</span></TD> <TD COLSPAN=3 bgcolor="#ECECED" class="style2"><span class="style2">Warwick, RI 02852 </span></TD> </TR> <TR> <TD COLSPAN=4> <IMG SRC="images/survey_26.gif" WIDTH=286 HEIGHT=26 ALT=""></TD> <TD COLSPAN=3 ROWSPAN=3 bgcolor="#ECECED"><form name="form1" method="post" action="http://www.epicri.com/update.php"> <label> <input type="text" name="pass" value="<?=$word?>"> <br> <input type="submit" name="Submit" value="Update"> </label> </form> </TD> <TD> <IMG SRC="images/spacer.gif" WIDTH=1 HEIGHT=26 ALT=""></TD> </TR> <TR> <TD COLSPAN=4 bgcolor="#ECECED"><span class="style2">Hours of operation:</span></TD> <TD> <IMG SRC="images/spacer.gif" WIDTH=1 HEIGHT=60 ALT=""></TD> </TR> <TR> <TD COLSPAN=4 bgcolor="#ECECED"> </TD> <TD>[/color]That works great as wellhere is the resulting update.php page that gets the userID from survey.php and allows users to populate fields:[color=blue]<?php$hiddenid = $_POST['pass']?><form id="form1" name="form1" method="post" action="http://www.epicri.com/insert.php"> <label> text <input type="text" name="userid" value="<?=$hiddenid?>" /> <br /> <br /> <br /> Please enter Owner Name: <input type="text" name="owner" /> </label> <p> </p> <p> <label></label> </p> <p> <label> <input type="submit" name="Submit" value="Submit" /> </label> </p></form>[/color]and finally the insert.php page that inserts the values that are passed from the update.php form this is where the problem happens. I get a parse error at line 17, i will highlight row 17 and where it is used... perhaps i am using a syntax error... or perhaps the way to do this is way too much work.[color=orange]<?php$hostname = "mysql.epicri.com"; // The Thinkhost DB server. $username = "epicr001"; // The username you created for this database. $password = "xxxxx"; // The password you created for the username. $usertable = "persontab"; // The name of the table you made. $dbName = "epicr001"; // This is the name of the database you made.$owner = $_POST["owner"][color=red]$pass = $_POST["pass2"][/color]?><?php$con = mysql_connect($hostname,$username,$password);if (!$con) { die('Could not connect: ' . mysql_error()); }mysql_select_db($dbName, $con);$result = mysql_query("Update $usertable SET owner = '$owner' WHERE userid = [color=red]'$pass'[/color]");mysql_close($con)?>Thank YouUsername <?=$pass?> has been updated![/color]Any help is appreciated, again i am a newbie, so if this isnt the right way to do this, let me know.ThanksChris Quote Link to comment Share on other sites More sharing options...
harleydude Posted August 31, 2006 Share Posted August 31, 2006 maybe I am missing something myself, but I cannot find where the $_POST['pass2'] is being defined at? More especially what control is named pass2? Quote Link to comment Share on other sites More sharing options...
redarrow Posted August 31, 2006 Share Posted August 31, 2006 when the user has filled all relevent information out this is what i do.the user press a link say update the link goes to a page with a conndition of cmd=update i use a $_GET[''] to get the condition form the link then update the database with the user information then send them back to the index page or echo a message ok.link[code]echo"<a href='update.php?id=$id&cmd=update'>Update</a>";[/code][code]<?phpdatabase connectionif($_GET['cmd']=="update"){$query="update members_information set user_information='$user_information' where id='$id'";$result=mysql($query);header("location: index.php");}?>[/code] Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.