Jump to content

tobimichigan

Members
  • Posts

    207
  • Joined

  • Last visited

Everything posted by tobimichigan

  1. I just went to that directory pf, yes it is appearing on the images folder. What do think might be wrong?
  2. You seem to be close to the answer pf, I adjusted the code thus and there was a slight improvement: check_image.php <?php $db = mysql_connect("localhost","root","") or die ("Unable to connect. Check your connection parameters."); mysql_select_db("moviesite", $db) or die(mysql_error($db)); //change this path to match your images directory $dir ="C:/xampp/htdocs/WroxPhp6.0/img"; //make sure the uploaded file transfer was successful if ($_FILES["uploadfile"]["error"] != UPLOAD_ERR_OK) { switch ($_FILES["uploadfile"]["error"]) { case UPLOAD_ERR_INI_SIZE: die("The uploaded file exceeds the upload_max_filesize directive " . "in php.ini."); break; case UPLOAD_ERR_FORM_SIZE: die("The uploaded file exceeds the MAX_FILE_SIZE directive that " . "was specified in the HTML form."); break; case UPLOAD_ERR_PARTIAL: die("The uploaded file was only partially uploaded."); break; case UPLOAD_ERR_NO_FILE: die("No file was uploaded."); break; case UPLOAD_ERR_NO_TMP_DIR: die("The server is missing a temporary folder."); break; case UPLOAD_ERR_CANT_WRITE: die("The server failed to write the uploaded file to disk."); break; case UPLOAD_ERR_EXTENSION: die("File upload stopped by extension."); break; } } //get info about the image being uploaded $uploadfile = $_POST["uploadfile"]; $image_caption = $_POST["caption"]; $image_username = $_POST["username"]; $image_date = date("Y-m-d"); list($width, $height, $type, $attr) = getimagesize($_FILES["uploadfile"]["tmp_name"]); // make sure the uploaded file is really a supported image switch ($type) { case IMAGETYPE_GIF: $image = imagecreatefromgif($_FILES["uploadfile"]["tmp_name"]) or die("The file you uploaded was not a supported filetype."); $ext = ".gif"; break; case IMAGETYPE_JPEG: $image = imagecreatefromjpeg($_FILES["uploadfile"]["tmp_name"]) or die("The file you uploaded was not a supported filetype."); $ext = ".jpg"; break; case IMAGETYPE_PNG: $image = imagecreatefrompng($_FILES["uploadfile"]["tmp_name"]) or die("The file you uploaded was not a supported filetype."); $ext = ".png"; break; default: die("The file you uploaded was not a supported filetype."); } //insert information into image table $query = "INSERT INTO images (image_caption, image_username, image_date) VALUES ('$image_caption.', '$image_username', '$image_date')"; $result = mysql_query($query, $db) or die (mysql_error($db)); //retrieve the image_id that MySQL generated automatically when we inserted //the new record $last_id = mysql_insert_id(); //because the id is unique, we can use it as the image name as well to make //sure we don’t overwrite another image that already exists $imagename = $last_id.$ext; // update the image table now that the final filename is known. $query = "UPDATE images SET image_filename = '.$imagename.' WHERE image_id = '$last_id'"; $result = mysql_query($query, $db) or die (mysql_error($db)); //save the image to its final destination switch ($type) { case IMAGETYPE_GIF: imagegif($image, $dir . '/' . $imagename); break; case IMAGETYPE_JPEG: imagejpeg($image, $dir . '/' . $imagename, 100); break; case IMAGETYPE_PNG: imagepng($image, $dir . '/' . $imagename); break; } imagedestroy($image); ?> <!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>Here's your pic</title> </head> <body> <h1> So how does it feel to be famous? </h1 > <p> Here is the picture you just uploaded to our servers: </p > <img src="images/ <?php echo $imagename; ?>" style="float:left;"> <table> <tr> <td> Image Saved as: </td> <td> <?php echo $imagename; ?> </td> </tr> <tr> <td> Image Type: </td> <td> <?php echo $ext; ?> </td> </tr> <tr> <td> Height: </td> <td> <?php echo $height; ?> </td > </tr> <tr> <td> Width: </td> <td> <?php echo $width; ?> </td > </tr> <tr> <td> Upload Date: </td > <td > <?php echo $image_date; ?> </td > </tr> </table> </body> </html> Now, the image_filename is no longer empty on the table..its now actually showing the image_filename, but the only problem here now is displaying on the html page..its still showing the "X" thing rather than the real image uploaded to the folder. What am I getting wrong this time?
  3. Oh by the way, I reading one of wrox's books..I wonder why the codes in some of these texts don't run at all..
  4. These r my files: Upload.php <?php $db = mysql_connect("localhost","root","") or die ("Unable to connect. Check your connection parameters."); mysql_select_db("moviesite", $db) or die(mysql_error($db)); ?> <!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>upload_image</title> </head> <body> <form action="check_image.php" method="post" enctype="multipart/form-data"> <table> <tr> <td> Your Username </td> <td> <input type="text" name="username"/> </td> </tr> <td> Upload Image* </td> <td> <input type="file" name="image_filename"/> </td> </tr> <tr> <td colspan="2"> <small> <em> * Acceptable image formats include: GIF, JPG/JPEG and PNG. </em> </small> </td> </tr> <tr> <td> Image Caption <br/> </td> <td> <input type="text" name="caption" /> </td> </tr > <tr> <td colspan="2" style="text-align: center"> <input type="submit" name="submit" value="Upload"/> </td> </tr> </table> </form> </body> </html> check_image.php <?php $db = mysql_connect("localhost","root","") or die ("Unable to connect. Check your connection parameters."); mysql_select_db("moviesite", $db) or die(mysql_error($db)); //change this path to match your images directory $dir ="C:/xampp/htdocs/WroxPhp6.0/img"; //make sure the uploaded file transfer was successful if ($_FILES["uploadfile"]["error"] != UPLOAD_ERR_OK) { switch ($_FILES["uploadfile"]["error"]) { case UPLOAD_ERR_INI_SIZE: die("The uploaded file exceeds the upload_max_filesize directive " . "in php.ini."); break; case UPLOAD_ERR_FORM_SIZE: die("The uploaded file exceeds the MAX_FILE_SIZE directive that " . "was specified in the HTML form."); break; case UPLOAD_ERR_PARTIAL: die("The uploaded file was only partially uploaded."); break; case UPLOAD_ERR_NO_FILE: die("No file was uploaded."); break; case UPLOAD_ERR_NO_TMP_DIR: die("The server is missing a temporary folder."); break; case UPLOAD_ERR_CANT_WRITE: die("The server failed to write the uploaded file to disk."); break; case UPLOAD_ERR_EXTENSION: die("File upload stopped by extension."); break; } } //get info about the image being uploaded $uploadfile = $_POST["uploadfile"]; $image_caption = $_POST["caption"]; $image_username = $_POST["username"]; $image_date = date("Y-m-d"); list($width, $height, $type, $attr) = getimagesize($_FILES["uploadfile"]["tmp_name"]); // make sure the uploaded file is really a supported image switch ($type) { case IMAGETYPE_GIF: $image = imagecreatefromgif($_FILES["uploadfile"]["tmp_name"]) or die("The file you uploaded was not a supported filetype."); $ext = ".gif"; break; case IMAGETYPE_JPEG: $image = imagecreatefromjpeg($_FILES["uploadfile"]["tmp_name"]) or die("The file you uploaded was not a supported filetype."); $ext = ".jpg"; break; case IMAGETYPE_PNG: $image = imagecreatefrompng($_FILES["uploadfile"]["tmp_name"]) or die("The file you uploaded was not a supported filetype."); $ext = ".png"; break; default: die("The file you uploaded was not a supported filetype."); } //insert information into image table $query = "INSERT INTO images (image_caption, image_username, image_date) VALUES ('$image_caption.', '$image_username', '$image_date')"; $result = mysql_query($query, $db) or die (mysql_error($db)); //retrieve the image_id that MySQL generated automatically when we inserted //the new record $last_id = mysql_insert_id(); //because the id is unique, we can use it as the image name as well to make //sure we don’t overwrite another image that already exists $imagename = $last_id.$ext; // update the image table now that the final filename is known. $query = "UPDATE images SET image_filename = '.$imagename.' WHERE image_id = '' . $last_id; $result = mysql_query($query, $db) or die (mysql_error($db)); //save the image to its final destination switch ($type) { case IMAGETYPE_GIF: imagegif($image, $dir . '/' . $imagename); break; case IMAGETYPE_JPEG: imagejpeg($image, $dir . '/' . $imagename, 100); break; case IMAGETYPE_PNG: imagepng($image, $dir . '/' . $imagename); break; } imagedestroy($image);" ?> <!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>Here's your pic</title> </head> <body> <h1> So how does it feel to be famous? </h1 > <p> Here is the picture you just uploaded to our servers: </p > <img src="images/ <?php echo $imagename; ?>" style="float:left;"> <table> <tr> <td> Image Saved as: </td> <td> <?php echo $imagename; ?> </td> </tr> <tr> <td> Image Type: </td> <td> <?php echo $ext; ?> </td> </tr> <tr> <td> Height: </td> <td> <?php echo $height; ?> </td > </tr> <tr> <td> Width: </td> <td> <?php echo $width; ?> </td > </tr> <tr> <td> Upload Date: </td > <td > <?php echo $image_date; ?> </td > </tr> </table> </body> </html> This is my table: <?php $db = mysql_connect("localhost", "root", "") or die ("Unable to connect. Check your connection parameters."); mysql_select_db("moviesite", $db) or die(mysql_error($db)); //create the images table $query = 'CREATE TABLE images ( image_id INTEGER NOT NULL AUTO_INCREMENT, image_caption VARCHAR(255) NOT NULL, image_username VARCHAR(255) NOT NULL, image_filename VARCHAR(255) NOT NULL DEFAULT "", image_date DATE NOT NULL, PRIMARY KEY (image_id) ) ENGINE=MyISAM'; mysql_query($query, $db) or die (mysql_error($db)); echo "Images table successfully created."; ?> Now, the problem I'm encountering is this: 1. When I execute this script, all the table fields are filled but the image_filename is empty. 2. On the html output, an "x" displays rather than the actual image uploaded. What am I doing wrong now? Please can some1 tell me? Be so grateful.
  5. Did you say immediately run select query? How on earth am I supposed to do that Pik ? Did you get my question at all? I'm saying if an authenticated logged user updates his username, password with this => code <?phpinclude("cn.php");$msg="Record_Updated";//$username=$_GET['username'];if (!@$_SESSION['username']){ header("location:Not_Logged.php"); }$select="select * from users where username='$_SESSION[username]'"; $rs_cat=mysqli_query($con,$select);$row=mysqli_fetch_array($rs_cat);$username=$row['username'];$password=$row['password'];$id=$row['id'];if (isset($_POST['update'])) {//this actually was one of my trouble spot now corrected $update=$_POST['update']; //this was another place i MISSED but now corrected$username=$_POST['username'];$password=$_POST['password']; //finally where id='$row[id]' I used now works after passing it as a parameter$update="UPDATE users SET username='$_POST[username]', password='$_POST[password]' where id='$row[id]'";$ud=mysqli_query($con,$update);}//}?><!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>UPDATE</title></head><body><p><li><?php echo ("<a href='Logout.php?user=$_SESSION[username]&sessid=$sessid&id=$id'>Logout</a>");?></li><li><?php echo ("<a href='update.php?user=$_SESSION[username]&sessid=$sessid&id=$id'>Update</a>");?></li><?php //echo $_SESSION['username'];?><table align="center" ><form name="login" action="<?php $_SERVER['PHP_SELF'];?>" " method="post"/><tr><td><th scope="col"><strong>UPDATE</strong></th></td></tr><tr><td>USERNAME<th scope="col"><input name="username" type="text" value="<?php echo ("$row[username]");?>"/></th></td></tr><tr><td>PASSWORD<th scope="col"><input name="password" type="password" value="<?php echo ("$row[password]");?>" /></th></td></tr><tr><td><th scope="col"><input name="update" type="submit" value="UPDATE" /></th></td></tr><tr><td><th scope="col"><input name="id" type="hidden" value="<?php echo $row[id];?>" /></th></td></form></table></body></html> the form does not display the updated values until the user logs out and in again. What do you think might be wrong there?
  6. Sorry, guys been off the net a couple of days or so...back to business. Yea, Pik, u're sure right about that..though I saw it before reading your reply to this topic...thanks anyway... but check below for something else... If this hasn't been set then the page/form will just submit to itself, so for validation purposes you do need to have something defined in the action="" attribute, but if your not bothered about W3C validation, just leave it blank; personally I would just put the filename in of the file that is using it Cheers, Rw rwwd, thanks also for the response, but let me remind you that its not necessary to do that in php...acod 2 1 of the texts I read up (sitepoint) when I was just starting up in php/mysql has 2 do with normalization...thanks anyway.. While I was offline, I managed to get the script to work... here's how I went about it I commented on the trouble spots: <?php include("cn.php"); $msg="Record_Updated"; //$username=$_GET['username']; if (!@$_SESSION['username']){ header("location:Not_Logged.php"); } $select="select * from users where username='$_SESSION[username]'"; $rs_cat=mysqli_query($con,$select); $row=mysqli_fetch_array($rs_cat); $username=$row['username']; $password=$row['password']; $id=$row['id']; if (isset($_POST['update'])) {//this actually was one of my trouble spot now corrected $update=$_POST['update']; //this was another place i MISSED but now corrected $username=$_POST['username']; $password=$_POST['password']; //finally where id='$row[id]' I used now works after passing it as a parameter $update="UPDATE users SET username='$_POST[username]', password='$_POST[password]' where id='$row[id]'"; $ud=mysqli_query($con,$update); } //} ?> <!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>UPDATE</title> </head> <body> <p><li><?php echo ("<a href='Logout.php?user=$_SESSION[username]&sessid=$sessid&id=$id'>Logout</a>");?></li> <li><?php echo ("<a href='update.php?user=$_SESSION[username]&sessid=$sessid&id=$id'>Update</a>");?></li> <?php //echo $_SESSION['username'];?> <table align="center" > <form name="login" action="<?php $_SERVER['PHP_SELF'];?>" " method="post"/> <tr> <td> <th scope="col"><strong>UPDATE</strong></th> </td> </tr> <tr> <td> USERNAME <th scope="col"><input name="username" type="text" value="<?php echo ("$row[username]");?>"/></th> </td> </tr> <tr> <td> PASSWORD <th scope="col"><input name="password" type="password" value="<?php echo ("$row[password]");?>" /></th> </td> </tr> <tr> <td> <th scope="col"><input name="update" type="submit" value="UPDATE" /></th> </td> </tr> <tr> <td> <th scope="col"><input name="id" type="hidden" value="<?php echo $row[id];?>" /></th> </td> </form> </table> </body> </html> Pik and rwwd, The only thing left now is that after it updates, it seems to leave the form empty rather than reflect the actual updated values..why? Until I log out and log in again, before the form shows it. What do you guys think might be wrong there?
  7. If I can't get a valid answer from here I wonder where I could then get 1...besides this is the best php forum I have come to know on the internet..would some1 please come to the rescue?
  8. Here's my modified code: <?php include("cn.php"); //$username=$_GET['username']; if (!@$_SESSION['username']){ header("location:Not_Logged.php"); } $oldname = $_SESSION['username']; $select="select * from users where username='$_SESSION[username]'"; $rs_cat=mysql_query($select); $row=mysql_fetch_array($rs_cat); $id=$row['id']; $old_user_name = $row['username']; $old_password = $row['password']; if (isset($_POST['update'])) { $update=$_GET['update'];} else {$update=0;} if ($update = "1") { $username=$_POST['username']; $password=$_POST['password']; $update="UPDATE users SET username='$username', password='$password' where username = '$_SESSION[username]'"; $ur=mysql_query($update) or die (mysql_error()); } //} ?> <!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>UPDATE</title> </head> <body> <?php //echo $_SESSION['username'];?> <table align="center" > <form name="login" action="" method="post"/> <tr> <td> <th scope="col"><strong>UPDATE</strong></th> </td> </tr> <tr> <td> USERNAME <th scope="col"><input name="username" type="text" value="<?php echo ("$row[username]");?>"/></th> </td> </tr> <tr> <td> PASSWORD <th scope="col"><input name="password" type="password" value="<?php echo ("$row[password]");?>" /></th> </td> </tr> <tr> <td> <th scope="col"><input name="update" type="submit" value="UPDATE" /></th> </td> </tr> <tr> <td> <th scope="col"><input name="id" type="hidden" value="<?php echo $row[id];?>" /></th> </td> </form> </table> </body> </html> By the way lite, here is my db struc -- phpMyAdmin SQL Dump -- version 3.2.4 -- http://www.phpmyadmin.net -- -- Host: localhost -- Generation Time: Sep 10, 2010 at 04:51 PM -- Server version: 5.1.41 -- PHP Version: 5.3.1 SET SQL_MODE="NO_AUTO_VALUE_ON_ZERO"; /*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */; /*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */; /*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */; /*!40101 SET NAMES utf8 */; -- -- Database: `test` -- -- -------------------------------------------------------- -- -- Table structure for table `users` -- CREATE TABLE IF NOT EXISTS `users` ( `id` int(233) NOT NULL AUTO_INCREMENT, `username` varchar(233) DEFAULT NULL, `password` varchar(233) DEFAULT NULL, PRIMARY KEY (`id`) ) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=2 ; -- -- Dumping data for table `users` -- INSERT INTO `users` (`id`, `username`, `password`) VALUES (1, '', ''); /*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */; /*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */; /*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */; The problem now is that the values in the db aren't showing again...what really is going on in here?
  9. Lite, the unique key is "id" still don't know why this script is not updating...any other ideas? U can run it it for your self and see..I'm yet to really know what could be wrong...
  10. Please is there some1 out there that could help me with this script..I need to know why my db values are not being updated after clicking update..please some1 come to the rescue...
  11. Ok Lite, here's the code that loads the update page: <?php include("cn.php"); //$username=$_GET['username']; if (!@$_SESSION['username']){ header("location:Not_Logged.php"); } ?> <!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>Welcomee</title> </head> <body> Welcome <?php echo ("$_SESSION[username]");?> <p><li><?php echo ("<a href='Logout.php?user=$_SESSION[username]&sessid=$sessid'>Logout</a>");?></li> <li><?php echo ("<a href='update.php?user=$_SESSION[username]&sessid=$sessid'>Update</a>");?></li> </body> </html> As per the session variable, it is in cn.php, here's it: <?php session_start(); $sessid=md5(uniqid(rand())); $host="localhost"; $user="root"; $password=""; $db="test"; $con=mysqli_connect("$host","$user","$password","$db"); //$select=mysql_select_db('test',$con); if (!@$con) { echo ("Con Failed").mysql_error(); } //else //echo "Full Connection Established...Nice Work"; //else echo ("Connected and Db selected..Nice Work"); ?> Finally, here's the update code that isn't still working: <?php include("cn.php"); //$username=$_GET['username']; if (!@$_SESSION['username']){ header("location:Not_Logged.php"); } $select="select * from users where username='$_SESSION[username]'"; $rs_cat=mysqli_query($con,$select); $row=mysqli_fetch_array($rs_cat); $username=$row['username']; $password=$row['password']; if (isset($_POST['update'])) { $update=$_GET['update'];} else {$update=0;} if ($update = "1") { $update="UPDATE users SET username='$username', password='$password' where username='$_SESSION[username]'"; $ur=mysqli_query($con,$update) or die (mysql_error()); } //} ?> <!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>UPDATE</title> </head> <body> <?php //echo $_SESSION['username'];?> <table align="center" > <form name="login" action="" method="post"/> <tr> <td> <th scope="col"><strong>UPDATE</strong></th> </td> </tr> <tr> <td> USERNAME <th scope="col"><input name="username" type="text" value="<?php echo ("$row[username]");?>"/></th> </td> </tr> <tr> <td> PASSWORD <th scope="col"><input name="password" type="password" value="<?php echo ("$row[password]");?>" /></th> </td> </tr> <tr> <td> <th scope="col"><input name="update" type="submit" value="UPDATE" /></th> </td> </tr> <tr> <td> <th scope="col"><input name="id" type="hidden" value="<?php echo $row[id];?>" /></th> </td> </form> </table> </body> </html> What else do you think could be wrong here?
  12. Lite, thanks for your responses I'm so grateful...I have made some of your corrections but the db is not updating yet but still reflecting the old values after clicking the old values r still there...what am I doing wrong now? <?php include("cn.php"); //$username=$_GET['username']; if (!@$_SESSION['username']){ header("location:Not_Logged.php"); } $select="select * from users where username='$_SESSION[username]'"; $rs_cat=mysqli_query($con,$select); $row=mysqli_fetch_array($rs_cat); $username=$row['username']; $password=$row['password']; if (isset($_POST['update'])) { $update=$_GET['update'];} else {$update=0;} if ($update = "1") { //this is where I implemented your corrections... $username=$_GET['username']; $username=$_POST['username']; $password=$_GET['password']; $password=$_POST['password']; $update="UPDATE users SET username='$username', password='$password' where username='$_POST[username]'"; $ur=mysqli_query($con,$update) or die (mysql_error()); } //} ?> <!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>UPDATE</title> </head> <body> <?php //echo $_SESSION['username'];?> <table align="center" > <form name="login" action="" method="post"/> <tr> <td> <th scope="col"><strong>UPDATE</strong></th> </td> </tr> <tr> <td> USERNAME <th scope="col"><input name="username" type="text" value="<?php echo ("$row[username]");?>"/></th> </td> </tr> <tr> <td> PASSWORD <th scope="col"><input name="password" type="password" value="<?php echo ("$row[password]");?>" /></th> </td> </tr> <tr> <td> <th scope="col"><input name="update" type="submit" value="UPDATE" /></th> </td> </tr> <tr> <td> <th scope="col"><input name="id" type="hidden" value="<?php echo $row[id];?>" /></th> </td> </form> </table> </body> </html> where is the missing link now?
  13. Lightbearer, thanks for your response but please could you be more clearer in your explanation with an example? I mean what exactly am I doing wrong here?
  14. Please could some1 just point out why this php code is not updating the my-sql db? It displays the content of the db but does not update accordingly.. <?php include("cn.php"); //$username=$_GET['username']; if (!@$_SESSION['username']){ header("location:Not_Logged.php"); } if (isset($_POST['update'])) { $update=$_GET['update'];} else {$update=0;} if ($update = "1") { $username=$_GET['username']; $id=$_GET['id']; $username=$_POST['username']; $password=$_POST['password']; $select="select * from users where username='$_SESSION[username]'"; $rs_cat=mysqli_query($con,$select); $row=mysqli_fetch_array($rs_cat); $username=$row['username']; $password=$row['password']; $update="UPDATE users SET username='$username', password='$password' where id='$id'"; $ur=mysqli_query($con,$update) or die (mysql_error()); } ?> <!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>UPDATE</title> </head> <body> <?php //echo $_SESSION['username'];?> <table align="center" > <form name="login" action="" method="post"/> <tr> <td> <th scope="col"><strong>UPDATE</strong></th> </td> </tr> <tr> <td> USERNAME <th scope="col"><input name="username" type="text" value="<?php echo ("$row[username]");?>"/></th> </td> </tr> <tr> <td> PASSWORD <th scope="col"><input name="password" type="password" value="<?php echo ("$row[password]");?>" /></th> </td> </tr> <tr> <td> <th scope="col"><input name="update" type="submit" value="UPDATE" /></th> </td> </tr> <tr> <td> <th scope="col"><input name="id" type="hidden" value="<?php echo $row[id];?>" /></th> </td> </form> </table> </body> </html> Any sharp locator would be appreciated...
  15. It actually, gives access to the session start: <?phpif (!@session_register("login_name")) {header("location:Not_Logged") } ///include ("includes/secure.php");?> Once I comment or ignore the include like above... But if I uncomment it it resumes to deny access to any page at all..."Session_Expired"
  16. Code Gents, I'm having a bit of fuss here Gents, <?php if (!@session_register("login_name")){ header("location:Not_Logged")} include ("includes/secure.php"); ?> Here's secure.php <?php session_start(); if (isset($_GET['sessid'])) { $sessid = addslashes($_GET['sessid']); } else { $sessid = "0"; } include("sql.php"); $sql="SELECT * from sessid WHERE sessid ='$sessid'"; $rsCat_query=mysql_query($sql); $rsCat=mysql_fetch_array($rsCat_query); $timeu_q=$rsCat["timeu"]; $cust_id=$rsCat["userid"]; $permission_q=$rsCat["permission"]; $ip_q=$rsCat["ip"]; $time_n=strtotime("now"); $time=(($time_n)-($timeu_q)); $ip_now = getenv("REMOTE_ADDR"); $sql3="UPDATE sessid SET timeu = '$time_n' where sessid = '$sessid'"; if ($sessid == "") { include("header4.php"); header("location:NoSession_id.php"); die(); } elseif ($rsCat == 0) { include("header5.php"); header("location:NoSession_id.php"); die(); } elseif ($time >= 900) { include("header3.php"); header("location:Session_Expired.php"); die(); } //elseif ($ip_now != $ip_q) { //include("header2.php"); //echo "<br><br><br><center>Your address doesn't match the one you logged in with. <a href=\"login.php\" class=\"toplink\">Click Here</a> to login again.<br><br><br>"; //die(); //} mysql_query($sql3); ?> The problem here is that instead of logging out idle users, it permanently shows"Session_Expired.php" without a chance of logging in the 1st place. Any better ideas?
  17. Wow, way 2 go guz..I'm gonna implement ur corrections and get back 2 u soon...thanks a mil..
  18. Hello Gekko, please could you tell what exactly is making the code output F,F,F,FF, instead of the real grades? Here's my code: <?php $grade = array("A","B","C","D","E","F"); $adno = $_GET['adno']; $grade[0]=A; $grade[1]=B; $grade[2]=C; $grade[3]=D; $grade[4]=E; $grade[5]=F; $adno=$_GET['adno']; $select = mysql_query("select * from acadinfo where adno='$adno'") or die('<p>Error Retrieving<br/>'.'Error: ' .mysql_error() . '</p>'); echo "<table width='548' border='1'> <tr> <th width='26' scope='col'>ADMISSION NO.</th> <th width='26' scope='col'>MATHEMATICS</th> <th width='26' scope='col'>ENGLISH</th> <th width='26' scope='col'>PHYSICS</th> <th width='26' scope='col'>CHEMISTRY</th> <th width='365' scope='col'>BIOLOGY</th> </tr> <tr><th scope='row'>$adno</th>"; $datalist = mysql_fetch_array($select); $num=mysql_num_rows($select); //$datalist = htmlspecialchars($datalist); foreach($datalist as $data){ if (intval($data) >= 80) { echo "<td>$grade[0]</td>"; } else { if (intval($data) >= 70 && intval($data) < 80) { echo "<td>$grade[1]</td>"; } else { if (intval($data) >= 60 && intval($data) < 70) { echo "<td>$grade[2]</td>"; }else { if (intval($data) >= 50 && intval($data) < 60) { echo "<td>$grade[3]</td>"; } else { if (intval($data) >= 40 && intval($data) < 50) { echo "<td>$grade[4]</td>"; } else { if (intval($data) <= 39 && intval($data) < 40) { echo "<td>$grade[5]</td>"; } } } } } } } echo "</tr></table>"; ?> By the way the int problem was solved by implementing your correction...thanks
  19. Fatal error: Call to undefined function int() in C:\xampp\htdocs\details.php on line 135 <?php $grade = array("A","B","C","D","E","F"); $adno = $_GET['adno']; //$grade[0]=A; //$grade[1]=B; //$grade[2]=C; //$grade[3]=D; //$grade[4]=E; //$grade[5]=F; $adno=$_GET['adno']; $select = mysql_query("select * from acadinfo where adno='$adno'") or die('<p>Error Retrieving<br/>'.'Error: ' .mysql_error() . '</p>'); echo "<table width='548' border='1'> <tr> <th width='26' scope='col'>ADMISSION NO.</th> <th width='26' scope='col'>MATHEMATICS</th> <th width='26' scope='col'>ENGLISH</th> <th width='26' scope='col'>PHYSICS</th> <th width='26' scope='col'>CHEMISTRY</th> <th width='365' scope='col'>BIOLOGY</th> </tr> <tr><th scope='row'>$adno</th>"; $datalist = mysql_fetch_array($select); //$datalist = htmlspecialchars($datalist); foreach($datalist as $data){ if (int($data) >= 80) { echo "<td>$grade[0]</td>"; } else { if (int($data) >= 70 && int($data) < 80) { echo "<td>$grade[1]</td>"; } else { if (int($data) >= 60 && int($data) < 70) { echo "<td>$grade[2]</td>"; }else { if (int($data) >= 50 && int($data) < 60) { echo "<td>$grade[3]</td>"; } else { if (int($data) >= 40 && int($data) < 50) { echo "<td>$grade[4]</td>"; } else { if (int($data) <= 39 && int($data) < 40) { echo "<td>$grade[5]</td>"; } } } } } } } echo "</tr></table>"; ?> Please can I stand corrected? I m working on student grades... Line 135-if (int($data) >= 80) {
  20. Excellent try Ted...I think I'm almost there... I implemeted all your corrections as follows: <?php $grade = array("A","B","C","D","E","F"); $adno = $_GET['adno']; //$grade[0]=A; //$grade[1]=B; //$grade[2]=C; //$grade[3]=D; //$grade[4]=E; //$grade[5]=F; $adno=$_GET['adno']; $select = mysql_query("select * from acadinfo where adno='$adno'") or die('<p>Error Retrieving<br/>'.'Error: ' .mysql_error() . '</p>'); echo "<table width='548' border='1'> <tr> <th width='26' scope='col'>ADMISSION NO.</th> <th width='26' scope='col'>MATHEMATICS</th> <th width='26' scope='col'>ENGLISH</th> <th width='26' scope='col'>PHYSICS</th> <th width='26' scope='col'>CHEMISTRY</th> <th width='365' scope='col'>BIOLOGY</th> </tr> <tr><th scope='row'>$adno</th>"; $datalist = mysql_fetch_array($select); $datalist = htmlspecialchars($datalist); foreach($datalist as $data){ if (int($data) >= 80) { echo "<td>$grade[0]</td>"; } else { if (int($data) >= 70 && int($data) < 80) { echo "<td>$grade[1]</td>"; } else { if (int($data) >= 60 && int($data) < 70) { echo "<td>$grade[2]</td>"; }else { if (int($data) >= 50 && int($data) < 60) { echo "<td>$grade[3]</td>"; } else { if (int($data) >= 40 && int($data) < 50) { echo "<td>$grade[4]</td>"; } else { if (int($data) <= 39 && int($data) < 40) { echo "<td>$grade[5]</td>"; } } } } } } } echo "</tr></table>"; ?> In the output, I'm getting this weird error: Warning: htmlspecialchars() expects parameter 1 to be string, array given in C:\xampp\htdocs\Ekeoma\details.php on line 132 Warning: Invalid argument supplied for foreach() in C:\xampp\htdocs\Ekeoma\details.php on line 134 where line 132=$datalist = htmlspecialchars($datalist); and line 134=foreach($datalist as $data){ Please what is wrong now?
  21. Hi Code Gurus, Please my target is to display "A","B",C","D", OR "E" depending on what score exists in the database. But the code below seems to be displaying just A,B,C,D,E respectively without cognisance of the score limit. Please what do I do to make it do this? <?php $grade=array("A","B","C","D","E","F"); $adno=$_GET['adno']; $select=mysql_query("select * from acadinfo where adno='$adno'"); $num=mysql_num_rows($select); $a=1; if(!@select) { die('<p>Error Retrieving<br/>'. 'Error: ' .mysql_error() . '</p>');} while ($datalist=mysql_fetch_array($select)){ $adno=htmlspecialchars($datalist["adno"]); $math=htmlspecialchars($datalist["math"]); $eng=htmlspecialchars($datalist["eng"]); $physics=htmlspecialchars($datalist["physics"]); $chem=htmlspecialchars($datalist["chem"]); $biology=htmlspecialchars($datalist["biology"]); $economics=htmlspecialchars($datalist["economics"]); $yoruba=htmlspecialchars($datalist["yoruba"]); echo ("<table width='548' border='1'>"); echo("<tr> <th width='26' scope='col'>ADMISSION NO.</th> <th width='26' scope='col'>MATHEMATICS</th> <th width='26' scope='col'>ENGLISH</th> <th width='26' scope='col'>PHYSICS</th> <th width='26' scope='col'>CHEMISTRY</th> <th width='365' scope='col'>BIOLOGY</th> </tr>"); echo("<tr> <th scope='row'>$adno</th>"); if ($datalist >=$grade) { echo("<td>$grade[0]</td>");} if ($datalist >=70) { echo("<td>$grade[1]</td>");} if ($datalist >=60) { echo("<td>$grade[2]</td>");} if ($datalist >=50) { echo("<td>$grade[3]</td>");} if ($datalist >=40) { echo("<td>$grade[4]</td>");} if ($datalist <=39) { echo("<td>$grade[5]</td>");} echo("</tr>"); echo("</table>"); $a++; } ?>
  22. Please can some1 tell me how to loop through these values.. and the out put comes appropriately??
  23. Fellow Coders, Please is there a way I could assign a value to an exisitng numeric array type in php? I am trying to output "A" if the math score is >=80, B if >=70 etc this is to alternate for 7 subjects. But so far I'm only geting the results for Math please kindly help... <?php $grade=array("A","B","C","D","E","F"); $adno=$_GET['adno']; $select=mysql_query("select * from acadinfo where adno='$adno'"); $num=mysql_num_rows($select); $a=1; if(!@select) { die('<p>Error Retrieving<br/>'. 'Error: ' .mysql_error() . '</p>');} while ($datalist=mysql_fetch_array($select)){ $adno=htmlspecialchars($datalist["adno"]); $math=htmlspecialchars($datalist["math"]); $eng=htmlspecialchars($datalist["eng"]); $physics=htmlspecialchars($datalist["physics"]); $chem=htmlspecialchars($datalist["chem"]); $biology=htmlspecialchars($datalist["biology"]); $economics=htmlspecialchars($datalist["economics"]); $yoruba=htmlspecialchars($datalist["yoruba"]); echo ("<table width='548' border='1'>"); echo("<tr> <th width='26' scope='col'>ADMISSION NO.</th> <th width='26' scope='col'>MATHEMATICS</th> <th width='26' scope='col'>ENGLISH</th> <th width='26' scope='col'>PHYSICS</th> <th width='26' scope='col'>CHEMISTRY</th> <th width='365' scope='col'>BIOLOGY</th> <th width='365' scope='col'>ECONOMICS</th> <th width='365' scope='col'>YORUBA</th> </tr>"); for each ($grade as ($g)){ echo("<tr> <th scope='row'>$adno</th>"); if ($datalist >=$g) { echo("<td>$grade[0]</td>");} elseif ($datalist >=70) { echo("<td>$grade[1]</td>");} elseif ($datalist >=60) { echo("<td>$grade[2]</td>");} elseif ($datalist >=50) { echo("<td>$grade[3]</td>");} elseif ($datalist >=40) { echo("<td>$grade[4]</td>");} elseif ($datalist <=39) { echo("<td>$grade[5]</td>");} echo("</tr>"); echo("</table>"); $a++; } } ?>
×
×
  • 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.