Jump to content

magickfirebird

Members
  • Posts

    12
  • Joined

  • Last visited

magickfirebird's Achievements

Newbie

Newbie (1/7)

1

Reputation

  1. My code so far: try {$conn = new PDO("mysql:host=$servername;dbname=$dbname", $username, $password);$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);} catch(PDOException $e) {echo "Connection failed: " . $e->getMessage();} ini_set('display_errors', 1); error_reporting(E_ALL); $firstnameErr = $lastnameErr = $artistidErr = $emailErr = $passwordErr = "";$firstname = $lastname = $artistid = $email = $password = ""; if ($_SERVER["REQUEST_METHOD"] == "POST") {if (empty($_POST["firstname"])) {$firstnameErr = "First Name is required";} else {$firstname = regcheck($_POST["firstname"]); if (!preg_match("/^[a-zA-Z ]*$/",$firstname)) {$firstnameErr = "Only letters and white space allowed"; }} if (empty($_POST["lastname"])) {$lastnameErr = "Last Name is required";} else {$lastname = regcheck($_POST["lastname"]); if (!preg_match("/^[a-zA-Z ]*$/",$lastname)) {$lastnameErr = "Only letters and white space allowed"; }} if (empty($_POST["artistid"])) {$artistidErr = "Artist ID is required";} else {$artistid = regcheck($_POST["artistid"]); if (!preg_match("/^[a-zA-Z ]*$/",$artistid)) {$artistidErr = "Only letters and white space allowed"; }} if (empty($_POST["email"])) {$emailErr = "Email address is required";} else {$email = regcheck($_POST["email"]); if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {$emailErr = "Invalid email address format";}} if (empty($_POST["password"])) {$passwordErr = "Password is required";} else {$password = regcheck($_POST["password"]); if (!preg_match("/^[a-zA-Z ]*$/",$password)) {$passwordErr = "Only letters and white space allowed"; }}} function regcheck($data) { $data = trim($data); $data = stripslashes($data); $data = htmlspecialchars($data); return $data;}?> <br /><h2>Registration</h2> <p><span class="error">* required field.</span></p><form method="post" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>"> First Name: <input type="text" name="firstname" value="<?php echo $firstname;?>"> <span class="error">* <?php echo $firstnameErr;?></span><br><br> Last Name: <input type="text" name="lastname" value="<?php echo $lastname;?>"> <span class="error">* <?php echo $lastnameErr;?></span><br><br> Artist ID: <input type="text" name="artistid" value="<?php echo $artistid;?>"> <span class="error">* <?php echo $artistidErr;?></span><br><br> E-mail address: <input type="text" name="email" value="<?php echo $email;?>"> <span class="error">* <?php echo $emailErr;?></span><br><br> Password: <input type="text" name="password" value="<?php echo $password;?>" /><span class="error">* <?php echo $passwordErr;?></span><br /><br /> <input type="submit" name="submit" value="Enter"> </form> <?php echo "<h2>Your Input:</h2>"; ?>Name: <?php echo $firstname; ?> <?php echo $lastname;echo "<br>"; ?>E-mail Address: <?php echo $email;echo "<br>"; ?>Artist ID: <?php echo $artistid;echo "<br>"; ?>Password: <?php echo $password;echo "<br>";?><br /><input type="submit" name="submit" value="Submit to create" /> After information is entered into the form and "Entered" it goes to the "Your input area". From here I would like it to be INSERTED to the table file.
  2. I have a sign up page that when the person fills in the form and hits the Enter button it post below for them to verify that their information is correct. From this spot I would like for it to create a new insert into an existing table. Do I need to go back up in my coding to the "try" section when I set my if statements for my first form and create my "insert" code?
  3. My page comes up with the form as I intend for it to look. I am opening with PDO: try {$conn = new PDO("mysql:host=$servername;dbname=$dbname", $username, $password); $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); echo "Connect successfully";} catch(PDOException $e) {echo "Connection failed: " . $e->getMessage();} And it checks to make sure the field is not empty and that correct: if (empty($_POST["lastname"])) {$lastnameErr = "Last Name is required";} else {$lastname = regcheck($_POST["lastname"]); if (!preg_match("/^[a-zA-Z ]*$/",$lastname)) {$lastnameErr = "Only letters and white space allowed"; }} if (empty($_POST["loginid"])) {$loginidErr = "Login ID is required";} else {$loginid = regcheck($_POST["loginid"]); if (!preg_match("/^[a-zA-Z ]*$/",$loginid)) {$loginidErr = "Only letters and white space allowed"; }} I am back to trying to compare loginid that is entered into the form to the loginid’s that have already been entered into the table, test5. This is the last try that I’ve made, and of course it is not working without errors. : // This is where the form field is checked to see if the field is blank or filled if (empty($_POST["loginid"])) {$loginidErr = "Login ID is required";} else {$loginid = regcheck($_POST["loginid"]); if (!preg_match("/^[a-zA-Z ]*$/",$loginid)) {$loginidErr = "Only letters and white space allowed"; }} // and to make sure that the login id used is not already being used. $sql = "SELECT 'loginid' FROM test5"; $result = $conn->query($sql); if (compare($loginid = "loginid")) {$loginidErr = "Login ID already exist. Select new Login ID.";} else {$loginid = reqcheck($_POST["loginid"]);}
  4. Before starting on my registration page I created a few tables and was able to insert into them. Then I worked on printing the files out from the tables. After both of these I started working on the registration page. While putting together my print page I did use the PDO code that I found on this site. After reading your last post I went back to my insert programs to make it into a prepared statement program. Of course, the first few times I ran it, it came up with errors, mostly typing errors, normal stuff. Now it runs without any errors and shows the message that a new record was created but in fact it was not inserted into the table. Would you look over the code for me? Thank you. // create connection $conn = new MySQLi($servername, $username, $password, $dbname); // check connection if ($conn->connect_error) {die("Connection failed:" . $conn->connect_error);} // prepare and bind $stmt = $conn->prepare("INSERT INTO test5 (firstname, lastname, loginid, email, password) VALUES (?, ?, ?, ?, ?)"); $stmt->bind_param("sss", $firstname, $lastname, $loginid, $email, $password); // set parameters and execute $firstname = "jon"; $lastname = "see"; $loginid = "tank"; $email = "jon@exeee.com"; $password = "super"; $stmt->execute(); echo "New records created successfully"; $stmt->close(); $conn->close();
  5. Ok, my comparison is part Wof a registration page for my website. I was able to write code that if loginid was already in the table it came back with an error message that Login ID already existed. Except that when I put in a different loginid it still came up with the error message. At the current time when the form is submitted it shows up below the form to go over before submitting into the table. When I put in the new loginid it does change to information below but it still has the error message. Now the problem is, that while trying to fix this problem I have a new problem. It currently shows the error message that it is required for each field, and when I enter the information and it goes below the error messages leave except for the loginid error message which changes to login ID already exists (when it doesn't). I'm sure it's just something that I left out or added to much to. I would appreciate your looking over some of the code for me. $sql = "SELECT loginid FROM test5"; $result = $conn->query($sql); {if (exists) {$loginidErr = "Login ID already exist. Select new Login ID.";} else {$loginid = reqcheck($_POST["loginid"]);} if (empty($_POST["firstname"])) {$firstnameErr = "First Name is required";} else {$firstname = reqcheck($_POST["firstname"]); if (!preg_match("/^[a-zA-Z ]*$/",$firsename)) {$firstnameErr = "Only letters and white space allowed";}} if (empty($_POST["lastname"])) {$lastnameErr = "Last Name is required";} else {$lastname = reqcheck($_POST["lastname"]); if (!preg_match("/^[a-zA-Z ]*$/",$lastname)) {$lastnameErr = "Only letters and white space allowed";}} . . . function query($data) {$data = trim($data); $data = stripslashes($data); $data = htmlspecialchars($data); return $data;} function reqcheck($data) {$data = trim($data); $data = stripslashes($data); $data = htmlspecialchars($data); return $data;} . . . <span class="error">* required field.</span> <form action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>" method="post"> <br /> First Name: <input type="text" name="firstname" value="<?php echo $firstname;?>" /> <span class="error">* <?php echo $firstnameErr;?></span><br /><br /> Last Name: <input type="text" name="lastname" value="<?php echo $lastname;?>" /> <span class="error">* <?php echo $lastnameErr;?></span><br /><br /> Login id: <input type="text" name="loginid" value"<?php echo $loginid;?>" /> <span class="error">* <?php echo $loginidErr;?></span><br /><br /> . .
  6. I'm at a point that I need to verify that the record that is being entered doesn't already exist. I seem to be overlooking in the tutorials how to do this comparison. I'm also not sure if it can be done at the same time as making sure a required field is not empty of if it needs to run before all of the check for empty fields is ran. if (empty($_POST["loginid"])) {$loginidErr = "A login ID is required";} else {$loginid = reqcheck($_POST["loginid"]); if (!preg_match("/^[a-zA-Z ]*$/",$loginid)) {$loginidErr = "Only letters and white space allowed";}}
  7. Thank you. I've put a few pages of my site together and am now back to working on the page for family to upload onto. Heading to PHP and seeing if I can put the information together. Thanks.
  8. I am building my website a little at a time. Right now I am working on a form to allow people to send an email to me. Currently the only areas to be entered is their name, email address, and their question/comment. When I hit submit it does bring up my email program so that an email may be sent. In the body of the email it shows: name=(the name entered), email=(the email address entered), and submit=Send. As you can see it doesn't move the content of the comment text area to the email. Would you please look over the code for me? Thank you. <form action="MAILTO:daphne@familycreativeart.com" method="post" enctype="text/plain"> <br /><br />Name: <br /><input type="text" name="name" />* required <br /><br />E-mail Address: <br /><input type="text" name="email" />* rquired <br /><br />Comment: <br /><textarea rows="4" cols="50"> </textarea>* required <br /><br /> <input type="submit" name="submit" value="Send" /> <input type="reset" name="reset" value="Reset" /></form>
  9. Thank you for the information. A few years ago I took online classes to receive a "degree" which included web design. It hit on the different coding languages in a short time frame. Now I am trying to put the steps together to achieve the outcome that I want. I think what I need to help is an outline of the steps to get to where I am going. At this point the short outline would be a sign-in page, then they can go to their web page and up load pic and descriptions. That's how it looks on their end. On my end I know there are more steps. They would need to register which would set up a file (MySQL) so that when they sign in PHP would check if they are registered and accept that they are allowed to make changes. Then I would have to create their page with areas for them to upload their pics and areas for their text. Am I on the right track so far? My host does have an area for MySQL users and for FTP users. I haven't noticed an area for MySQL files. Thank you.
  10. I would like to learn more on the programming skills needed for this. Thank you.
  11. I am working on a website for my family that we may use to show/sell our craft items on. I'm looking for a way that they may upload their information to their web page. Any help/direction is appreciated. Thank you.
×
×
  • Create New...