elmas156 Posted September 5, 2008 Share Posted September 5, 2008 Hey guys, I'm having problems with this code and after several hours of going over it and trying different things I just can't seem to figure out what's wrong. What I have is a link to this page and, using the GET method I make the users email and lp variables. With this information I select several pieces of information from my database to set variables so that I can make those variables values in the form on this page... this way the user does not have to type in any of the information that isn't going to change because it's already there. After the form is submitted, the new values are made into slightly different variables then updated in the database. The problem is, they are not updating in the database. I know the variables are being passed because I've tested them by echoing them onto the page. Please let me know if you can see something that I'm overlooking. Here's the code: <?php include("conf.inc.php"); // Includes the db and form info. session_start(); // Starts the session. $email=$_GET['email']; $flp=$_GET['lp']; $result = mysql_query("SELECT year,color,make,model,state,drive,engine,cylinders,oiltype,oilbrand,special,vehicleid FROM vehicles WHERE email = '$email' AND lp = '$flp'"); $row = mysql_fetch_row( $result ); $fyear = $row[0]; $fcolor = $row[1]; $fmake = $row[2]; $fmodel = $row[3]; $fstate = $row[4]; $fdrive = $row[5]; $fengine = $row[6]; $fcylinders = $row[7]; $foiltype = $row[8]; $foilbrand = $row[9]; $fspecial = $row[10]; $vehicleid = $row[11]; if (!isset($_POST['editvehicle'])) { "Show the form" } else { $year = form($_POST['year']); $color = form($_POST['color']); $make = form($_POST['make']); $model = form($_POST['model']); $state = form($_POST['state']); $lp = form($_POST['lp']); $drive = form($_POST['drive']); $engine = form($_POST['engine']); $cylinders = form($_POST['cylinders']); $oiltype = form($_POST['oiltype']); $oilbrand = form($_POST['oilbrand']); $special = form($_POST['special']); mysql_query("UPDATE vehicles SET year = '$year',color = '$color' WHERE vehicleid = '$vehicleid'") or die (mysql_error()); header("Location: members.php"); } ?> Link to comment https://forums.phpfreaks.com/topic/122830-solved-whats-wrong-with-my-code/ Share on other sites More sharing options...
ranjuvs Posted September 5, 2008 Share Posted September 5, 2008 You haven't set the $vehicleid variable... Link to comment https://forums.phpfreaks.com/topic/122830-solved-whats-wrong-with-my-code/#findComment-634317 Share on other sites More sharing options...
elmas156 Posted September 5, 2008 Author Share Posted September 5, 2008 $vehicleid is set at the top of the page when all the initial variables are set: $vehicleid = $row[11]; As far as I know it shouldn't change from it initial value but I'll play with it some more and see what I can do. Thanks for your input. Link to comment https://forums.phpfreaks.com/topic/122830-solved-whats-wrong-with-my-code/#findComment-634320 Share on other sites More sharing options...
ranjuvs Posted September 5, 2008 Share Posted September 5, 2008 After posting the variable $vehicleid will get reset. Your form should have a hidden filed that stores the vehicleid and then get that variable using $vehicleid = form($_POST['vehicleid ']); Link to comment https://forums.phpfreaks.com/topic/122830-solved-whats-wrong-with-my-code/#findComment-634322 Share on other sites More sharing options...
elmas156 Posted September 5, 2008 Author Share Posted September 5, 2008 I stand corrected, you were right ranjuvs. I added a hidden tag to the form and set the $vehicleid variable again after the form was submitted... works like a charm now. Thanks very much! Link to comment https://forums.phpfreaks.com/topic/122830-solved-whats-wrong-with-my-code/#findComment-634323 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.