PHP - Why Simple Insert Wont Work-help Me Please
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> Similar TutorialsThis topic has been moved to Other Programming Languages. http://www.phpfreaks.com/forums/index.php?topic=354391.0 i need help trying to get this delete feature to work its not deleting from the database (by the way i took out my database names and passwords at the top of the file) is it possible someone could help me, ive been working on this for like a week and cant figure out the problem. thanks! you can email me at spr_spng@yahoo.com picture 2.png is showing what it looks like Code: [Select] <?php $host="localhost"; // Host name $username="username"; // Mysql username $password="password"; // Mysql password $db_name="database_name"; // Database name $tbl_name="table_name"; // Table name // Connect to server and select databse. mysql_connect("$host", "$username", "$password")or die("cannot connect"); mysql_select_db("$db_name")or die("cannot select DB"); $sql="SELECT * FROM $tbl_name"; $result=mysql_query($sql); $count=mysql_num_rows($result); ?> <style> /*table affects look of the whole table look */ table { margin-left: auto; margin-right: auto; border: 1px solid #330000; border-collapse:collapse; width:70%; border-width: 5px 5px 5px 5px; border-spacing: 1px; border-style: outset outset outset outset; border-color: #330000 #330000 #330000 #330000; border-collapse: separate; background-color: #330000; #800517 f535aa #330000 school color #9A0000 school color2 #991B1E school color3 #CCCC99 school color4 #9A0000 } /*th is table header */ th { text-align: left; height: 2.5em; background-color: #330000; color: #FC0; font-size:1.5em; } /*td is table data or the cells below the header*/ td { text-align: left; height:1.0em; font-size:1.0em; vertical-align:bottom; padding:10px; border-width: 5px 5px 5px 5px; padding: 8px 8px 8px 8px; border-style: outset outset outset outset; border-color: #9A0000 #9A0000 #9A0000 #9A0000; background-color: #CCCC99; -moz-border-radius: 0px 0px 0px 0px; } </style> <table width="400" border="0" cellspacing="1" cellpadding="0"> <tr> <td><form name="form1" method="post" action=""> <table width="400" border="0" cellpadding="3" cellspacing="1" bgcolor="#CCCCCC"> <tr> <td bgcolor="#FFFFFF"> </td> <td colspan="4" bgcolor="#FFFFFF"><strong>Pick Which Rows you want to delete, Then press delete.</strong> </td> </tr> <tr> <td align="center" bgcolor="#FFFFFF"><strong>Id</strong></td> <td align="center" bgcolor="#FFFFFF"><strong>Name</strong></td> <td align="center" bgcolor="#FFFFFF"><strong>Lastname</strong></td> <td align="center" bgcolor="#FFFFFF"><strong>Email</strong></td> <td align="center" bgcolor="#FFFFFF">delete</td></tr> <?php while($rows=mysql_fetch_array($result)){ ?> <tr> <td bgcolor="#FFFFFF"><? echo $rows['id']; ?></td> <td bgcolor="#FFFFFF"><? echo $rows['name']; ?></td> <td bgcolor="#FFFFFF"><? echo $rows['lastname']; ?></td> <td bgcolor="#FFFFFF"><? echo $rows['email']; ?></td> <td align="center" bgcolor="#FFFFFF"><input name="checkbox[]" type="checkbox" id="checkbox[]" value="<? echo $rows['id']; ?>"></td> </tr> <?php } ?> <tr> <td colspan="5" align="center" bgcolor="#FFFFFF"><input name="delete" type="submit" id="delete" value="Delete"></td> </tr> <? // Check if delete button active, start this // edited if($delete){ for($i=0;$i<$count;$i++){ $del_id = $checkbox[$i]; $sql = "DELETE FROM $tbl_name WHERE id='$del_id'"; $result = mysql_query($sql); } // if successful redirect to delete_multiple.php if($result){ echo "<meta http-equiv=\"refresh\" content=\"0;URL=delete_multiple.php\">"; } } mysql_close(); ?> </table> </form> </td> </tr> </table> require_once 'includes/upload.class.php'; $upload = new uploads(); $details = $upload->getFileInformation($id); <?php echo $details['upload_desc']; ?> then here the class. require_once 'db.class.php'; class uploads extends database { private $uploadData; function uploadFile() { public function getFileInformation($id) { $this->uploadData = $this->readData("uploadfiles", "upload_id", $id); return $this->uploadData; } But it wont work! Hey all Hope ya can help. its almost done just having problems with the new data getting inserted into the current table. Code: [Select] foreach($_SESSION as $key => $value) { $key = $value; } echo $item_number . "<br>" . $po_number . "<br>" . $lot_number . "<br>" . $amount ; $query = "SELECT * FROM invintory WHERE item_number ='$item_number'"; $result = mysql_query($query) or die ("couldnt execute query." . mysql_error()); while ($row = mysql_fetch_array($result)) { $onhand = $row['onhand']; } echo $onhand ; $newamount=$onhand+$amount; echo $newamount; [color=red]mysql_query("INSERT INTO invintory WHERE item_number ='$item_number'(onhand) values ('$newamount')");[/color] mysql_query("INSERT INTO recvied(item_number,po_number,lot_number,amount) values ('$item_number','$po_number','$lot_number','$amount')"); ?>The part in red seems to be the problem I've Basically got this script and everything works. Except for the part that it doesen't insert "$_FILES['file']['name']" into the image_url. Any Ideas guys? Code: [Select] <? include "includes/config.php"; if (isset($_POST['add'])) { if ((($_FILES["file"]["type"] == "image/gif") || ($_FILES["file"]["type"] == "image/jpeg") || ($_FILES["file"]["type"] == "image/png")) && ($_FILES["file"]["size"] < 20000)) { if ($_FILES["file"]["error"] > 0) { echo "Return Code: " . $_FILES["file"]["error"] . "<br />"; } else { if (file_exists("images/" . $_FILES["file"]["name"])) { echo $_FILES["file"]["name"] . " already exists. "; echo $_FILES['file']['name']; } else { move_uploaded_file($_FILES["file"]["tmp_name"], "images/" . $_FILES["file"]["name"]); } } } else { echo "Sorry, but only PNG, JPG, and GIF files are allowed."; } mysql_connect ($mysql_host, $mysql_user, $mysql_pass); mysql_select_db ($mysql_db); $image_url = "http://localhost/admin/images/". $_FILES['file']['name'] .""; $sql = "INSERT INTO test (title, link, description, image_url) VALUES ('$_POST[title]', '$_POST[link]', '$_POST[description]', '$image_url')"; if (!mysql_query($sql)) { die('Error: ' . mysql_error()); } header( 'Location: portfolio.php' ); mysql_close(); } ?> Code: [Select] <form enctype="multipart/form-data" method="post"> <p> <strong>TITLE</strong><br/> <input type="text" name="title" class="box"/> </p> <p> <strong>LINK</strong><br/> <input type="text" name="link" class="box"/> </p> <p> <strong>IMAGE</strong><br/> <input type="file" class="box" name="file"/> </p> <p> <strong>DESCRIPTION</strong><br/> <input type="textarea" name="description" class="box"/> </p> <p> <input name="add" type="submit" id="submit" tabindex="5" class="com_btn" value="ADD WORK"/> </p> </form> $last = mysql_query("SELECT MAX('id') FROM comments WHERE submittedby='$username'"); can any1 help me? Ok, I am a complete noob when it comes to php. I am slowly learning it but I turned to youtube for a tutorial on a registration/login page. I found a good tutorial http://www.youtube.com/watch?v=ngqeWUIDlnk&feature=channel but for some reason my php is NOT working. I have it exactly the way he does but it wont echo anything or work at all. The login page worked great in his tutorial. What do I have wrong? I cant figure it out. Please help! echo "<h1>Register</h1>"; $submit = $_POST['submit']; $fullname = strip_tags($_POST['name']); $username = strip_tags($_POST['user']); $password = strip_tags($_POST['password']); $verifypassword = strip_tags($_POST['verifypassword']); $date = date("Y-m-d"); if ($submit) { if($fullname&&$username&&$password&&$verifypassword) { password = md5($password); verifypassword= = md5($verifypassword); } else echo "Please fill in all fields!"; } Code: [Select] <html> <form action='register.php' method='POST'> <table> <tr> <td>Full Name:</td> <td><input type='text' name='name'></td> </tr> <tr> <td>Username:</td> <td><input type='text' name='user'></td> </tr> <tr> <td>Password:</td> <td><input type='password' name='password'></td> </tr> <tr> <td>Verify Password:</td> <td><input type='password' name='verifypassword'></td> </tr> </table> <p><input type='submit' name='submit' value='Submit'></p> </form> </html> Hi guys, I have an update page where users can update their information, i have a different update page which works fine with almost the same code, but this one wont update anything. it does show the data but it wont update it, can u help please? <?php session_start(); include ("../../global.php"); //welcome messaage $username=$_SESSION['username']; echo "$username"; $query=mysql_query("SELECT id FROM users WHERE username='$username'"); while($row = mysql_fetch_assoc($query)) { $user_id = $row['id']; } $ref=$_GET['reference']; if (isset($_POST['register']) && $_POST['register']){ $title = addslashes(strip_tags($_POST['title'])); $update=mysql_query("UPDATE msg SET title ='$title' WHERE reference='$ref'"); } ?> <html> <head> </head> <body> <form action='edit-msgs.php' method='POST' enctype='multipart/form-data'> Title:<br /> <input type='text' name='title' id='title' value='<?php $getdata = "SELECT title FROM msg WHERE reference='$ref' AND referal_id='$user_id'"; $result = mysql_query($getdata); $row = mysql_fetch_assoc($result); echo $row['title'];?>'><p /> <input type='submit' name='register' value='Update'> </form> </body> </html> For some reason this wont work.. Index is jsut returned blank ... Hmm Index.php : <?php include("http://www.website.com/cookie.php"); ?> Cookie.php: <?php if (isset($_COOKIE["background"])) $background = $_COOKIE['background']; else $background = " bgcolor='#FFFFFF'"; ?> It works perfectly if I just enter the code without using a include ... Hi, I am not sure why but my script is not working. Choose a post is not working http://beta.cwuforum.com/stock/tech.php Code: [Select] <?PHP $idofp = $_REQUEST['bida']; ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <title>Ryan Weekly</title> <style type="text/css"> body { background-color: #E3E5E2; } </style> </head> <style type="text/css"> <!-- body { font-size:12px; font-family:Verdana, Arial, Helvetica, sans-serif; } div#wrapper { width: 80%; background-color:#FFFFFF; margin-top: 50px; margin-bottom: 50px; margin-left: auto; margin-right: auto; padding: 0px; border: thin solid #000000; } div#header { padding: 15px; margin: 0px; text-align: center; } div#nav { width: 25%; padding: 10px; margin-top: 1px; float: left; border: thin solid #000000; } div#main { margin-left: 30%; margin-top: 1px; padding: 10px; border: thin solid #000000; } div#underhead { padding: 15px; margin: 0px; border-top: thin solid #000000; } { ul.nav a:hover, ul.nav a:active, ul.nav a:focus { /* this changes the background and text color for both mouse and keyboard navigators */ background: #6F7D94; color: #FFF; } .content ul, .content ol { padding: 0 15px 15px 40px; /* this padding mirrors the right padding in the headings and paragraph rule above. Padding was placed on the bottom for space between other elements on the lists and on the left to create the indention. These may be adjusted as you wish. */ } /* ~~ The navigation list styles (can be removed if you choose to use a premade flyout menu like Spry) ~~ */ ul.nav { list-style: none; /* this removes the list marker */ border-top: 1px solid #666; /* this creates the top border for the links - all others are placed using a bottom border on the LI */ margin-bottom: 15px; /* this creates the space between the navigation on the content below */ } ul.nav li { border-bottom: 1px solid #666; /* this creates the button separation */ } ul.nav a, ul.nav a:visited { /* grouping these selectors makes sure that your links retain their button look even after being visited */ padding: 5px 5px 5px 15px; display: block; /* this gives the link block properties causing it to fill the whole LI containing it. This causes the entire area to react to a mouse click. */ text-decoration: none; background: #8090AB; color: #000; } ul.nav a:hover, ul.nav a:active, ul.nav a:focus { /* this changes the background and text color for both mouse and keyboard navigators */ background: #6F7D94; color: #FFF; } /* ~~ The footer ~~ */ .footer { padding: 10px 0; background: #6F7D94; position: relative;/* this gives IE6 hasLayout to properly clear */ clear: both; /* this clear property forces the .container to understand where the columns end and contain them */ } /* ~~ miscellaneous float/clear classes ~~ */ .fltrt { /* this class can be used to float an element right in your page. The floated element must precede the element it should be next to on the page. */ float: right; margin-left: 8px; } .fltlft { /* this class can be used to float an element left in your page. The floated element must precede the element it should be next to on the page. */ float: left; margin-right: 8px; } .clearfloat { /* this class can be placed on a <br /> or empty div as the final element following the last floated div (within the #container) if the #footer is removed or taken out of the #container */ clear:both; height:0; font-size: 1px; line-height: 0px; } --> </style> <body> <div align="Left"> <p><img src="indexp.png" width="728" height="90" /></p> </div> <div id="underhead"> <form id="bida2" name="form1" method="post" action="tech.php"> Choose Post: <label for="id"></label> <select name="id" id="bida"> <option value="ad1">Google Chrome Netbook </option> </select> <input type="submit" name="send" id="send" value="View" /> </form> </div> <?php include("menu.php"); ?> <div id="main"> <?PHP if (empty($idofp)) include ("canoncamera1.php"); if ($idofp == ad1) include ("chromenetbook.php"); ?> </div> Ryan Weekly 2009 - 2011 (May 11, 2011 at 6:00PM Is our 3 Year anniversary!) </body> </html> why cant I get this to echo? something so simple i dont understand what im doing wrong. can i simply not beable to display a sql timestamp with out converting 2011-12-19 14:57:45 Code: [Select] <?php $ban3 = "SELECT date FROM banned WHERE id = '".mysql_real_escape_string($_SESSION['user_id'])."'"; $ban2 = mysql_query($ban3) or die(mysql_error()); $ban1 = mysql_fetch_array($ban2); $pop = $ban1['date']; echo $pop; ?> well, i have a hosting site and i enter via cpanel,(just in case it matters) and i am trying to use the mai() function but it won't work.. :S this is my code Code: [Select] <?php $to = "pato.llaguno@gmail.com"; $subject = "Hi!"; $body = "Hi,\n\nHow are you?"; if (mail($to, $subject, $body)) { echo("<p>Message successfully sent!</p>"); } else { echo("<p>Message delivery failed...</p>"); } ?> the output is Message successfully sent! but i don't get any mail in the adress specified :S I have a php page which is ran after a form is posted from the previous page. I am having trouble getting the SQL strings to work. When the page is ran online there is no WSOD or error message but the tables in my database are not being updated. Any help with this would be greatly appreciated.
Attached Files
payment.php 1.79KB
4 downloads It works other then the fact it won't go to another page to see results. <?php // Get the search variable from URL $var = @$_GET['q'] ; $trimmed = trim($var); //trim whitespace from the stored variable // rows to return $limit=10; // check for an empty string and display a message. if ($trimmed == "") { echo "<p>Please enter a search...</p>"; exit; } // check for a search parameter if (!isset($var)) { echo "<p>We dont seem to have a search parameter!</p>"; exit; } //connect to your database ** EDIT REQUIRED HERE ** mysql_connect("localhost","username","password"); //(host, username, password) //specify database ** EDIT REQUIRED HERE ** mysql_select_db("database") or die("Unable to select database"); //select which database we're using // Build SQL Query $query = "select * from the_table where 1st_field like \"%$trimmed%\" order by 1st_field"; // EDIT HERE and specify your table and field names for the SQL query $numresults=mysql_query($query); $numrows=mysql_num_rows($numresults); // If we have no results, offer a google search as an alternative if ($numrows == 0) { echo "<h4>Results</h4>"; echo "<p>Sorry, your search: "" . $trimmed . "" returned zero results</p>"; echo "<p><a href=\"http://www.google.com/search?q=" . $trimmed . "\" target=\"_blank\" title=\"Look up " . $trimmed . " on Google\">Click here</a> to try the search on google</p>"; } // next determine if s has been passed to script, if not use 0 if (empty($s)) { $s=0; } // get results $query .= " limit $s,$limit"; $result = mysql_query($query) or die("Couldn't execute query"); // display what the person searched for echo "<p>You searched for: "" . $var . ""</p>"; // begin to show results set echo "Results"; $count = 1 + $s ; // now you can display the results returned while ($row= mysql_fetch_array($result)) { $title = $row["1st_field"]; echo "$count.) $title" ; $count++ ; } $currPage = (($s/$limit) + 1); //break before paging echo "<br />"; // next we need to do the links to other results if ($s>=1) { // bypass PREV link if s is 0 $prevs=($s-$limit); print " <a href=\"$PHP_SELF?s=$prevs&q=$var\"><< Prev 10</a>  "; } // calculate number of pages needing links $pages=intval($numrows/$limit); // $pages now contains int of pages needed unless there is a remainder from division if ($numrows%$limit) { // has remainder so add one page $pages++; } // check to see if last page if (!((($s+$limit)/$limit)==$pages) && $pages!=1) { // not last page so give NEXT link $news=$s+$limit; echo " <a href=\"$PHP_SELF?s=$news&q=$var\">Next 10 >></a>"; } $a = $s + ($limit) ; if ($a > $numrows) { $a = $numrows ; } $b = $s + 1 ; echo "<p>Showing results $b to $a of $numrows</p>"; ?> Any idea why I cant get the order by to work? $res = mysql_query ("SELECT COUNT(*), LEFT(`comment`, 3) AS truncated from comments where navn='$rows[navn]' AND adresse='$rows[adresse]' ORDER BY time desc" ) or die(mysql_error()); Test code test.php Code: [Select] <script type="text/javascript"> $(document).ready(function(){ $("#sub").click(function(){ $("#test").load("sub.php"); $.get("sub.php", { uid: $("#sub").attr('uid') }); }); }); </script> <a href="#" id="sub" uid="1">Sub</a> <div id="test"> </div> sub.php Code: [Select] <?php $id = $_GET['uid']; echo $id; ?> I am trying to load a file after clicking the href which has an extra attribute so i can query the database with it, however the get method seems to be not working, it works on other pages though. Error message i get Quote Notice: Undefined index: uid in C:\xampp\htdocs\sub.php on line 2 Here is the code: Code: [Select] <?php $db = mysql_query(" SELECT story_id FROM story_info WHERE story='$story_form' AND user='$username' ")or die(mysql_error()); $rows = mysql_fetch_assoc($db); $id = $rows['story_id']; ?> All of the variables are defined earlier in the code. Well PHP manual says that the script execution will be delayed by $x seconds if you write a codes like this: Code: [Select] $x = 5; //5 secs sleep($x); Now I have this script in which I write the four lines to the screen one by one, each should be delayed by 5 secs after the last line is output to the screen. It does not work out at all... Code: [Select] echo "Update setting 1:"; sleep(5); echo "Success! <br>Updating setting 2"; sleep(5); echo "Success! <br>Updating setting 3"; sleep(5); echo "Success! <br>Updating setting 4"; Instead, the entire script execution is delayed by 15 secs, with all four lines output at the same time. Why is this happening? Is there a way to fix it? Please help... |