Jump to content

JackW

Members
  • Posts

    12
  • Joined

  • Last visited

Contact Methods

  • Website URL
    http://www.panhandleyardsale.com/

Profile Information

  • Gender
    Not Telling

JackW's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. You got me. The code is not for questions it is messages then the second table will be for comments. For each message there may be numerous (comments) replies. Tables below. table messages message_ID int 6 school var 10 name var 60 post_day var 50 reply_day var 50 message Med_Txt subject var 240 table replies reply_ID int 6 name var 60 message_ID var 20 reply_day var 50 message Med_Txt
  2. Duh! I have looked there and cannot understand what I am reading.
  3. I have a MySQL data base with two tables. (questions then answers?) I need to query the second table to find related results from a query on the first table. Here is what I have, How do I get it to combine the two queries? <?php $db = @mysqli_connect('localhost', 'unsabook', 'Password', 'unsabook'); if (!$db) { echo "Error: " . mysqli_connect_error(); exit(); } $rs_message = $db->query ("SELECT * FROM `messages` ORDER BY `message_ID` ASC LIMIT 0,200"); while ( $message_array = $rs_message->fetch_assoc() ) { echo '<div class="left10">'; echo $message_array['message_ID']; echo ' &nbsp; '; echo $message_array['name']; echo ' &nbsp; '; echo $message_array['subject']; echo ' <br>'; echo $message_array['message']; $message_ID = $message_array['message_ID']; echo '</div>'; } // 2nd table is below $rs_replies = $db->query ("SELECT * FROM `replies` WHERE `message_ID` = '".$message_ID."' ORDER BY `reply_ID` DESC"); while($reply_array = mysqli_fetch_assoc($rs_replies)) { echo '<div class="left10">'; echo $reply_array['reply_ID']; echo ' &nbsp; '; echo $reply_array['name']; echo ' &nbsp; '; echo $reply_array['message_ID']; echo ' &nbsp; '; echo $reply_array['reply_day']; echo ' &nbsp; '; echo $reply_array['message']; echo '</div>'; } $db->close(); ?>
  4. I spent several days (weeks) trying to do something similar.  Finally got it to working.  It renames and uploads a picture to the server, then adds information including picture name to my data base.  It may be of some help to you.  The code is in my last post at: http://www.phpfreaks.com/forums/index.php/topic,117897.0.html
  5. Finally it works.  Here is the code in 3 pages that works for me. Hope it well be of help to someone. [color=teal]First page is html[/color] <body> <form enctype="multipart/form-data" name="picture" onSubmit="return formVerify(this)" action="add5.4.php" method="post"> <!-- MAX_FILE_SIZE must precede the file input field -->     <input type="hidden" name="MAX_FILE_SIZE" value="82000" />     <!-- Name of input element determines name in $_FILES array -->     Send this file: <input name="file" type="file" /> <br /><br />     <input type="submit" value="Send File" /> </form> </body> [color=teal]Next page is php[/color] <body> <?php if (($_FILES["file"]["type"] == "image/gif") || ($_FILES["file"]["type"] == "image/jpeg") || ($_FILES["file"]["type"] == "image/pjpeg") || ($_FILES["file"]["type"] == "image/jpg")) { echo 'That is valid picture file.<br>'; } else     {     echo 'There is an error in your file!  Your file must be a jpg or gif format and no larger that 80k'; exit;     }  //This function separates the extension from the rest of the file name and returns it function findexts ($filename) { $filename = strtolower($filename) ; $exts = split("[/\\.]", $filename) ; $n = count($exts)-1; $exts = $exts[$n]; return $exts; } //This applies the function to our file $ext = findexts ($_FILES['file']['name']) ; //This line assigns a time stapm to a variable. You could also use a random number here if you prefer. $ran = time() ; //This takes the timestamp (or random number) you generated and adds a . on the end, so it is ready of the file extension to be appended. $ran2 = $ran."."; //This assigns the subdirectory you want to save into... make sure it exists! //find this path using phpinfo.php $target = "/home/content/y/o/u/yoursite/html/uploads/"; //This combines the directory, the random file name, and the extension $target = $target . $ran2.$ext; $image = $ran2.$ext; //Writes the photo to the server if(move_uploaded_file($_FILES['file']['tmp_name'], $target)) { echo "Your picture file has been renamed and uploaded as ".$ran2.$ext; echo '<br>Please complete the form below and click submit to post your listing.'; echo '<form  action="putin.php" method="POST"> Name: <input type="text" name="name"><br> E-mail: <input type="text" name = "email"><br> Phone: <input type="text" name = "phone"><br> <input type="hidden" name="picture"value="'; echo$image; echo '">'; echo '<input type="submit" value="Submit"> </form>'; } else { echo 'Sorry, there was a problem uploading your file.'; } ?> </body> [color=teal]Final page is php and puts it together.[/color] <body> <?php $username="your_data"; $password="your_password"; $database="your_data_base"; //This gets all the other information from the form $name=$_POST['name']; $email=$_POST['email']; $phone=$_POST['phone']; $pic=$_POST['picture']; // Connects to your Database @$db = mysql_pconnect('your_data','your_password','your_data_base'); mysql_select_db('yourtable') or die( "Unable to select database"); //Writes the information to the database { mysql_query("INSERT INTO `yourtable` VALUES (NULL,'$name', '$email', '$phone', '$pic')"); } $results=mysql_query($query); { echo 'Thank you for your Listing'; } mysql_close($db); ?> </body>
  6. :( I tried putting the } in several places and get a code telling me Parse error: parse error, unexpected '}' in ---add6.php on line 36. Where should I put it? I am giving up for tonight.  Maybe tomorrow it will make sense to me. Thank you for your help.
  7. I need more help.  This is what I have now.  If I leave the else statment out it tells me I have an unexpetected T function.  With it in I get an error of unexpected else.  I probably don't understand the die function. I am really getting frustrated. <?php if (($_FILES["file"]["type"] == "image/gif") || ($_FILES["file"]["type"] == "image/jpeg") || ($_FILES["file"]["type"] == "image/pjpeg") || ($_FILES["file"]["type"] == "image/jpg") && ($_FILES["file"]["size"] < 20000))   { if ($_FILES["file"]["error"] > 0)die ( "Sorry, there was a problem with your file. It may not be a picture file or is larger than 4k.")     else  [color=red]//(if I leave this else out I get an error of unexpected T_function with it in I get an error of unexpected else)[/color] //This function separates the extension from the rest of the file name and returns it function findexts ($filename) { $filename = strtolower($filename) ; $exts = split("[/\\.]", $filename) ; $n = count($exts)-1; $exts = $exts[$n]; return $exts; } //This applies the function to our file $ext = findexts ($_FILES['file']['name']) ; //This line assigns a random number to a variable. You could also use a timestamp here if you prefer. $ran = rand () ; //This takes the random number (or timestamp) you generated and adds a . on the end, so it is ready of the file extension to be appended. $ran2 = $ran."."; //This assigns the subdirectory you want to save into... make sure it exists! $target = "/My_site_info/uploads/"; //This combines the directory, the random file name, and the extension $target = $target . $ran2.$ext; $image = $ran2.$ext; //Writes the photo to the server } if(move_uploaded_file($_FILES['file']['tmp_name'], $target)) { echo "The file has been uploaded as ".$ran2.$ext; echo '<form  action="putin.php" method="POST"> Name: <input type="text" name="name"><br> E-mail: <input type="text" name = "email"><br> Phone: <input type="text" name = "phone"><br> <input type="hidden" name="picture"value="'; echo$image; echo '">' ; echo'<input type="submit" value="Submit"> </form>'; } else { echo "Sorry, there was a problem uploading your file."; } ?>
  8. Thank You.  I will give that a try.
  9. I have been trying for days to write a code that will upload a picture to my server after renaming it, verifying that it is a picture and not oversized, then add a link to my data base.  What I have put together works fine when all requirements are met, however if I substitute a file that is not a picture (example .txt)  page 2 either locks up as a blank page or uploads the incorrect file to the site. No error message of any kind. What am I doing wrong? Your help will be greatly appreciated.  Here is my code: Page 1 <html> <body> <form action="add6.php" method="post" enctype="multipart/form-data"> <label for="file">Filename:</label> <input type="file" name="file" id="file" /> <br /> <input type="submit" name="submit" value="Upload Picture" /> </form> </body> </html> Page 2 <html> <body> <?php if (($_FILES["file"]["type"] == "image/gif") || ($_FILES["file"]["type"] == "image/jpeg") || ($_FILES["file"]["type"] == "image/pjpeg") || ($_FILES["file"]["type"] == "image/jpg") && ($_FILES["file"]["size"] < 20000))   {   if ($_FILES["file"]["error"] > 0)     {     echo "Return Code: " . $_FILES["file"]["error"] . "<br />";     }       else   { //This function separates the extension from the rest of the file name and returns it function findexts ($filename) { $filename = strtolower($filename) ; $exts = split("[/\\.]", $filename) ; $n = count($exts)-1; $exts = $exts[$n]; return $exts; } //This applies the function to our file $ext = findexts ($_FILES['file']['name']) ; //This line assigns a random number to a variable. You could also use a timestamp here if you prefer. $ran = rand () ; //This takes the random number (or timestamp) you generated and adds a . on the end, so it is ready of the file extension to be appended. $ran2 = $ran."."; //This assigns the subdirectory you want to save into... make sure it exists! $target = "/My_site_info/uploads/"; //This combines the directory, the random file name, and the extension $target = $target . $ran2.$ext; $image = $ran2.$ext; //Writes the photo to the server if(move_uploaded_file($_FILES['file']['tmp_name'], $target)) { echo "The file has been uploaded as ".$ran2.$ext; echo '<form  action="putin.php" method="POST"> Name: <input type="text" name="name"><br> E-mail: <input type="text" name = "email"><br> Phone: <input type="text" name = "phone"><br> <input type="hidden" name="picture"value="'; echo$image; echo '">' ; echo'<input type="submit" value="Submit"> </form>'; } else { echo "Sorry, there was a problem uploading your file."; } } } ?> </body> </html> Page 3 <html> <body> <?php $username="Myusername"; $password="mypasswordy"; $database="mydatabase"; //This gets all the other information from the form $name=$_POST['name']; $email=$_POST['email']; $phone=$_POST['phone']; $pic=$_POST['picture']; // Connects to your Database @$db = mysql_pconnect('myinfo,'mydatabase','mypasswordy'); mysql_select_db('mydatabase') or die( "Unable to select database"); //Writes the information to the database { mysql_query("INSERT INTO `mytable` VALUES (NULL,'$name', '$email', '$phone', '$pic')"); } $results=mysql_query($query); { echo 'Thank you for Submitting your information; } mysql_close($db); ?> </body> </html>
  10. Put something like this in the head section: <!-- Script goes here --> <script type="text/javascript"language="JavaScript1.2"> /* Validate an Email address */ function validateEmail(emailString) { /* The characters don't belong in a valid email address */ invalidChars = " /:,;"; /* You must enter something */ if (emailString == "") { window.alert("Please enter a valid email address!"); return false; } /* There must be something BEFORE the at sign */ if (emailString.indexOf("@", 0) == 0) { window.alert("Please enter a valid email address!"); return false; } /* There must be an at sign at, or after, the second character */ if (emailString.indexOf("@", 1) == -1) { window.alert("Please enter a valid email address!"); return false; } /* There must be a period somewhere */ if (emailString.indexOf(".", 0) == -1) { window.alert("Please enter a valid email address!"); return false; } /* Check for invalid characters */ for (i=0; i<invalidChars.length; i++) { if (emailString.indexOf(invalidChars.charAt(i), 0) > -1) { window.alert("Bad character(s) in email address!", invalidChars.charAt(i), i); return false; } } /* We made it! The email looks good! */ return true; } /* Verify a form */ function formVerify(join) { /* Check that the user entered a city */ if (join.first.value == "") { window.alert("You must enter your first name"); join.first.focus(); join.first.select(); return false; } /* Check that the user entered a last name */ if (join.last.value == "") { window.alert("You must enter your last name"); join.last.focus(); join.last.select(); return false; } /* Check that the user entered an address */ if (join.address.value == "") { window.alert("You must enter your address"); join.address.focus(); join.address.select(); return false; } /* Check that the user entered a city */ if (join.city.value == "") { window.alert("You must enter your city"); join.city.focus(); join.city.select(); return false; } /* Check that the user entered a Zip Code */ if (join.zip.value == "") { window.alert("You must enter your zip code"); join.zip.focus(); join.zip.select(); return false; } /* Check that the user entered a phone number */ if (join.phone.value == "") { window.alert("You must enter your phone number"); join.phone.focus(); join.phone.select(); return false; } /* Check that the user entered a user name */ if (join.contact.value == "") { window.alert("You must enter your user name"); join.contact.focus(); join.contact.select(); return false; } /* Check that the user entered a name */ if (join.pass.value == "") { window.alert("You must enter your password"); join.pass.focus(); join.pass.select(); return false; } /* Go validate the email address */ else if(!validateEmail(join.email.value)) { join.email.focus(); join.email.select(); return false; } else return true; } </script> Then start your form something like this: <form name="join" onSubmit="return formVerify(this)" action="customerjoin.php" method="post"> That works for my join form.  You will need to modify it to suit your needs. Jack
  11. Thank you :) I will give that a try, and also try to find information on SQL injections and about mysql_real_escape_string()
  12. I think I have a duh question. I am attaching an ID number to the url Example someurl?variable1. The ID number is there and I can retrieve it.  How do I get it into my select * from query? Here is my code: // open data base @ $db = mysql_pconnect('someserver.net', 'somedatabase', ' My password'); mysql_select_db('somedatabase1') or die( "Unable to select database"); //fetch Row ID number $var1 = $_GET['variable1']; echo $var1; { $query= 'SELECT * FROM `sometable` WHERE `ID` LIKE [color=red]??[/color]  LIMIT 0, 5 '; $query_results=mysql_query($query); $match_results=mysql_num_rows($query_results); } for ($i=0; $i < $match_results; $i++) { $row=mysql_fetch_array($query_results); echo ($row ['body'] ); } mysql_close($db); The variable I want is being transferred and it shows up at echo $var1 just fine.  How do I get it to be where the [color=red]??[/color] is in: $query= 'SELECT * FROM `sometable` WHERE `ID` LIKE [color=red]??[/color]  LIMIT 0, 5 '; Everything I have tried has presented me with an error message. If I replace the ?? with the ID number I do get the results I want, but how do I get it place the ID number in the select line automatically?  ???
×
×
  • 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.