Search the Community
Showing results for tags 'php mysqli'.
-
Hello, I am new to php and stuck on this msqli function. I would like to echo out all the results divided by commas and apostrophe. Example: "23232","324231","342533" With the last one not having a comma. Here is what I came up with and not sure why I am getting errors. I think this is the issue but not sure: $list.= $result->'"'.video_code.'",'; Thanks. $sql = 'SELECT video_code FROM yt_videos WHERE yt_video_item_id="'.$vidid.'" ORDER BY RAND() LIMIT 10'; $query = mysqli_query($db_conx, $sql); $list=''; while ($result = $query ->fetch_object()) { $list.= $result->'"'.video_code.'",'; } echo $list=substr($list,0,-1);
-
I'm testing this form before adding validation and I can't figure out why the file name comes through as 0 in the banner directory. And it says text/x-generic instead of image/x-generic in the type column, if I highlight the file and click view the image shows. everything in the database is correct and the form is set to enctype=multipart/form-data. Need a set of fresh eyes to look at it, Thanks! <?php $form_complete = FALSE; $imageDirectory = "banners/"; $records = array(); if (isset($_POST['url'], $_FILES ['images'] ['name'], $_POST['expires'])) { $images = $_FILES ['images'] ['name']; $type = $_FILES ['images'] ['type']; $size = $_FILES ['images'] ['size']; $temp = $_FILES ['images'] ['temp_name']; $error = $_FILES ['images'] ['error']; $url = 'url'; $url = preg_match("/\b(??:https?|ftp):\/\/|www\.)[-a-z0-9+&@#\/%?=~_|!:,.;]*[-a-z0-9+&@#\/%=~_|]/i", $url); $expires = date('M d Y', strtotime('+ $expires days')); $expires = 'expires'; move_uploaded_file($temp,$imageDirectory .$images); //the path to the image file $imagePath = $imageDirectory.$images; $expires = $_POST ['expires']; $url = $_POST['url']; $images = 'banners/'.$_FILES['images']['name']; echo "<p><br /><a href='$url'><img src='$imagePath'/></a><br /> Expires: $expires </p>"; $insert = $db_conn->prepare("INSERT INTO adverts (images,url,expires) VALUES (?,?,?)"); $insert->bind_param('sss', $images, $url, $expires); $insert->execute(); } $form_complete = TRUE; ?>
-
I am working through a php CMS tutorial and I can't get my data to display. It's like my variable ($pg) is invisible. If I uncomment the first include in the content div, I get an error that content/.php can't be found (notice the missing file name). I am passing the values of home, blog, contact and gallery through the URL. I have home.php, blog.php, contact.php and gallery.php in a folder called content. Each of the files contains lorem ipsum text and that's all. I have added an error check and I get no errors...just an empty div. My code is as follows: <?php // Setup document: include ('config/setup.php'); //--------------------------------------------------- //Check if page variable is set if ($_GET['page']='') { $pg = 'home'; }else{ $pg = $_GET['page']; } //--------------------------------------------------- ?> <!doctype html> <html> <head> <meta charset="utf-8"> <title>Dynamic Sites LLC</title> <link rel="stylesheet" type="text/css" href="css/styles.css"> </head> <body> <div class="header temp_block"> <?php include ('template/header.php');?> </div> <div class="nav_main temp_block"> <?php include ('template/nav_main.php');?> </div> <div class="content temp_block"> <?php //include ('content/' . $pg . '.php'); // database connection, query $q = "SELECT * FROM pages WHERE name = '$pg' AND status = 1 LIMIT 1"; $r = mysqli_query($dbc, $q); $page = mysqli_fetch_assoc($r); echo '<h1>'.$page['title'].'</h1>'; echo '<div class="content_body">'.$page['body'].'</div>'; ?> </div> <div class="footer temp_block"> <?php include ('template/footer.php');?> </div> </body> </html> My nav_main.php is as follows: <?php ## Main Navigation ?> <a href="index.php?page=home">Home</a> - <a href="index.php?page=gallery">Gallery</a> - <a href="index.php?page=blog">Blog</a> - <a href="index.php?page=contact">Contact Us</a> Any help would be appreciated. Aaron
-
hi guys, i've been having some issues with authenticating a person who logs into my website. I'm using crypt to hash the password from when they register with no salt defined. the code i've used on my login page is this if( $page_mode == 'Login' ) { require "globe.php"; //simple post from below $username = htmlentities(trim($_POST['username'])); $username = mysqli_real_escape_string($mysqli, $username); $password = trim($_POST['password']); $query = mysqli_query($mysqli, "SELECT * FROM Persons WHERE Username = '$username'"); $row = mysqli_fetch_assoc($query); $numrows = mysqli_num_rows($query); $dbuser = $row['Username']; $dbpass = $row['Password']; $hashed_password = crypt($password, $dbpass); if( ($username == '') || ($password == '') ) { $error_string .= '<font color=red>You have left either the username or password field blank!</font>'; } else if ($numrows == 1) { if ($dbuser == $username) { if ($hashed_password == $password) { $error_string .= '<font color=red>Details checked out</font>'; } else { $error_string .= '<font color=red>No username can be found! (1)</font>'; } } } else { $error_string .= '<font color=red>No username can be found! (2)</font>'; } } everything is fine until it gets to the if statement where it checks the hashed password agaist the user inputted password ($password). it always seems to fail. I've been at this for days now and its really starting to annoy me. Would be so grateful if someone could suggest a solution.