PHP - Inserting Data From Dropdown Into Mysql Table
Hello there! I've been banging my head on this for a while and I just can't seem to get it to work properly. I have a dropdown menu which selects information from table1 using a select statement (this table is called 'lid'). It selects the firstname, lastname and member id from this table and shows it in the dropdown menu. I'm glad I got that part working but the hard thing is inserting the data that the user selects into another table. So when you select the id member from this dropdown menu it only inserts a blank row into table2 (which is called 'teamlid'). Can you guys help me? How can I insert the id member into my table2? What am I doing wrong here? Thanks a million! This is my first post so if I'm doing anything wrong, let me know and I'll fix it asap! My code: <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Boast & Drive</title> <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.css"> <style type="text/css"> .wrapper{ width: 650px; margin: 0 auto; } .page-header h2{ margin-top: 0; } table tr td:last-child a{ margin-right: 15px; } </style> </head> <body> <div class="container-fluid"> <div class="row"> <div class="col-md-12"> <div class="page-header clearfix"> <h2 class="pull-left">Teamleden</h2> <div class="btn-toolbar"> <a href="read.php" class="btn btn-primary btn-lg pull-right">Terug</a> </div> </div> <?php mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT); error_reporting(E_ALL); //Verbinding maken met de database require_once "login.php"; $sql = "SELECT tl.teamnaam, tl.tl_ID, tl.lidnummer, l.voornaam, l.achternaam FROM teamlid tl JOIN lid l ON tl.lidnummer = l.lidnummer ORDER BY tl.teamnaam;"; if($result = mysqli_query($conn, $sql)) { if(mysqli_num_rows($result) > 0) { echo "<table class='table table-bordered table-striped'>"; echo "<thead>"; echo "<tr>"; echo "<th>Teamnaam</th>"; echo "<th>Tl_ID</th>"; echo "<th>Lidnummer</th>"; echo "<th>Voornaam</th>"; echo "<th>Achternaam</th>"; echo "</tr>"; echo "</thead>"; echo "<tbody>"; while($row = mysqli_fetch_array($result)){ echo "<tr>"; echo "<td>" . $row['teamnaam'] . "</td>"; echo "<td>" . $row['tl_ID'] . "</td>"; echo "<td>" . $row['lidnummer'] . "</td>"; echo "<td>" . $row['voornaam'] . "</td>"; echo "<td>" . $row['achternaam'] . "</td>"; echo "<td>"; echo "<a href='update.php?id=". $row['lidnummer'] ."' title='Gegevens wijzigen' data- toggle='tooltip'><span class='glyphicon glyphicon-pencil'></span></a>"; echo "<a href='delete.php?id=". $row['lidnummer'] ."' title='Lid verwijderen' data- toggle='tooltip'><span class='glyphicon glyphicon-trash'></span></a>"; echo "</td>"; echo "</tr>"; } echo "</tbody>"; echo "</table>"; mysqli_free_result($result); } else{ echo "<p class='lead'><em>Er zijn geen gegevens om weer te geven.</em></p>"; } } else{ echo "De volgende fout is gevonden: " . mysqli_error($conn); } ?> <form name="dropdown" method="post"> <div class="page-header clearfix"> <h2 class="pull-left">Teamlid toevoegen</h2> </div> <p>Selecteer hieronder met behulp van het dropdown menu een lid welke je aan bovenstaand team wilt toevoegen</p> <div class="container-fluid"> <div class="row"> <?php // Variabelen aanmaken en tonen met lege waardes $teamnaam = $lidnummer = ''; // Code voor dropdown. Selecteert voornaam, achternaam en lidnummer van tabel lid) $sql = "SELECT voornaam, achternaam, lidnummer FROM lid ORDER BY achternaam"; $result = mysqli_query($conn, $sql); echo "<select id='teamLid' name='teamLid'>"; echo "<option>--Selecteer Lid--</option>"; while ($row = mysqli_fetch_array($result)) { echo "<option value='" . $row['lid'] . "'>" . $row['voornaam'] . " " . $row['achternaam'] . " " . $row['lidnummer'] . "</option>"; } echo "</select>"; if (isset($_POST["id"]) && !empty($_POST["id"])) { $id = $_POST["teamLid"]; $stmt = $conn->prepare("INSERT INTO teamlid (teamnaam, lidnummer) VALUES (?,?)"); $stmt->bind_param('si', $param_teamnaam, $param_lidnummer); $param_teamnaam = $teamnaam; $param_lidnummer = $lidnummer; $stmt->execute(); } // Verbinding sluiten mysqli_close($conn); ?> <div> <input type="hidden" name="id" value="<?php echo $id; ?>" /> <input type="submit" name="submit" class="btn btn-primary" value="Toevoegen"> </div> </div> </div> </form> </div> </div> </body> </html>
Similar Tutorialsi want insert data from text box in html form.there are many text boxes gave name using 2 loops..please tell how can insert data to table?please reply Stuck again on simple code. I am trying to insert some fields extracted from one table into another. I'm using code that worked elsewhere. The SQL statement flies, the script runs, the input array is printed back I get an echo back from the end of the script but nothing is added to the table. Even aded an echo print_r in the conditional and I know the data is getting to the execute command. The script follows with a sample of the input array. I have attached am image of the table I am trying to insert the data into. --Kenoli The script: <?php require '__classes/DB.php'; $sql = "SELECT name, table_id, image_name, description, medium FROM tbl_person_data "; $stmt = $pdo->query($sql); $array1 = $stmt->fetchall(PDO::FETCH_ASSOC); $stmt = $pdo->prepare("INSERT INTO Images (name, person_id, filename, description, medium) VALUES (?,?,?,?,?)"); //$pdo->beginTransaction(); foreach ($array1 as $row) { $stmt->execute($row); } echo "<pre>"; print_r ($row); echo "</pre>"; echo '<h4>Got to end of file</h4>'; ?> $array1: The input array [0] => Array ( [name] => Carol Lettko [table_id] => 21 [image_name] => Carol_Lettko-DSC_3022.jpg [description] => Baby Herons/Brickyard [medium] => photo ) [1] => Array ( [name] => [table_id] => 22 [image_name] => Carol_Lettko-DSC_0164.JPG [description] => Heron/Brickyard [medium] => photo ) [2] => Array ( [name] => [table_id] => 23 [image_name] => Carol_Lettko-IMG_5723.jpg [description] => Kayaker/Brickyard [medium] => photo )
hello dear experts
good day dear friend - i need your help. import urllib import urlparse import re # import peewee import json from peewee import * #from peewee import MySQLDatabase ('cpan', user='root',passwd='rimbaud') db = MySQLDatabase('cpan', user='root',passwd='rimbaud') class User(Model): name = TextField() cname = TextField() email = TextField() url = TextField() class Meta: database = db # this model uses the cpan database User.create_table() #ensure table is created url = "http://search.cpan.org/author/?W" html = urllib.urlopen(url).read() for lk, capname, name in re.findall('<a href="(/~.*?/)"><b>(.*?)</b></a><br/><small>(.*?)</small>', html): alk = urlparse.urljoin(url, lk) data = { 'url':alk, 'name':name, 'cname':capname } phtml = urllib.urlopen(alk).read() memail = re.search('<a href="mailto:(.*?)">', phtml) if memail: data['email'] = memail.group(1) data = json.load('email') #your json data file here for entry in data: #assuming your data is an array of JSON objects user = User.create(name=entry["name"], cname=entry["cname"], email=entry["email"], url=entry["url"]) user.save() guess that there a data-file must exist: one that have been created by the script during the parsing... is this right? ) martin@linux-70ce:~/perl> python cpan_100.py Traceback (most recent call last): File "cpan_100.py", line 47, in <module> data = json.load('email') #your json data file here File "/usr/lib/python2.7/json/__init__.py", line 286, in load return loads(fp.read(), AttributeError: 'str' object has no attribute 'read' martin@linux-70ce:~/perl> this script does not work ) martin@linux-70ce:~/perl> python cpan_100.py Traceback (most recent call last): File "cpan_100.py", line 47, in <module> data = json.load('email') #your json data file here File "/usr/lib/python2.7/json/__init__.py", line 286, in load return loads(fp.read(), AttributeError: 'str' object has no attribute 'read' martin@linux-70ce:~/perl>well i suppose that in the first part of the script - the parser - part we parse data and - therefore we should create a file. I guess that this file is taken up within the second part of the script... load data . well why the script does not work!? hello friends, actually i am trying to insert data in mysql database. here is my code <?php include_once("../includes/database.php"); ?> <!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"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Insert Product</title> </head> <body> <form action="insert_product.php" method="post" enctype="multipart/form-data"> <table align="center" width="600"> <tr align="center"> <td colspan="8"><h2> Insert New Post</h2></td> </tr> <tr> <td align="right"><b>Product Title :</b></td> <td><input type="text" name="product_title" size="50" style="background-color:#06C; color:#FFF" /></td> </tr> <tr> <td align="right"><b>Product Category :</b></td> <td> <select name="product_cat" style="background-color:#06C; color:#FFF" > <option>Select A Category </option> <?php $get_cats = "SELECT * FROM categories"; $run_cats = mysqli_query($con, $get_cats); while($row_cats = mysqli_fetch_array($run_cats)){ $cat_id = $row_cats['cat_id']; $cat_title = $row_cats['cat_title']; echo "<option value='$cat_id'>$cat_title</option>"; } ?> </select> </td> </tr> <tr> <td align="right"><b>Product Platform :</b></td> <td> <select name="product_brand" style="background-color:#06C; color:#FFF" > <option>Select A Platform </option> <?php $get_brands = "SELECT * FROM brands"; $run_brands = mysqli_query($con, $get_brands); while($row_brands = mysqli_fetch_array($run_brands)){ $brand_id = $row_brands['brand_id']; $brand_title = $row_brands['brand_title']; echo "<option value='$brand_id'>$brand_title</option>"; } ?> </select> </td> </tr> <tr> <td align="right"><b>Product Image :</b></td> <td><input type="file" name="product_image" /></td> </tr> <tr> <td align="right"><b>Product Price :</b></td> <td><input type="text" name="product_price" style="background-color:#06C; color:#FFF" /></td> </tr> <tr> <td align="right" valign="top"><b>Product Description :</b></td> <td><textarea name="product_desc" cols="50" rows="10" style="background-color:#06C; color:#FFF" ></textarea></td> </tr> <tr> <td align="right"><b>Product Keywords :</b></td> <td><input type="text" name="product_keywords" size="50" style="background-color:#06C; color:#FFF" /></td> </tr> <tr align="center"> <td colspan="8"><input type="submit" name="insert_post" value="Submit Now" /></td> </tr> </table> </form> </body> </html> <?php if(isset($_POST['insert_post'])){ $product_title = $_POST['product_title']; $product_cat = $_POST['product_cat']; $product_brand = $_POST['product_brand']; $product_price = $_POST['product_price']; $product_desc = $_POST['product_desc']; $product_keywords = $_POST['product_keywords']; $product_image = $_FILES['product_image']['name']; $product_image_tmp = $_FILES['product_image']['tmp_name']; move_uploaded_file($product_image_tmp,"product_image/$product_image"); $sql = "INSERT INTO products (product_cat,product_brand,product_title,product_price,product_desc,product_image,product_keywords) VALUES ('$product_cat','$product_brand','$product_title','$product_price','$product_desc','$product_image','$product_keywords')"; $query = mysqli_query($con, $sql); if($query){ echo "<script>alert('Product Has Been Inserted')</script>"; echo "<script>windoow.open('insert_product.php','_self')</script>"; exit(); }else{ echo "<script>alert('errror')</script>"; } } ?>but somehow its not inserting data into my table can somebody tell wherre m i doing mistake. the categories and brands are displaying from database. But its not inserting data here is my database script. <?php $con = mysqli_connect("localhost","root","","sg"); ?> Hello, I'm having trouble inserting data into a MySQL table. The user has a form which is HEIGHT and WIDTH and NUMBER_OF_OBSERVATIONS. All these values are stored in the same table. NUMBER_OF_OBSERVATIONS does what it needs to and inserts its calculated results into the database, as does DATE_TIME. I've been trying for a couple of days to get this done, and I am having no luck in getting it sorted. Any help is greatly appreciated! Generator.php Code: [Select] $WIDTH = $_POST['WIDTH']; $HEIGHT = $_POST['HEIGHT']; $NUMBER_OF_OBSERVATIONS = $_POST['NUMBER_OF_OBSERVATIONS']; $db1 = new Number_Information(); $db1->openDB(); $OBSERVATION_ID = $db1->insert_Observation(); echo "<br /><br />Success. ID: <strong>$OBSERVATION_ID<strong>"; $db1->closeDB(); Number_Information.php Code: [Select] function insert_Observation() { //$Date_Now = datetime(); $sql = "INSERT INTO Observations (DATE_TIME, HEIGHT, WIDTH) VALUES (NOW(), '{$esc_HEIGHT}','{$esc_WIDTH}' )"; $result = mysql_query($sql, $this->conn); if (!$result) { die("SQL Insertion error: " . mysql_error()); } else { return mysql_insert_id($this->conn); } The table name is Observations Again - Any help is greatly appreciated! I want to take data from one table and insert it into another in the same database, the problem is the two tables have different values so it wouldn't be as simple as using an INSERT INTO script. From table 1 I want to extract a row ID as well as a field called systems. I then want to insert that into the second table which is structured, Id (null) Name (games) Value (the data given from Systems in the other) ID2 (the ID from the other table) Category (news) Any ideas how I can go about this? Hello, me again. I have created a little forum - very very basic. main_forum.php : Code: [Select] <?php $host="localhost"; // Host name $username="yvonnedp"; // Mysql username $password="yvonne"; // Mysql password $db_name="forum"; // Database name $tbl_name="forum_question"; // Table name // Connect to server and select databse. mysql_connect('localhost', 'yvonnedp', 'yvonne')or die("cannot connect"); mysql_select_db("$db_name")or die("cannot select DB"); $sql="SELECT * FROM $tbl_name ORDER BY id"; // OREDER BY id DESC is order result by descending $result=mysql_query($sql); ?> <table width="90%" border="0" align="center" cellpadding="3" cellspacing="1" bgcolor="#CCCCCC"> <tr> <td width="6%" align="center" bgcolor="#E6E6E6"><strong>#</strong></td> <td width="53%" align="center" bgcolor="#E6E6E6"><strong>Topic</strong></td> <td width="15%" align="center" bgcolor="#E6E6E6"><strong>Views</strong></td> <td width="13%" align="center" bgcolor="#E6E6E6"><strong>Replies</strong></td> <td width="13%" align="center" bgcolor="#E6E6E6"><strong>Date/Time</strong></td> </tr> <?php while($rows=mysql_fetch_array($result)){ // Start looping table row ?> <tr> <td bgcolor="#FFFFFF"><? echo $rows['id']; ?></td> <td bgcolor="#FFFFFF"><a href="view_topic.php?id=<? echo $rows['id']; ?>"><? echo $rows['topic']; ?></a><BR></td> <td align="center" bgcolor="#FFFFFF"><? echo $rows['view']; ?></td> <td align="center" bgcolor="#FFFFFF"><? echo $rows['reply']; ?></td> <td align="center" bgcolor="#FFFFFF"><? echo $rows['datetime']; ?></td> </tr> <?php // Exit looping and close connection } mysql_close(); ?> create_topic.php : Code: [Select] <table width="400" border="0" align="center" cellpadding="0" cellspacing="1" bgcolor="#CCCCCC"> <tr> <form id="form1" name="form1" method="post" action="add_topic.php"> <td> <table width="100%" border="0" cellpadding="3" cellspacing="1" bgcolor="#FFFFFF"> <tr> <td colspan="3" bgcolor="#E6E6E6"><strong>Create New Topic</strong> </td> </tr> <tr> <td width="14%"><strong>Topic</strong></td> <td width="2%">:</td> <td width="84%"><input name="topic" type="text" id="topic" size="50" /></td> </tr> <tr> <td valign="top"><strong>Detail</strong></td> <td valign="top">:</td> <td><textarea name="detail" cols="50" rows="3" id="detail"></textarea></td> </tr> <tr> <td><strong>Name</strong></td> <td>:</td> <td><input name="name" type="text" id="name" size="50" /></td> </tr> <tr> <td> </td> <td> </td> <td><input type="submit" name="Submit" value="Submit" /> <input type="reset" name="Submit2" value="Reset" /></td> </tr> </table> </td> </form> </tr> </table> add_topic.php : Code: [Select] <?php $host="localhost"; // Host name $username="yvonnedp"; // Mysql username $password="yvonne"; // Mysql password $db_name="forum"; // Database name $tbl_name="forum_question"; // Table name // Connect to server and select database. mysql_connect('localhost', 'yvonnedp', 'yvonne')or die("cannot connect"); mysql_select_db("$db_name")or die("cannot select DB"); // get data that sent from form $topic=$_POST['topic']; $detail=$_POST['detail']; $name=$_POST['name']; $datetime=date("d/m/y h:i:s"); //create date time $sql="INSERT INTO $tbl_name(topic, detail, name, datetime)VALUES('$topic', '$detail', '$name', '$datetime')"; $result=mysql_query($sql); if($result){ echo "Successful<BR>"; echo "<a href=main_forum.php>View your topic</a>"; $email_from = "forums@thenewme.co.za"; $email_to = "info@thenewme.co.za"; $email_subject = "The New Me - New Forum Topic"; $email_message = "A new topic has been posted on the Forum!\n"; $email_message .= "Check it out : http://www.thenewme.co.za/forum/main_forum.php"; $headers = 'From: '.$email_from."\r\n"; 'Reply-To: '.$email_from."\r\n" . 'X-Mailer: PHP/' . phpversion(); @mail($email_to, $email_subject, $email_message, $headers); } else { echo "ERROR"; } mysql_close(); ?> add_answer.php : Code: [Select] <?php $host="localhost"; // Host name $username="yvonnedp"; // Mysql username $password="yvonne"; // Mysql password $db_name="forum"; // Database name $tbl_name="forum_answer"; // Table name // Connect to server and select databse. mysql_connect('localhost', 'yvonnedp', 'yvonne')or die("cannot connect"); mysql_select_db("$db_name")or die("cannot select DB"); // Get value of id that sent from hidden field $id=$_POST['id']; // Find highest answer number. $sql="SELECT MAX(a_id) AS Maxa_id FROM $tbl_name WHERE question_id='$id'"; $result=mysql_query($sql); $rows=mysql_fetch_array($result); // add + 1 to highest answer number and keep it in variable name "$Max_id". if there no answer yet set it = 1 if ($rows) { $Max_id = $rows['Maxa_id']+1; } else { $Max_id = 1; } // get values that sent from form $a_name=$_POST['a_name']; $a_answer=$_POST['a_answer']; $datetime=date("d/m/y H:i:s"); // create date and time // Insert answer $sql2="INSERT INTO $tbl_name(question_id, a_id, a_name, a_answer, a_datetime)VALUES('$id', '$Max_id', '$a_name', '$a_answer', '$datetime')"; $result2=mysql_query($sql2); if($result2){ echo "Successful<BR>"; echo "<a href='view_topic.php?id=".$id."'>View your answer</a>"; // If added new answer, add value +1 in reply column $tbl_name2="forum_question"; $sql3="UPDATE $tbl_name2 SET reply='$Max_id' WHERE id='$id'"; $result3=mysql_query($sql3); $email_from = "forums@thenewme.co.za"; $email_to = "info@thenewme.co.za"; $email_subject = "The New Me - New Forum Answer"; $email_message = "A new answer to a forum topic has been posted on the Forum!\n"; $email_message .= "Check it out : http://www.thenewme.co.za/forum/main_forum.php"; $headers = 'From: '.$email_from."\r\n"; 'Reply-To: '.$email_from."\r\n" . 'X-Mailer: PHP/' . phpversion(); @mail($email_to, $email_subject, $email_message, $headers); } else { echo "ERROR"; } mysql_close(); ?> view_topic : Code: [Select] <?php $tbl_name2="forum_answer"; // Switch to table "forum_answer" $sql2="SELECT * FROM $tbl_name2 WHERE question_id='$id'"; $result2=mysql_query($sql2); while($rows=mysql_fetch_array($result2)){ ?> <table width="400" border="0" align="center" cellpadding="0" cellspacing="1" bgcolor="#CCCCCC"> <tr> <td><table width="100%" border="0" cellpadding="3" cellspacing="1" bgcolor="#FFFFFF"> <tr> <td bgcolor="#F8F7F1"><strong>ID</strong></td> <td bgcolor="#F8F7F1">:</td> <td bgcolor="#F8F7F1"><? echo $rows['a_id']; ?></td> </tr> <tr> <td width="18%" bgcolor="#F8F7F1"><strong>Name</strong></td> <td width="5%" bgcolor="#F8F7F1">:</td> <td width="77%" bgcolor="#F8F7F1"><? echo $rows['a_name']; ?></td> </tr> <tr> <td bgcolor="#F8F7F1"><strong>Answer</strong></td> <td bgcolor="#F8F7F1">:</td> <td bgcolor="#F8F7F1"><? echo $rows['a_answer']; ?></td> </tr> <tr> <td bgcolor="#F8F7F1"><strong>Date/Time</strong></td> <td bgcolor="#F8F7F1">:</td> <td bgcolor="#F8F7F1"><? echo $rows['a_datetime']; ?></td> </tr> </table></td> </tr> </table><br> <? } $sql3="SELECT view FROM $tbl_name WHERE id='$id'"; $result3=mysql_query($sql3); $rows=mysql_fetch_array($result3); $view=$rows['view']; // if have no counter value set counter = 1 if(empty($view)){ $view=1; $sql4="INSERT INTO $tbl_name(view) VALUES('$view') WHERE id='$id'"; $result4=mysql_query($sql4); } // count more value $addview=$view+1; $sql5="update $tbl_name set view='$addview' WHERE id='$id'"; $result5=mysql_query($sql5); mysql_close(); ?> the problem is. With add_answer, I am not able to insert an answer. This has worked for the very first question, but all subsequent questions, I am unable to add answers. It keeps telling me ERROR. This is where the live forum is : http://www.thenewme.co.za/forum/main_forum.php Can it be an issue with the field that gets autmatically incremented? i have echo'd the data which get entered in when someone types in an answer, and everything is perfect! Can anyone help me? I'm sorry to be back so soon, but I'm up against another mystery. I'm using the code below to enter a bunch of css data from a spreadsheet into a mysql table. I think the data file is OK. The array created by the script checks out with print_r. (There are many more records than shown. I truncated it to save space.) The problem is that I get this error regarding my sql statement, not the data or anything else: 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 'check, name, phone, email, entry_fee, print_fee, image_name, description, med...' at line 1 in /Users/studio/Sites/BannerProject/b-as/_test_site/csv_to_array.php:242 Stack trace: #0 /Users/studio/Sites/BannerProject/b-as/_test_site/csv_to_array.php(242): PDO->prepare('INSERT INTO tbl...') #1 {main} thrown in /Users/studio/Sites/BannerProject/b-as/_test_site/csv_to_array.php on line 242 I've typed it in a dozen times to make sure there are no errors and keep getting the same error. I tried running a test file and gradually increasing the number of placeholders and at some point I always end up getting the same error, I can delete the most recent addition and it works again. Then I can add another placeholder exactly as before and it works the second time. It feels like a ghost in the machine. Any idea what I am doing wrong? An I typing something I don't see? <?php require '__classes/Db.php'; $csvData = '1,FALSE,Carol Lettko,,,TRUE,FALSE,Carol_Lettko-DSC_3022.jpg,Baby Herons/Brickyard,photo,,, ,,,925-285-0320,cjl164@aol.com,,,Carol_Lettko-DSC_0164.JPG,Heron/Brickyard,photo,,, ,,,,,,,Carol_Lettko-IMG_5723.jpg,Kayaker/Brickyard,photo,,, ,,,,,,,,,,,, 2,FALSE,Louise Williams,,,TRUE,FALSE,Louise_Williams-BirdsOfAFeatherAOPR.jpg,Alligator with Words,Book Excerpt,,, ,,,510-232-9547,lkw@louisekwilliams.com,,,Louise_Williams-Hope-TheFairyChickenAOPR.jpg,Hope The Fairy Chicken,,,, ,,,The d exatrfrfvct/.*tygrvurr,,,,,,,,, ,,,,,,,,,,,, 3,TRUE,Dorothy Leeland,,lelanddorothy@gmail.com,TRUE,FALSE,DJ_Lee-bridge at dusk 700px width.jpg,Bridge,photo,,, ,,,,,,,DJ_Lee-friends 700px width.jpg,Friends,photo,,, ,,,,,,,DJ_Lee-hybiscus 700 px wide.jpg,Hibiscus,photo,,, ,,,,,,,,,,,, 4,FALSE,Rita Gardner,,,TRUE,FALSE,Rita_Gardner-Explosion - Gardner photo.JPG,Explosion,photo,,, ,,,,tropicrita@msn.com,,,Rita_Gardner-Ferry Point tables and chair - Gardner.JPG,Ferry Point Tables,photo,, , ,,,,,,,Rita_Gardner-Forks - Gardner photo.JPG,Forks,photo,,, ,,,,,,,,,,,, '; $lines = explode(PHP_EOL, $csvData); $array1 = array(); foreach ($lines as $line) { $array1[] = str_getcsv($line); } $stmt = $pdo->prepare("INSERT INTO tbl_person_data (number, check, name, phone, email, entry_fee, print_fee, image_name, description, medium, select, orient, site) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?)"); foreach ($array1 as $row) { $stmt->execute('$row'); } echo '<pre>'; print_r($array1); echo '</pre>'; ?>
Hi all, I'm trying to display a form based on a dropd own selection. The drop down is propagated from a database query. I have the drop down list displaying, but when I click submit, I can't get the result to display. Code: [Select] $sql="SELECT id, company_name FROM webprojects ORDER BY company_name ASC"; $result=mysql_query($sql); $options=""; while ($row=mysql_fetch_array($result)) { $id=$row["id"]; $company_name=$row["company_name"]; $options.="<OPTION VALUE=\"$id\">".$company_name; } ?> <!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"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>PHP Dynamic Drop Down Menu</title> </head> <body> <form id="form1" name="form1" method="post" action="selected.php"> <SELECT NAME=id> <OPTION VALUE=0>Choose <?=$options.="<OPTION VALUE=\"$id\">".$company_name.'</option>';?> </SELECT> <label> <input type="submit" name="submit" id="submit" value="Submit" /> </label> </form> </body> </html> Any help is greatly appreciated Hi? im just a beginner in php i just want to ask how to insert a data into a table from a dropdown list. I have concatenate the itemid and description to form the dropdown list. But when i viewed my item_table the itemid and description columns are null. can you help me with this.. this is my php code for the dropdown list... <?php $query = "SELECT CONCAT(itemid,' ', '-',' ', description) AS Item FROM item_table"; $result = mysql_query($query) or die(mysql_error()); $dropdown = "<SELECT CONCAT(itemid,' ' '-',' ', description) AS Item FROM item_table>"; while($row = mysql_fetch_assoc($result)) { $dropdown .= "\r\n<option value='{$row['Item']}'>{$row['Item']}</option>"; } $dropdown .= "\r\n</select>"; echo $dropdown; ?> this my code for inserting data into the item_table... <?php if(isset($_POST ['submit'])) { $itemid = $_POST['itemid']; $description = $_POST['description']; $datein = $_POST['datein']; $qtyin = $_POST['qtyin']; $unitprice = $_POST['unitprice']; $unit = $_POST['unit']; $category = $_POST['category']; $empid = $_POST['empid']; $message =''; if(($itemid && $description == "")||($itemid && $description == null)) { header("location:IncomingEntry.php?msg=Incorrect"); exit(); } else { $link = mysql_connect('localhost', 'root', '') or die(mysql_error()); $db_selected = mysql_select_db('inventory', $link); $message=''; $query = "INSERT INTO incoming_table (itemid , description, datein, qtyin, unitprice, unit, category, empid) VALUES ('".$itemid."', '".$description."', '".$datein."', '".$qtyin."', '".$unitprice."', '".$unit."', '".$category."', '".$empid."')"; if (!mysql_query($query,$link)) { die('Error: ' . mysql_error()); } header("location: IncomingEntry.php?msg=1 record added"); } } ?> Hi, I don know how to explain this in words too well, so i have create 2 images to show what I need. What I need to do is use whats in the first image (table.jpg)(the database) to create whats in the second image (dropdown.jpg)(the drop-down menu) The results of the form will be entered into the database. category_id will be the value thats inserted. Many kind regards Eoin [attachment deleted by admin] Hello to all, I have problem figuring out how to properly display data fetched from MySQL database in a HTML table. In the below example I am using two while loops, where the second one is nested inside first one, that check two different expressions fetching data from tables found in a MySQL database. The second expression compares the two tables IDs and after their match it displays the email of the account holder in each column in the HTML table. The main problem is that the 'email' row is displayed properly while its while expression is not nested and alone(meaning the other data is omitted or commented out), but either nested or neighbored to the first while loop, it is displayed horizontally and the other data ('validity', 'valid_from', 'valid_to') is not displayed.'
Can someone help me on this, I guess the problem lies in the while loop? <thead> <tr> <th data-column-id="id" data-type="numeric">ID</th> <th data-column-id="email">Subscriber's Email</th> <th data-column-id="validity">Validity</th> <th data-column-id="valid_from">Valid From</th> <th data-column-id="valid_to">Valid To</th> </tr> </thead> Here is part of the PHP code:
<?php while($row = $stmt->fetch(PDO::FETCH_ASSOC)) { echo ' <tr> <td>'.$row["id"].'</td> '; while ($row1 = $stmt1->fetch(PDO::FETCH_ASSOC)) { echo ' <td>'.$row1["email"].'</td> '; } if($row["validity"] == 1) { echo '<td>'.$row["validity"].' month</td>'; }else{ echo '<td>'.$row["validity"].' months</td>'; } echo ' <td>'.$row["valid_from"].'</td> <td>'.$row["valid_to"].'</td> </tr>'; } ?>
Thank you. hello. i have an issue where the data stored with an image is not saving to a mysql table. the image data is ok, just not the selections from the dropdown lists. here is the code <?php include ('connect.php'); // Insert any new image into database if(isset($_POST['xsubmit']) && $_FILES['imagefile']['name'] != "") { $fileName = $_FILES['imagefile']['name']; $fileSize = $_FILES['imagefile']['size']; $fileType = $_FILES['imagefile']['type']; $content = addslashes (file_get_contents($_FILES['imagefile']['tmp_name'])); $jeweltype = $_POST['jeweltype']; $jewelsize = $_POST['jewelsize_in']; $jewelcolour = $_POST['jewelcolour_in']; $jewelmaterial = $_POST['jewelmaterial_in']; $jewelgender = $_POST['jewelgender_in']; if(!get_magic_quotes_gpc()) { $fileName = addslashes($fileName); } // Checking file size if ($fileSize < 150000) { mysql_query ("INSERT into jewel_images (name,size,type,content,jeweltype,jewelsize,jewelcolour,jewelmaterial,jewelgender) " . "values ('$fileName','$fileSize','$fileType','$content','$jeweltype','$jewelsize','$jewelcolour','$jewelmaterial','$jewelgender')"); } else { $err = "The Image file to too large!"; } } // Find out about latest image $gotten = mysql_query("select * from jewel_images order by row_id desc"); $row = mysql_fetch_assoc($gotten); $bytes = $row['content']; // If this is the image request, send out the image if ($_REQUEST['pic'] == 1) { header("Content-type: $row[type];"); print $bytes; } ?> <html> <head> <title>Upload an image to a database</title> </head> <body> <font color="#FF3333"><?php echo $err ?></font> <table> <form name="Upload" enctype="multipart/form-data" method="post"> <tr> <td>Upload <input type="file" name="imagefile"><br /> Jewelery Type: <select> <?php $sql="SELECT jeweltype FROM jeweltypes"; $result =mysql_query($sql); while ($data=mysql_fetch_assoc($result)){ ?> <option value ="jeweltype" ><?php echo $data['jeweltype'] ?></option> <?php } ?> </select> <br /> Jewelery Size: <select> <?php $sql="SELECT jewelsize FROM jewelsizes"; $result =mysql_query($sql); while ($data=mysql_fetch_assoc($result)){ ?> <option value ="jewelsize" ><?php echo $data['jewelsize'] ?></option> <?php } ?> </select> <br /> Jewelery Colour: <select> <?php $sql="SELECT jewelcolour FROM jewelcolours"; $result =mysql_query($sql); while ($data=mysql_fetch_assoc($result)){ ?> <option value ="jewelcolour_in" ><?php echo $data['jewelcolour'] ?></option> <?php } ?> </select> <br /> Jewelery Material: <select> <?php $sql="SELECT jewelmaterial FROM jewelmaterials"; $result =mysql_query($sql); while ($data=mysql_fetch_assoc($result)){ ?> <option value ="jewelmaterial_in" ><?php echo $data['jewelmaterial'] ?></option> <?php } ?> </select> <br /> Jewelery Gender: <select> <?php $sql="SELECT jewelgender FROM jewelgenders"; $result =mysql_query($sql); while ($data=mysql_fetch_assoc($result)){ ?> <option value ="jewelgender_in" ><?php echo $data['jewelgender'] ?></option> <?php } ?> </select> <br /> <input type="submit" name="xsubmit" value="Upload"> </td> </tr> <tr> <td>Latest Image</td> </tr> <tr> <td><img src="?pic=1"></td> </tr> </form> </table> </body> </html> ============================================== here is the query =============================================== <html> <head><title>Your Page Title</title></head> <body> <?php $database="josh_jewel"; mysql_connect ("localhost", "xxxxxxxxx", "yyyyyyyyyyyy"); @mysql_select_db($database) or die( "Unable to select database"); $result = mysql_query( "SELECT jewelcolour FROM jewel_images" ) or die("SELECT Error: ".mysql_error()); $num_rows = mysql_num_rows($result); print "There are $num_rows records.<P>"; print "<table width=400 border=1>\n"; while ($get_info = mysql_fetch_row($result)){ print "<tr>\n"; foreach ($get_info as $field) print "\t<td><font face=arial size=1/>$field</font></td>\n"; print "</tr>\n"; } print "</table>\n"; ?> </body> </html> I have a script that is supposed to allow a user to add their details to a members table in the database. It acts as if the user has been added to the database by stating the thank you message, but there is no entry into the database. I can connect to the database and have another script running OK that allows me to view all of the information in the members table with a loop (this data was entered using php my admin's GUI). Here is the script that is supposed to add the member. Any help would be greatly appreciated. <?php error_reporting(-1); $user_name = "root"; $password = ""; $database = "test"; $server = "localhost"; $db_handle = mysql_connect($server, $user_name, $password); $db_found = mysql_select_db($database, $db_handle); if ($db_found) { $SQL = "INSERT INTO members (fname, sname, email, password, gender) VALUES ('$_POST[fname]','$_POST[sname]','$_POST[email]','$_POST[password]','$_POST[gender]')"; $result = mysql_query($SQL); mysql_close($db_handle); print "Thanks for joining us ".$_POST['fname']."."; } else { print "Database NOT Found"; mysql_close($db_handle); } ?> Can you add a WHERE clause in $row? For example: $row['city_display'] WHERE city_display = 1 $row['city_display'] WHERE city_display = 2 etc... How can this be done? I am trying to get specific data from a MySQL table but cannot seem to find a proper command. Code: [Select] $link = mysqli_connect('#####', '########', '########'); $user = $_SESSION['username']; $email = mysqli_query($link,"select email from members where username='$user'"); echo $email; Specifically, I am trying to get the email address stored for the user specified by the session, and display that address. However, I do not get any output with the current code, and am not sure what to try next. I have tried mysqli_fetch_row() but it only returns an error. I have MySQL table with the following fields: user=>varchar product=>varchar Amount=>int Date=>date Note=>tinytext I can't add value to these field by the following php code: $date = date("Y.m.d"); $query = "INSERT INTO order VALUES ('farhad', 'Mango', '10', '$date', 'hello')"; $result = mysql_query($query) or die(mysql_error()); I receive the following warning: Warning: date(): It is not safe to rely on the system's timezone settings. You are *required* to use the date.timezone setting or the date_default_timezone_set() function. In case you used any of those methods and you are still getting this warning, you most likely misspelled the timezone identifier. We selected 'Europe/Paris' for '2.0/DST' instead in C:\inetpub\wwwroot\Okern\~order.php on line 10 Call Stack: 0.0047 325856 1. {main}() C:\inetpub\wwwroot\Okern\~order.php:0 0.0274 344912 2. date() C:\inetpub\wwwroot\Okern\~order.php:10 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'order VALUES ('farhad', 'Mango', '10', '2011.04.17', 'hello')' at line 1 Hi all, I'm new to php/myslq and I'm going crazy trying to figure this one out I'm building a personal calendar and I want to display the data into a HTML table. Code: [Select] //query the database $query = "SELECT * FROM tbl_events WHERE event_day=$day AND event_month=$month AND event_year=$year"; $query = mysql_query($query); //build the table echo '<table>'; for ($y = 0; $y < 6; $y++){ echo '<tr><td>'; //insert the data here echo '</td></tr>'; } echo '</table>'; When I store the events into the database, I assign a slot for each one depending on the hour. I don't want to use more than 6 events daily, hence the for loop. The problem I have is how to I insert the data into the designed <td>? In a particular day I could have only 2 events: event 1 - slot 2, event 2 - slot 6. I want to be able to enter each event into its own cell I hope I'm making myself clear enough. Sorry for any English mistakes if any. Thank you Hello, can someone help me with my proggraming problem please. Am new in this so i still have lots problems. I need to put all data from my MySQL table in one table in html. There is catch... i need to design output to give me table with x rows and 3 columns, so it means while reading data from database it need put every 4th in new row. And if there isnt 3 data (or better say if there isnt 3 full <td>) in row code will automatically add empty <td> or 2 in table. So...did somebody do this before or have some code ? All i got for now is Code: [Select] $td ='<td align="center"><img src="'.$row['name'].'.png" /> <p style="font-family:Verdana, Geneva, sans-serif; font-size:15px"> Number: <b style="font-size:40px;">'.$row['serial'].'</b></p> <br><img width="90" height="29" src="'.$logo.'"/></td>'; $tr ='<tr>'.$td.'</tr>'; $html='<table border="1" align="center">'.$tr.'</table>'; Thanks. Hello, I know i'm new, i hope it wont stop you guys from putting 5 minutes of your time to help me out. I need a script to get some data from mysql and put this into a table. i have a mysql database called "denora" In there is a table called "chan" In table chan are the columns: chanid (unique number), channel, currentusers, mode_ls I would like the script to make a html table that lists the top10 channels (most "currentusers" on top) And when "mode_ls" is "Y" it must not be shown (secret channel) My knowledge of php and mysql arent that great so i really hope someone takes the time to help me uit Kind regards Stefan |