Jump to content

LivingReceiver

Members
  • Posts

    12
  • Joined

  • Last visited

LivingReceiver's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. Thank you everybody all for the help, especially you, Ch0cu3r. Finally I can get this website on it's feet! I've been told this in the past, actually. I'm a very inexperienced coder (especially in PHP), but years and years ago I used to try to make little websites, and I always used MySQL. I never have taken the time to switch over, or even consider what it would be like to switch. I'll keep that in mind for the future, however. I only need this website for a few weeks of sampling so I didn't think of doing anything different. Thank you for you help anyhow!
  2. Already changed the $pic to pic situation. Here is the current code in its entirety: <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="refresh" content="5;url=entries.php"> </head> <body> <text><i>Processing may take up to five seconds. You will be redirected shortly.</i></text><p> <div style="display:block;"> <img src="base.gif" width="10" height="36"/> <img src="base2.gif" width="10" height="36"/> <img src="base3.gif" width="10" height="36"/> <img src="base4.gif" width="10" height="36"/> <img src="base5.gif" width="10" height="36"/> <img src="base6.gif" width="10" height="36"/> <?php $pic = array('50.gif','100.gif','200.gif','250.gif','150.gif','300.gif'); shuffle($pic); echo "<li style=\"display: inline;\"> <img src=\"$pic[0]\" width=\"27\" height=\"36\">"; echo '<input type="hidden" value="'.$pic[0].'" name="pic" />'; ?> </div> </body> </html> <?php $con=mysql_connect("website", "database", "password"); if (!$con) { die('Could not connect: ' . mysql_error()); } /* Selecting database */ mysql_select_db("database", $con); /*Storing values*/ $sql="INSERT INTO databasename (name1, age2, pic) VALUES ('$_POST[name1]','$_POST[age2]','$_POST[pic]')"; if (!mysql_query($sql,$con)) { die('Error: ' . mysql_error()); } mysql_close($con); ?>
  3. Oh wow, sorry about that! I fixed the $_POST['pic'] issue, but it still isn't showing up. I'm starting to wonder if I added it incorrectly. The row's name is "pic" and it's type is "varchar(10)" Could that be the problem? Thank you so much for all your help,
  4. It won't show up. Also, now my previous inputs won't show up in the database. <?php $con=mysql_connect("website", "database", "password"); if (!$con) { die('Could not connect: ' . mysql_error()); } /* Selecting database */ mysql_select_db("database", $con); /*Storing values*/ $sql="INSERT INTO database (name1, age2, $pic) VALUES ('$_POST[name1]','$_POST[age2]','$_POST[$pic[$0]')"; if (!mysql_query($sql,$con)) { die('Error: ' . mysql_error()); } ?> Am I putting something in the wrong place?
  5. This was my code for choosing the array. (Sorry for its messiness.) <?php $pic = array('50.gif','100.gif','200.gif','250.gif','150.gif','300.gif'); shuffle($pic); for( $i = 0; $i < 1; $i++) echo "<li style=\"display: inline;\"> <img src=\"$pic[$i]\" width=\"27\" height=\"36\"> </li>"; ?>
  6. I have been trying to finish up a website for a while now and I can't seem to figure out how to do this. Right now I want one out of four pictures to randomly be selected and presented on a webpage. I have already achieved this through the shuffle() function. However, I want the name of whichever picture shows up to be recorded in my MySQL database. How do I go about doing this? I searched online and came across the function serialize(), but then I was advised not to use it since I only wanted the name of one of the pictures in the array instead of all of them. Does anyone have any functions/sample code that may be of use? (Example in case I didn't explain clearly: I have four pictures: a.ipg, b.jpg, cjpg, d.jpg Let's say the shuffle() function choses b.jpg to be displayed on the webpage. How could I get b.jpg to be sent to my database?) Thank you.
  7. I was receiving help on my array and I was told to add that... (I realize my coding is very sloppy-- I haven't worked on coding for about five years.) No, those aren't new-- those were supposed to be deleted, but I suppose I forgot. I was messing around with some HTML.. I vaguely remembered those tags working, but my memory of this is pretty much shot. Thank you for you suggestion! I'll let you know how it goes. Thank you so much! Edit: Tried the code hansford fixed, and the problem was solved. Ginerjim, you were completely right about the solution. Thank you so much!
  8. Hi there! I am trying to get a list of images in line with each other-- the only thing giving me trouble is the fact that I want the last picture to be randomly chosen from an array of images. Everything seems to work just fine except for the fact that the randomized image and the other images won't stay on the same line. In other words, I want the images to show up like this: xxxxxxrandom ..but it keeps showing up like this: xxxxxx random <html> <text><red><large><i>Processing may take up to five seconds. You will be redirected shortly.</i></large></red></text><p> <meta http-equiv="refresh" content="5;url=entries.php"> <img src="base.gif" width="10" height="36"/> <img src="base2.gif" width="10" height="36"/> <img src="base3.gif" width="10" height="36"/> <img src="base4.gif" width="10" height="36"/> <img src="base5.gif" width="10" height="36"/> <img src="base6.gif" width="10" height="36"/> <?php $pic = array('50.gif','100.gif','200.gif','250.gif','150.gif','300.gif'); shuffle($pic); ?> <?php for( $i = 0; $i < 1; $i++) echo "<li style=\"display: inline;\"> <img src=\"$pic[$i]\" width=\"27\" height=\"36\"> </li>"; ?> </html> Would anyone be able to tell me what I may be doing wrong? Thank you so much!
  9. Hello Everyone! I was just wondering if anyone knew how to code a word generator that will give an three outputs without repeating any of the words. I want to make three radio buttons that have a random generated word from a list of words I created, but none of the words can repeat. I have the list of the words on a text file, and this is the code I am currently using. (All I did was repeat it three times to get the three outputs, but when I tested it I have had times where it repeats the same word three times.) <?php $filename="words.txt"; $words=file($filename); shuffle($words); $word=$words[0]; echo $word; ?> Any ideas? Thanks!
  10. Thank you so much for the help! I got the whole three letter name + poln thing down, but I'm having trouble adding it into a radio button. Any suggestions? <?php $email = "myemail@email.com"; print "<p>The following information was submitted from the form:<p><table width=\"450\" border=\"0\"><tr><td style=\"BORDER: #efecd6 1px solid;\"><table border=\"0\" width=\"100%\" cellpadding=\"5\" cellspacing=\"0\"> <tr><td width=\"35%\">First Name</td><td>".$_REQUEST[name1]."</td></tr> <tr><td width=\"35%\">Age</td><td>".$_REQUEST[age2]."</td></tr> <tr><td width=\"35%\">Gender</td><td>".$_REQUEST[gen3]."</td></tr> </table></td></tr></table> "; $message = "The following information was submitted from the form on your website:\n"; $message .= "First Name: ".$_REQUEST[name1]."\n\n"; $message .= "Age: ".$_REQUEST[age2]."\n\n"; $message .= "Gender: ".$_REQUEST[gen3]."\n\n"; mail( $email, "myemail@email.com", $message, "From: $email X-Priority: 1 (Highest)" ); ?> <?php $var = $_POST['name1']; $please = echo substr_replace($var, 'poln', 3) . "<br />\n"; ?> <p> Imagine you are at a grocery store and you see the four sodas listed below. Which one would you choose? </p> <form method="POST" action="testsend.php"> <p><select name="select1" size="1"> <input type= "radio" value="annies"></input> <input type= "radio" value="pears"></input> <input type= "radio" value="$please"></input> </select></p> <p><input type="submit" name="submit"> </p> </p> </form> I'm also having trouble figuring out how to make a list of 3 letter phrases to put in front of 'poln' and insert them, while making sure they don't start with the same letter as $please. (Am I even able to make the substr_replace () a variable?) Do I make a php file and list them all under the same variable? So sorry for all the questions, I'm completely new to PHP ><. Thanks to everyone for all your help! P.S. Christian, do you think protecting the website will be necessary since I am just really using the url on a school computer? I'm not really promoting it too much online. (It's for a science project I'm conducting.)I'm not sure. Thank you so much for your help!
  11. Hey! My name is Molly and I am currently attempting to create a form for use in a science project I am conducting. This form has inputs for the usual name, age, gender, etc. The only difference is, after the subjects are done filling out the name, age, and gender inputs, they need to be taken to the next page that will give them four options. Each option will have a three letter (or two letter, if their name is three letters or less) prefix (I can create all of these, they all have to be completely different) , and the same ending. (For example, 'poln'.) The fourth option will take the first three letters of the submitted name (or two letters, if their name is three letters long or less) and tack it onto the same ending. ('poln'). Then the subject needs to be able to choose this option, and submit all the information to my sql database. Here's an example situation; Your name is Sarah. You go to the website and type in your name, age, and click on your gender. You click the next button, and you see a page with four choices; Molpoln Addpoln Sarpoln Tarpoln You select your choice and press submit, which sends the information to a data base. Now have pretty much no experience with php, this is incredibly difficult for me. I have understood how to great the normal inputs i.e. text boxes for name/age and radio buttons for gender, but the rest is almost impossible. In short, 1. How do I "fix" the name input so that the code will take the first three letters and tack it onto the ending? 2. How do I "upload" the other choices so that whenever the name is given, the other three choices must start with a different letter? 3, How do I make these options clickable? 4. How do I submit it all to my sql database? This is what I have so far for my index page <html> <body> <style> .robotext {font-weight: bold; font-size: 9pt; color: #999999; font-family: Arial, Helvetica, sans-serif; text-decoration: none} .robolink:link {font-weight: bold; font-size: 9pt; color: #999999; font-family: Arial, Helvetica, sans-serif; text-decoration: none} .robolink:hover {font-weight: bold; font-size: 9pt; color: #979653; font-family: Arial, Helvetica, sans-serif; text-decoration: underline} .robolink:visited {font-weight: bold; font-size: 9pt; color: #979653; font-family: Arial, Helvetica, sans-serif; text-decoration: none} </style> <script language="Javascript"> function validate(){ var allok = true; if(sproject.First_Name__1.value == ""){ alert('Invalid input for First Name'); return false; } if(isNaN(sproject.Age__2.value)){ alert('Invalid input for Age, this must be a number') return false; } document.sproject.Submit.disabled="disabled"; return true; } </script> <form name="sproject" method="Post" action="http://agreatperhaps...nf/entries.php" onsubmit="return validate();"> <form method="post" action="update.php" <table width="100%" border="0" cellpadding="5" cellspacing="0"> <tr><td>First Name</td><td><input type="edit" name="name1" value="" size="15"></td></tr> <tr><td>Age</td><td><input type="edit" name="age2" value="" size="2"></td></tr> <tr><td valign=top>Gender</td><td valign=top> <input type="radio" name="gen3" value="Female" checked>Female<br> <input type="radio" name="gen3" value="Male">Male<br> </td></tr> <tr><td colspan=2><input type="submit" name="Submit" value="submit"></td></tr> </body> </html> And here is my update.php page <html> <body> <?php $name1 = $_POST[ ' name1 ' ]; $age2 = $_POST [ 'age2 ']; $gen3 = $_POST [ 'gen3 ']; mysql_connect ("provider", "databasename", "databasepassword") or die ('Error: ' . mysql_error ()) mysql_select_db ("databsename"); $query= "INTERT INTO TestTable (name1, age2, gen3) VALUES ('NULL', '".$name1."', '".$age2."', '".gen3."') mysql_query ($query) or die ('Error updating database'); echo "Database Updated With: " .$name1." ".$age2." ?> </body> </html> Thank you so much!
×
×
  • 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.