PHP - Post Variable, Do Query And Insert Into Table Same Php
hi ..
hit little snag Ive got html <form name="formx" method="POST" action="connect.php" class='ajaxform'> and about 4 varibles in that form .. now how to properly
query table users so i can find out which prefix correspond with that user
Insert into table "upis" in this case that prefix with 3 variables..
everything in single,.. in this case connect.php file
I know how to do QUERY and INSERT INTO but i don't know how to connect with 2 different tbl or db and do the query and input of data.. every time I put 2 of them together .. never works out..
this is example.. i dont know is this right way to do it ..
Similar TutorialsHello, I'm working on a PHP register form, all I want to do, is to be able to insert an extra variable into the database: Code: [Select] // now we insert it into the database $insert = " INSERT INTO users (username, password) VALUES ('".$_POST['username']."', '".$_POST['pass']."') "; $add_member = mysql_query($insert); right, so I have the username and password variable being passed. But I also want to pass a variable into a column called 'weaponAttachments', all I want for this variable to be is 5000. So, in other words, something like this: 5000['weaponAttachments'] Thanks i want a situation where, when i upload something into my database, it creates a new table, everytime, i saw this
$forum = "CREATE TABLE IF NOT EXISTS for_".$id." ( How can i use single quote for values? $qry='insert into tablename values('a','b');'; I have tried several attempts and can get data to select and using echo display it, however, I need to take this data and insert it into the database in a separate table. I have the following which does hafl the job, can I get some pointers on the rest. I have looked everywhere and not found a solution, at all. // Selects the data I need <?php mysql_connect("PRIVATE INFO","PRIVATE INFO","PRIVATE INFO") or die("Could not connect: " . mysql_error()); mysql_select_db("wpdb"); $result = mysql_query("SELECT ID FROM wp_posts WHERE post_title LIKE '%future%' AND post_status = 'publish' OR post_title LIKE '%option%' AND post_content LIKE '%fundamental%' AND post_status = 'publish' ORDER BY post_date DESC"); while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) { echo $row['ID']; echo "<br />";}; ?> Thought maybe something like the following would work, but am at a loss: INSERT INTO wp_term_relationships (object_id, term_taxonomy_id, term_order) SELECT ID FROM wp_posts WHERE post_title LIKE '%future%' AND post_status = 'publish' OR post_title LIKE '%option%' AND post_content LIKE '%fundamental%' AND post_status = 'publish' ORDER BY post_date DESC while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) VALUES ($row['ID'], '25', '0') Good evening,
I am working on a program that takes images, and casts them into an associated array, I then want to display thumbnails of those images into a 3 column by 4 row table...
[image][image][image]
[image][image][image]
[image][image][image]
[image][image][image]
(For my visual friends)
here is my current, pardon for the mess, but right now, functionality is more important.
<!DOCTYPE html> <html> <head> <title>Zodiac Gallery</title> </head> <body> <h2 style="text-align:center">Zodiac Gallery</h2> <p>Click a thumbnail image to see enlarged view.</p> <?php $ZodiacArray = array ( "Images/rat.jpg" => "Rat", "Images/ox.jpg" => "Ox", "Images/tiger.jpg" => "Tiger", "Images/rabbit.jpg" => "Rabbit", "Images/dragon.jpg" => "Dragon", "Images/snake.jpg" => "Snake", "Images/horse.jpg" => "Horse", "Images/goat.jpg" => "Goat", "Images/monkey.jpg" => "Monkey", "Images/rooster.jpg" => "Rooster", "Images/dog.jpg" => "Dog", "Images/pig.jpg" => "Pig"); foreach ($ZodiacArray as $image => $zodiac) { echo "<table> <tr> <td><img src="$image" alt="$zodiac" style="width:68px;height:65px"></td <td><img src="$image" alt="$zodiac" style="width:68px;height:65px"></td> <td><img src="$image" alt="$zodiac" style="width:68px;height:65px"></td> </tr> <tr> <td><img src="$image" alt="$zodiac" style="width:68px;height:65px"></td> <td><img src="$image" alt="$zodiac" style="width:68px;height:65px"></td> <td><img src="$image" alt="$zodiac" style="width:68px;height:65px"></td> </tr> <tr> <td><img src="$image" alt="$zodiac" style="width:68px;height:65px"></td> <td><img src="$image" alt="$zodiac" style="width:68px;height:65px"></td> <td><img src="$image" alt="$zodiac" style="width:68px;height:65px"></td> </tr> <tr> <td><img src="$image" alt="$zodiac" style="width:68px;height:65px"></td> <td><img src="$image" alt="$zodiac" style="width:68px;height:65px"></td> <td><img src="$image" alt="$zodiac" style="width:68px;height:65px"></td> </tr> </table>"; ?>Help is welcome, thank you. I have a photo album style gallery to build and i'm finding it dificult to list all the table names (these are names of photo albums) and then enter the data into a seperate query for each album name (these will change often so i cant keep updating the file as normal. this will then post all the data to the xml file and show the set of photos in the individual albums in a flash file. can anyone help me where im going wrong at all? <?php $dbname = 'cablard'; if (!mysql_connect('localhost', 'cablard', '')) { echo 'Could not connect to mysql'; exit; } $sql = "SHOW TABLES FROM $dbname"; $result = mysql_query($sql); if (!$result) { echo "DB Error, could not list tables\n"; echo 'MySQL Error: ' . mysql_error(); exit; } while ($row = mysql_fetch_row($result)) { echo "Table: {$row[0]}\n"; } mysql_free_result($result); $query = "SELECT * FROM photo ORDER BY id DESC"; $result2 = mysql_query ($query) or die ("Error in query: $query. ".mysql_error()); while ($row = mysql_fetch_array($result2)) { echo " <image> <date>".$row['date']."</date> <title>".$row['title']."</title> <desc>".$row['description']."</desc> <thumb>".$row['thumb']."</thumb> <img>".$row['image']."</img> </image> "; } ?> Thanks James I am retrieving a rowfrom a table and when I post the row variable it doesnt read it. ___ $query = "SELECT * FROM $tbl_name"; $result = mysql_query($query) or die(mysql_error()); while($row = mysql_fetch_array($result)){ echo $row['name']; echo "<br />"; $postinfo = 'p_doctor_name=' . $row .'&p_name_type=A&p_search_type=BEGINS'; __ This outputs p_entity_name=&p_name_type=A&p_search_type=BEGINS Note that it is missing $row Do I need to put it in an array? First page adds a new job number, then the order page loaded with the job number id as a get id. Basically there is a while loop in the order page which shows products/services client can order and he chooses what he requires 'one or eight services' (8 in total) and some other variables like date of order and client name etc. Here is the order item code The first sql statement executes fine, but in the second sql query nothing happens $sql="insert into job_order(order_num,order_date,order_customer_id, order_remarks) values(".$_GET['id'].",NOW(),".$_POST['companyBox'].",'".$_POST['remarkBox']."');"; $res=mysql_query($sql); $id=mysql_insert_id(); foreach($_POST as $key => $value) { if(!empty($value)) { $key.' => '.trim(strip_tags($value)); $order="INSERT INTO orderprod (order_num,prod_id,order_amount,teeth_amount) VALUES ('$_GET[id]','$value','$value','$value');"; $orderres=mysql_query($order) or die(mysql_error()); } }?>$sql="insert into job_order(order_num,order_date,order_customer_id, order_remarks) values(".$_GET['id'].",NOW(),".$_POST['companyBox'].",'".$_POST['remarkBox']."');"; $res=mysql_query($sql); $id=mysql_insert_id(); foreach($_POST as $key => $value) { if(!empty($value)) { $key.' => '.trim(strip_tags($value)); $order="INSERT INTO orderprod (order_num,prod_id,order_amount,teeth_amount) VALUES ('$_GET[id]','$value','$value','$value');"; $orderres=mysql_query($order) or die(mysql_error()); } } ?> ============= This is the formI have removed parts which are irrelevant. Please note that dateBox and companyBox are not required to be looping as they are only for first table, echo "<form action=".$config_basedir."./vieworder.php?id=".$_GET['id']." name=form1 method=post>";?><table><tr><td><h4>JOB ORDER</H4></TD><TD></TD></TR><TR><TD>ORDER NUMBER</TD><TD><?PHP ECHO $_GET['id'] ?></td></tr><tr><td>ORDER DATE</td><td><input type=text name=dateBox></td></tr> <tr><td>COMPANY NAME</td><td><?PHP$sql="select * from customers";$res=mysql_query($sql);echo "<select name=companyBox><option value=''>Please select</option>";WHILE($fetch=mysql_fetch_assoc($res)){ echo "<option value='".$fetch['id']."'>".$fetch['cust_name']."</option>";} echo "</select>"; echo "</td></tr>"; ?> </table> <table><tr><th>ITEM</th><th>QUANTITY</th><th>N0. of Teeths</th></tr><tr><?PHP$sql="select * from products";$res=mysql_query($sql); WHILE($fetch=mysql_fetch_assoc($res)){ echo "<td><input type=text name=desBox value='".$fetch['prod_id']."'>".$fetch['prod_name']."</td><td><input type=text name=quantBox></td><td><input type=text name=teethBox></td>";echo "</tr>";}echo "</table>";?>echo "<form action=".$config_basedir."./vieworder.php?id=".$_GET['id']." name=form1 method=post>"; ?> <table> <tr> <td><h4>JOB ORDER</H4></TD><TD></TD> </TR> <TR> <TD>ORDER NUMBER</TD><TD><?PHP ECHO $_GET['id'] ?></td> </tr> <tr> <td>ORDER DATE</td><td><input type=text name=dateBox></td> </tr> <tr> <td>COMPANY NAME</td><td> <?PHP $sql="select * from customers"; $res=mysql_query($sql); echo "<select name=companyBox><option value=''>Please select</option>"; WHILE($fetch=mysql_fetch_assoc($res)){ echo "<option value='".$fetch['id']."'>".$fetch['cust_name']."</option>";} echo "</select>"; echo "</td></tr>"; ?> </table> <table> <tr> <th>ITEM</th><th>QUANTITY</th><th>N0. of Teeths</th> </tr> <tr> <?PHP $sql="select * from products"; $res=mysql_query($sql); WHILE($fetch=mysql_fetch_assoc($res)){ echo "<td><input type=text name=desBox value='".$fetch['prod_id']."'>".$fetch['prod_name']."</td> <td><input type=text name=quantBox></td> <td><input type=text name=teethBox></td>"; echo "</tr>";} echo "</table>"; ?> HERE IS THE IMAGE showing the populated services. http://dubads.com/images/order.jpg If you also have any feedback on my code, please do tell me. I wish to improve my coding base. Basically when you fill out the register form, it will check for data, then execute the insert query. But for some reason, the query will NOT insert into the database. In the following code below, I left out the field ID. Doesn't work with it anyways, and I'm not sure it makes a difference. Code: Code: [Select] mysql_query("INSERT INTO servers (username, password, name, type, description, ip, votes, beta) VALUES ($username, $password, $name, $server_type, $description, $ip, 0, 1)"); Full code: Code: [Select] <?php include_once("includes/config.php"); ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title><? $title; ?></title> <meta http-equiv="Content-Language" content="English" /> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <link rel="stylesheet" type="text/css" href="style.css" media="screen" /> </head> <body> <div id="wrap"> <div id="header"> <h1><? $title; ?></h1> <h2><? $description; ?></h2> </div> <? include_once("includes/navigation.php"); ?> <div id="content"> <div id="right"> <h2>Create</h2> <div id="artlicles"> <?php if(!$_SESSION['user']) { $username = mysql_real_escape_string($_POST['username']); $password = mysql_real_escape_string($_POST['password']); $name = mysql_real_escape_string($_POST['name']); $server_type = mysql_real_escape_string($_POST['type']); $description = mysql_real_escape_string($_POST['description']); if(!$username || !$password || !$server_type || !$description || !$name) { echo "Note: Descriptions allow HTML. Any abuse of this will result in an IP and account ban. No warnings!<br/>All forms are required to be filled out.<br><form action='create.php' method='POST'><table><tr><td>Username</td><td><input type='text' name='username'></td></tr><tr><td>Password</td><td><input type='password' name='password'></td></tr>"; echo "<tr><td>Sever Name</td><td><input type='text' name='name' maxlength='35'></td></tr><tr><td>Type of Server</td><td><select name='type'> <option value='Any'>Any</option> <option value='PvP'>PvP</option> <option value='Creative'>Creative</option> <option value='Survival'>Survival</option> <option value='Roleplay'>RolePlay</option> </select></td></tr> <tr><td>Description</td><td><textarea maxlength='1500' rows='18' cols='40' name='description'></textarea></td></tr>"; echo "<tr><td>Submit</td><td><input type='submit'></td></tr></table></form>"; } elseif(strlen($password) < 8) { echo "Password needs to be higher than 8 characters!"; } elseif(strlen($username) > 13) { echo "Username can't be greater than 13 characters!"; } else { $check1 = mysql_query("SELECT username,name FROM servers WHERE username = '$username' OR name = '$name' LIMIT 1"); if(mysql_num_rows($check1) < 0) { echo "Sorry, there is already an account with this username and/or server name!"; } else { $ip = $_SERVER['REMOTE_ADDR']; mysql_query("INSERT INTO servers (username, password, name, type, description, ip, votes, beta) VALUES ($username, $password, $name, $server_type, $description, $ip, 0, 1)"); echo "Server has been succesfully created!"; } } } else { echo "You are currently logged in!"; } ?> </div> </div> <div style="clear: both;"> </div> </div> <div id="footer"> <a href="http://www.templatesold.com/" target="_blank">Website Templates</a> by <a href="http://www.free-css-templates.com/" target="_blank">Free CSS Templates</a> - Site Copyright MCTop </div> </div> </body> </html> when i remove the action from the form it submits the post correctly if not it goes to the action url withoutposting Code: [Select] <form action="https://www.sandbox.paypal.com/cgi-bin/webscr" target="_top" method="post"> <input type="hidden" name="cmd" value="_s-xclick"> <input type="hidden" name="hosted_button_id" value="wwww"> <?php <input type="hidden" name="item_name" id="item_name" value="<?php echo $md5c;?>"> <input type="image" src="https://www.sandbox.paypal.com/en_US/i/btn/btn_paynowCC_LG.gif" border="0" name="submit" alt="Submit Form"> <img alt="" border="0" src="https://www.sandbox.paypal.com/en_US/i/scr/pixel.gif" width="1" height="1"> </form> <?php if(isset($_POST['submit_x']) || isset($_POST['submit_x'])) { //$Subscription_id = mysql_real_escape_string($md5c); $PropertyID = mysql_real_escape_string($rowData['ID']); $User_ID = mysql_real_escape_string($rowData['User_ID']); $item_name=mysql_real_escape_string($_POST['item_name']); //$query = 'INSERT INTO SP_subscriptions(id,) values("'.$item_name.'")'; $query = 'INSERT INTO SP_subscriptions(id,PropertyID,User_ID) values("'.$item_name.'","'.$PropertyID.'","'.$User_ID.'")'; $success = mysql_query($query); echo $query; } else echo 'POST nada'; var_dump($_POST); var_dump($query); ?> Hi - I have an HTML form which is dynamically produced using CodeIgniter / PHP and presents products a customer has ordered. When the customer has finished changing his quantities they must now submit the form. My problem is that my form will contain many of the same named fields for example, 'Product ID', or 'Product Name' or 'quantity'. So now when it gets processed a typical post array like product id could look like this: Code: [Select] Array ( [0] => 28 [1] => 24 [2] => 101 [3] => 23 [4] => 17 ) Of course I get an error: Quote Severity: Notice Message: Array to string conversion Filename: mysql/mysql_driver.php I really need some advice on how I should pre-process the various POST arrays so I can get them into my DB. A very grateful student of PHP ! Thanks Ok .I tried to look for the problem for about 1 hour but I can't see what's wrong whit the following code: In firebug the post values appear correctly like so:id=116&usern=asdawe&com=qweqw&page=116&submit=submit and the inserc() function works correctly because i tried it whit a array of data created by my; Code: [Select] <?php if(isset($_POST['submit'])) { $comment = new comment; $comment->storeform($_POST); $comment->insertc(); } ?> <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="POST"> <input type="hidden" name="id" value="<?php echo $result['article']->id ?>"/> <ul> <li> <input type="text" name="usern" id="usern" /> </li> <li> <textarea name="com" id="com" COLS=40 ROWS=6></textarea> </li> <input type="hidden" name="page" value="<?php echo $result['article']->id ?>" /> <input type="submit" name="submit" value="submit" /> </ul> </form> Code: [Select] <?php class comment{ public $id = null; public $usern = null; public $com = null; public $page = null; public function __construct($data=array() ) { if( isset($data['id']) ) $this->id= (int)$data['id']; if( isset($data['usern']) ) $this->usern= preg_replace ( "/[^\.\,\-\_\'\"\@\?\!\:\$ a-zA-Z0-9()]/", "", $data['usern'] ); if( isset($data['com']) ) $this->com= preg_replace ( "/[^\.\,\-\_\'\"\@\?\!\:\$ a-zA-Z0-9()]/", "", $data['com'] ); if( isset($data['page']) ) $this->page= (int)$data['page']; } public function storeform ( $params ) { // Store all the parameters $this->__construct( $params ); } public function insertc() { $con = new PDO(DBN,DB_USER,DB_PASS); $sql = "INSERT INTO comments (usern,com,page) VALUES (:usern,:com,:page)"; $st =$con->prepare($sql); $st->bindValue( ":usern", $this->usern, PDO::PARAM_STR ); $st->bindValue( ":com", $this->com, PDO::PARAM_STR ); $st->bindValue( ":page", $this->page, PDO::PARAM_INT ); $st->execute(); $this->id = $con->lastInsertId(); $con = null; } } ?> When i click my submit button i am posting the following. Array ( [submitStaffOrder] => [staffMember] => Array ( [0] => 2 [1] => ANYCHEF1 ) [date] => Array ( [0] => 2020-02-18 [1] => 2020-02-18 ) [startTime] => Array ( [0] => 11:01 [1] => 10:10 ) [finishTime] => Array ( [0] => 11:01 [1] => 10:01 ) [delExisting] => Array ( [0] => [1] => toDel ) ) I would like to update/insert if delExisting is blank and delete if it has toDel in there. I have the following but i am pretty sure the if is not working. $date = $_POST['date']; $stime = $_POST['startTime']; $ftime = $_POST['finishTime']; $del = $_POST['delExisting']; $staff = $_POST['staffMember']; $stmt = $conn -> prepare(" INSERT IGNORE INTO ssm_staff_order (job_id, staff_id, staff_start_time, staff_finish_time, staff_start_date, staff_finish_date) VALUES (?,?,?,?,?,?) ON DUPLICATE KEY UPDATE staff_start_time = VALUES(staff_start_time), staff_finish_time = VALUES(staff_finish_time); "); $delstmt = $conn -> prepare(" DELETE FROM ssm_staff_order WHERE staff_id = ? AND job_id = ? AND staff_start_date = ? "); foreach ($staff as $key => $staffId) { if ($del == '') { $start = $date[$key].' '.$stime[$key]; $finish = $date[$key].' '.$ftime[$key]; $stmt -> bind_param('isssss', $jid, $staffId, $start, $finish, $date[$key], $date[$key]); $stmt -> execute(); } if ($del == 'toDel') { $delstmt -> bind_param('sis', $staffId, $jid, $date[$key]); $delstmt -> execute(); } } } Can i do what i am trying to do or am i way off here?
I struggle with arrays Edited February 24, 2020 by AdamhumbugI want to remove the HTTP:// or HTTPS:// from the insert into the DB. The Viewer may put just www, or copy the entire URL with the HTTP:// or HTTPS://
I tried using the preg-replace but couldn't seem to get it to work.
Any other recommendation?
Thanks in advance,
Mike
Hi Folks,
Firstly I am new, I have read several topics here and learned a lot, I would class myself as 'slightly better than basic', but my knowledge is mostly gained from reading code.
I am making a simple POST form for work, the data gets inserted into MySQL, nice and easy, I can make it work if I write out the statement completely, BUT I need to make a new form, it will have HUNDREDS of input fields, I really don't want to write the code, and I figured programmatically is a good way to go anyway as forms change and new forms may be required, so I set about building a function to completely handle my post data, bind it to a statement and insert it into a table, I have scrapped it a half dozen times already because something fundamentally doesn't work, but I am very close! The function can write the statement, but I need to bind the POST values before I can insert, something going wrong here and I would appreciate some help, I have a feeling it's a problem with an array, but anyway I will show you what I have, give you some comments as to my reasoning, and hopefully you can help me with the last bit
public function getColumnNames($table){ $sql = "SELECT COLUMN_NAME FROM INFORMATION_SCHEMA.COLUMNS WHERE table_name = :table"; try { $stmt = $this->dbh->prepare($sql); $stmt->bindValue(':table', $table, PDO::PARAM_STR); $stmt->execute(); $output = array(); while($row = $stmt->fetch(PDO::FETCH_ASSOC)){ $output[] = $row['COLUMN_NAME']; } $all = array($output); $a1 = array_slice($output, 1); // I don't want column 1, it contains the ID, its auto incremented. $a2 = array_slice($a1, 0, -3); // I don't want the last 3 columns as they have default values $selected = array($a2); // contains all the columns except those excluded by array_slice, columns now match all of the input fields on the form foreach ($selected as $row){ $fields = "`" . implode('`, `', $row) . "`"; // I'm making `fields` here, $bind = ":" . implode(', :', $row); // And making :values here } return array ( "raw" => $all, "fields" => $fields, "bind" => $bind ); } catch(PDOException $pe) { trigger_error('Could not connect to MySQL database. ' . $pe->getMessage() , E_USER_ERROR); } } public function addRecord(){ $col = array(); $col = $this->getColumnNames("table"); $raw = array($col['raw']); $fields = array($col['fields']); $bind = array($col['bind']); $columnList = implode('`, `', $fields); $paramList = implode(', ', $bind); $sql = "INSERT INTO `{$this->dbtable}` ($columnList) VALUES ($paramList)"; return $sql; // this returns something like: INSERT INTO `table` (`field1`, `field2`, `field3`) VALUES (:field1, :field2, :field3)";perfect I thought, now I just need to bind the values from $_POST... then I get stuck. Edited by luke3, 08 January 2015 - 12:10 PM. Hi, can anyone help me I'm new to coding and have been having trouble getting my code to insert into the database. I have checked the connection and that works fine but it says you're registered but it dosen't input it into the database. This is the code i have in my script: <?php echo "<h1>Register</h1>"; $submit = $_POST ['submit']; //form data $fullname = strip_tags($_POST ['fullname']); $username = strip_tags($_POST ['username']); $password = strip_tags($_POST ['password']); $repeatpassword = strip_tags($_POST ['repeatpassword']); $date = date ("Y-m-d"); if ($submit) { //check for existance if ($fullname&&$username&&$password&&$repeatpassword) { //check passwords match if ($password==$repeatpassword) { //check char length of username and fullname if (strlen($username)>25||strlen($fullname)>25) { echo "Maximum limit for username and fullname is 25 characters!"; } else { //check password length if (strlen($password)>25||strlen($password)<6) { echo "Your password must be between 6 and 25 characters!"; } else { //register the user //encrypt password $password = md5 ($password); $repeatpassword = md5 ($repeatpassword); //open database $connect = mysql_connect ("localhost","","") or die ("couldn't connect!"); mysql_select_db ("phplogin") or die ("couldn't find db!"); mysql_query ("INSERT INTO users VALUES ('','$fullname','$username','$password','$date')"); die ("You've been registered! <a href='index.php'>Click here</a> to return to login page"); } } } else echo "Your passwords do not match!"; } else echo "Please fill in <b>all</b> fields."; } ?> <html> <form action='register.php' method='POST'> <table> <tr> <td>Your Full name:</td> <td><input type='text' name='fullname' value='<?php echo $fullname ?>'></td> </tr> <tr> <td>Your Username:</td> <td><input type='text' name='username' value='<?php echo $username ?>'></td> </tr> <tr> <td>Your Password:</td> <td><input type='password' name='password'></td> </tr> <tr> <td>Repeat your password:</td> <td><input type='password' name='repeatpassword'></td> </tr> </table> <input type='submit' name='submit' value='Register'> </form> </html> I need to insert a query but with the ID # from another table. Here is the query I am using to select which works fine. // get reviews $strQuery = sprintf("SELECT * FROM messages WHERE intItemID = %d", intval($intProductID)); $queryGetReviews = db_query($strQuery); However my insert doesn't seem to be picking up the %d. //query to insert data into table $sql = " INSERT INTO messages SET firstname = '$name', message = '$message' WHERE intItemID=%d" ; $result = mysql_query($sql); if(!$result) { echo "Failed to insert record"; } else { echo "Record inserted successfully"; } } Please help! Hi
I am very new to PHP & Mysql.
I am trying to insert values into two tables at the same time. One table will insert a single row and the other table will insert multiple records based on user insertion.
Everything is working well, but in my second table, 1st Table ID simply insert one time and rest of the values are inserting from 2nd table itself.
Now I want to insert the first table's ID Field value (auto-incrementing) to a specific column in the second table (only all last inserted rows).
Ripon.
Below is my Code:
<?php $con = mysql_connect("localhost","root","aaa"); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("ccc", $con); $PI_No = $_POST['PI_No']; $PO_No = $_POST['PO_No']; $qry = "INSERT INTO wm_order_entry ( Order_No, PI_No, PO_No) VALUES( NULL, '$PI_No', '$PO_No')"; $result = @mysql_query($qry); $val1=$_POST['Size']; $val2=$_POST['Style']; $val3=$_POST['Colour']; $val4=$_POST['Season_Code']; $val5=$_POST['Dept']; $val6=$_POST['Sub_Item']; $val7=$_POST['Item_Desc']; $val8=$_POST['UPC']; $val9=$_POST['Qty']; $N = count($val1); for($i=0; $i < $N; $i++) { $profile_query = "INSERT INTO order_entry(Size, Style, Colour, Season_Code, Dept, Sub_Item, Item_Desc, UPC, Qty, Order_No ) VALUES( '$val1[$i]','$val2[$i]','$val3[$i]','$val4[$i]','$val5[$i]','$val6[$i]','$val7[$i]','$val8[$i]','$val9[$i]',LAST_INSERT_ID())"; $t_query=mysql_query($profile_query); } header("location: WMView.php"); mysql_close($con); ?>Output is attached. I have this PHP file that I intend to provide the answers to only four questions in a little quiz in a "Questions" table: QuestionID, QuestionText Questions: 1 Which is NOT part of the FAT TOM acronym? 2 Of the following choices, which has a better chance of creating a foodborne illness? 3 How should food NEVER be thawed? 4 Where should pesticides be stored? The answers should go in the Answers table: "QuestionID, OptionText, CorrectAnswer" I have hundreds of questions and answers, but I need to get this small sample working first. The following code runs without triggering an error but it doesn't insert any data. <?php $link = mysql_connect('PathToMyData', 'myUsername', 'MyPassword'); // specifics removed for security if (!$link) { die('Could not connect: ' . mysql_error()); } mysql_select_db('quiz'); $sql = "INSERT INTO ANSWERS (QuestionID,OptionText,CorrectAnswer) // CorrectAnswer is type BOOL (Correct=1 Wrong Answer=0) (VALUES (1,'food',0), (1,'alkalinity',1), (1,'time',0), (1,'temperature',0), (1,'oxygen',0), (1,'moisture',0), (2,'celery sticks',0), (2,'beef jerky',0), (2,'cranberry juice',0), (2,'baked potato',1), (2,'saltine cracker',0), (3,'in the refrigerator',0), (3,'in a pot in the kitchen at room temperator',1), (3,'as a part of the cooking process',0), (3,'under cool running water',0), (4,'close to the food preparation area for easy access',0), (4,'in a locked storage area away from food',1), (4,'in the dry storage area',0), (4,'in a bin or box under the sink',0);)"; $result = mysql_query($sql); // executes the query // close database mysql_close($link); ?> Then I go back to the MySQL admin area at my host's site and query up "SELECT * FROM Answers;" and nothing! It's still empty! As I said, no error was triggered, but nothing was inserted. This is discouraging. Hello every body,, i want to create a new database (auto generate duty assigned using form) in PHP and mysql..
i have four input fields:-
Name, Subject, Class & weekly lectures
now i want to insert name,subject & class into database, when i insert number of weekly lecture in field four..
insert automaticlly in database multiple time which i write in field four (weekly lecture)
database: table structure i have already is:::
id-name-subject-class-period-monday-tuesday-wednesday-thursday-friday-saturday
anybody please help me to create this database or just insert query ....
|