Jump to content

Search the Community

Showing results for tags 'insert'.

  • Search By Tags

    Type tags separated by commas.
  • Search By Author

Content Type


Forums

  • Welcome to PHP Freaks
    • Announcements
    • Introductions
  • PHP Coding
    • PHP Coding Help
    • Regex Help
    • Third Party Scripts
    • FAQ/Code Snippet Repository
  • SQL / Database
    • MySQL Help
    • PostgreSQL
    • Microsoft SQL - MSSQL
    • Other RDBMS and SQL dialects
  • Client Side
    • HTML Help
    • CSS Help
    • Javascript Help
    • Other
  • Applications and Frameworks
    • Applications
    • Frameworks
    • Other Libraries
  • Web Server Administration
    • PHP Installation and Configuration
    • Linux
    • Apache HTTP Server
    • Microsoft IIS
    • Other Web Server Software
  • Other
    • Application Design
    • Other Programming Languages
    • Editor Help (PhpStorm, VS Code, etc)
    • Website Critique
    • Beta Test Your Stuff!
  • Freelance, Contracts, Employment, etc.
    • Services Offered
    • Job Offerings
  • General Discussion
    • PHPFreaks.com Website Feedback
    • Miscellaneous

Find results in...

Find results that contain...


Date Created

  • Start

    End


Last Updated

  • Start

    End


Filter by number of...

Joined

  • Start

    End


Group


AIM


MSN


Website URL


ICQ


Yahoo


Jabber


Skype


Location


Interests


Age


