Jump to content

sasori

Members
  • Posts

    332
  • Joined

  • Last visited

Everything posted by sasori

  1. but sir based on the example in the php manual it can also be mysqli_query($mysqlilink,$query); i think i fixed the error the only problem now is it doesn't greet the username who logins in here's the script i made for the login page <?php echo "Hello,{$_GET['user_name']}Welcome to the secret page"; ?> from the login.php script i edited the header location as header("Location: http://localhost/webapp/logingreet.php?userid=$row[userid]"); i wonder what's wrong now ?
  2. i created 2 scripts, one for display of the login form and the other is the logic code. //this is the login code loginform.php <?php if(isset($message)) { echo "$message"; } echo "<form action='$_SERVER[php_SELF]' method='POST'>"; echo "<label for='user_name'>username</label>"; echo "<input type='text' name='user_name' id='user_name' value='$user_name' />"; echo "<label for='password'>password</label>"; echo "<input type='text' name='passowrd' id='password' value='$password' />"; echo "<input type='hidden' name='sent' value='yes' />"; echo "<input type='submit' value='Log in' />"; ?> //this is the logic code login.php <?php if(isset($_POST['sent']) && $_POST['sent'] == "yes") { foreach($_POST as $field => $value) { if(empty($value)) { $blank_array[] = $field; } else { $good_value[$field] = strip_tags(trim($value)); } } //end foreach if(sizeof($blank_array) > 0 ) { echo " you need to enter both userid and password"; extract($good_value); extract($blank_array); include('loginform.php'); exit(); } //end if blanks found include('db.php'); $cxn = mysqli_connect($host,$user,$pwd,$db) or die ("can't connect to db"); $query = "SELECT userid FROM users WHERE userid='$_POST[user_name]' AND password=md5('$_POST[user_name]')"; $result = mysqli_query($cxn,$query) or die("can' execute query"); $n_row = mysqli_num_rows($result); if($n_row < 1) { $message = "User id and password not found!"; extract($_POST); exit(); } else { $row = mysqli_fetch_assoc($result); header("Location: loginfom.php?userid=$row[userid]"); // <-- i don't know if this line is correct } } //end submit else { $user_name = ""; $password = ""; include("loginform.php"); } ?> then when i run login.php file and input the code it says, can't execute query i can't figure out what's wrong with my coding
  3. thank you to both of you..it is working fine now cheers
  4. any other way sir? i did what you said $destination = 'c:\wamp\tmp'."\\".$_FILES['pix']['name']; $tmp_file = $_FILES['pix']['tmp_name']; move_uploaded_file($tmp_file,$destination); echo "<b>successfully uploaded {$_FILES['pix']['name']} ({$_FILES['pix']['size']})<b>"; echo "<form action='upload.php' method='get'>"; echo "<input type='submit' value='Upload another file'>"; echo "</form>"; echo "<br/>"; echo "<br/>"; echo "<img src='getimage.php?id". $destination."' alt=''/>"; still nothing happened..it just uploads the file and no display at all
  5. i edited my script and inserted your logic code <?php if(!isset($_POST['upload'])) { include("formupload.php"); } else { if($_FILES['pix']['tmp_name'] == "none") { echo " file not uploaded"; include("formupload.php"); exit(); } if(!preg_match("/image/",$_FILES['pix']['type'])) { echo "<b>LOL! it's not a picture</b>"; include("formupload.php"); exit(); } else { $destination = 'c:\wamp\tmp'."\\".$_FILES['pix']['name']; $tmp_file = $_FILES['pix']['tmp_name']; move_uploaded_file($tmp_file,$destination); echo "<b>successfully uploaded {$_FILES['pix']['name']} ({$_FILES['pix']['size']})<b>"; echo "<form action='upload.php' method='get'>"; echo "<input type='submit' value='Upload another file'>"; echo "</form>"; echo "<br/>"; echo "<br/>"; $path = 'c:\wamp\tmp'."\\".$_FILES['pix']['name']; $extension = substr($path, -3); if($extension == "jpg" || $extension == "jpeg") { header("Content-type: image/jpeg"); } elseif($extension == "gif") { header("Content-type: image/gif"); } elseif($extension == "bmp") { header("Content-type: image/bmp"); } elseif($extension == "png") { header("Content-type: image/png"); } readfile($path); echo "<img src='$path'/>"; } } ?> it got worst sir ???
  6. sir, i don't use a database as for the moment.. i don't know how to display the photo here' i tried this echo "<img src='".$_FILES['pix']['name']."' />"; and still it doesn't display ..can you tell me how the proper way to echo the absolute path? the images are being sent to c:\wamp\tmp folder
  7. how ? let's say another user uploaded a photo and i don't know what the name of the photo was, all i know is the path which is c:\wamp\tmp , so how am i gonna display the photo after upload when i don't even know the name of the file ? (this bothers me)
  8. I created an formupload.php and upload.php script #### formupload.php ### <html> <body> <b>UPLOAD YOUR SHIT IN THERE</b> <form enctype="multipart/form-data" action="<?php echo $_SERVER['PHP_SELF'] ?>" method="POST"> <input type="hidden" name="MAX_FILE_SIZE" value="500000" /> <input type="file" name="pix" size="60" /> <input type="submit" name="upload" value="upload picture" /> </form> </body> </html> ##### upload.php #### <?php if(!isset($_POST['upload'])) { include("formupload.php"); } else { if($_FILES['pix']['tmp_name'] == "none") { echo " file not uploaded"; include("formupload.php"); exit(); } if(!preg_match("/image/",$_FILES['pix']['type'])) { echo " it's not a picture "; include("formupload.php"); exit(); } else { $destination = 'c:\wamp\tmp'."\\".$_FILES['pix']['name']; $tmp_file = $_FILES['pix']['tmp_name']; move_uploaded_file($tmp_file,$destination); echo "successfully uploaded {$_FILES['pix']['name']} ({$_FILES['pix']['size']})"; echo "<form action='upload.php' method='get'>"; echo "<input type='submit' value='Upload another file'>"; echo "</form>"; echo "<br/>"; } } ?> and the question is how am I gonna display the uploaded photo on the same page?
  9. I was able to configure the problem myself, first, i created a process2.php for the checkbox to use in processing the submit button $category = array("Clothes","Food","Furnitures","Health","Toys"); echo "<ol>\n"; foreach($_POST as $category) { foreach($category as $field => $value) { echo "<li>Category = $value</li>\n"; } } cheers
  10. the out put is supposed to be, let's say I clicked the checkbox with name Furniture, it should be 1.) Category = Furniture that's why the rest of the code are being messed up if I change the $_POST in process.php
  11. and now this is the ouput after doing that
  12. i did just did your tip .. and it ruined the supposed to be output, istead of 1. Category = Furniture ...the output is now Furniture = Furniture and also the other blocks that uses my 'process.php' code where ruined here's my actual practice code <?php include('db.php'); echo "<html>\n"; echo "<head><title>Practice Shit</title></head>\n"; echo "<body>\n"; // CUSTOMER DETAIL echo "<fieldset><b><legend>Customer</legend></b>\n"; $labels = array("fname" => "first name", "lname" => "last name", "phone" => "phone number"); $submit = "details"; echo "<div align='center'>\n"; echo "<form action='process.php' method='POST'>\n"; foreach($labels as $field => $label) { echo "<label for='$field'>$label</label> \n"; echo "<input type='text' name='$field' size='15%' maxlength='15'/>\n"; } echo "<input type='submit' value='$submit'>\n"; echo "</form>\n"; echo "</div>\n"; echo "</fieldset>\n"; // CATEGORIES MENU $cxn = mysqli_connect($host,$user,$pwd,$db) or die ("can't connect"); $query = "SELECT cat FROM products ORDER BY cat ASC"; $result = mysqli_query($cxn,$query) or die ("can't connect"); echo "<fieldset><b><legend>Categories</legend></b>\n"; echo "<div align='center'>\n"; echo "<form action='process.php' method='POST'>\n"; echo "<select name='Category'>\n"; while($row = mysqli_fetch_assoc($result)) { extract($row); echo "<option value='$cat'>$cat</option>\n"; } echo "</select>\n"; echo "<input type='submit' value='select' category'>\n"; echo "</form>\n"; echo "</div>\n"; echo "</fieldset>\n"; //DATE $months = array("January","February","March","April","May", "June","July","August","September","October","November", "December"); echo "<fieldset><b><legend>Date</legend></b>\n"; echo "<div align='center'>\n"; echo "<form>\n"; echo "<select name='Month'>\n"; foreach($months as $value) { echo "<option value='$value'"; if($value == date('F',time())) { echo " selected "; } echo "> $value</option>\n"; } echo "</select>\n"; echo "<select name='Day'>\n"; for($i=1;$i<=31;$i++) { echo "<option value='$i' "; if($i == date('d',time())) { echo " selected "; } echo "> $i</option>\n"; } echo "</select>\n"; echo "<select name='Year'>\n"; $year = date('Y'); for($i=$year;$i<=$year+3;$i++) { echo "<option value='$i'"; if($i == $year) { echo " selected "; } echo "> $i </option>\n"; } echo "</select>\n"; echo "</form>\n"; echo "</div>\n"; echo "</fieldset>\n"; //RADIO BUTTONS echo "<fieldset><b><legend>Categories</legend></b>\n"; echo "<div align='center'>\n"; echo "<form action='process.php' method='POST'>\n"; $query2 = "SELECT cat FROM products ORDER BY cat"; $result3 = mysqli_query($cxn,$query2) or die ("can't connect"); while($row = mysqli_fetch_assoc($result3)) { extract($row); echo "<input type='radio' name='Category' value='$cat' />$cat\n"; echo "<br/>\n"; } echo "<input type='submit' value='select category' />"; echo "</form>"; echo "</div>\n"; echo "</fieldset>"; echo "<fieldset><b><legend>CheckBox</legend></b>\n"; $query = "SELECT DISTINCT cat FROM products ORDER BY cat"; echo "<form action='process.php' method='post'>\n"; $result4 = mysqli_query($cxn,$query) or die ("can't connect"); while($row = mysqli_fetch_assoc($result4)) { extract($row); echo "<input type='checkbox' name='category[$cat]' id='$cat' value='$cat' />\n"; echo "<label for ='$cat'>$cat</label>\n"; } echo "<input type='submit' value='select category'>\n"; echo "</fieldset>\n"; echo "</body>\n"; echo "</html>\n"; mysqli_close($cxn); ?> what should i do now? all other blocks are using that process.php so when i changed the $_POST attribute ..the code gone crazy
  13. I already have a 'process.php' that outputs an the $_POST array sir <?php echo "<html><head><title>Hello Telephone</title></head>\n"; echo "<body>\n"; echo "<ol>\n"; foreach($_POST as $field => $value) { echo "<li>$field = $value</li>\n"; } echo "</ol>\n"; echo "<form action='dryrun.php' method='GET'>\n"; echo "<input type='submit' value='back' />\n"; echo "</form>\n"; echo "</body>\n"; echo "</html>\n"; ?> i got confused more with your tip i don't understand what to do now lol
  14. I have data in the table products as follows ,cid,cat,,, ,'1','Furniture',,, ,'2','Toys',,, ,'3','Clothes',,, ,'4','Food',,, then i created this simple script include('db.php'); $cxn = mysqli_connect($host,$user,$pwd,$db) or die ("can't connect"); $query = "SELECT DISTINCT cat FROM products ORDER BY cat"; $result = mysqli_query($cxn,$query) or die ("can't connect"); echo "<form action='process.php' method='post'>"; while($row = mysqli_fetch_assoc($result)) { extract($row); echo "<input type='checkbox' name='category[$cat]' value='$cat' />\n"; echo "<label for='$cat'>$cat</label>"; } echo "<input type='submit' value='select category' />"; echo "</form>"; the question now is, why is that after i selected a category from the check box, then onclicked the submit button. the output says "Category = Array" I don't know what am missing in my code, help me configure this thing out Sir/s ???
  15. ok it worked.. thanks for the help sir ..topic solved
  16. i have this select form for a year option echo "<select name='Year'>\n"; $year = date('Y'); for($i=$year; $i<=$year+7; $i++) { echo "<option value='$year' "; if($i == date('Y',time())) { echo " selected "; } echo "> $i </option>\n"; } echo "</select>\n"; the code is working fine at first glance of the page..but when i refresh the page, the selected years turns to the last value let's say today is 2008 but when i click refresh button of the browser it turns to 2015 what should i do now so that even if i refresh the page it will still select the current year such as 2008 ? ???
  17. this one is working fine as well...but i got confuse on the foreach body ???
  18. working fine now thanks
  19. am sorry sir,, but your code doesn't show the months inside the dropdown...
  20. i created a drop down menu for "month" <?php $months = array(1 =>"January","February","March", "April","May","June", "July","August","September", "October","November","December"); $today = time(); $monthMO = date("M",$today); echo "<form action='process.php' method='POST'>"; echo "<select name='month'>"; for($n=1; $n<=12 ;$n++) { echo "<option value='$n' "; if(($monthMO == $n) && ($monthMO == $today)) { echo " Selected "; } echo "> $months[$n]\n</option>"; } echo "</select>"; echo "</form>"; ?> my question is how will you make the form select the month today as the default selected everytime i run the script...because as of this moment, that script default is january ???
  21. case solved...thanks for replies.
  22. what should i do? i have this data in my phone table ,uid,fname,lname,phone ,1,jena,malone,234325 when i delete that data with uid ='1' then input the same data, the uid increments + 1..what should i do in order to make the new data as no. 1 ? because even if i update table and set uid as 1. the next data input will be 3 and not 2
  23. ok done ALTER TABLE `phone` CHANGE `phonenumber` `phonenumber` VARCHAR( 15 ) NULL DEFAULT NULL case solved
  24. Help. I inserted a phone number in my table, but the result changes i don't know what's going on. kindly help me what to do. here's the screenshot
  25. (based from the tutorial in w3schools.com) let's say the user created this xml script <note> <to>Tove</to> <from>Jani</from> <body>Don't forget me this weekend!</body> </note> and it should output this and then let's say the user decided to add an element later on in the script like <note> <date>2008-01-10</date> <to>Tove</to> <from>Jani</from> <heading>Reminder</heading> <body>Don't forget me this weekend!</body> </note> w3cshool said, the application will not crash because it can still detect the <to>, <from>, and <body> elements in the XML document and produce the same output. so my question now is..what's gonna happen with the <date> ? where did it go ? why was it not detected at all ? (im new to this thing)
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.