sql-insert

I want to implement something that doesn't allow the user to rate more than once

天大地大妈咪最大 提交于 2020-01-07 09:28:17
问题 I have used someone else's code that uses the ipaddress way. However, I would like to use a code that checks for the current userid and the id number. $ipaddress = md5($_SERVER['REMOTE_ADDR']); // here I am taking IP as UniqueID but you can have user_id from Database or SESSION /* Database connection settings */ $con = mysqli_connect('localhost','root','','database'); if (mysqli_connect_errno()) { echo "<p>Connection failed:".mysqli_connect_error()."</p>\n"; } /* end of the connection */ if

Can't Get Simple SQL Insert to Work

心已入冬 提交于 2020-01-07 09:18:08
问题 <?php include_once("database.php"); ?> <?php include_once("header.php"); ?> <?php if ($_POST['submit'] ) { $food_name = $_POST['food_name']; $food_calories = $_POST['food_calories']; echo $food_name . $food_calories; if (!empty($food_name) && !empty($food_calories) ) { $query = 'INSERT INTO foods VALUES(0, $food_name, $food_calories)'; mysqli_query($con, $query) or die(mysqli_error($con)); echo 'added'; } else {echo'fail';} } else {echo'fa2oo';} ?> <h1> Please Fill out Form Below to Enter a

How to insert a picture into BLOB column in Oracle table using INSERT syntax?

試著忘記壹切 提交于 2020-01-07 07:49:32
问题 I have a simple table where I want to insert an image that exists on my machine.I would like to insert the picture into my table's BLOB column. Just wondering how can I do it. I understand that there are some existing solutions which are related to BLOB but none have helped me directly by using INSERT SYNTAX. CREATE TABLE test(id int,photo BLOB); INSERT INTO test VALUES(1,'Path of the picture\filename'); 回答1: First of all, create a directory to store images and grant read, write permission to

Oracle truncating column

谁说胖子不能爱 提交于 2020-01-06 19:55:19
问题 I have the following query. insert into ORDER_INFO(ORDINF_PK,ORDINF_LGNDET_PK_FK,MEDIA_TYPE,ORDINF_MUSIC_FK,DAT) values (1,1,'Music',21,TO_DATE('14-OCT-2015','DD-MON-YYYY')); insert into ORDER_INFO(ORDINF_PK,ORDINF_LGNDET_PK_FK,MEDIA_TYPE,ORDINF_MUSIC_FK,ORDINF_SERIES_FK,DAT) values (2,2,'Series',71,23,TO_DATE('07-NOV-2015','DD-MON-YYYY')); however when I do: select * from ORDER_INFO; I get: truncating (as requested) before column ORDINF_SERIES_FK truncating (as requested) before column

Error when trying to insert values in Postgres query inside Bash script

戏子无情 提交于 2020-01-06 07:01:52
问题 I'm executing the query as follows: ssh user@XX.XX.1XX.XX "PGPASSWORD=myPassword psql -U psqlUser -h XX.XX.XX.XX -p 5432 -d myDB -c 'INSERT INTO table(\"CPU_IDLE_TIME\",\"TOTAL_SIZE\",\"USED_SIZE\",\"USED_STORAGE_P\") VALUES ($idlecputime,$totalSize,$usedSize,$usedStoragePercentage)';" I obtain the values previous to this query doing snmpwalks. In order for the query to work the values have to be surrounded by single quotes (' '). I tried putting single quotes around the variable but

Error when trying to insert values in Postgres query inside Bash script

≯℡__Kan透↙ 提交于 2020-01-06 07:01:21
问题 I'm executing the query as follows: ssh user@XX.XX.1XX.XX "PGPASSWORD=myPassword psql -U psqlUser -h XX.XX.XX.XX -p 5432 -d myDB -c 'INSERT INTO table(\"CPU_IDLE_TIME\",\"TOTAL_SIZE\",\"USED_SIZE\",\"USED_STORAGE_P\") VALUES ($idlecputime,$totalSize,$usedSize,$usedStoragePercentage)';" I obtain the values previous to this query doing snmpwalks. In order for the query to work the values have to be surrounded by single quotes (' '). I tried putting single quotes around the variable but

How do I grab info from one table while still adding values?

喜夏-厌秋 提交于 2020-01-06 03:31:05
问题 I'm working on a project and am trying to grab a key from another table while still grabbing from the values given. For example... INSERT INTO Essay (student_ID, student_essay) VALUES (`Students.student_ID`, 'I WANNA BE THE VERY BEST'); I need to grab the student_ID from the Students table (otherwise the numbers will be off since student_ID is auto-increment), but I need to be able to insert the value of the essay. 回答1: You need to use the Max(id) function. You can use Max(id) function also

SQL Arithmetic Overflow for Identity Insert

依然范特西╮ 提交于 2020-01-05 19:06:12
问题 I have an error with arithmetic overflow inserting values into a lookup table with a row-id set as TINYINT datatype. This IS NOT a case where the number of unique records exceeds 255 values. This is a bit more unusual and did not occur during the first tests of this setup. The production version of the code below actually only has 66 unique values, but it is possible that new values could be added (slowly and in very small numbers) over time... 255 available slots should be more than enough

Inserting multiple tables with transaction in mysql

混江龙づ霸主 提交于 2020-01-05 17:21:48
问题 I want to insert two tables A(id,firstName, lastName) and B(id, id from A, xyz) . How can I insert the two tables simultaneously using transaction? And also if B is not inserted then rollback the A also. Could you please help me. 回答1: Use mysql_insert_id() if you're going down that path. <? mysql_query("START TRANSACTION"); $q1 = mysql_query("INSERT INTO table A (id, firstName, lastName) VALUES (?, ?, ?)"); // This is your baby. The id of the last record inserted $last_inserted_id = mysql

MySQL insert data from other table

陌路散爱 提交于 2020-01-05 13:06:37
问题 This question is similar to my previous question except this is INSERT instead of update I have two tables: contacts and companies. contacts has : id, group_id, company_id, email, company companies has: id, group_id, name, email so using this query UPDATE contacts c INNER JOIN companies co ON c.company_id = co.id SET c.group_id = co.group_id, c.company = companies.name I can move update data from company to contacts where there contact.company_id = company.id. But how can I do INSERT instead