-
Posts
12 -
Joined
-
Last visited
Profile Information
-
Gender
Female
babymac's Achievements

Newbie (1/5)
0
Reputation
-
Yes! I read about this and am not sure why I chose to use mysqli_fetch_array. Thank you so much for pointing that out. Off to read more!
-
I really appreciate your comment and want to learn. I am taking a beginning php class and have not learned anything about error reporting. Perhaps this is a problem with the curriculum, but for now I am trying to get this code to function. I have spent nearly 2 days reading and working on this simple assignment. I'm finally getting an output, but it's doubling the info and I also need to put it into a table. I will attach the new code - if anyone can give me some insight, I'd be so grateful. I will look up error reporting now! Thanks again! <!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" xml:lang="en" lang="en"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/> <title>Creating Directory</title> </head> <body> <?php //Label variables $dbhost = "localhost"; $dbuser = "xxxxxx"; $dbpword = "xxxxxx"; $dbname = "xxxxxx"; $dbtable = "Address_Book"; $fname = $_POST['fname']; $lname = $_POST['lname']; $address = $_POST['address']; $phone = $_POST['phone']; $email = $_POST['email']; $bday = $_POST['bday']; //Initiate connection $con=mysqli_connect($dbhost, $dbuser, $dbpword, $dbname); // Check connection if (mysqli_connect_errno($con)) { echo "Failed to connect to MySQL: " . mysqli_connect_error(); } $query = "SELECT * FROM $dbtable"; $result = mysqli_query($con, $query); while($row = mysqli_fetch_array($result)) { foreach($row as $key => $value){ echo $key; echo $value; } } mysqli_close($con); ?> </body> </html>
-
I'm struggling to print table data. I have a simple address book in mysql and want to loop through each item and print. I've read everything I can get my hands on and nothing is showing. Any thoughts are greatly appreciated! Thanks for your time! <!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" xml:lang="en" lang="en"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/> <title>Creating Directory</title> </head> <body> <?php //Label variables $dbhost = "localhost"; $dbuser = "xxxxxx"; $dbpword = "xxxxxx"; $dbname = "xxxxxx"; $dbtable = "Address_Book"; $fname = $_POST['fname']; $lname = $_POST['lname']; $address = $_POST['address']; $phone = $_POST['phone']; $email = $_POST['email']; $bday = $_POST['bday']; //Initiate connection $con=mysqli_connect($dbhost, $dbuser, $dbpword, $dbname); // Check connection if (mysqli_connect_errno($con)) { echo "Failed to connect to MySQL: " . mysqli_connect_error(); } $result = mysqli_query( "SELECT * FROM $dbtable") or die("SELECT Error: ".mysqli_error()); while($data = mysqli_fetch_array($result, MYSQL_ASSOC)){ foreach($data as $key => $value){ echo $key; echo $value; } } mysqli_close($con); ?> </body> </html>
-
Wow - it wasn't until I saw the code in the format here that I saw the missing comma plain as day. Fixed - nevermind! I don't know how to delete a post or I would.
-
I'm just learning and am trying to insert data into a table via myphpadmin. I have MAMP running and servers are on. Simple Input Form, then php script follows. I'm getting an error: Column count doesn't match value count at row 1. I've counted my variables over and over and they seem to match to me but this is my first time every doing this so perhaps I'm missing it. Also, I put x's through the sensitive login info and am interested what others do here. Again, this is just a simple assignment that I'm doing on localhost but am looking to the future also. Any thoughts? Thanks! <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://wwww.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/> <title> Database Input Form </title> </head> <body> <p><h3>Please enter the following information:</h3></p> <form action="pa4.php" method="post"> <p>First Name: <input type="text" name="fname" size="20" /> </p> <p>Last Name: <input type="text" name="lname" size="20" /> </p> <p>Address: <input type="text" name="address" size="60" /> </p> <p>Phone: <input type="text" name="phone" size="13" /> </p> <p>Email: <input type="text" name="email" size="50" /> </p> <p>Birthdate: <input type="text" name="bday" size="10" /> </p> <input type="submit" name="submit" value="Submit" /> </form> </body> </html> <!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" xml:lang="en" lang="en"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/> <title>Creating Directory</title> </head> <body> <?php //Label variables $dbhost = "localhost"; $dbuser = "xxxxxx"; $dbpword = "xxxxxx"; $dbname = "xxxxxx"; $dbtable = "Address_Book"; $fname = $_POST['fname']; $lname = $_POST['lname']; $address = $_POST['address']; $phone = $_POST['phone']; $email = $_POST['email']; $bday = $_POST['bday']; //Initiate connection $con=mysqli_connect($dbhost, $dbuser, $dbpword, $dbname); // Check connection if (mysqli_connect_errno($con)) { echo "Failed to connect to MySQL: " . mysqli_connect_error(); } $sql = "INSERT INTO $dbtable (First_Name, Last_Name, Adress, Phone, Email, Birthdate) VALUES ('$fname', '$lname', '$address' '$phone', '$email', '$bday')"; if (!mysqli_query($con,$sql)) { die('Error: ' . mysqli_error($con)); } echo "1 record added"; mysqli_close($con); ?>
-
Hi everyone, I'm working on an assignment and am looking for some advice as to where to start. What I'm trying to do: "Create a form and a script to upload files into a directory. If that directory does not exist, create it with 0777 permissions. Use ‘getcwd’ function to ensure that the script can be ported from machine to machine (Use varying file sizes for use in part 2)." then "Create a script to loop through the directory where you are uploading files to. List the directory contents in order by file size. (Tip: create an array of all the file names and file sizes, then use one of the array sort functions to sort them by file size.) Loop through the final, sorted array and print out the file name and file size to a text file outside the uploaded file directory." I'm not looking for someone to do my work, I'm just totally lost and don't know where to even look. Here's the small amount of code I have so far. :/ Help? <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://wwww.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/> <title> Input Form </title> </head> <body> <p><h3>Please upload file(s):</h3></p> <form enctype="multipart/form-data" action="pa3.php" method="POST"> File 1: <input type="file" name="file1" maxlength="20000"/><br/> File 2: <input type="file" name="file2" maxlength="10000"/><br/> File 3: <input type="file" name="file3" maxlength="15000"/><br/> <input type="submit" name='enter' value="Upload Files" /><br/> </form> </body> </html> <?php // Create the directory: mkdir ("/path/to/my/dir", 0777); ?>
-
Session variables not carried onto subsequent pages
babymac replied to babymac's topic in PHP Coding Help
I actually have one other question if anyone could explain. The code is doing what I want now, I just don't understand one part of the display. When a field is not entered, the user is shown the statment "Please make sure all input fields are entered." and then the link to go back. When all fields are entered correctly, the user is shown their information and a link to go forward as well as the link to go back. The 'go back' link appears at the top. While I'm happy it's there, it's not included in the if statement for when all fields are not empty. Can someone explain to me why this is? <?php //Create a script that starts a session: session_start(); $_SESSION['fname'] = $_POST['fname']; // First Name $_SESSION['lname'] = $_POST['lname']; // Last Name $_SESSION['email'] = $_POST['email']; // Email Address // Check if the form has been submitted: if ($_SERVER['REQUEST_METHOD'] == 'POST') { // Handle the form: if ( (empty($_POST['fname'])) or (empty($_POST['lname'])) or (empty($_POST['email'])) ) // Forgot a field: echo '<p>Please make sure all input fields are entered.</p>'; echo '<a href="http://studentweb.wilmu.edu/sites/lpeer79627/pa2.html"><br />Click to go back and change your information</a>'; } if ( (!empty($_POST['fname'])) && (!empty($_POST['lname'])) && (!empty($_POST['email'])) ) { // Print the received data: echo '<p> You entered your first name as: ' . $_SESSION['fname'] . ' </p> <p> You entered your last name as: ' . $_SESSION['lname'] . ' </p> <p> You entered your email as: ' . $_SESSION['email'] . ' </p>'; echo '<a href="http://studentweb.wilmu.edu/sites/lpeer79627/pa2final.php"><br />Continue to final screen</a>'; } ?> -
Session variables not carried onto subsequent pages
babymac replied to babymac's topic in PHP Coding Help
I've got it. Thank you so very much for your help. -
Session variables not carried onto subsequent pages
babymac replied to babymac's topic in PHP Coding Help
Sorry - I guess I'm not sure. I am trying to put the href's at the bottom of the page up into the if statements. One to go back if fields are not entered, and one to move forward to the next page. I've tried wrapping them in '<p></p>' statments, etc, and nothing seems to take away the parse error. -
Session variables not carried onto subsequent pages
babymac replied to babymac's topic in PHP Coding Help
I'm getting parse errors if I paste them into the php area. -
Session variables not carried onto subsequent pages
babymac replied to babymac's topic in PHP Coding Help
Yes! I just figured it out. Thank you so so much! For future views to this post, I needed to delete the session variables at the top of the third page and just echo in the statements. I do have one other question - I have updated the code a bit and would like to have one link show to go back and edit info, and another link show to continue to final screen. They both appear at the bottom, and I don't know how to include them inside the php code. Thoughts? <?php //Create a script that starts a session: session_start(); $_SESSION['fname'] = $_POST['fname']; // First Name $_SESSION['lname'] = $_POST['lname']; // Last Name $_SESSION['email'] = $_POST['email']; // Email Address // Check if the form has been submitted: if ($_SERVER['REQUEST_METHOD'] == 'POST') { // Handle the form: if ( (empty($_POST['fname'])) or (empty($_POST['lname'])) or (empty($_POST['email'])) ) // Forgot a field: echo '<p>Please make sure all input fields are entered.</p>'; } if ( (!empty($_POST['fname'])) && (!empty($_POST['lname'])) && (!empty($_POST['email'])) ) { // Print the received data: echo '<p> You entered your first name as: ' . $_SESSION['fname'] . ' </p> <p> You entered your last name as: ' . $_SESSION['lname'] . ' </p> <p> You entered your email as: ' . $_SESSION['email'] . ' </p>'; } ?> <a href="http://studentweb.wilmu.edu/sites/lpeer79627/pa2.html"><br />Click to go back and change your information</a> <a href="http://studentweb.wilmu.edu/sites/lpeer79627/pa2final.php"><br />Continue to final screen</a> -
Hi everyone, I'm new to PHP and am taking a class but things aren't coming together as I'd hoped. I'm trying to utilize sessions to carry info from page to page. It brings it to the next page, but not the next. What I'm trying to do is: -Make a simple input form. -Show entered information on next page via the use of a session. -Third page shows final information. On a bigger scale, I'd like to have some if statements added if a field is left blank but want to get this figured out first. Thanks for any comments/suggestions! -Lórien FIRST PAGE: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://wwww.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/> <title> Input Form </title> </head> <body> <form action="pa2.php" method="POST"> <p>First Name: <input type='text' name='fname' size='30'/> </p> <p>Last Name: <input type='text' name='lname' size='30'/> </p> <p>Email Address: <input type='text' name='email' size='45'/> </p> <input type="submit" name='enter' value="Submit" /><br/> </form> </body> </html> SECOND PAGE: <?php //Create a script that starts a session: session_start(); $_SESSION['fname'] = $_POST['fname']; $_SESSION['lname'] = $_POST['lname']; $_SESSION['email'] = $_POST['email']; // Print the received data: echo '<p> You entered your first name as: ' . $_SESSION['fname'] . ' </p> <p> You entered your last name as: ' . $_SESSION['lname'] . ' </p> <p> You entered your email as: ' . $_SESSION['email'] . ' </p>'; ?> <a href="http://studentweb.wilmu.edu/sites/lpeer79627/pa2.html"><br />Click to go back and change your information</a> <a href="http://studentweb.wilmu.edu/sites/lpeer79627/pa2final.php"><br />Yes, my information is correct!</a> THIRD PAGE: <?php //Create a script that starts a session: session_start(); $_SESSION['fname'] = $_POST['fname']; $_SESSION['lname'] = $_POST['lname']; $_SESSION['email'] = $_POST['email']; // Print the received data: print '<p><h2>Here is your information:</h2></p> <p> Name: ' . $_SESSION['fname'] . ', ' . $_SESSION['lname'] . ' </p> <p> Email: ' . $_SESSION['email'] . ' </p>'; ?>