PHP - Php Mysql Simple Script Not Working.
Hello. i am writing an API for lua... that sends POST requests to a php script. this php script is malfunctioning. below is the code and error.
Similar Tutorialswell I lowered my standards massively. LOL. I decided to google, "php upload and display image", instead of "php gallery". Here is the error I get Warning: copy(/images/sheila.jpg) [function.copy]: failed to open stream: No such file or directory in /hermes/bosweb/web173/b1739/sl.brendansite1/public_html/ealike2/smallgallery/smallgallery.php on line 59 and here is the script that I mostly understand. I thought it was the ..images/, but now I don't know what it is. any help greatly appreciated. thank you. below is the code for the page. Code: [Select] <!-- Start PHP Code For Image Upload --> <?php //define a maxim size for the uploaded images in Kb define ("MAX_SIZE","5060"); //This function reads the extension of the file. It is used to determine if the file is an image by checking the extension. function getExtension($str) { $i = strrpos($str,"."); if (!$i) { return ""; } $l = strlen($str) - $i; $ext = substr($str,$i+1,$l); return $ext; } //This variable is used as a flag. The value is initialized with 0 (meaning no error found) //and it will be changed to 1 if an errro occures. //If the error occures the file will not be uploaded. $errors=0; //checks if the form has been submitted if(isset($_POST['Submit'])) { //reads the name of the file the user submitted for uploading $image=$_FILES['image']['name']; //if it is not empty if ($image) { //get the original name of the file from the clients machine $filename = stripslashes($_FILES['image']['name']); //get the extension of the file in a lower case format $extension = getExtension($filename); $extension = strtolower($extension); //if it is not a known extension, we will suppose it is an error and will not upload the file, //otherwise we will do more tests if (($extension != "jpg") && ($extension != "jpeg") && ($extension != "png") && ($extension != "gif")) { //print error message echo '<h2>Unknown extension!</h2>'; $errors=1; } else { //get the size of the image in bytes //$_FILES['image']['tmp_name'] is the temporary filename of the file //in which the uploaded file was stored on the server $size=filesize($_FILES['image']['tmp_name']); //compare the size with the maxim size we defined and print error if bigger if ($size > MAX_SIZE*1024) { echo '<h2>You have exceeded the file size limit! Please reduce the image size to 100 Kb or less!</h2>'; $errors=1; } //we will give an unique name, for example the time in unix time format $image_name=$filename; //the new name will be containing the full path where will be stored (images folder) $newname="../images/".$image_name; //we verify if the image has been uploaded, and print error instead $copied = copy($_FILES['image']['tmp_name'], $newname); if (!$copied) { echo '<h2>Copy unsuccessful!</h2>'; $errors=1; }}}} //If no errors registred, print the success message if(isset($_POST['Submit']) && !$errors) { echo "<h2>File Uploaded Successfully!</h2><br />"; echo "<img src='http://ealike.com/images/<?php echo $image_name; ?> />"; } ?> <!-- End PHP Code For Image Upload --> <!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>Untitled Document</title> </head> <body> <!-- Start Image Upload Form --> <form name="newad" method="post" enctype="multipart/form-data" action=""> <input type="file" name="image"> <input name="Submit" type="submit" value="Upload image"> </form> <!-- End Image Upload Form --> </body> </html> I have a form on my website which actions login.php. The login.php code is below: <?php include('includes/classes.php.inc'); session_start(); $link = new BaseClass(); $data = $link->query("SELECT * FROM logins"); $pass_accepted = false; if($_REQUEST['username'] && $_REQUEST['password']){ $username = $_REQUEST['username']; $password = $_REQUEST['password']; while($row = mysql_fetch_array($data)){ if(($row['username']==$useranme)&&($row['password']==$password){ echo 'Password correct!'; $_SESSION['loggedin']=true; $pass_accepted = true; } } } else { echo 'You did not enter a username or password!'; } if(!$pass_accepted){ echo 'Your password is incorrect'; } echo '<br>Please <a href="index.php">click here</a> to return to page'; ?> I have checked that my references are all correct however even when I enter the correct password it returns saying the password is incorrect. Any idea on why this could be? I am happy to answer any follow up questions. Regards Not really sure what to ask because I don't know what the problem is. Maybe just need a fresh set of eyes to find out whats wrong. I am trying selecting content from a database table but its not working. I am not getting any errors just a blank screen where the content should be displayed. html Code: [Select] <table> <tbody> <tr> <th>Topic</th> <th>Name</th> <th>Date</th> </tr> <?php include 'server/forum.php'; ?> </tbody> </table> php Code: [Select] <?php require_once('load_data.php'); $con = mysql_connect($db_host, $db_user, $db_pwd); if (!$con) { die('Could not connect to database: ' . mysql_error()); } $dbcon = mysql_select_db($database); if (!$dbcon) { die('Could not select database: ' . mysql_error()); } $sql = "SELECT * FROM $table ORDER BY id"; $result = mysql_query($sql) or die("Error ". mysql_error(). " with query ". $sql); if (!$result) { die("Query to show fields from table failed:".mysql_error()); } $row = mysql_fetch_array($result) while($row) { echo '<tr>'; echo '<td class="forumtd"><b>'; echo '<a href="topic.php?id='.$row['id'].'">'.stripslashes(htmlspecialchars($row['topic'])).'</a>'; echo "</b></td>"; echo '<td class="forumtd"><em>'; echo stripslashes(htmlspecialchars($row['name'])); echo "</em></td>"; echo '<td class="forumtd">'; echo date("l M dS, Y", $row['date']); echo "</td>"; echo "</tr>"; } mysql_close($con); ?> Hey guys! I'm not that good with PHP, and I really need to finish this script. I'm having a hard time finding the problem..it keeps saying Error, query failed and I've also checked the database info, connectivity info and even tried a connection and database selection verification to see if that was working. Is there any other error you guys can find in the script that may be causing the message? Edit: The files I want to be able to upload should be pdf's, txts, docs, etc. Would that be possible with this script? Thanks!! Code: [Select] <form method="post" enctype="multipart/form-data"> <table width="350" border="0" cellpadding="1" cellspacing="1" class="box"> <tr> <td width="246"> <input type="hidden" name="MAX_FILE_SIZE" value="104857600"></td> <td width="80"> </td> </tr> </table> <p>Archivo: <input name="userfile" type="file" id="userfile" /> </p> <p>Nomb <label for="name"></label> <input type="text" name="nombrelista" id="nombrelista" /> </p> <p>Password (para luego borrar si necesario): <input type="text" name="pass" id="pass" /> </p> <p> <input name="upload" type="submit" class="box" id="upload" value=" Upload " /> </p> <?php if(isset($_POST['upload']) && $_FILES['userfile']['size'] > 0) { $fileName = $_FILES['userfile']['name']; $tmpName = $_FILES['userfile']['tmp_name']; $fileSize = $_FILES['userfile']['size']; $fileType = $_FILES['userfile']['type']; $filePass = $_POST['pass']; $nombreLista = $_POST['nombrelista']; $fp = fopen($tmpName, 'r'); $content = fread($fp, filesize($tmpName)); $content = addslashes($content); fclose($fp); $host_db = "localhost"; $user_db = "melkien_rudesa"; $pass_db = "jorlan2407"; $base_db = "melkien_rudesa"; $link = mysql_connect($host_db, $user_db, $pass_db); if (!$link) { die('Could not connect: ' . mysql_error()); mysql_close($link); } mysql_select_db($base_db, $link) or die(mysql_error()); if(!get_magic_quotes_gpc()) { $fileName = addslashes($fileName); } $query = "INSERT INTO 'upload'('nombrelista', 'name', 'pass', 'size', 'type', 'content' ) VALUES ('$nombreLista', $fileName', '$filePass', $fileSize', '$fileType', '$content')"; mysql_query($query) or die('Error, query failed'); echo "<br>File $fileName uploaded<br>"; mysql_close($link); } ?> </form> The code.... very simple: $punc_body = explode(". ", $body); foreach ($punc_body as $k => $v) { $v = ucfirst($v); echo $v . "<br>"; // this is only here for testing purposes. } $body = implode(". ", $punc_body); Why doesn't this work? I threw in the echo $v in which it shows that it is doing everything properly, however when I implode the array everything that was capitalized is reverted back to lower-case. Can someone tell me whats wrong or what I'm missing here please. Hello, I am trying to pick up php again and just exercising my skills. So I have it so that it fills my form with the values of what I want to edit, and when I click the edit button, it doesn't edit any of the information. When I echo out $result, I get a MYSQL query string that has the same values as the table, so its not getting the new values that are edited. <?php @mysql_connect('localhost', 'root', '') or die("Could not connect to Mysql Server. " . mysql_error()); @mysql_select_db('tutorials') or die("Could not connect to Database. " . mysql_error()); if(isset($_GET['edit'])) { $id = $_GET['edit']; $query = "SELECT `username`, `password` FROM `users` WHERE `id` = '$id'"; $result = mysql_query($query); $row = mysql_fetch_array($result); $name = $row['username']; $password = $row['password']; } if(isset($_POST['edit'])) { $id = $_GET['edit']; $query = "UPDATE `users` SET `username` = '$name', `password` = '$password' WHERE `id` = '$id'"; $result = mysql_query($query); echo $query; if(!$result) { echo mysql_error(); }else{ echo 'updated post'; } } ?> <form method="POST" action="" > <input type="text" name="name" value="<?php echo $name; ?>" /> First name <br /> <input type="text" name="password" value="<?php echo $password; ?>" /> Last name <br /> <input type="submit" name="edit" value="edit" /> </form> I believe it has something to do with the values of $name and $password in the form conflicting with the first if isset and the second if isset. Thanks for any help possible hi i am having a problem with a php script. i have 3 files index.php, home.html.php, form.html.php. home.html.php is working fine, if has a form that is submitting fine but when it submits i get a problem. maybe someone can help me out please i would be grateful as i am new. the is nothing wrong with anything else mysql database is running fine and there is no problem with connection. index.php (you can ignore what is commented out) <?php include $_SERVER['DOCUMENT_ROOT'] . '/includes/db.inc.php'; //$_GET['id'] is categoryid if (isset($_GET['id'])) { include $_SERVER['DOCUMENT_ROOT'] . '/includes/db.inc.php'; $id = mysqli_real_escape_string($link, $_GET['id']); $sql = "SELECT businessid FROM businesscategory WHERE categoryid LIKE '$id'"; $result = mysqli_query($link, $sql); if ($result !='') { $businessid = mysqli_fetch_array($result); $sql = "SELECT content FROM business WHERE id LIKE '$businessid'"; $result = mysqli_query($link, $sql); } if ($result !='') { $content = mysqli_fetch_array($result); include 'form.html.php'; exit(); } } /* // The basic SELECT statement $select = 'SELECT content'; $from = ' FROM business'; $where = ' WHERE TRUE'; $id = mysqli_real_escape_string($link, $_GET['id']); if ($category != '') // An owner is selected { $where .= " AND categoryid='$categoryid"; } $categoryid = mysqli_real_escape_string($link, $_GET['category']); if ($categoryid != '') // A category is selected { $from .= ' INNER JOIN businesscategory ON id = business'; $where .= " AND categoryid='$categoryid'"; } $text = mysqli_real_escape_string($link, $_GET['text']); if ($text != '') // Some search text was specified { $where .= " AND content LIKE '%$text%'"; } $result = mysqli_query($link, $select . $from . $where); if (!$result) { $error = 'Error fetching businesses.'; include 'error.html.php'; exit(); } while ($row = mysqli_fetch_array($result)) { $businesses[] = array('id' => $row['id'], 'text' => $row['content']); } include 'form.html.php'; exit(); } */ $result = mysqli_query($link, 'SELECT id, name FROM category ORDER BY name'); if (!$result) { $error = 'Error fetching categories: ' . mysqli_error($link); include 'error.html.php'; exit(); } while ($row = mysqli_fetch_array($result)) { $categories[] = array('id' => $row['id'], 'text' => $row['name']); } include 'home.html.php'; ?> form.html.php <?php include_once $_SERVER['DOCUMENT_ROOT'] . '/includes/helpers.inc.php'; ?> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <meta http-equiv="content-type" content="text/html; charset=windows-1250"> <meta name="generator" content="PSPad editor, www.pspad.com"> <title>Business</title> </head> <body> it works <?php echo $content; ?> </body> </html> Hi, this is my first post:) pretty sure i will be posting here in the future. Anyway i am having trouble with a php script which downloads a file from a mysql database. This php script works for text files and should work for most files from what i understand. When downloading a text file, the whole file is downloaded from the server. When downloading an mp3 file, only 16kb are downloaded and the file does not play. When looking at the data in the database, it displays that the full file is there (correct amount of bytes, so there is nothing wrong with my upload php script). Does anyone have any suggestions as to what I can change to make this work? Code: [Select] <?php if(isset($_GET['id'])) { // if id is set then get the file with the id from database $link=mysql_connect('localhost', 'root', ''); @mysql_select_db('filemgr') or die ("<p>Could not connect to mysql!</p>"); $id = $_GET['id']; $query = "SELECT name, type, size, content " . "FROM upload WHERE id = '$id'"; $result = mysql_query($query) or die('Error, query failed'); list($name, $type, $size, $content) = mysql_fetch_array($result); header("Content-length: $size"); header("Content-type:$type"); header("Content-Disposition: attachment; filename=$name"); echo $content; mysql_close($link); exit; } ?> Hello, im very green to php and I am having trouble creating a simple log in script. Not sure why this is not working, maybe a mysql_query mistake? I am not receiving any errors but nothing gets updated in the members table and my error message to the user displays. any help is appreciated! here is my php: <?php session_start(); $errorMsg = ''; $email = ''; $pass = ''; if (isset($_POST['email'])) { $email = ($_POST['email']); $pass = ($_POST['password']); $email = stripslashes($email); $pass = stripslashes($pass); $email = strip_tags($email); $pass = strip_tags($pass); if ((!$email) || (!$pass)) { $errorMsg = '<font color="#FF0000">Please fill in both fields</font>'; }else { include 'scripts/connect_db.php'; $email = mysql_real_escape_string ($email); $pass = md5($pass); $sql = mysql_query("SELECT * FROM members WHERE email='$email' AND password='$pass'"); $log_check = mysql_num_rows($sql); if ($log_check > 0) { while($row = mysql_fetch_array($sql)) { $id = $row["id"]; $_SESSION['id']; $email = $row["email"]; $_SESSION['email']; $username = $row["username"]; $_session['username']; mysql_query("UPDATE members SET last_logged=now() WHERE id='$id' LIMIT 1"); }//Close while loop echo "You are logged in"; exit(); } else { $errorMsg = '<font color="#FF0000">Incorrect login data, please try again</font>'; } } } ?> and the form: <?php echo $errorMsg; ?> <form action="log_in.php" method="post"> Email:<br /> <input name="email" type="text" /><br /><br /> Password:<br /> <input name="password" type="password" /><br /><br /> <input name="myBtn" type="submit" value="Log In" /> </form> Hi can someone pls help, im tryin a tutorial but keep getting errors, this is the first one i get after registering. You Are Registered And Can Now Login Warning: Cannot modify header information - headers already sent by (output started at /home/aretheyh/public_html/nealeweb.com/regcheck.php:43) in /home/aretheyh/public_html/nealeweb.com/regcheck.php on line 46 When I echo the POST, it echoes the correct value. The MySQL portion seems to just ignore it all together. I've tried changing the dropdown option to just a text field, same thing occurred. I have text fields right above this particular one that update just fine with the SAME exactly scripting. if POST, update query, done. Works. This one for some reason will not. MySQL portion: if ($_POST['bUpdate']){ mysql_query("UPDATE `Patients` SET `b` = '$_POST[bUpdate]' WHERE `id` = '".$_GET['id']."'"); } echo $_POST['bUpdate']; Form Portion: Code: [Select] <tr onmouseover="color(this, '#baecff');" onmouseout="uncolor(this);"> <td width="310" colspan="2" align="center"><span class="fontoptions">Postcard Status </span><br /> <? if ($data['b'] == 1){ echo '<select name="bUpdate"><option value="1" selected>Yes</option><option value="0">No</option></select>'; } else { echo '<select name="bUpdate"><option value="1">Yes</option><option value="0" selected>No</option></select>'; } ?> </td> </tr> <html> <head></head> <body> My favourite bands a <ul> <?php // define arrays $morebands = array('Desturbed', 'Anthrax'); $artists = array('Metallica', 'Evanescence', 'Linkin Park', 'Guns n Roses', "$morebands"); // loop over it // print array elements foreach ($artists as $a) { if ($a != 'Array'){ echo '<li>'.$a; } Else { foreach ("${$a}" as $b){ echo '<li>'.$b; } } } ?> </ul> </body> </html> I can not figure out why this will not work:( I would like the foreach to run through the array as normal, but if it encounters a nested array, loop it as well. I know this likely is not the right, or best way to do this, but I am just learning PHP through a tutorial and I learn best by doing... So I take the lessons, make them more complicated, then figure out how to make it happen (like so). right now I am working on http://devzone.zend.com/node/view/id/635 anyhow thanks for any help! Hi, I have a php form that I use to try to get matching data from the database that I put into the form. So if I enter date of birth 9-4-80 and first name Dave and lastname Smith. When I submit it the code should pull all of the matching terms out of the database and display. Now I get the following error when I submit the form. Query: Resource id #2 Failed with error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'Resource id #2' at line 1 any help Greatly appreciated. thank you! here is the code Code: [Select] <?php ini_set ("display_errors", "1"); error_reporting(E_ALL); $host = " "; $database = " "; $username = " "; $password = " "; $tbl_name = "users"; $conn = mysql_connect($host, $username, $password) or die("Could not connect: " . mysql_error()); if($conn) { mysql_select_db($database); echo "connected to database!!"; } else { echo "failed to select database"; } //include('bouncer.php'); //$currentUser = $_SESSION['myusername']; if(isset($_POST['submit'])) { $first = mysql_real_escape_string( $_POST['first']); $last = mysql_real_escape_string( $_POST['last']); $dob = mysql_real_escape_string( $_POST['dob']); //THE SEARCH FUNCTION $sql = mysql_query ( "SELECT * FROM users WHERE firstname LIKE '%$first%' OR lastname LIKE '%$last%' OR dob LIKE '%$dob%' ") or die(mysql_error()); $result = mysql_query($sql) or die( "<br>Query: $sql<br>Failed with error: " . mysql_error() ); if (!$result) { echo "Could not successfully run query ($sql) from DB: " . mysql_error(); exit; } if (mysql_num_rows($result) == 0) { echo "No rows found, nothing to print so am exiting"; exit; } while ($row = mysql_fetch_assoc($result)) { echo $row["firstname"]; echo $row["lastname"]; echo $row["dob"]; } }//if(isset($_POST['submit'])) ?> <html> <body> <form action="login_success8.php" method="post"> <p> <input type="text" name="first" size="20" /> First name<br /> <input type="text" name="last" size="20" /> Last name<br /> <input name="dob" type="text" size="20" id="dob" /> Date of Birth<br /> <input type="submit" name="submit" value="Search" /> <input type="reset" value="Reset fields" /> </p> </form> </body> </html> The following mysql query is not returning rows like I expect it to. '$update_field' is a variable, matching an actual field name in table 'users'. 'user_task[1]' is an integer value. What am I missing here? Code: [Select] $query_update_user = "UPDATE users SET ".$update_field." = 'Y' WHERE user_no = '".$user_task[1]."'"; I'm trying my first PHP code :
<!DOCTYPE html>
<?php
</body>
Result : nothing, just a blank screen ... Am I missing something ?
Regards, Martin I am running PHP Version 5.3.1. The following Code does not write to my database. It is code that I took from the PHP Pocket Reference from O'Reilly but it does not work... What's wrong with this code? Thanks in advance. Guy <?php if($vote && !$already_voted) SetCookie('already_voted',1); ?> <html> <head> <title>Name the Baby</title> </head> <h3>Name the Baby</h3> <form action="baby.php" method="POST"> <p>Suggestion: <input type="text" name="new_name"/> </p> <input type="submit" value="Submit idea and/or vote"/> <?php mysql_pconnect("localhost","root","password"); $db = "babynames"; $table = "baby_names"; if($new_name) { if(!mysql_db_query($db, "insert into $table values ('$new_name',0)")) { echo mysql_errno().': '. mysql_error()."<br />\n"; } } if($vote && $already_voted) { echo '<p><b>Hey, you voted already '; echo "Vote ignored.</b></p>\n"; } else if($vote) { if(!mysql_db_query($db, "update $table set votes=votes+1 where name='$vote'")) { echo mysql_errno().': '. mysql_error()."<br />\n"; } } $result=mysql_db_query($db,"select sum(votes) as sum from $table"); if($result) { $sum = (int) mysql_result($result,0,"sum"); mysql_free_result($result); } $result=mysql_db_query($db, "select * from $table order by votes DESC"); echo <<<EOD <table border="0"><tr><th>Vote</th> <th>Idea</th><th colspan="2">Votes</th></tr> EOD; while($row=mysql_fetch_row($result)) { echo <<<FOO <tr><td align="center"> <input type="radio" name="vote" value="$row[0]"></td> <td>$row[0]</td> <td align="right">$row[1]</td> <td> FOO; if ($sum && (int)$row[1]) { $per = (int)(100 * $row[1]/$sum); echo '<img src="bline.gif" height=12 '; echo "width=$per> $per %</td>"; } echo "</tr>\n"; } echo "</table>\n"; mysql_free_result($result); ?> <input type="submit" value="Submit idea and/or vote" /> <input type="reset" /> </form> </body></html> Hi, I am new to php, and I have run into a problem. The tutorial I am using has provided me with this exact code. But it does not work for me. Its very simple. Here is the HTML page: Code: [Select] <body> <FORM ACTION="welcome.php" METHOD=POST> First Name: <INPUT TYPE=TEXT NAME="name"> <INPUT TYPE=SUBMIT VALUE="GO"> </FORM> </body> And here is the php page: <body> <?php echo( "Welcome to our Web site, $name!" ); ?> </body> You can see the problem live at <http://www.freewaycreative.com/test> (dont mind the digits below) The name just does not show. Anyone know why? Thanks! Hey all,
This code was given to me by my client who swears it works, yet I can't seem to get it to function. <?php $now = time(); // or your date as well $your_date = strtotime("2016-06-01"); $datediff = $now - $your_date; $referrals = number_format(162250 + (floor($datediff/(60*60*24)) * 527) + (87920 + (floor($datediff/(60*60*24)) * 45))); ?> //javascript: <script> //vars from template var referrals = "<?php echo $referrals;?>"; var currentdate = new Date(); jQuery("document").ready(function() { jQuery ("#sp-menu > div > nav > ul > li:nth-child(1) > a").html("Home"); jQuery(".referrals").html(referrals); jQuery(".current_date").html((currentdate.getMonth()+1) + "/" + currentdate.getDate() + "/" + currentdate.getFullYear()); jQuery(window).on("scroll", function() { var scrollPos = jQuery(window).scrollTop(); if (scrollPos <= 0) { jQuery(".counter").fadeIn(); jQuery(".sec-nav").fadeIn(); } else { jQuery(".counter").fadeOut(); jQuery(".sec-nav").fadeOut(); } }); }); </script>
I've got to be missing something pretty basic here.. considering the query is pretty basic. I'm trying to figure out how to pull a query as an array so I can compare it against another array (array_diff) I'm doing a mysql_fetch_array, and I'm getting an error ( mysql_fetch_array(): supplied argument is not a valid MySQL result resource): Quote $checker = "SELECT ID FROM edible_uses"; $result2 = mysql_fetch_array($checker) or die(mysql_error()); //echoing to see if I'm getting what I need. echo $row['ID']; I've done a mysql_query and I get results. The table name and all that is correct. I'm stumped. This seems like a pretty simple query? I tried mysql_fetch_assoc as well. Same result? I tried it with an extra set of parenthesis around it. nope. |