Donation Link

  1. I have extensively searched the web for this but haven't found anything that can help! At the moment I have three loops: // loop 1 finds the answers if(isset($_POST['qanswer'])){ ($question = $_POST['qanswer']); for($i=0; $i < count($question); $i++) { echo "POSTED ANSWERS" . $question[$i] . "<br/>"; } } else { echo '<p style="color: Red">No Answers POSTED!</p>'; } // loop 2 finds the comments if(isset($_POST['canswer'])){ ($comment = $_POST['canswer']); for($i=0; $i < count($comment); $i++) { echo "POSTED COMMENTS" . $comment[$i] . "<br/>"; } } else { echo '<p style="color: Red">No Comments POSTED!</p>'; } // loop 3 combines the answers and comments for($x = 0; $x < count($comment); $x++){ if(isset($question[$x])){ $question[$x] = $question[$x] . ' ' . $comment[$x]; } } $result = $question; // saves the answers and comments as a string ($result) Each comment[$i] is the same key and $question[$i]. Inserting into the table i have: $query = "INSERT INTO audit_data (Q4101, Q4102, Q4103, Q4104, etc...) VALUES '$result[0]','$result[1]','$result[2]','$result[3]','$result[4]', etc...)"; mysqli_query($link, $query) or die(mysqli_error($link)." Q=".$query); 1) is this the best way to go about this? 2) It is nearly working, i can get the $question and $comment into the first columns for instance: $result[0] to result[10] but if i try to insert further on in the table say $result[40] to $result[50] i only get the $question values and no $comment values. I have looked at array_map and preg_match on the manual but not sure how or which one to use. I don't want the table normalized and i am aware of injection problems.
  2. Hello, I´m trying to insert data from a form into a mysql table using mysqli and php. I use the code below to connect to the database: $host = "myhost"; $db = "a5066994_tutors"; $user = "a5066994_tutors"; $pass = "mypassword"; $connection = mysqli_connect("$host", "$user", "$pass", "$db"); if ($connection->errno) { printf("Connect failed: %s\n", $connection->error); exit(); and the code below to insert: $stmt = $connection->prepare("INSERT INTO tutorials (Author, Website, Title, Body1, Body2, Body3, Body4, Subtitle1, Subtitle2, Subtitle3, Subtitle4, Category, WTitle, Userid) VALUES ('$author','$website', '$title', '$text1', '$text2', '$text3', '$text4', '$s1', '$s2', '$s3', '$s4', '$cat', '$wtitle', '$userid') "); And it results in this error: Call to a member function execute() on a non-object I have also tried doing a var dump of the connection, which results in: object(mysqli)#1 (0) { } and a var dump of the statement, which results in: bool(false) Any help would be great, thank you!
  3. Hi there! I've been having some trouble for quite some time now with a form. I have a table that I'm grabbing data from. I want to update multiple rows with a form. However, I have multiple text boxes under each row I want to update with only one submit button. When I press the submit button nothing happens. I'm not sure why. I've been having trouble with this forever, like I said. I would really, really like to get this done as it's holding me back from doing other things on my site. I will post the part of the code where I'm having the trouble. I don't think I will need to post the whole code since there are other parts of it that don't involve this at all. Here is the code: if($action == "stock") { $setprice = $_POST['price']; $updateprice = $_POST['updateprice']; echo "<a href=?action=edit>Edit Shop</a> | <a href=?action=view&user=$showusername>View Shop</a> | <a href=?action=stock>View Stock</a> | <a href=?action=quick>Quick Stock</a><br><br><font size=5>Stock Shop</font><br><br>"; $eq = "SELECT * FROM uitems WHERE username='$showusername' AND location='2' GROUP BY theitemid"; $ee = mysql_query($eq); while($erow = mysql_fetch_array($ee)) { $eeloc = $erow['location']; $eeid = $erow['theitemid']; $eenowid = $erow['uitemid']; $eeprice = $erow['price']; $wq = "SELECT * FROM items WHERE itemid='$eeid'"; $ww = mysql_query($wq); while($wrow = mysql_fetch_array($ww)) { $cq = mysql_query("SELECT * FROM uitems WHERE username='$showusername' AND location='2' AND theitemid='$eeid'"); $lcq = mysql_num_rows($cq); $fid = $wrow['itemid']; $fname = $wrow['name']; $fimage = $wrow['image']; $frarity = $wrow['rarity']; $fdesc = $wrow['description']; echo "<br>$fname<br><img src=/images/items/$fimage><br><br>"; ?> <input type="text" name="price" value="<?php echo "$eeprice"; ?>"><br></form> <?php } ?> <?php } ?> <br><br><input type="submit" name="updateprice" value="Update Prices"><br><br> <form action="<?php echo "$PHP_SELF"; ?>" method="POST"></form> <?php if(isset($setprice)) { mysql_query("UPDATE uitems SET price='$setprice' WHERE username='$showusername' AND theitemid='$fid'"); echo "<font color=green>Success! Your prices have been set and updated!</font><br><br>"; } } Before anybody says anything about it, I know my variable names are ridiculous.. so you don't even need to say that, lol. I have trouble naming my variable because I use so many in my codes. I'll have to come up with a better way to name them. Basically what this code is doing is grabbing the data with the specific location, displaying it and displaying the form. However, the form is not updating. Any help would be appreciative! Also, there was a time when the form DID work, but it did not update.... it just reloaded the page and left the text fields blank. Thanks again guys!
  4. I'm trying to include a checkbox group in a form submission. The user can check one, two, or all three of the choices. I need only the checked boxes to how can i do that? help me with a small example if possible so that i can nderstand well,plzzz. Thank you!
  5. Hello All, I have a data table with the columns firstname, lastname and rank. I am moving those values from that table into an archive table and the archive table has the same structure, but an additional date on the end. Obviously to tell the different between the repeating values. I have a query like this...... $insert = "INSERT INTO archive (firstname, lastname, rank) VALUES (SELECT firstname, lastname, era FROM old)"; How can I add the mysql command CURDATE() into that insert command? Can I add parentheses inside of the parentheses around the SELECT command?? Thanks in advance??
  6. Hi, I'm not new to Sql or PHP or atleast I hope not . I coded a simple register form in HTML and this file opens a 'newuser.php' which in turn opens another one, and another finally after checking all INPUT fields, reaches a 'enterintodb.php' . Now, here's the joke. Every field enters into the table of MySql except for the password field. All entries including 1st name, last name, etc etc. get added to the table and like I said , password doesn't add. Just to be sure, at the end I echo all the fields and then echo "New user created !" . No MySql error or any syntax error displayed. The password field echoes w/o any problems, it displays the entered password. But no entry in the DB . password column : varchar(255) , utf16_general_ci , Iv also attached the enterintodb.php file . the others don't matter, coz when I echo $password, it displays perfectly. in the form this is the password field " <input type="password" name="password" size="20" style="border-left-width=0px"> " and don't worry about sql auth, i run a separate PHP file for that before enterintodb.php So, guys, help me out please Here's the attachment = enterintodb.php
  7. I would like to update a table or insert if a specific combination of indices do not already exist. The table is very simple. CREATE TABLE `sessProdLnk` ( `products_id` varchar(20) NOT NULL, `sessions_id` varchar(255) NOT NULL, `qty` int(6) NOT NULL, KEY `products_id` (`products_id`), KEY `sessions_id` (`sessions_id`) ENGINE=MyISAM DEFAULT CHARSET=latin1 So, I would like to search for a match between my data, and any row in sessProdLnk where both the sessions_id and products_id match. Then I would like to update any entries in qty where they match, and insert a new row for any data pairs that do not have matches. I know some of this comparison may have to be done programmatically in the php script, but I am still getting to know MYSQL and was wondering how much of the work it will do for me given these parameters.
  8. Hi guys, I am using this code: function importCsv($file, $table) { $fieldseparator = ","; $lineseparator = "\n"; $fileOpen = fopen($file, "r"); $fileSzie = filesize($file); $fileContent = fread($fileOpen,$fileSize); fclose($fileOpen); $fileLines = 0; $fileQuiries = ""; $fileLineArray = array(); foreach(explode($lineseparator,$fileContent) as $fileLine) { $fileLines++; $fileLine = trim($fileLine," \t"); $fileLine = str_replace("\r","",$fileLine); $fileLine = str_replace("'","\'",$fileLine); $fileLineArray = explode($fieldseparator,$fileLine); $fileLineMySql = implode("','",$fileLineArray); $query = "INSERT INTO `$table` VALUES(NULL,'$fileLineMySql')"; $mysqli->query($query); } } My issue is that the field contains a comma (",") and this stuffs up the INSERT. How can I escape this comma so the code does not think it is a different mysql table column? Thanks in advance.
  9. Hi all, this my first post. I'd like to insert values of checkboxes as a string using a comma as a delimiter. So I have these checkboxes: <input type="checkbox" class="checkbox" name="box[]" value="1">One</input> <input type="checkbox" class="checkbox" name="box[]" value="2">Two</input> <input type="checkbox" class="checkbox" name="box[]" value="3">Three</input> Then I'd have a code like this, which is obviously wrong hence I wrote it for illustration only, it should also have an explode function for the delimiter: if (isset($_POST['box'])) { $newbox = array(); foreach($_POST['box'] as $boxArr){ array_push($newbox, $boxArr); } $query="INSERT INTO boxesTable (boxes) VALUES ('$newbox')"; } Any help would be much appreciated.
×
×
  • 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.