PHP - Simple Php Form Not Working
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> Similar TutorialsHi, 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! Hi, I am learning PHP now, so pardon my silly question which I am not able to resolve from a week. I have created a simple web form where in I display the values entered by a user. <form action ="reply.php" id="myForm" method="post" > Name: <input type="text" name="name" size="25" maxlength="50" /> <br> </br> Description: <textarea name="editor1"> </textarea> <input type="submit" value="Submit" /> </form> and reply.php contains: <?php echo "In reply page"; foreach($_POST as $field => $value) { echo "$field = $value"; } ?> When I click on the submit button, I just get a blank page without any values from the form. Can anyone please let me know what am I missing? Set up: I am using Netbeans with PHP bundle added on to it. When i run only a simple php proj it displays that page in localhost/nameofproj, but when I run a php file along with a jsp file, it runs in localhost:8080/nameofproj. Is this the reason(localhost:8080 instead of just localhost ) for showing a blank page, not even a simple echo stmt, when i click on submit? I even re installed netbeans, still no luck. Thanks in advance. 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> 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. 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 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); ?> I am trying to use JSONReader (along with PHP & XPATH) to parse a very large JSON file, then display search results. A stream parser (such as JSONREader) is recommended over JSON_decode when parsing large files. This simple code below is not displaying any results (in the echo statements). Any advice is greatly appreciated. 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 well 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> Hi, I am performing some whois query using phpwois. http://www.phpwhois.org/ So after doing its object output i.e. Code: [Select] $whois = new Whois(); $result = $whois->Lookup($domain); $winfo = ''; $utils = new utils; $winfo = $utils->showHTML($result); , I am getting following data for for phpfreaks.com> Code: [Select] regrinfo->Array domain->Array name->phpfreaks.com nserver->Array ns1.serverpowered.net->204.13.168.4 ns2.serverpowered.net->216.12.222.4 ns3.serverpowered.net->66.97.171.74 ns4.serverpowered.net->66.97.171.254 status->Locked changed->2011-08-29 created->2001-10-11 expires->2016-10-11 registered->yes owner->Array name->Web Freaks address->Array 0->Contact Administrative () admin->Array email->domains@thewebfreaks.com name->Contact Administrative phone->4072751117 fax->+1.4072757706 address->Array 0->Web Freaks 4->3700 Commerce Blvd 5->Suite 154 6->Kissimmee, FL 34741 7->US tech->Array email->domains@thewebfreaks.com name->Contact Administrative phone->4072751117 fax->+1.4072757706 address->Array 0->Web Freaks 4->3700 Commerce Blvd 5->Suite 154 6->Kissimmee, FL 34741 7->US regyinfo->Array registrar->ENOM, INC. referrer->http://www.enom.com servers->Array 0->Array server->com.whois-servers.net args->domain =phpfreaks.com port->43 1->Array server->whois.enom.com args->phpfreaks.com port->43 type->domain Now I want to show Domain registrar (Enom, INC.) So I did following Code: [Select] echo $winfo['regyinfo']; Now above code shows following >> Code: [Select] registrar->ENOM, INC. referrer->http://www.enom.com servers->Array 0->Array server->com.whois-servers.net args->domain =phpfreaks.com port->43 1->Array server->whois.enom.com args->phpfreaks.com port->43 type->domain To obtain I mean to show ENOM, INC, I used following > Code: [Select] echo $winfo['regyinfo']['registrar']; But it gave error, so I used following >> Code: [Select] $temp = $winfo['regyinfo']; echo $temp['registrar']; But it give output as follows : < I dont know what wrong I am doing ? If it is showing regyinfo, then it should also show registrar. Thanks 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. Hi, I'm trying to make a simple slideshow with forward and back buttons that change the image inside a div in php. When I press the "further" button, it jumps from index[0] to index[1] and never shows the first image. Then when I click more it doesn't go forward. When I click back, it goes back to a black screen div. Any help getting this to work is GREATLY appreciated because I've been trying for 2 days with tutorials and can't get it. Thanks. Derek Here are the php parts that are relevant, my page was too large and confusing to include. first, the $background array where I store my images. Code: [Select] $background = array ( "<img src='sundragon_environments/ocean/ocean1_FRAME.jpg'/>", "<img src='sundragon_environments/ocean/ocean1_FRAME2.jpg'/>" ); then the code to move the images forward and backwards if the buttons are pressed. Code: [Select] if(!empty($_POST['further'])) { $currentBackground=next($background); } elseif(!empty($_POST['back'])) { $currentBackground=prev($background); } and now to echo out the images inside the div. Code: [Select] <div id="background"><?php echo $currentBackground;?></div> 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. Hi, Im trying to pull an email from an url, and then echo the email as value into a email form-- under the "from" heading. The echo is not working i get blanks. here is the code: <?php $thisurl='$_SERVER['REQUEST_URI']'; $thepart = explode('/', $thisurl); $themail='$thepart[2]'; ?> <form method="post" action="sendit.php"> To: <br><input type="text" name="to" size="44" value="<?php for($i=1; $i<=$lines; $i=$i+1) { $names[$i] = str_replace("<br>", "", $names[$i]); $names[$i] = str_replace("\n", "", $names[$i]); echo $names[$i].';'; } ?>"><br> From: <br><input type="text" name="email" size="44" value="<?php echo '$themail'; ?>" readonly><br> Subject: <br><input type="text" name="subject" size="44" /><br><br> <?php session_start(); if(!isset($_SESSION['User'] )) header('Location : error.php'); ?> im not being redirected even when the $_SESSION['User'] is not set neither does it display any error message other than a white blank space. Please help me som1 as how I can make this to work or suggest any other altenatives so as to get it redirected as i dont want anonymous users to access some contents unles he logs in as members. Thanx Hello, I am trying to make a page with a text box in where the user enters their post code and hits 'Submit' then it loads a new page with an embeded google maps map of that area. with the following code: <iframe width="425" height="350" frameborder="0" scrolling="no" marginheight="0" marginwidth="0" src="http://www.google.com/maps?f=q&source=s_q&hl=en&geocode=&q=gym+**POSTCODE**&sll=37.0625,-95.677068&sspn=30.461748,86.572266&ie=UTF8&hq=gym&hnear=**POSTCODE**,+United+Kingdom&output=embed"></iframe><br /><small><a href="http://www.google.com/maps?f=q&source=embed&hl=en&geocode=&q=gym+**POSTCODE**&sll=37.0625,-95.677068&sspn=30.461748,86.572266&ie=UTF8&hq=gym&hnear=**POSTCODE**,+United+Kingdom" style="color:#0000FF;text-align:left">View Larger Map</a> I have typed **POSTCODE** where the user input needs to go.. Any ideas how this could be done? Thanks On my website i have a form for customers to get in touch with me. This forum points to a php script to email me and tell them it has been submitted(via html). Here is the forum and the php script. Form from html file Code: [Select] <form id="supportform" name="Support Form" method="post" action="php/formemail.php"> <table width="100%" border="0"> <tr> <td width="22%">Name:</td> <td width="78%"><input type="text" name="name" id="name" /></td> </tr> <tr> <td>Email:</td> <td><input type="text" name="email" id="email" /></td> </tr> <tr> <td>Company:</td> <td><input type="text" name="company" id="company" /></td> </tr> <tr> <td>Phone:</td> <td><input type="text" name="phone" id="phone" /></td> </tr> <tr> <td>Operating System:</td> <td><input type="text" name="os" id="os" /></td> </tr> <tr> <td>What Do You Need Help With?</td> <td><input type="text" name="problem" id="problem" /></td> </tr> <tr> <td>Additional Clarification:</td> <td><textarea name="additional" id="additional" cols="45" rows="3"></textarea></td> </tr> <tr> <td>Contact Preference:</td> <td><select name="preference" id="preference"> <option value="null">Please Select</option> <option value="phone">Phone</option> <option value="email">Email</option> </select></td> </tr> <tr> <td>How Did You Hear Of Us?</td> <td><select name="advert" id="advert"> <option value="null">Please Select</option> <option value="radio">Radio</option> <option value="newspaper">Newspaper</option> <option value="other">Other</option> </select></td> </tr> <tr> <td><input type="submit" name="Submit" id="submit" value="Submit" style="width:100px;height:30px" /> <input type="reset" name="reset" id="reset" value="Reset" style="width:62px;height:30px;" /></td> <td> </td> </tr> </table> </form> Here is php script Code: [Select] <?PHP /*Subject an email variables */ $emailSubject = 'PHP Email Script'; $webMaster = 'me@mysite;otherperson@gmail.com'; /* Gathering Data Variables */ $nameField = $_POST['name']; $emailField = $_POST['email']; $companyField = $_POST['company']; $phoneField = $_POST['phone']; $osField = $_POST['os']; $problemField = $_POST['problem']; $additionalField = $_POST['additional']; $preferenceField = $_POST['preference']; $advertField = $_POST['advert']; $body = <<<EOD <br><hr><br> Name: $nameField <br> Email: $emailField <br> Company: $companyField <br> Phone: $phoneField <br> OS: $osField <br> Problem: $problemField <br> Additional Info: $additionalField <br> Preference: $preferenceField <br> Advertising: $advertField <br> <br> Have a nice day! EOD; $headers = "From: $emailField\r\n"; $headers .= "Content-type: text/html\r\n"; $success = mail($webMaster, $emailSubject, $body, $headers); /* Results rendered as HTML */ $theResults = <<<EOD <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <title>Title</title> <link rel="shortcut icon" href="images/favicon.ico" type="image/x-icon" /> <link href="css.css" rel="stylesheet" type="text/css"> <style type="text/css"> body { background-color: #FFF; } </style> </head> <body> <div class="header"><a href="#"><img src="" alt="" name="greenhead" width="100%" height="17" id="greenhead" style="background: #B1FB17; display:block;" /></a> <!-- end .header --></div> <div class="content"> <h1> </h1> <h1><img src="/images/logo2.jpg" width="194" height="152" align="middle"> Tech Suppport MT</h1> <h1 align="center">Success!</h1> <h2 align="center">Your information has been submitted to us.</h2> <p align="center"> </p> <p align="center"><a href="/index.html">index - Home</a></p> <p> </p> <p> </p> <p> </p> </div> <div class="footer"> <h4 align="center">footer</h4> <!-- end .footer --></div> <!-- end .container --> </body> </html> EOD; echo "$theResults"; ?> Everything works as it should except both people are getting two emails. One email with everything correct and the correct results. And another with all null values from an unknown sender. I should not be receiving one from an unknown sender with empty values. Thanks for any help. |