PHP - Mysql Insert
I don't understand where the empty value is. I've substituted the variables for text and still have the same problem.
Code: Code: [Select] $sql = "INSERT INTO courses (course#, name, subject, semester, ap)VALUES('$courseNum', '$courseName', '$subject', '$semester', '$ap')"; Error: 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 '' at line 1 Similar TutorialsCan anyone tell me why this is not INSERTing? My array data is coming out just fine.. I've tried everything I can think of and cannot get anything to insert.. Ahhhh! <?php $query = "SELECT RegionID, City FROM geo_cities WHERE RegionID='135'"; $results = mysqli_query($cxn, $query); $row_cnt = mysqli_num_rows($results); echo $row_cnt . " Total Records in Query.<br /><br />"; if (mysqli_num_rows($results)) { while ($row = mysqli_fetch_array($results)) { $insert_city_query = "INSERT INTO all_illinois SET state_id=$row[RegionID], city_name=$row[City] WHERE id = null" or mysqli_error(); $insert = mysqli_query($cxn, $insert_city_query); if (!$insert) { echo "INSERT is NOT working!"; exit(); } echo $row['City'] . "<br />"; echo "<pre>"; echo print_r($row); echo "</pre>"; } //while ($rows = mysqli_fetch_array($results)) } //if (mysqli_num_rows($results)) else { echo "No results to get!"; } ?> Here is my all_illinois INSERT table structu CREATE TABLE IF NOT EXISTS `all_illinois` ( `state_id` varchar(255) NOT NULL, `city_name` varchar(255) NOT NULL ) ENGINE=MyISAM DEFAULT CHARSET=latin1; Here is my source table geo_cities structu CREATE TABLE IF NOT EXISTS `1` ( `CityId` varchar(255) NOT NULL, `CountryID` varchar(255) NOT NULL, `RegionID` varchar(255) NOT NULL, `City` varchar(255) NOT NULL, `Latitude` varchar(255) NOT NULL, `Longitude` varchar(255) NOT NULL, `TimeZone` varchar(255) NOT NULL, `DmaId` varchar(255) NOT NULL, `Code` varchar(255) NOT NULL ) ENGINE=MyISAM DEFAULT CHARSET=latin1; Hello, I'm having a bit of a problem here, all help to this issues would be much appreciated I am trying to use text boxes to insert numbers into the database based on what is inputed. If I have a string, like this for example: $variable = 09385493; And I want to insert it into the database like this: mysql_query("INSERT INTO integers(number) VALUES ('$variable')"); When checking the integers table in my database, looking at the number field, the $variable that was inserted is outputted as 9385493 Notice the number zero was taken out of the front of the number. If the number is double 0's (009385493), both of those zero's would disappear, too. Thanks Hi guys I have a registration form working fine, my database is as below: userid username password repeatpassword I have added another column which is "name", users can update their profile once they have logged in so I have created updateprofile.php and when I login-->go to update profile and insert my name nothing adds to mysql name column this is my code below: <?php include ("global.php"); //username session $_SESSION['username']=='$username'; $username=$_SESSION['username']; //welcome messaage echo "Welcome, " .$_SESSION['username']."!<p>"; if ($_POST['register']) { //get form data $name = addslashes(strip_tags($_POST['name'])); $update = mysql_query("INSERT INTO users (name) VALUES ('$_POST[name]') WHERE username='$username'"); } ?> <form action='updateprofile.php' method='POST'> Company Name:<br /> <input type='text' name='name'><p /> <input type='submit' name='register' value='Register'> </form> can you please tell me where in this code is wrong? Im new in php so please excuse me if I have silly mistakes. thanks in advance I have this code: <?php $con = mysql_connect("localhost","hhh","hhh"); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("hhh", $con); // -------------------- // Avatar insert check // -------------------- session_start(); $name = $_POST[name]; $group = $_POST[group]; $age = $_POST[age]; $usernameid = $_SESSION[id]; $result = mysql_query("SELECT * FROM avatars WHERE name='$_POST[name]'"); $num = mysql_numrows($result); if ($num == 0) { mysql_query("INSERT INTO avatars (id, usernameid, name, group, age, xp) VALUES ('', '$usernameid', '$name', '$group', '$age', '0')"); header( 'Location: me/' ) ; } else echo 'Sorry, please pick a new name'; ?> And it does everything but put the data into the datebase. If I add a session befor and after '$request' they both run, but the sql doesn't. No error returns, if just redirects to the other page. Any help? well this is truely embarrising...i have a insert statement which works within phpmyadmin but when using mysqli_query it returns a error.
INSERT INTO users (username, timestamp) VALUES ('test', UTC_TIMESTAMP())Unknown column 'timestamp' in 'field list' i've been playing about with this for a few hours now ...tried changing the column name (timestamp), adding ` around column names as well as table name. the column exists which is the strangest part, and ive even checked there is no space after the column name in the db. whats going on please? I need help badly! What I want to do is insert into database the value from the selected radio group buttons.. All of them. There are 10 radio groups total (they can be less, but not more). Thanks! Code: [Select] <?php require_once('Connections/strana.php'); mysql_select_db($database_strana, $strana); ?> <link href="css/styles.css" rel="stylesheet" type="text/css" /> <table width="100%" height="100%" style="margin-left:auto;margin-right:auto;" border="0"> <tr> <td align="center"> <form action="" method="post" enctype="multipart/form-data" name="form1"> <table> <?php $tema = mysql_query("SELECT * from prasanja where tip=2")or die(mysql_error()); function odgovor1($string) { $string1 = explode("/", $string); echo $string1[0]; } function odgovor2($string) { $string1 = explode("/", $string); echo $string1[1]; } while ($row=mysql_fetch_array($tema)) { $id=$row['prasanje_id']; $prasanje=$row['prasanje_tekst']; $tekst=$row['odgovor']; ?> <tr> <td> </td> </tr> <tr> <td class="formaP"> <?php echo $prasanje?> </td> </tr> <tr> <td class="formaO"> <p> <label> <input type="radio" name="Group<?php echo $id?>" value="<?php odgovor1($tekst) ?>" /> <?php odgovor1($tekst) ?></label> <br /> <label> <input type="radio" name="Group<?php echo $id?>" value="<?php odgovor2($tekst) ?>" /> <?php odgovor2($tekst) ?></label> <br /> </p></td> </tr> <tr> <td> <br /> </td> </tr> <?php } ?> </table> <input align="left"type="submit" name="submit" value="Внеси" > </form> </td> </tr> </table> prasanje = question tekst/odgovor = answer The answer table: id - primary question_id - the questions ID whose answer is selected in the radio group user_id - cookie takes care of this answer - the value from radio group date - automatic I have a mysql insert statement generated with php that is not populating the table. I've echoed the statement and if I copy and paste into phpmyadmin it works fine. The result of the mysql_query function is true. I've emptied the table so there are no primary key conflicts. I've put the statement in a try catch and it does not display a exception. What else can I try? Here's the statement INSERT INTO `wp_term_relationships` (object_id, term_taxonomy_id, term_order) VALUES (1597,83,0) Works absolute fine if I copy and paste into phpmyadmin. Does not populated the table if run through mysql_query Hi. I think you all know me by now so I'll cut to the chase. Code: [Select] <?php $host="edited"; $username="edited"; $password="edited"; $db_name="edited"; $tbl_name="topic"; // Connect to server and select databse. mysql_connect("$host", "$username", "$password")or die("cannot connect"); mysql_select_db("$db_name")or die("cannot select DB"); $name=$_POST['name']; $detail=$_POST['details']; $sql="INSERT INTO $tbl_name(topic, detail, datetime)VALUES('$name', '$detail', NOW())"; $result=mysql_query($sql); if($result){ header("location:site.html");} else{ echo("I have failed you master.");} ?> Displayed error: "I have failed you master." Anyone know a possible cause? Thanks. Bye. Hi anyone here know how to insert $GET variable into mysql, i don't know how to put this variable between curly bracket, when i put on top insert query, i got error 'Could not insert admin'...please help Code: [Select] <?php mysql_connect("localhost","root","") or die(mysql_error()); mysql_select_db("healthsystem") or die(msql_error()); [color=red]//GET varibable $id = $_GET['id'];[/color] // file properties $file = $_FILES['image']['tmp_name']; if (!isset($file)) echo "Please select an image"; else { $image = addslashes(file_get_contents($_FILES['image']['tmp_name'])); $image_name = addslashes($_FILES['image']['name']); $image_size = getimagesize($_FILES['image']['tmp_name']); if ($image_size==FALSE) echo "That's not an image."; else { $insert = "INSERT INTO image_tbl(m_id,name,image) VALUES ('$id','$image_name','$image')"; $insert2=mysql_query($insert) or die("Could not insert admin"); print "Personal Wellness Successfully Submitted"; } } ?> I have an old site written for PHP 5.4 and under and trying (very trying) to get it to work with PHP 7x without much luck. Due to all the changes in 7 my code is one big error message, but one thing at a time. I cannot get the follow code to work at all, even though it worked in PHP 5. Error:
QUERY ERROR: 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 'viewuser.php?u=666' id='member'>THE PREDATOR [666] was added to the hit' at line 1 I have tried at least 20+ different ways of doing this but just can't get the right syntax to get it inserted into MySQL, the code below is just the latest version. If I echo the a href line out, it works perfect. I am sure it is something ridiculously simple, but I have been 4 hours and counting on this now. Thanks gangevent_add_2($gangdata['gangID'], "<a href='viewuser.php?u=".$r['userid']."' ".$csscode[$r['userlevel']-1].">".$r['username']."</a> [".$r['userid']."] was added to your hitlist"); function gangevent_add_2($gang, $text) { global $db; $csscode; $db->query("UPDATE users SET gangevent = gangevent + 1 WHERE gang={$gang}"); $db->query("INSERT INTO gangevents VALUES('','$gang', UNIX_TIMESTAMP(),'$text')"); }
Hey guys for some reason this code is not working i can't see a problem myself could someone please have a look and point the issue out to me. what i mean by it not working is it won't insert into the database or show a mysql_error. thanks in advance Code: [Select] $guestip = $_SERVER['REMOTE_ADDR']; $time = date('G:i'); $date = date("y-m-d"); $query = mysql_query("SELECT * FROM IP_Address") or die(mysql_error()); while($row = mysql_fetch_assoc($query)){ if($guestip != $row['ip']){ //insert into db. mysql_query("INSERT INTO IP_Address(id, ip, date, time) VALUES(NULL,'$questip','$date','$time')") or die(mysql_error()); echo "inserted in to database"; echo mysql_error(); }else{ // add hit count and update time and date. echo "already in db"; } } I've got Code: [Select] for ($i=1; $i<=5; $i++) { if(isset($_POST['partsusedqty'.$i]) && $_POST['partsusedqty'.$i] != "" && $_POST['partsusedqty'.$i] != "0.00") { mysql_query("INSERT INTO partsused (ptnumber, partqty, partdesc, partprice) VALUES ($ticket, '$partsusedqty'.$i, '$partsuseddesc'.$i, '$partsusedprice'.$i)") or die(mysql_error()); } } I need to know the correct formatting to put these variable variables as values in the mysql query. With this particular code, I get the error "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 '.1, ''.1, ''.1)' at line 2" I've tried formatting this an endless number of ways, but I used this particular example because its the one I really thought should work. Everything I've tried that doesn't throw an error put the $partsusedqty in the partqty, partdesc, and partprice fields. Thanks for any help! I have a Form on registration.html through which i trying to get data in mysql through the below php script but there is and mysql syntax error please help me with the below code. Code: [Select] <?php $conn = mysql_connect("localhost", "onlinewe_meghraj", "password123") or die(mysql_error()); $db = mysql_select_db("onlinewe_college") or die(mysql_error()); $name1 = $_POST['name1']; $name2 = $_POST['name2']; $year = $_POST['year']; $department = $_POST['deparment']; $group = $_POST['group']; $in_name = $_POST['in_name']; $in_address = $_POST['in_address']; $phone = $_POST['phone']; $email = $_POST['email']; $mobile1 = $_POST['mobile1']; $mobile12 = $_POST['mobile2']; $comment = $_POST['comment']; $result=mysql_query("INSERT INTO register (name1, name2, year, department, group, in_name, in_address, phone, email, mobile1, mobile2, date, comment) VALUES ('$name1', '$name2', '$year', '$department', '$group', '$in_name', '$in_address', '$phone', '$email', '$mobile1', '$mobile2', '".date("Y-m-d h:i:s")."', '$comment')") or die("Insert Error: ".mysql_error()); echo "REGISTRATION DONE"; ?> Please reply. Thank you. I am trying to add a value, input into a form, to a MySQL database. However, something must be wrong with the casting, because if there is a space in the form value, then I get an error, as in: //$_POST['string'] == '1blah 2blah'; sql = "INSERT INTO table (some_string) VALUES ($_POST[string])"; $sql_result = mysql_query($sql) or die ('The error is as follows: ' . mysql_error() . '<br /><br />Value could not be added.'); Then I get the following error: The error is as follows: 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 '2blah' at line 1 I've entered paragraphs into a database before, so this error is now to me. The column 'some_value' is a type: varchar(50). Can you guys tell me where is the error please...
$sql2= ('CREATE TABLE `'.$pub_unik.'` (ID SERIAL,ID_Use CHAR(30),Comment TEXT,Like INT,Score CHAR(30))');I can't find... Thank you guys This is probably some obvious error I have made, but I cannot figure it out. I have made a few pages and now I am debugging them. My first page is called insert_purchase_order.php; on this page a person will enter some data in fields and hit the insert button. Then, the data is passed to another page, but when I try to insert into mysql it does not give me any errors, but I have no new rows either. The code for my 2nd page: Code: [Select] <?php session_start(); $action=$_GET[action]; if ($action==insert){ $randid=$_POST['randid']; $vendor=$_POST["vendor"]; $purchase_order_date=$_POST["purchase_order_date"]; $ship=$_POST["ship"]; $fob=$_POST["fob"]; $terms=$_POST["terms"]; $buyer=$_POST["buyer"]; $freight=$_POST["freight"]; $req_date=$_POST["req_date"]; $confirming_to=$_POST["confirming_to"]; $remarks=$_POST["remarks"]; $tax=$_POST["tax"]; $con = mysql_connect("localhost","root","pass"); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("main", $con); mysql_query("INSERT INTO purchase_order (randid, vendor, purchase_order, ship, fob, terms, buyer, freight, req_date, confirming_to, remarks, tax) VALUES ($randid, $vendor,$purchase_order_date,$ship, $fob, $terms, $buyer, $freight, $req_date, $confirming_to, $remarks, $tax)"); mysql_close($con); echo 'Data Accepted...'; echo '<br/>'; echo 'P.O. Inserted Successfully'; }else{ echo 'Error... Please Contact Bruce.'; echo 'Bruce, no data was passed from the insert_purchase_order.php page.'; } ?> <a href="http://localhost/insert_purchase_order_items.php?po= <?php echo $randid; ?>">Insert Purchase Order Items</a> I have permissions and everything. Thanks guys, im having a problem here thats making me crazy im making a system and i want to insert the current date in the mysql. I have the field called 'data' in the DB, but when i make the code to insert all the other fields, including the 'data', its work perfectly... unless that damn date! $query = "INSERT INTO news (id, titulo, mensagem, data) VALUES (NULL, '$titulo', '$mensagem', 'date(\"d/m/Y\")')"; whats wrong with that? its stores in DB as '0000-00-00'. hello can anyone help me how to insert GET variable into mysql <?php $page_title = 'Personal Wellness'; include ('template/header.inc'); include_once('config.php'); $id = $_GET['id']; if(isset($_POST['submit'])) //if submit was pressed { if(strlen($_POST['height'])<1) //if there was no height { print "You did not enter a height."; } else if(strlen($_POST['weight'])<1) //no weight { print "You did not enter a weight."; } else if(strlen($_POST['bodyfat'])<1) //no bodyfat { print "You did not enter a Body Fat Range"; } else if (strlen ($_POST['bodywater'])<1) //no bodywater { print "You did not enter a Body Water Range"; } else if( strlen($_POST['musclemass'])<1) //no musclemass { print "You did not enter a Muscle Mass"; } else if (strlen ($_POST['physiqueratt'])<1) //no physiqueratt { print "You did not enter a Physique Ratings"; } else if (strlen ($_POST['bonemass'])<1) //no bonemass { print "You did not enter a Bone Mass"; } else if (strlen ($_POST['bmr'])<1) //no bmr { print "You did not enter a BMR"; } else if (strlen ($_POST['basalmetabolic'])<1) //no basalmetabolic { print "You did not enter a Basal Metabolic Age"; } else if (strlen ($_POST['visceralfat'])<1) //no visceralfat { print "You did not enter a Visceral Fat"; } else if(strlen($_POST['registrationmonth'] && $_POST['registrationday'] && $_POST['registrationyear'])<1) // no date { print "You did not enter a date of birth"; } else //all fields met { $id=$_GET['id']; $height=$_POST['height']; $weight=$_POST['weight']; $bodyfat=$_POST['bodyfat']; $bodywater=$_POST['bodywater']; $musclemass=$_POST['musclemass']; $physiqueratt=$_POST['physiqueratt']; $bonemass=$_POST['bonemass']; $bmr=$_POST['bmr']; $basalmetabolic=$_POST['basalmetabolic']; $visceralfat=$_POST['visceralfat']; $date=$_POST['registrationyear'] . '-' . $_POST['registrationmonth'] . '-' . $_POST['registrationday']; $insertadmin="INSERT into personalwelness (m_id,height,weight,body_fat,body_water,muscle_mas s,physique_ratt,bone_mass,bmr,basal_metabolic,visc eral_fat,evaluation_date) values ('$id','$height','$weight','$bodyfat','$bodywater','$mus clemass','$physiqueratt','$bonemass','$bmr','$basa lmetabolic','$visceralfat','$date')"; //registering admin in databae echo $insertadmin; $insertadmin2=mysql_query($insertadmin) or die("Could not insert admin"); print "Personal Wellness Successfully Submitted"; } } ?> <form method="post" class="form" action="<?php echo $_SERVER['PHP_SELF'];?>"> <fieldset><legend>Enter Personal Wellness Information in the form below:</legend> <table width="80%" border="0"> <tr> <td width="16%">Height(CM)</td> <td width="2%">:</td> <td width="82%"><label for="height"></label> <input type="text" name="height" id="height" value="<?php if (isset($_POST['height'])) echo $_POST['height'];?>" /></td> </tr> <tr> <td>Weight(KG)</td> <td>:</td> <td><label for="weight"></label> <input type="text" name="weight" id="weight" value="<?php if (isset($_POST['weight'])) echo $_POST['weight'];?>" /></td> </tr> <tr> <td >Body Fat Range</td> <td>:</td> <td><label for="body fat"></label> <input type="text" name="bodyfat" id="bodyfat" value="<?php if (isset($_POST['bodyfat'])) echo $_POST['bodyfat'];?>" ></td> </tr> <tr> <td>Body Water Range(%)</td> <td>:</td> <td><label for="bodywater"></label> <input type="text" name="bodywater" id="bodywater" value="<?php if (isset($_POST['bodywater'])) echo $_POST['bodywater'];?>"/></td> </tr> <tr> <td>Muscle Mass</td> <td>:</td> <td><label for="musclemass"></label> <input type="text" name="musclemass" id="musclemass" value="<?php if (isset($_POST['musclemass'])) echo $_POST['musclemass'];?>"></td> </tr> <tr> <td>Physique Ratings</td> <td>:</td> <td><label for="physiqueratt"></label> <input type="text" name="physiqueratt" id="physiqueratt" value="<?php if (isset($_POST['physiqueratt'])) echo $_POST['physiqueratt'];?>"></td> </tr> <tr> <td>Bone Mass</td> <td>:</td> <td><label for="bonemass"></label> <input type="text" name="bonemass" id="bonemass" value="<?php if (isset($_POST['bonemass'])) echo $_POST['bonemass'];?>" /></td> </tr> <tr> <td>BMR</td> <td>:</td> <td><label for="bmr"></label> <input type="text" name="bmr" id="bmr" value="<?php if (isset($_POST['bmr'])) echo $_POST['bmr'];?>"/></td> </tr> <tr> <td>Basal Metabolic Age</td> <td>:</td> <td><label for="basalmetabolic"></label> <input type="text" name="basalmetabolic" id="basalmetabolic" value="<?php if (isset($_POST['basalmetabolic'])) echo $_POST['basalmetabolic'];?>"></td> </tr> <tr> <td>Visceral Fat</td> <td>:</td> <td><label for="visceralfat"></label> <input type="text" name="visceralfat" id="visceralfat" value="<?php if (isset($_POST['visceralfat'])) echo $_POST['visceralfat'];?>"></td> </tr> <tr> <td>Evaluation Date</td> <td>:</td> <td> <?php echo date_picker("registration")?></td> </tr> </table> </fieldset> <div align="center"><input type="submit" name="submit" value="Submit" /> </div> </form> <?php function date_picker($name, $startyear=NULL, $endyear=NULL) { if($startyear==NULL) $startyear = date("Y")-100; if($endyear==NULL) $endyear=date("Y")+50; $months=array('','January','February','March','Apr il','May', 'June','July','August', 'September','October','November','December'); // Month dropdown $html="<select name=\"".$name."month\">"; for($i=1;$i<=12;$i++) { $html.="<option value='$i'>$months[$i]</option>"; } $html.="</select> "; // Day dropdown $html.="<select name=\"".$name."day\">"; for($i=1;$i<=31;$i++) { $html.="<option $selected value='$i'>$i</option>"; } $html.="</select> "; // Year dropdown $html.="<select name=\"".$name."year\">"; for($i=$startyear;$i<=$endyear;$i++) { $html.="<option value='$i'>$i</option>"; } $html.="</select> "; return $html; } ?> <?php include ('template/footer.inc'); ?> |