princeofpersia Posted January 12, 2011 Share Posted January 12, 2011 Hi Guys, in code below i dont see any reason why it doesnt add anything into my mysql, can u please tell me where is wrong? <?php session_start(); include ("includes/db.php"); include ("includes/function.php"); //authentication if (loggedin()==FALSE) { Header("Location: login.php"); exit(); } //username session $_SESSION['username']=='$username'; $username=$_SESSION['username']; echo "Welcome, " .$_SESSION['username']."!<p>"; //get details from user table to be passed to page(text fields) $getdetails=mysql_query("SELECT * FROM users WHERE username='$username'"); while($row = mysql_fetch_array($getdetails)) { $users_id=$row['id']; $first_name=$row['first_name']; $last_name=$row['last_name']; $email=$row['email']; } /////////////////////////////////////// //****************************// //post starts here if (isset($_POST['next']) && $_POST['next']) { $myfirstname = addslashes(strip_tags($_POST['firstname'])); $mylastname = addslashes(strip_tags($_POST['lastname'])); $myemail = addslashes(strip_tags($_POST['email'])); $mybookingdate = addslashes(strip_tags($_POST['datetime'])); $mytime = addslashes(strip_tags($_POST['time'])); $myseatnumber = addslashes(strip_tags($_POST['seatnumber'])); $ride_id=1; //check if booking exists $checkbooking=mysql_query("SELECT * FROM booking WHERE date='$mybookingdate' AND time='$mytime' AND seat_no='$myseatnumber'"); if (mysql_num_rows($checkbooking)>=1) { echo "Seat No $myseatnumber For $mybookingdate at $mytime has been already taken, Please try a different seat, time or date"; } else { $addbooking=mysql_query("INSERT INTO booking (ride_id, users_id, time, date, seat_no) VALUES ('$ride_id','$users_id','$mytime','$mybookingdate','$myseatnumber'"); } } ?> <html> <head> <link type="text/css" href="css/smoothness/jquery-ui-1.8.6.custom.css" rel="stylesheet" /> <script type="text/javascript" src="includes/jquery-1.4.2.min.js"></script> <script type="text/javascript" src="includes/jquery-ui-1.8.6.custom.min.js"></script> <script type="text/javascript"> $(function() { $('#datetime').datepicker({ dateFormat: 'dd.mm.yy' }); }); </script> </head> <body> <form name="booking" method="post" action=""> <p>First Name:<br /> <input type="text" name='firstname' value="<? echo "$first_name";?>"> <p>Last Name:<br /> <input type="text" name='lastname' value="<? echo "$last_name";?>"> <p>Email:<br /> <input type="text" name='email' value="<? echo "$email";?>"> <p>Choose a Date:<br /> <input type="text" name='datetime' id="datetime"> </p> <p> Select a Time:<br/> <select name='time'> <option value="9:00">9:00 <option value="9:07">9:07 <option value="9:14">9:14 <option value="9:21">9:21 <option value="9:28">9:28 <option value="9:35">9:35 <option value="9:42">9:42 <option value="9:49">9:49 <option value="9:56">9:56 <option value="10:03">10:03 <option value="10:10">10:10 <option value="10:17">10:17 <option value="10:24">10:24 <option value="10:31">10:31 <option value="10:38">10:38 <option value="10:45">10:45 <option value="10:52">10:52 <option value="10:59">10:59 <option value="11:02">11:02 <option value="11:09">11:09 <option value="11:16">11:16 <option value="11:23">11:23 <option value="11:30">11:30 <option value="11:37">11:37 <option value="11:44">11:44 <option value="11:51">11:51 <option value="11:58">11:58 </select> </p> <p> Select Seat Number:<br/> <select name='seatnumber'> <option value="1">Seat 1 <option value="2">Seat 2 <option value="3">Seat 3 <option value="4">Seat 4 <option value="5">Seat 5 <option value="6">Seat 6 <option value="7">Seat 7 <option value="8">Seat 8 <option value="9">Seat 9 <option value="10">Seat 10 <option value="11">Seat 11 <option value="12">Seat 12 <option value="13">Seat 13 <option value="14">Seat 14 <option value="15">Seat 15 <option value="16">Seat 16 <option value="17">Seat 17 <option value="18">Seat 18 <option value="19">Seat 19 <option value="21">Seat 20 <option value="22">Seat 22 <option value="23">Seat 23 <option value="24">Seat 24 <option value="25">Seat 25 <option value="26">Seat 26 <option value="27">Seat 27 <option value="28">Seat 28 <option value="20">Seat 29 <option value="30">Seat 30 <option value="31">Seat 31 <option value="32">Seat 32 <option value="33">Seat 33 <option value="34">Seat 34 <option value="35">Seat 35 <option value="36">Seat 36 <option value="37">Seat 37 <option value="38">Seat 38 <option value="39">Seat 39 <option value="40">Seat 40 <option value="41">Seat 41 <option value="42">Seat 42 <option value="43">Seat 43 <option value="44">Seat 44 <option value="45">Seat 45 <option value="46">Seat 46 <option value="47">Seat 47 <option value="48">Seat 48 </select> <p> <input type='submit' name='next' value='Next Step'> </form> <p> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/224137-why-simple-insert-wont-work-help-me-please/ Share on other sites More sharing options...
trq Posted January 12, 2011 Share Posted January 12, 2011 What is going on here? $_SESSION['username']=='$username'; $username=$_SESSION['username']; Besides the fact that variables are not interpolated when in single quotes, $username is also not defined anywhere. Quote Link to comment https://forums.phpfreaks.com/topic/224137-why-simple-insert-wont-work-help-me-please/#findComment-1158165 Share on other sites More sharing options...
princeofpersia Posted January 12, 2011 Author Share Posted January 12, 2011 this is for a welcome msg, does it have anything to do with insert? Quote Link to comment https://forums.phpfreaks.com/topic/224137-why-simple-insert-wont-work-help-me-please/#findComment-1158166 Share on other sites More sharing options...
princeofpersia Posted January 12, 2011 Author Share Posted January 12, 2011 and also can u please tell me what do u mean by Besides the fact that variables are not interpolated Quote Link to comment https://forums.phpfreaks.com/topic/224137-why-simple-insert-wont-work-help-me-please/#findComment-1158167 Share on other sites More sharing options...
princeofpersia Posted January 12, 2011 Author Share Posted January 12, 2011 anyone? Quote Link to comment https://forums.phpfreaks.com/topic/224137-why-simple-insert-wont-work-help-me-please/#findComment-1158174 Share on other sites More sharing options...
trq Posted January 12, 2011 Share Posted January 12, 2011 Where is $username defined? Quote Link to comment https://forums.phpfreaks.com/topic/224137-why-simple-insert-wont-work-help-me-please/#findComment-1158176 Share on other sites More sharing options...
princeofpersia Posted January 12, 2011 Author Share Posted January 12, 2011 from a login page Quote Link to comment https://forums.phpfreaks.com/topic/224137-why-simple-insert-wont-work-help-me-please/#findComment-1158178 Share on other sites More sharing options...
trq Posted January 12, 2011 Share Posted January 12, 2011 unless you have register_globals enabled (which you shouldn't they where disabled by default some 8+ years ago for security reasons) your data will be in either the $_POST or $_GET arrays, depending on your forms method. This piece of code.... //username session $_SESSION['username']=='$username'; $username=$_SESSION['username']; echo "Welcome, " .$_SESSION['username']."!<p>"; Should then be.... //username session $_SESSION['username'] == $_POST['username']; echo "Welcome, " .$_SESSION['username']."!<p>"; Quote Link to comment https://forums.phpfreaks.com/topic/224137-why-simple-insert-wont-work-help-me-please/#findComment-1158179 Share on other sites More sharing options...
princeofpersia Posted January 12, 2011 Author Share Posted January 12, 2011 done that, still issue with mysql insert Quote Link to comment https://forums.phpfreaks.com/topic/224137-why-simple-insert-wont-work-help-me-please/#findComment-1158182 Share on other sites More sharing options...
trq Posted January 12, 2011 Share Posted January 12, 2011 What does mysql_error have to say? Quote Link to comment https://forums.phpfreaks.com/topic/224137-why-simple-insert-wont-work-help-me-please/#findComment-1158184 Share on other sites More sharing options...
princeofpersia Posted January 12, 2011 Author Share Posted January 12, 2011 no errors at all Quote Link to comment https://forums.phpfreaks.com/topic/224137-why-simple-insert-wont-work-help-me-please/#findComment-1158186 Share on other sites More sharing options...
trq Posted January 12, 2011 Share Posted January 12, 2011 But you don't have any error handling in your script? Seriously, this could go on forever. you have queries that rely on other queries executing successfully, but you never check any of these queries execute successfully or return data. The general idea is.... if ($result = mysql_query($sql)) { if (mysql_num_rows($result)) { // $result contains data. } else { // no records found } } else { // query failed, handle the error. } Apply that logic to all your code and post back if your still having issues. Quote Link to comment https://forums.phpfreaks.com/topic/224137-why-simple-insert-wont-work-help-me-please/#findComment-1158188 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.