scm22ri Posted August 8, 2012 Share Posted August 8, 2012 Whenever a user submits a new vehicle all information is being processed besides the user_id information. I'm not sure why this isn't working. Below is my syntax. http://whatsmyowncarworth.com/auto-practice/display-member-info.php (member info) http://whatsmyowncarworth.com/auto-practice/display-database.php (database info) http://whatsmyowncarworth.com/auto-practice/submit-information.php Thanks everyone! submit-information.php syntax <html> <head> <title>Submit Information</title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> <script type="text/javascript"> <!-- Form Validation --> function validate_form ( ) { valid = true; if ( document.form.year.value == "" ) { alert ( "Year must not be blank." ); valid = false; } if ( document.form.make.value == "" ) { alert ( "Make must not be blank." ); valid = false; } if ( document.form.model.value == "" ) { alert ( "Model must not be blank." ); valid = false; } if ( document.form.price.value == "" ) { alert ( "Price must not be blank." ); valid = false; } if ( document.form.extcolor.value == "" ) { alert ( "Exterior Color must not be blank." ); valid = false; } if ( document.form.intcolor.value == "" ) { alert ( "Interior Color must not be blank." ); valid = false; } if ( document.form.engine.value == "" ) { alert ( "Engine must not be blank." ); valid = false; } if ( document.form.mileage.value == "" ) { alert ( "Mileage must not be blank." ); valid = false; } if ( document.form.transmission.value == "" ) { alert ( "Transmission must not be blank." ); valid = false; } if ( document.form.fueltype.value == "" ) { alert ( "Fuel Type must not be blank." ); valid = false; } if ( document.form.state.value == "" ) { alert ( "State must not be blank." ); valid = false; } if ( document.form.city.value == "" ) { alert ( "City/Town must not be blank." ); valid = false; } if ( document.form.number.value == "" ) { alert ( "Favorite Number must not be blank." ); valid = false; } return valid; } <!-- Form Validation --> </script> </head> <body bgcolor="#FFFFFF" text="#000000"> <form action="insert.php" method="post" enctype="multipart/form-data" name="form" id="form" onsubmit="return validate_form ( );"> <table> <tr> <td>Year:</td> <td><select name="year"> <option value="2012">2012</option> <option value="2011">2011</option> <option value="2010">2010</option> <option value="2009">2009</option> <option value="2008">2008</option> <option value="2007">2007</option> <option value="2006">2006</option> <option value="2005">2005</option> <option value="2004">2004</option> <option value="2003">2003</option> <option value="2002">2002</option> <option value="2001">2001</option> <option value="2000">2000</option> <option value="1999">1999</option> <option value="1998">1998</option> <option value="1997">1997</option> <option value="1996">1996</option> <option value="1995">1995</option> <option value="1994">1994</option> <option value="1993">1993</option> <option value="1992">1992</option> <option value="1991">1991</option> <option value="1990">1990</option> </select></td> </tr> <tr> <td>Make:</td> <td><input type="text" name="make"></td> </tr> <tr> <td>Model:</td> <td><input type="text" name="model"></td> </tr> <tr> <td>Price:</td> <td><input type="text" name="price"></td> </tr> <tr> <td>Exterior Color:</td> <td><input type="text" name="extcolor"></td> </tr> <tr> <td>Interior Color:</td> <td><input type="text" name="intcolor"></td> </tr> <tr> <td>Engine:</td> <td><input type="text" name="engine"></td> </tr> <tr> <td>Mileage:</td> <td><input type="text" name="mileage"></td> </tr> <tr> <td>Transmission:</td> <td><select name="transmission"> <option value="Automatic">Automatic</option> <option value="Standard">Standard</option> </select></td> </tr> <tr> <td>Fuel Type:</td> <td><select name="fueltype"> <option value="Gas">Gas</option> <option value="Diesel">Diesel</option> </select></td> </tr> <tr> <td>State:</td> <td><select name="state"> <option value="Alabama">Alabama</option> <option value="Alaska">Alaska</option> <option value="Arizona">Arizona</option> <option value="Arkansas">Arkansas</option> <option value="California">California</option> <option value="Colorado">Colorado</option> <option value="Connecticut">Connecticut</option> <option value="Delaware">Delaware</option> <option value="Florida">Florida</option> <option value="Georgia">Georgia</option> <option value="Hawaii">Hawaii</option> <option value="Idaho">Idaho</option> <option value="Illinois">Illinois</option> <option value="Indiana">Indiana</option> <option value="Iowa">Iowa</option> <option value="Kansas">Kansas</option> <option value="Kentucky">Kentucky</option> <option value="Louisiana">Louisiana</option> <option value="Maine">Maine</option> <option value="Maryland">Maryland</option> <option value="Massachusetts">Massachusetts</option> <option value="Michigan">Michigan</option> <option value="Minnesota">Minnesota</option> <option value="Mississippi">Mississippi</option> <option value="Missouri">Missouri</option> <option value="Montana">Montana</option> <option value="Nebraska">Nebraska</option> <option value="Nevada">Nevada</option> <option value="New Hampshire">New Hampshire</option> <option value="New Jersey">New Jersey</option> <option value="New Mexico">New Mexico</option> <option value="New York">New York</option> <option value="North Carolina">North Carolina</option> <option value="North Dakota">North Dakota</option> <option value="Ohio">Ohio</option> <option value="Oklahoma">Oklahoma</option> <option value="Oregon">Oregon</option> <option value="Pennsylvania">Pennsylvania</option> <option value="Rhode Island">Rhode Island</option> <option value="South Carolina">South Carolina</option> <option value="South Dakota">South Dakota</option> <option value="Tennessee">Tennessee</option> <option value="Texas">Texas</option> <option value="Utah">Utah</option> <option value="Vermont">Vermont</option> <option value="Virginia">Virginia</option> <option value="Washington">Washington</option> <option value="West Virginia">West Virginia</option> <option value="Wisconsin">Wisconsin</option> <option value="Wyoming">Wyoming</option> </select></td> </tr> <tr> <td>City/Town:</td> <td><input type="text" name="city"></td> </tr> <tr> <td>Fav. Number?</td> <td><input type="text" name="number"></td> </tr> <tr> <td><input type="submit" name="submit" value="Submit"></td> </tr> </table> </form> </body> </html> >>>>>>>>>>>>>>>>>>>>> insert.php syntax <?php //Connect to the database through our include include_once "init.php"; $user_id = mysql_real_escape_string($_POST['user_id']); $year = mysql_real_escape_string($_POST['year']); $make = mysql_real_escape_string($_POST['make']); $model = mysql_real_escape_string($_POST['model']); $price = mysql_real_escape_string($_POST['price']); $extcolor = mysql_real_escape_string($_POST['extcolor']); $intcolor = mysql_real_escape_string($_POST['intcolor']); $engine = mysql_real_escape_string($_POST['engine']); $trans = mysql_real_escape_string($_POST['transmission']); $fuel = mysql_real_escape_string($_POST['fueltype']); $mileage = mysql_real_escape_string($_POST['mileage']); $state = mysql_real_escape_string($_POST['state']); $city = mysql_real_escape_string($_POST['city']); $number = mysql_real_escape_string($_POST['number']); /*$insert = 'INSERT INTO car_info(year, make, model, price, exteriorcolor, interiorcolor, engine, transmission, fueltype, mileage, state, city, number) VALUES("'.$year.'","'.$make.'","'.$model.'","'.$price.'","'.$extcolor.'","'.$intcolor.'","'.$engine.'","'.$trans.'","'.$fuel.'","'.$mileage.'","'.$state.'","'.$city.'","'.$number.'")';*/ $insert = 'INSERT INTO car_info(user_id, year, make, model, price, exteriorcolor, interiorcolor, engine, transmission, fueltype, mileage, state, city, number) VALUES("'.NULL.'","'.$year.'","'.$make.'","'.$model.'","'.$price.'","'.$extcolor.'","'.$intcolor.'","'.$engine.'","'.$trans.'","'.$fuel.'","'.$mileage.'","'.$state.'","'.$city.'","'.$number.'")'; mysql_query($insert); echo 'Thanks for submitting your vehicle information.<br /><br /> To return to the homepage, <a href="submit-information.php">click here</a>'; ?> Quote Link to comment https://forums.phpfreaks.com/topic/266816-user_id-isnt-being-processed-when-submitting-form-cant-determine-whats-wrong/ Share on other sites More sharing options...
Pikachu2000 Posted August 8, 2012 Share Posted August 8, 2012 There is no element in your form named 'user_id'. Quote Link to comment https://forums.phpfreaks.com/topic/266816-user_id-isnt-being-processed-when-submitting-form-cant-determine-whats-wrong/#findComment-1367834 Share on other sites More sharing options...
scm22ri Posted August 8, 2012 Author Share Posted August 8, 2012 Hi, Thanks for the reply. That's correct! but I tried passing my user_id as a hidden field, above the year and when inserted into the database I'm still not getting anything. Is my INSERT INTO etc .... syntax incorrect? Thanks! <tr> <td><input type="hidden" name="user_id"></td> </tr> Quote Link to comment https://forums.phpfreaks.com/topic/266816-user_id-isnt-being-processed-when-submitting-form-cant-determine-whats-wrong/#findComment-1367904 Share on other sites More sharing options...
Pikachu2000 Posted August 8, 2012 Share Posted August 8, 2012 It has no value= attribute, so all it will be is an empty string. What are you trying to accomplish, and where is the user_id value supposed to come from? Quote Link to comment https://forums.phpfreaks.com/topic/266816-user_id-isnt-being-processed-when-submitting-form-cant-determine-whats-wrong/#findComment-1367910 Share on other sites More sharing options...
scm22ri Posted August 8, 2012 Author Share Posted August 8, 2012 Hi Guys, Thanks for the replies. I think I know where I'm going wrong. My session id are assigned to id and not "user_id" so I'm assuming this would have an affect because when a user is logged in the session should know what number is assigned to that user. Here's my login syntax <?php if ($_POST['email']) { //Connect to the database through our include include_once "connect_to_mysql.php"; $email = stripslashes($_POST['email']); $email = strip_tags($email); $email = mysql_real_escape_string($email); $password = ereg_replace("[^A-Za-z0-9]", "", $_POST['password']); // filter everything but numbers and letters $password = md5($password); // Make query and then register all database data that - // cannot be changed by member into SESSION variables. // Data that you want member to be able to change - // should never be set into a SESSION variable. $sql = mysql_query("SELECT * FROM members WHERE email='$email' AND password='$password' AND emailactivated='1'"); $login_check = mysql_num_rows($sql); if($login_check > 0){ while($row = mysql_fetch_array($sql)){ // Get member ID into a session variable $id = $row["id"]; session_register('id'); $_SESSION['id'] = $id; // Get member username into a session variable $username = $row["username"]; session_register('username'); $_SESSION['username'] = $username; // Update last_log_date field for this member now mysql_query("UPDATE members SET lastlogin=now() WHERE id='$id'"); // Print success message here if all went well then exit the script header("location: member_profile.php?id=$id"); exit(); } // close while } else { // Print login failure message to the user and link them back to your login page print '<br /><br /><font color="#FF0000">No match in our records, try again </font><br /> <br /><a href="login.php">Click here</a> to go back to the login page.'; exit(); } }// close if post ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <title>Login to your profile</title> <script type="text/javascript"> <!-- Form Validation --> function validate_form ( ) { valid = true; if ( document.logform.email.value == "" ) { alert ( "Please enter your User Name" ); valid = false; } if ( document.logform.pass.value == "" ) { alert ( "Please enter your password" ); valid = false; } return valid; } <!-- Form Validation --> </script> </head> <body> <div align="center"> <h3><br /> <br /> Log in to your account here<br /> <br /> </h3> </div> <table align="center" cellpadding="5"> <form action="login.php" method="post" enctype="multipart/form-data" name="logform" id="logform" onsubmit="return validate_form ( );"> <tr> <td class="style7"><div align="right">Email Address:</div></td> <td><input name="email" type="text" id="email" size="30" maxlength="64" /></td> </tr> <tr> <td class="style7"><div align="right">Password:</div></td> <td><input name="password" type="password" id="password" size="30" maxlength="24" /></td> </tr> <tr> <td> </td> <td><input name="Submit" type="submit" value="Login" /></td> </tr> </form> </table> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/266816-user_id-isnt-being-processed-when-submitting-form-cant-determine-whats-wrong/#findComment-1367914 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.