Jump to content

Sigmahokies

Members
  • Posts

    90
  • Joined

  • Last visited

Everything posted by Sigmahokies

  1. Hello everyone I'm trying to remove a html tag option when detect string to match. For example, if string show "Apple" in produce list that is not available, so, remove this option. I tried to grey it out, seem it doesn't work very good. my code: $disable = "<option disable>String</option>"; $picktable = $GaryDB->prepare("SHOW TABLES"); $picktable->execute(); while($row6 = $picktable->fetch()) { if($row6[0] == "String") { $row6[0] = str_replace("<option>String</option>",$disable,"<option>String</option>"); } $pick .= "<option value='$row6[0]'>".$row6[0]."</option>"; } unless you have better logic to remove or grey it out... Thank you Gary
  2. Never mind! I found a solution! I used wrong method. Now, I corrected method, Now, it won't go to sub number anymore. If you want to see my solution, let me know, I can put in those code in next reply.
  3. No, that is not what I mean. I mean if there is 0 in field, do nothing. if more than 0, do something. I tried to put null, but it doesn't work. I need something method that do nothing to prevent message error in browser, because I put unsigned in field in the database. I put do something after else because it's not 0 in field. for example, In switch system, this method "break;" can stop the function. Now, I need something method to stop function when it comes to 0.
  4. Hi everyone, I'm trying to stop the programming to subtract more that will go to below from 0, I set up the unsigned in phpmyadmin, but it went sentence error if it come to -1 or below. I mean, if start with 3 or 4, then subtract by 1, till reach 0, then stop, I need something that can ignore program to subtract if it reach 0. for example: $sql = $GaryDB->prepare("SELECT howMany from bracelets"); $check = $sql->execute; if($check->rowCount() == 0) { No program in this function } else { do program } Get it? How you do that?
  5. There is a reference in url already. I set up the loop in link like this: bracelets.php?=bracelets earrings.php?=earrings kids.php?=kids necklaces.php?=necklaces rings.php?=rings then There is file name already - bracelets.php, earrings.php, kids.php, necklaces.php, and rings.php. So, $_GET should grab reference key from those string in URL, but it didn't. I think $_GET doesn't grab when it come with array. I used implode to convert array to string, but still not work.
  6. Hi everyone, I don't know why $_GET didn't get string from URL from another page. can you help? here my code: First page: <?php require("connection.php"); error_reporting(E_ALL); $sql = $GaryDB->prepare("SHOW TABLES"); $list = ""; $list2 = ""; $sql->execute(); while ($row = $sql->fetch()) { $list .= "<a href='$row[0].php?=$row[0]'>".$row[0]."</a><br />"; } ?> <!DOCTYPE HTML> <html lang="en"> <head> <title>Pinky's</title> <link href="paparazzi.png" rel="icon"> <style> * { font-family: Helvetica; text-decoration: none; } body { margin-left: 300px; margin-top: 100px; margin-right: 300px; } </style> </head> <body> <table> <tr><td>Please Select</td><td></td></tr> <tr><td><?php echo $list ?></td></tr> </table> </body> </html> link at left-bottom show localhost:8888/Braclets.php?=Braclet Then why can't $_GET get this strong "Bracelets"? next page: <?php require("connection.php"); $kids = $_GET['Kids']; echo $kids; $sql = $GaryDB->prepare("SELECT * FROM $kids"); echo $sql; ?>
  7. Yeah, ID exists, I put rowCount(), it said it is not successful. I don't see any error reporting...
  8. Yes, Select is successful. I tested it by echo quote SELECT before go to form. Problem is it won't get in database as updated. I should checked step by one, like update one, then next two, then next three...I'm trying to get used with PDO instead of mysqli because it's getting old. I can tell PDO is more easier than mysqli.
  9. Niche, There is no error show, even I put the error: $updatesql->execute() or die(print_r($updatesql->errorInfo(), true)); Still no show error. This method didn't update into database (Phpmyadmin)...
  10. Hello everyone I tried to create update site with PDO method, but not success. Can you help? I followed what instruct from w3school, but none of them are work. <?php include("connection.php"); if($_GET['update']) { $data = $_GET['update']; $prepare = "SELECT * FROM Members WHERE ID = $data"; $sql = $GaryDB->prepare($prepare); $sql->execute(); if($row = $sql->fetch()) { $form = "<tr><td>ID</td><td><input type='text' name='updated1' value='".$row['ID']."' readonly></td></tr> <tr><td>First Name:</td><td><input type='text' name='updated2' value='".$row['FirstName']."'></td></tr> <tr><td>Last name:</td><td><input type='text' name='updated3' value='".$row['LastName']."'></td></tr> <tr><td>Address:</td><td><input type='text' name='updated4' value='".$row['Address']."'></td></tr> <tr><td>State:</td><td><input type='text' name='updated5' value='".$row['State']."'></td></tr> <tr><td>Zip:</td><td><input type='text' name='updated6' value='".$row['Zip']."'></td></tr> <tr><td colspan='2' style='text-align: center'><input type='submit' name='submit' value='UPDATE'></td></tr>"; } } else { $form = "<tr><td>No ID in URL</td></tr>"; } if(isset($_POST['submit'])) { $id = $_POST['update1']; $first = $_POST['update2']; $last = $_POST['update3']; $address = $_POST['update4']; $state = $_POST['update5']; $zip = $_POST['update6']; $updatesql = $GaryDB->prepare("UPDATE Members SET FirstName = :first, LastName = :last, Address = :address, State = :state, Zip = :zip WHERE ID = :id"); $updatesql->bindParam(':id', $id, PDO::PARAM_INT); $updatesql->bindParam(':first', $first, PDO::PARAM_STR); $updatesql->bindParam(':last', $last, PDO::PARAM_STR); $updatesql->bindParam(':address', $address, PDO::PARAM_STR); $updatesql->bindParam(':state', $state, PDO::PARAM_STR); $updatesql->bindParam(':zip', $zip, PDO::PARAM_STR); $updatesql->execute(); if($updatesql->rowCount()) { $success = "<script>alert('success update')</script>"; } else { $success = "<script>alert('Not success update')</script>"; } } ?> <!DOCTYPE HTML> <html> <head> <title>Update site</title> <link href="red-sigma.png" rel="icon"> <link href="default.css" rel="stylesheet" type="text/css"> </head> <body> <a href='demonstration.php'>return to demonstration</a><br /> <h2>Welcome to Gary Taylor's Demonstration in update in database</h2> <?php echo $data ?> <?php echo $id, $first, $last, $address, $state, $zip; ?> <form action="update.php" method="post"> <table> <?php echo $form ?> <?php echo $success ?> </table> </form> </body> </html>
  11. Hi dsonesuk, I tried that, it won't work. I used session to save first call name from html to post, so i can use session string in second block in php to insert string in SQL syntax. I know it's not properly to do that, do you know how to save string for second block in php? It's about user pick table, then pick column in table that user picked. Like this: User pick name of table, then move this string word to SQL syntax, then user pick name of column, then move this strong to SQL syntax. Like - SELECT (picked name of column by user) FROM (picked name of table by user). Plus, how can you post as code form in this thread? I mean, screen of gray and courier font on display Thank you
  12. In HTML <table> <tr><td colspan="2">Sample of SELECT in column's name in table.</td></tr> <tr><td>SELECT <select name="col[]"> <?php echo $list ?> </select> FROM <?php echo $table2 ?></td><td><input type="submit" value="selected"></td></tr> </table> in PHP if (isset ($_POST['col'])) { $col = $_POST['col'][0]; $table3 = $_POST['col'][1]; $selsql = "SELECT $col FROM $table3"; /*$colquery = $GaryDB->query($selsql); while ($row2 = $colquery->fetch()) { $list2 .= "<tr><td>" . $row2[0] . "</td></tr>"; }*/ output: SELECT Name FROM (blank)
  13. No, add two dot before and after table2 is not solution. SQL syntax will not work. my original shows without dot is working. my point is name in select in html did not take two of them, just one took in.
  14. I said show tables work fine. my point is inside html, name in select didn't take TWO names. I set up array to take two. Like this: in HTML - <select name="col[]"> in PHP - $col = $_POST['col'][0]; $table3 = $_POST['col'][1]; so, it didn't take name col to second array to post, get it?
  15. I wish I can show you by record screen, but this forum limit to 500 KB
  16. I did that, show tables is work. it's what not work is name in html did not take two array to post, to send to SQL syntax. It took one name from, not two. my echo shows : Welcome to Gary Taylor's demonstration in PHP page. SELECT FirstName FROM Please select table: Memberscityuser_details Sample of SELECT in column's name in table. SELECT FROM SELECT FirstName FROM Look at "Select FirstName FROM" that's where table name is missing
  17. I was right, html shows table name didn't be post. how can I post table name? I used array to take two name to post, but it didn't work. Like this: select name="col[]", then, $col = $_POST['col][0]; $table3 = $_POST['col'][1]; but it didn't post from col 1
  18. Here you go <?php include("connection.php"); if(isset($mysqli_error)) { echo $mysqli_error; } $sqltable = "SHOW TABLES"; $querytable = $GaryDB->query($sqltable); while($row3 = $querytable->fetch()) { $table .= "<option value='$row3[0]'>" . $row3[0] . "</option>"; } if(isset($_POST['table'])) { $table2 = $_POST['table']; $sql = "SHOW COLUMNS FROM $table2 WHERE Field NOT IN ('id')"; $query = $GaryDB->query($sql); while ($row = $query->fetch()) { $list .= "<option value='$row[0]'>" . $row[0] . "</option>"; } } if (isset ($_POST['col'])) { $col = $_POST['col'][0]; $table3 = $_POST['col'][1]; $selsql = "SELECT $col FROM $table3"; $colquery = $GaryDB->query($selsql); while ($row2 = $colquery->fetch()) { $list2 .= "<tr><td>" . $row2[0] . "</td></tr>"; } } else { $list2 = "No column on table"; } ?> <html> <head> <title>Gary Taylor's demonstration PHP Page</title> </head> <body> <p>Welcome to Gary Taylor's demonstration in PHP page.</p> <br /> <form action="demonstration.php" method="post"> <table> <tr><td><?php echo $selsql ?></td></tr> <tr><td>Please select table: <select name="table"> <?php echo $table ?> </select></td><td><input type="submit" value="selected"></td></tr> </table> </form> <form action="demonstration.php" method="post"> <table> <tr><td colspan="2">Sample of SELECT in column's name in table.</td></tr> <tr><td>SELECT <select name="col[]"> <?php echo $list ?> </select> FROM <?php echo $table2 ?></td><td><input type="submit" value="selected"></td></tr> </table> </form> <table> <?php echo $list2 ?> </table> </body> </html>
  19. I think I know where it goes. I think second post didn't take from table name because it just took one name from second select, I added array into two Like this: <select name="col[]"> then $_POST['col'][0] && $_POST['col'][1]; is that incorrect? I mean, php put column name in, but it didn't put table name in SQL syntax
  20. Niche, I'm using PDO, not mysqli. I just set up the connection, it works perfectly, but I'm struggle with correct SQL syntax. like this: Fatal error: Uncaught PDOException: SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '' at line 1
  21. Hi everyone, I'm trying to create to select the name of table, then pick column in PHP, I succeed pick table, then put name table in variable, then put this variable to end of SQL syntax, then pick column name, then submit, but it went error by broke and violate of SQL syntax. Hey, It's not about SQL injection, this database is very useless. it's just practice. Can you help why it won't work? [php] $sqltable = "SHOW TABLES"; $querytable = $GaryDB->query($sqltable); while($row3 = $querytable->fetch()) { $table .= "<option value='$row3[0]'>" . $row3[0] . "</option>"; } if(isset($_POST['table'])) { $table2 = $_POST['table']; $sql = "SHOW COLUMNS FROM $table2 WHERE Field NOT IN ('id')"; $query = $GaryDB->query($sql); while ($row = $query->fetch()) { $list .= "<option value='$row[0]'>" . $row[0] . "</option>"; } } if(isset ($_POST['col'])){ $col = $_POST['col']; $selsql = "SELECT $col FROM $table2"; $colquery = $GaryDB->query($selsql); while ($row2 = $colquery->fetch()) { $list2 .= "<tr><td>" . $row2[0] . "</td></tr>"; } } else { $list2 = "No column on table"; } ?> <html> <head> <title>Gary Taylor's demonstration PHP Page</title> </head> <body> <p>Welcome to Gary Taylor's demonstration in PHP page.</p> <br /> <form action="demonstration.php" method="post"> <table> <tr><td><?php echo $selsql ?></td></tr> <tr><td>Please select table: <select name="table"> <?php echo $table ?> </select></td><td><input type="submit" name="submit2" value="selected"></td></tr> </table> </form> <form action="demonstration.php" method="post"> <table> <tr><td colspan="2">Sample of SELECT in column's name in table.</td></tr> <tr><td>SELECT <select name="col"> <?php echo $list ?> </select> FROM <?php echo $table2 ?></td><td><input type="submit" name="submit" value="selected"></td></tr> </table> </form> <table> <?php echo $list2 ?> </table> </body> </html> [/php] Thank you in advance times.
  22. dsonesuk, i forget to add .=, it showed now. Thank you!
  23. Hi everyone, I'm trying to use PDO to insert data in database, seem none of them success, it just breakdown after I click button to submit. what did I do wrong? [php] <?php /* check to see connection is working */ if(isset($_POST['submit'])) { $server = "localhost"; $username = "Sigma"; $password = ""; $dbname = "Register"; try { $connect = new PDO ("mysql:host=$server;dbname=$dbname", $username, $password); } catch (PDOException $error){ echo $error->getMessage(); } /* Insert data into database */ $firsts = $_POST['first']; $lasts = $_POST['last']; $town = $_POST['town']; $states = $_POST['state']; $zip = $_POST['zip']; $insert = "INSERT INTO `Members`(`firstName`, `lastName`, `town`, `states`, `zip`) VALUES (:firsts,:lasts,:town,:states,:zip)"; $result = $connect->prepare($insert); $result_run = $result->execute(array(":first"=>$firsts, ":last"=>$lasts, ":town"=>$town, ":state"=>$states, ":zip"=>$zip)); if($result_run) { echo '<script>alert("successfully added")"</script>'; } else { echo '<script>alert("failed added")"</script>'; } } ?> <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Gary's PDO website</title> <link rel="stylesheet" type="text/css" href="CSS/insert.css"> </head> <body> <p> <h2>Welcome to Gary Taylor's Demonstration</h2> <p> <h3>Insert Data in Database by PDO</h3> <form action="index.php" method="post"> <table> <tr><th colspan="2">Register here</th></tr> <tr><td>First Name:</td><td><label><input type="text" name="first" placeholder="Ex: Gary"> </label></td></tr> <tr><td>Last Name:</td><td><label><input type="text" name="last" placeholder="Ex: Taylor"> </label></td></tr> <tr><td>Town:</td><td><label><input type="text" name="town" placeholder="Ex: Richmond"> </label></td></tr> <tr><td>State:</td><td><label><input type="text" name="state" placeholder="Ex: VA"> </label></td></tr> <tr><td>Zip Code:</td><td><label><input type="text" name="zip" placeholder="Ex: 23238"> </label></td></tr> <tr><td colspan="2"><label><input type="submit" name="submit" value="Insert into database"></label></td></tr> </table> </form> </body> </html> [/php]
  24. Hello everyone, I'm trying to get abbreviate states from plain text into HTML select and option, seem it's not working. Can you help me? here my PHP code: /* Read file to insert as option in HTML */ $file = fopen("States.txt","r") or exit("Unable to read"); while(!feof($file)) { $states = fgets($file); $statelist = "<option value='".$states."'>".$states."</option>"; } fclose($file); Then <tr><td>State:</td><td><select id="abb" name="abb"><?php echo $statelist ?></select></td></tr> Thank you for help
×
×
  • Create New...