Search the Community
Showing results for tags 'php mysql database'.
-
I'm successfully connecting to my database but cannot retrieve/pull data from my database. I'm using wamp. I figured I can echo any message I want but as soon as I enter the while loop and try to echo anything or in my case echo the rows from the database it simply does not work. I don't get any errors when running on wamp and I'm running out of ideas as of why this is happening. I'm using a form tag and extracting the users/people stored in the database with gender = "male/female", depending on which "radio/option" the user decides. Any help would be highly appreciated. <html> <head> <title>Enter title here</title> </head> <body> <?php if ($_GET) { $gender = $_GET[ 'gender']; $connect = mysql_connect("localhost", "root", "mypassword"); if ($connect) { mysql_select_db("ourDatabase", $connect); $query = "SELECT * FROM mytable WHERE Gender = ' " . $gender. " ' "; $result = mysql_query($query); while($row = mysql_fetch_array($result) ) { echo $row[ ' Name ' ] . "<br/>" . $row[ ' Surname ' ] . "<br/>" . $row[ ' Email ' ] ; } } else { die (mysql_error() ); } } ?> <form action="" method = "GET"> find entries that are: <br/> <input type= "radio" name = "gender" value = "Male">Male</input><br/> <input type = "radio" name = "gender" value = "Female">Female</input><br/> <input type ="submit" value = "Select"/> </form> </body> <html>
-
Good day all. I am trying to achieve entering multiple email addresses to a mysql database field all at once. I wrote the following script to manage this but it's not working. I am seperating the emails with comma, but it only enters this (') into the database. I am trying to use implode function but I don't seem to be getting it right. Any help will be appreciated. Here is the code: <?php if(isset($_POST['submit'])){ $email = $_POST['email']; if(empty($email)) { echo '<p><font color="red"><strong>NO EMAIL ADDRESSES ENTERED</strong></font></p>'; $badinput = '<p><font color="red"><strong>PLEASE INPUT MEMBERS' EMAIL ADDRESSES</strong></font></p>'; echo $badinput; } else{ mysql_connect("somehost","someadmin","somepassword");//database connection mysql_select_db("somedatabase"); //inserting data order $allemails="('".implode("'), ('",$email)."')"; $membersemail = "INSERT INTO sometable (email) VALUES ('$allemails')"; //declare in the order variable $result = mysql_query($membersemail); //$membersemail executes } if($result){ echo '<center><font color="red"><h1>SUCCESS!!!</h1></font></center>'; echo '<center><h3>DATABASE POPULATED WITH MEMBERS' EMAIL ADDRESSES</h3></center>'; } } ?> <form name= "someform" method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>"> <center><table border="0" cellspacing="10"> <tbody> <tr> <td align="right"><span class="style5">Members' E-mail Addresses:</span> </td> <td><label for="email"></label> <textarea name="email" id="email" cols="45" rows="10"></textarea> </td> </tr> </tbody></table> <input type="submit" name="submit" value="Submit"> <input type="reset" name="reset" value="Reset"></center> </form> What am I doing wrong? Thanks all.