Jump to content

Jakesta42

New Members
  • Posts

    5
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

Jakesta42's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. Hello, I'm writing a PHP program in which textfields are printed (in a loop) into an HTML table. On a button click, another column is added to the table, and another textfield added. The problem is that when a new textfield is printed, it is slightly above the height of the other textfields (see attached picture if unclear). The code for this is below: <table border = '1' cellspacing = '4' style = "color: white"> <?php include "connectToDatabase.php"; //Initial script call to generate table from database ?> </table> //Code in connectToDatabase.php... $query = mysql_query("SELECT * FROM colin_table"); while($row = mysql_fetch_array($query)){ //$row represents each row in an array for($i = 0; $i < $limit; $i++){ //Print every element in the array if($row[$i] == null) echo "<td align = 'center'><input type = 'text' style = 'text-align: center; vertical-align: middle' align = 'center'>"; else echo "<td align = 'center'>" . $row[$i]; } echo "<td align = 'center'>"; echo "<tr align = 'center'>"; //Then move to the next row } //Loop that prints text boxes for every column in the HTML table $textBoxQuery = mysql_query("SELECT * FROM allColumnFields"); while($row = mysql_fetch_array($textBoxQuery)){ echo <<<END <td align = 'center'> <input type = 'text' style="margin-left:auto; text-align:center; vertical-align: middle; margin-right:auto;" name = "rowField"/> END; //THIS IS THE PART THAT NEEDS WORK. FOR SOME REASON NEW TEXTBOX IS HIGHER THAN THE OTHER BOXES } It's more of an aesthetic problem, but it's nonetheless something I'd like to get fixed. Any ideas? Jake
  2. Hello, I'm trying to take the value from an HTML form and insert it into a database on a button click. It inserts a null value into the database. The script is called submitColumnDetails.php. This is where I create the text field that I want to take the information from. This is in a separate file. echo <<<END <form action = "submitColumnDetails.php" method = "POST"> <input type = "text" name = "columnField"/> </form> END; This is the submitColumnDetails.php file <?php //Submit Column Data //-----------------------------------------------------// //Connect to localhost server $connector = mysql_connect("localhost", "root", "root"); if(!$connector){ //If user can't connect to database die('Could not connect: ' . mysql_error()); //Throw an error } //-----------------------------------------------------// mysql_select_db("colin_db", $connector); $newValue = $_POST["columnField"]; //Data from column field. THIS IS WHAT RETURNS NULL $newColumnQuery = "INSERT INTO `colin_db`.`allColumnFields` (`DATA`) VALUES ('$newValue')"; mysql_query($newColumnQuery); //Query to add form to main table $newColumnIntoMainTableQuery = "ALTER TABLE colin_table ADD ('$newValue' varchar(50))"; mysql_query($newColumnIntoMainTableQuery); //Query to add column to main table mysql_close($connector); //Close database connection echo "<script type = 'text/javascript'> window.location = 'index.php'</script>"; //Go back to original page ?> Even when I print out the $newValue, it does not print anything. What am I doing incorrectly?
  3. Hey, So I have a couple of files, and I'm trying to create a login script. There is a MySQL query that accesses a database with a list of usernames and passwords. I have a feeling something is wrong with my SQL query, because it's not working correctly. <?php $connect = mysql_connect("localhost", "root", "root"); if(!$connect){//If user can't connect to database die('Could not connect: ' . mysql_error()); //Throw an error } mysql_select_db("colin_db", $connect); //Get given username and password from username field and password field $givenUsername = $_POST["usernameField"]; $givenPassword = $_POST["passwordField"]; $myQuery = "SELECT * FROM ADMINS WHERE USERNAME = $givenUsername AND PASSWORD = $givenPassword"; $queryResult = mysql_query($myQuery); $numRows = mysql_num_rows($queryResult); if($numRows == 1){ //If the details are correct... //Reload the page and login echo "<script type = 'text/javascript'> window.location.reload() </script>"; echo "Details correct"; } elseif($numRows == 0){ //Else if the details are not found //Display error accordingly echo "Details not correct!"; //This is what happens every time } mysql_close($connect); ?> The database is configured correctly, but I'm not sure how to correctly create a SQL query to determine if the given username and password are correct. In case you'd like to see it, the segment from the index.php file is below. <form action = "login.php" method = "POST"> Admin Login: <br> Username: <input type = "text" name = "usernameField"/><br> <!-- Password field--> Password: <input type = "password" name = "passwordField"/><br> <!-- Username field --> <input type = "submit" value = "Login" name = "submitButton"/> <!-- Login button --> </form> Any ideas? Thanks, Jake
  4. Okay, that issue is fixed; thanks so much. Still another issue stands. Is my SQL right? Because it says that the details are not correct (in my customized error message), but the information in the database matches my input. Is the way I'm determining if the login details are correct right?
  5. Hey y'all, I'm trying to write a PHP script for a login function. There are three elements, two text fields (username and password) and a button which calls the script. Segment from index.php file: <form action = "login.php" method = "POST"> Admin Login: <br> Username: <input type = "text" name = "usernameField"/><br> <!-- Password field--> Password: <input type = "password" name = "passwordField"/><br> <!-- Username field --> <input type = "button" value = "Login" name = "submitButton"/> <!-- Login button --> </form> Segment from login.php file: <?php $connect = mysql_connect("localhost", "root", "root"); if(!$connect){//If user can't connect to database die('Could not connect: ' . mysql_error()); //Throw an error } mysql_select_db("colin_db", $connect); //Get given username and password from username field and password field $givenUsername = $_POST["usernameField"]; $givenPassword = $_POST["passwordField"]; $myQuery = "SELECT * FROM ADMINS WHERE USERNAME = '$givenUsername' AND PASSWORD = '$givenPassword'"; $queryResult = mysql_query($myQuery); $numRows = mysql_num_rows($queryResult); if($numRows == 1){ //If the details are correct... //Reload the page and login echo "<script type = 'text/javascript'> window.location.reload() </script>"; } elseif($numRows == 0){ //Else if the details are not found //Display error accordingly echo "Details not correct!"; } mysql_close($connect); ?> The problem is, when I click the login button, it doesn't do anything. What am I missing? (The information in the database is correct) Thanks, Jake 17583_.php
×
×
  • 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.