Jump to content

RonnieCosta50

Members
  • Posts

    28
  • Joined

  • Last visited

Everything posted by RonnieCosta50

  1. Thank you. That was exactly what I needed to get this working.
  2. I don't know any AJAX so that option is out the window. As for submitting the form to search.php... If I submit a form then it will reload the whole website. I only want it to search the database and display the data into the website without reloading the website. There are many textboxes and it would not work to reload the page every time a user switches textboxes.
  3. As for your 2 fields that don't clear when you submit form and the page reloads... I'm assuming your in the testing phase of your website and you probably do what I do when I test. Check that you didn't accidentally forget to delete the initial value of both of those textboxes. I always set initial values so that I don't have to keep filling in the form to make sure it is adding to the database. When you finished the adding to database code, it is likely that you forgot to delete the initial values. I don't see anything in your code that could do that by itself.
  4. I have a textbox. When the text that is typed into the textbox changes, I want to search my database for what is in the textbox. I want to do this rather than a search button because my website is really complicated and I'm simplifying it in my explanation to make it easy to understand. I currently have an alert in my textbox that displays the text that was typed in the textbox on change. It looks like this. <input name="txtPlayerName" tabindex="0" style="width: 150px; background-color: #BBAE85;" maxlength="15" required="required" autofocus="autofocus" placeholder="LoU screen name" onchange="alert(this.value)" /> I have a seperate php file called search.php. It contains my code to search the database based on criteria in my input textboxes. Question: How do I tell the textbox to run search.php onChange?
  5. Try taking the echos out of php mode. echo " ?> <script>alert('Product successfully added'</script>) <?php ";
  6. Hey buddy. Since you started over, I can see an error in your echo. echo "$fn"; When you want to write something specific, it is a string. You put that in quotes. example: echo"Ronnie is awesome"; When you are using a variable, you don't put it in quotes. $fn="Ronnie is awesome"; echo $fn; You shouldn't have started over.
  7. You can't do that with those else statements. You can only have 1 else statement per if statement. Put all those echos in a single else statment and watch it work. You will obviously want to make if statements for your echos though so if email is wrong then echo email is wrong blah blah blah. Just don't use more than one else per if. You can also use elseif
  8. Don't understand the problem. What is your final intention?
  9. Thanks for the code. It didn't work though but I modified it to work. Here is the code that worked for me for anyone else who reads this and wants to do this. Note: you should not do this. It's a security risk. I'm doing it because I have nothing on my server space and I'm learning php with it so I don't have to keep uploading the file to the server. <html><head><title>Execute PHP Code In A Textbox</title></head><body> <form action="" method="post"> <textarea name="code" cols="50" rows="20"></textarea><br> <input type="submit" name="submit" value="Execute"> </form> <?php if (isset($_POST['submit'])){ $code = $_POST['code']; eval($code); } ?> </body></html>
  10. Yeah now that you said it I guess if someone know my website then they could type php code to ask for the connection details and then they have all they need. Guess it's a bad idea. Thanks .
  11. Before I agree on exploding but then if the user inputs something like this, "What do you do if you step on a mine?" then you should create a list of words to take away from the search parameters. Put that list in a seperate php. Get rid of words in the string such as the words "the, if, you, do, a, etc". So now the search becomes "step on mine". I think the search results would be more effecitve. Then explode step on mine and put the new string in the variable %$quest_search%
  12. I have a textbox and a submit button. It's easy to make an echo so whatever is typed in the textbox, echos under the textbox. I want to do something a little more complicated. I want to run the php code that is entered in the textbox. For example if I put this in the textbox <?php echo"Hello World";?> or if I put an if statement in the textbox I want it to run it. I am trying to learn php and it would be great if I could just input code into a textbox to see the result rather than have to upload the file to the FTP server every time. Sometimes I'm not at my home computer and I want to sample some code I read on the php manual. Question: Is it possible to run php code that is typed into a textbox? <!DOCTYPE html> <html> <head> <meta content="text/html; charset=utf-8" http-equiv="Content-Type" /> <title>Learn PHP</title> </head> <body> <form method="post"> <input name="txtTextbox" style="width: 500px" type="text"><br> <?php $txtTextbox = $_POST['txtTextbox']; $search = $_POST['btnSubmit']; if ($search) { // Here's the part I need help on. echo '<p>';?> $txtTextbox; <?php echo '</p>'; // Assume I typed Hello World <?php echo $txtTextbox;?> in the textbox } echo'<br>'; ?> <input name="btnSubmit" type="submit" value="submit"> </form> </body> </html>
  13. 1. First off you should not require once your database connection. You should close the connection after your done using it to free up the server. 2. Your form method is "get". I'd use "post". 3. Your sql statement says '%$searchSubmit%' but you never told it what that variable was. Right above that line write in $searchSubmit = $_POST['searchSubmit']; I think that's about it. Don't forget to mark me as Solved if it worked.
  14. I guess if you don't want to use a database table, you could just echo. Replace this part... // DISPLAYS DATA FROM DATABASE INTO HTML TABLE while($rows=mysql_fetch_array($qrySELECT)) { echo'<tr>'; echo'<td style="width: 100px">'.$rows[$dbColumnName1].'</td>'; //$dbColumnName is the name is the column in your database. echo'<td style="width: 100px">'.$rows[$dbColumnName2].'</td>'; echo'</tr>'; } With this... // DISPLAYS DATA FROM DATABASE WITH ECHO while($rows=mysql_fetch_array($qrySELECT)) { echo'$rows[$dbColumnName1] </br>'; //$dbColumnName is the name is the column in your database. echo'$rows[$dbColumnName2] </br>'; }
  15. I think this is what you want. You want the user to search for something in the database and have it displayed. I'm assuming it will display more than one result so you will need an html table. <body> <form name="search" method="post"> // "search" is the name of the button. <!--here's a textbox for input.--> <input name="wsTextbox1" tabindex="0" style="width: 150px; background-color: #BBAE85;" maxlength="15" required="required" autofocus="autofocus" placeholder="Enter Search Criteria" /> <!--Here's a submit button--> <input type="submit" name="btnSubmit" value="Submit" class="button" style="width: 80px"/> <table> <?php // SEARCHES FOR DATA IN YOUR DATABASE $search = $_POST['search']; // The variable name $search is equal to the click of the search button. if ($search) // If the search button is clicked, { // since you want everything on one page, you will have to add code here for your database connection. // I'm just going to use multiple pages to demonstrate. include 'dbConnect.php'; // Connects to database. include 'dbTableName.php'; // Gets the database table name. include 'dbTableColumns.php'; // Gets the database table column names. // This is a sample sql statement. Modify it to the website criteria. $sqlSELECT = "SELECT * FROM $dbTableName WHERE $dbColumnName1 LIKE '%$wsTextbox1%' ORDER BY $dbColumn2 DESC, $dbColumn2 DESC LIMIT 10"; $qrySELECT=mysql_query("$sqlSELECT"); } // DISPLAYS DATA FROM DATABASE INTO HTML TABLE while($rows=mysql_fetch_array($qrySELECT)) { echo'<tr>'; echo'<td style="width: 100px">'.$rows[$dbColumnName1].'</td>'; //$dbColumnName is the name is the column in your database. echo'<td style="width: 100px">'.$rows[$dbColumnName2].'</td>'; echo'</tr>'; } </table></form></body> ?> This is how you refresh a page. But you don't need to do this because when you press the submit button it will reload the page automatically. But here's the code anyway for reference. echo "<meta http-equiv=\"refresh\" content=\"0;URL=../editHere.php\">"; Change the part that says ../editHere.php to match your directory and file name.
  16. Please provide more details. I'm confused about what you want to accomplish.
  17. I think your error is in this line of code. while($row = mysql_fetch_array($prd2)) Try this while($row = mysql_fetch_array($prd2, $i)) Or this if($row = mysql_fetch_array($prd2, $i)) I think your suppose to use an if statement in your case.
  18. I understand that if I use the primary key for anything at all wether it be linking tables together or using php code to manage tables by primary key that it would currupt the database. But if the primary key is not being used for any other reason besides to provide unique value to the database to work with, is there any problem with it? But yeah now that you say that there is no good reason to do this and I thought about it, I don't know why i spent 3 weeks developing this. I'm going to have to ponder a reason and get back to you if I come up with one.
  19. Woops! I'm an idiot. I said that wrong. What I ment to say is that it deletes a row but sql doesn't automatically insert the next row where there is a gap between auto incrementing primary keys. For example 123567. The number 4 was deleted from the database table. The next time you insert a row, it will become number 8. So my question... Question: Is there another way to get rid of those gaps in the database table.
  20. Hi. I was curious if anyone had any other methods of removing those NULL rows in a database table. If you don't use auto increment primary key for your database table then you don't have this problem. But if you do use auto increment primary key then when a row is deleted for whatever reason, sql will delete the row values of every column except the the primary key column. The primary key will remain and take up room in your database. I have heard that other developers export the database and create a new table and then import the database back in. That's how they solve this problem. I prefer using php code. But my question... Question: Is there another way to get rid of those NULL rows when using auto incrementing primary key in database table? PS: There is nothing wrong with the code below. It works. <?php // DATABASE PRIMARY KEY GAP FILLER // Developer: Ronnie Costa // Purpose: Cleans up the database table from all the NULL rows. // Explained: A database table with auto incrementing numbers as the primary key never deletes any primary keys. Not even if you delete a row from the table. You will just have row 5 for example and no other data will be present because it was deleted for whatever reason. This rearranges the rows to fill those empty gaps. // Directions: Modify the variable names to match the criteria of your database in includes dbConnect.php and dbTableName.php // Name this file dbPKGapFiller.php // Call this file from other php files like this <?php include 'dbPKGapFiller.php';?> include 'dbConnect.php'; // Must be deleted if already called by another php file that initiated dbConnect.php. include 'dbTableName.php'; // Must be deleted if already called by another php file that initiated dbTableName. // _____________________________ // DO NOT EDIT BELOW THIS LINE // _____________________________ $countFunction = "SELECT COUNT('$dbColumn1') AS num FROM $dbTableName"; // figures out how many rows there are in the database table. $data = mysql_query($countFunction) or die(mysql_error()); $row = mysql_fetch_assoc($data); $numRows = $row['num']; if ( $numRows > 1 ) // If there is more than one row in the database table, { $currentRow = 1; // Counter that is used to keep track of what row it left off on after it finishes updating a row. $PKIDvalue = $currentRow; // Counter that is used to update the current row in the database table. while ($currentRow <= $numRows) // While the counter hasn't reached the number of rows in the table, { $rowIDquery = mysql_query("SELECT * FROM $dbTableName WHERE $dbColumn1 = $PKIDvalue"); // Select the primary key($dbColumn1) that matches the number on the counter($PKIDvalue). $rowID = mysql_num_rows($rowIDquery); while ($rowID < 1) // While there is a NULL row in the database table, { $PKIDvalue = $PKIDvalue + 1; $rowIDquery = mysql_query("SELECT * FROM $dbTableName WHERE $dbColumn1 = $PKIDvalue"); $rowID = mysql_num_rows($rowIDquery); if ($rowID != 0) // If there is no primary key in the database table that matches the current counter number($PKIDValue), { mysql_query("UPDATE $dbTableName SET $dbColumn1=$currentRow WHERE $dbColumn1 = $PKIDvalue"); } } $currentRow = $currentRow + 1; // Increases the counter($currentRow) so that it can check the next row of the database table. $PKIDvalue = $currentRow; // Resets the counter($PKIDvalue) that is used to update the row in the database table. } } $reset = "ALTER TABLE $dbTableName AUTO_INCREMENT = 1"; mysql_query($reset); // Resets the primary key auto incrementor so that when it inputs a new row, it starts off in the new last row rather than the old one before it rearranged the rows. ?>
  21. <?php include 'dbConnect.php'; // Database Connection php file. include 'dbTableName.php'; // Contains 1 line of code. The name of your table in the database. I call it $dbTableName. include 'dbTableColumns.php'; // The names of all your columns in your database. Like your primary key is $dbColumn1. $qryDuplicateString = mysql_query("SELECT COUNT(*) AS count FROM $dbTableName WHERE $dbColumn2 = '$wsTextbox1' AND $dbColumn3 = '$wsDropDownList1'"); $duplicateRows = mysql_fetch_assoc($qryDuplicateString); $numOfRows = $duplicateRows['count']; if ($numOfRows<1) // If a row doesn't exist, {echo"Create Account";} else {echo"Choose alternative username";} ?> Hope this helps.
  22. Thank you Web Mason for your help. Got it working. SOLUTION $query = mysql_query("SELECT COUNT(*) AS count FROM $table WHERE $column3 = '127' AND $column5 = '555:555'"); $fetch = mysql_fetch_assoc($query); $numberOfRows = $fetch['count']; if ($numberOfRows>0) { echo"In IF: $numberOfRows </br>"; } else { echo"In else: $numberOfRows </br>"; }
  23. Forgot to mention what the problem was with this one. It is not entering the IF statement I think. $numRows says there is 2 rows. So if (2>0) should work no?
  24. Sorry I think I understand what you ment now but I'm not fully getting it. Here's what I came up with but it still not working. <?php $query = mysql_query("SELECT COUNT(*) AS count FROM $table WHERE $column3 = '127' AND $column5 = '555:555'"); $numRowsReferenceID = mysql_num_rows($query); $numRows = $numRowsReferenceID['count']; if ($numRows>0) { echo"Row exists!"; } else { echo"Row does not exist"; } echo"</br>TEST COMPLETE"; echo"Total Rows: $numRows"; // Says there is 2 rows ?>
  25. Yes you are right. If you type it directly into sql then it will return only 1 value. The value will be the number of rows that meet the criteria. But when you do it in php it will return a resource ID rather than the number. I'm trying to bypass it with mysql_num_rows.
×
×
  • 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.