PHP - Mysql Insert Statement With A Value Which Includes Semi-colon
Within PHP I am attempting to insert some data into a MySQL table, however the value that needs to be stored inside the database field contains a semi-colon ;
$q_options_data = "INSERT INTO mytable SET myfield = 'a:5:{s:13:\"administrator\";a:2:{s:4:\"name\";s:13:\"Administrator\";'"; I tried just escaping the ; with a \; but that didn't work I am using PHP 5.2.9 and MySQL 5.0.91-community Thanks, Chad Similar TutorialsHi SMF forum use semi-colom in url for example http://www.phpfreaks.com/forums/profile/?area=showposts;u=71740 after showposts there is semi-colon. Sometimes use hash(#) how can i do this with superglobal $_GET??? I am trying to insert a record into a mysql database which has a $ as part of the value of a field. But it seems that when the INSERT query is processed its actually looking for a variable with that name and not just inserting the raw text. Here is the insert query $query = "INSERT mytable SET myfield='I would like to have this field contain this information with a $matches[1] showing in the field value as well'"; $matches[1] has no value. Its not a variable which is in this script. I am not trying to insert the value of it. I just want to insert the actual text characters $matches[1] How can I do that? Hi, Im just having some trouble with this...maybe a fresh pair of eyes can help? Im getting a "Warning: mysqli_stmt::bind_param() [mysqli-stmt.bind-param]: Number of elements in type definition string doesn't match number of bind variables" error when I try run this: Code: [Select] $date = date("Y-m-d"); $header = $_POST['header']; $summary = $_POST['summary']; $content = $_POST['content']; $query = "INSERT INTO articles (pubdate, title, summary, content) VALUES(?, ?, ?, ?)"; $stmt = $mysqli->stmt_init(); if ($stmt->prepare($query)){ $stmt->bind_param('i,s,s,s', $date, $header, $summary, $content); $stmt->execute(); $stmt->close(); } else { echo "ERROR: SQL statement failure!"; echo "<a href='addnews.php'> -> OK</a>"; } $mysqli->close(); It looks fine to me, just can't see whats wrong lol! how to get the domain name of a website which includes my includes file. The code would need to be put within my includes file so when any site includes it the file will get the sites domain. to $currentDomain i have tried using: echo file_get_contents() instead of includes but i get the same issue I get back the includes domain. then code i have tried (in the includes file): Code: [Select] $curdomain1= $_SERVER['HTTP_HOST']; $pageUR1 = ereg_replace("/(.+)", "", $_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"]); $curdomain2 = str_replace("www.", "", $pageUR1); echo "<br> 1# Current Domain: ".$curdomain1; echo "<br> 2# Current Domain: ".$curdomain2; Hi, I would like to know how to write Insert data into a table statement where some of the data is coming from another table? I tried using Insert select statement but did not work. Here is what I am trying.... 1.........$sql = "INSERT INTO table1(id,fname, lname, gender, add1, add2, city, state, zip, country, email, phone, cellphone,employment,employmentinfo,dob, photo1,info) VALUES('$id','$fname','$lname','$gender','$add1','$add2','$city','$state','$zip','$country','$email','$phone','$cellphone','$employment','$employmentinfo','$dob','" . $image['name'] . "','$info') SELECT table2.id from table2 where table2.id=$id"; 2..........$sql = "INSERT INTO table1(id,fname, lname, gender, add1, add2, city, state, zip, country, email, phone, cellphone,employment,employmentinfo,dob, photo1,info) VALUES((SELECT id FROM table2 WHERE table2` WHERE username='".$_POST['username']."'),'$fname','$lname','$gender','$add1','$add2','$city','$state','$zip','$country','$email','$phone','$cellphone','$employment','$employmentinfo','$dob','" . $image['name'] . "','$info')"; I would appreciate your help. Thanks Smita Can 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; I have a simple INSERT statement that isn't inserting anything into one of the columns: coin_name I've gone over everything and can't figure out why. All other columns get data. HTML form passes everything fine. Is there a good way to debug this? I've triple checked everything and there are no type-o's that I see. Driving me mad... $query = "INSERT INTO Coin (coin_name, coin_value, coin_condition, year_minted, face_value, purchase_price) VALUES ('$coin_name', '$coin_value', '$coin_condition', '$year_minted', '$face_value', '$purchase_price');"; I am trying to create a query to insert data into a table in my Access database. I have the following query:
INSERT INTO Issues (DateRequested, CustomerID, ComputerID, Issue, ItemsIncl, ImageName) VALUES (#1/14/2015#, 1, 1, "Computer freezes while I'm on the internet.", "AC Adapter", "none.gif")which should be performed from within my PHP page. However, when I check the database afterward, the new record isn't there. I then tried performing the query directly in Access and it worked fine. Why would it work in Access, but not when I run the same query in PHP? Chris I have a bunch of checkboxes I am pulling from a database, like so. Code: [Select] <?$true_query = mssql_query("SELECT * FROM checkbox_datbase ORDER BY ID ASC"); while ($true_row = mssql_fetch_assoc($true_query)) { $eth_id = $true_row['ID']; $eth_name = $true_row['Value']; echo "<input type=\"checkbox\" name=\"eth_$eth_id\" value=\"1\" class=\"input\" id=\"Ethnic_01\"/>$eth_name <br />"; } ?>How do I put these into a database that I have settup where it needs to match up with a userid. I am trying to do this, and can get it to look correctly by echoing out the various parts, but I can't put while loops into a variable, right? So how would I get all of this into one line in my $sql variable? Code: [Select] echo "INSERT INTO new_database (UserId,"; $true_query = mssql_query("SELECT * FROM checkbox_datbase ORDER BY ID ASC"); while ($true_row = mssql_fetch_assoc($true_query)) { $eth_id = $true_row['ID']; $eth_eth_id = $_POST['eth_' . $eth_id . '']; echo " $eth_id, "; } echo "DateUpdated) VALUES ('$user_ID', "; $true_query = mssql_query("SELECT * FROM checkbox_datbase ORDER BY ID ASC"); while ($true_row = mssql_fetch_assoc($true_query)) { $eth_id = $true_row['ID']; $eth_eth_id = $_POST['eth_' . $eth_id . '']; echo "'$eth_eth_id', "; } echo "'$currenttime')"; This echoes something that looks like this INSERT INTO user_ethnicity (UserId, 1, 2, 3, 4, 5, 6, 7, 8, DateUpdated) VALUES ('', '', '', '', '', '', '', '', '', '2012-01-23 13:24:18 PM') , which I need the actual statement to be $sql = "INSERT INTO user_ethnicity (UserId, 1, 2, 3, 4, 5, 6, 7, 8, DateUpdated) VALUES ('259', '', '', '1', '', '1', '', '', '', '2012-01-23 13:24:18 PM')"; Can anyone help me with this? I am new to PHP and am currently learning the ropes. I have writen some code to insert a line into a mySQL database. I have created 3 fields in the mySQL database and am passing values two them. I can use a declared variable to pass information to the filed ID (Index filed in mySQL) but if I use a variable to pass purely text values the database is not updated. mysql_query( "INSERT INTO $tbl_name (category_Name, ID, test) VALUES ($category, $internalId, $category2)" ); If I replace the variables with specific text, the rows are added successfully. mysql_query( "INSERT INTO $tbl_name (category_Name, ID, test) VALUES ('werwerwer', $internalId, 'werrr')" ); It must be something stupid, I am sure. Full code below ob_start(); $host="localhost:8888"; // Host name $username=""; // Mysql username $password=""; // Mysql password $db_name="expenses"; // Database name $tbl_name="expense_category"; // Table name $category="test3"; $internalId="7"; $category2="test3"; // 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"); mysql_query( "INSERT INTO $tbl_name (category_Name, ID, test) VALUES ('werwerwer', $internalId, 'werrr')" ); echo "Done now 6!"; ?> Hello, guys. I am experiencing some problems with an INSERT statement in this page. It simply won't write to the database! I added echo at the bottom to check my variables and they print the values just fine. I checked the database, table and datafield names and everything is correct, plus I don't have any issues with the other 25 tables of my database. I'm using XAMPP btw... Any help would be appreciated! Code: [Select] <!DOCTYPE html> <html> <head> <meta content="text/html; charset=utf-8" http-equiv="content-type"> <title>Doctors</title> <link rel="stylesheet" href="style.css" media="screen" /> </head> <body > <?php session_start(); $inc_code=$_SESSION['incident']; $doc_code=$_REQUEST['doctor_code']; $con = mysql_connect("localhost","root",""); if (!$con) { die('Could not connect: ' . mysql_error()); } $mdb = "registry_db"; mysql_select_db($mdb, $con); mysql_query("SET NAMES 'utf8'", $con); ?> <div id="myform"> <p> <h2>Doctor in charge</h2> </p> <?php $sql="INSERT INTO doctors_per_incident(Incident_code, doctor_code) VALUES ('$inc_code', '$doc_code')"; echo "1 record added"." ".$inc_code." ".$doc_code; mysql_close($con); ?> </div> </body> </html> Folks, Tell me, do you see anything wrong in my INSERT ? If not, then why is it not INSERTING ? I get no php error, nor mysql error. Button I click. Then form data vanishes as if submitted. I check db and no submission came through! <?php //include('error_reporting.php'); ini_set('error_reporting','E_ALL');//Same as: error_reporting(E_ALL); ini_set('display_errors','1'); ini_set('display_startup_errors','1'); ?> <form name = "submit_link" method = "POST" action="<?php echo $_SERVER['PHP_SELF']; ?>"> <label for="domain">Domain:</label> <input type="text" name="domain" id="domain" placeholder="Input Domain"> <br> <label for="domain_email">Domain Email:</label> <input type="email" name="domain_email" id="domain_email" placeholder="Input Domain Email"> <br> <label for="url">Url:</label> <input type="url" name="url" id="url" placeholder="Input Url"> <br> <label for="link_anchor_text">Link Anchor Text:</label> <input type="text" name="link_anchor_text" id="link_anchor_text" placeholder="Input Link Anchor Text"> <br> <textarea rows="10" cols="20">Page Description</textarea> <br> <label for="keywords">Keywords:</label> <input type="text" name="keywords" id="keywords" placeholder="Input Keywords related to Page"> <br> <button type="submit">Click me</button> <br> <input type="reset"> <br> </form> <?php if($_SERVER['REQUEST_METHOD'] === 'POST') { /* if(ISSET($_POST['submit_link'])) {*/ mysqli_report(MYSQLI_REPORT_ALL|MYSQLI_REPORT_STRICT); mysqli_connect("localhost","root","","test"); $conn->set_charset("utf8mb4"); if(mysqli_connect_error()) { echo "Could not connect!" . mysqli_connect_error(); } $query = "INSERT into links (domain,domain_email,url,link_anchor_text,page_description,keywords) VALUES (?,?,?,?,?,?)"; $stmt = mysqli_stmt_init($conn); if(mysqli_stmt_prepare($stmt,$query)) { mysqli_stmt_bind_param($stmt,'ssssss',$_POST['domain'],$_POST['domain_email'],$_POST['url'],$_POST['link_anchor_text'],$_POST['page_description'],$_POST['keywords']); mysqli_stmt_execute($stmt); mysqli_stmt_close($stmt); mysqli_close($conn); } else { die("INSERT failed!"); } //} } ?>
@MacGuyver,
I will do the VALIDATIONS later. Remember, I was testing myself how much I can code without notes. What you see above was from my memory. Am still a beginner php student for 3yrs now, however! As for validation stuff will have to check notes and learn or relearn. Meaning, have to memorise the code before I add it here on current project. And so for now, ignore VALIDATIONS and let me know why it's not submitting data into db.
This topic has been moved to MySQL Help. http://www.phpfreaks.com/forums/index.php?topic=315503.0 I'm trying to create a INSERT query statement that makes use of the content of 'include' files. When I call up the include it simply echos it to the screen but I can't seem to capture the text string and actually make it function as part of the query. I've tried setting the include as a variable but again it only outputs to the screen. Help please! Here's a portion of the code... if (($_POST['sched_templates']) == "sched_TestingOnly.htm") { $query = include 'sched_TestingOnlyQuery1.htm'; } if (@mysql_query ($query)) { mysql_close(); // End adding Registration to the database header ('Location: redirectfile.htm'); exit(); } else { print "<p><b>Sorry, your entry could not be entered. } Hi guys, I have xml that looks like: <item> <title></title> <link></link> <description></description> <dc:date>2011-02-27T16:42:31-05:00</dc:date> </item> I can access title, link, and description just fine. But how do I access a tag that has a colon? I tried this: Code: [Select] $x = new SimpleXmlElement($content); $entry = $x->item; $entry->children('dc', true)->date; Thanks for looking. LR 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 I just implementet a PHP Guestbook in my Flash site, and it works almost perfectly. But i have one problem. Every time i try to write on the guestbook, and include a Colon : <---- , it wont work. How do i make it work? You can see the guestbook he http://www.meny-graphics.dk/blog by pressing "Mere" under the first entry, and scrolling down. The PHP file can be found he http://www.meny-graphics.dk/blog/GuestBook.php Thanks in advance! I have a table with 5 records with the following "id_number" for each record in ASC order: 2, 6, 74, 86,87 There is one other field called "tag_number" and for each record in ASC order here is the data: 50670, 50077, 1234, 1235, 1236 I have a text field and if I search for a spastic "tag_number" I want to return the record but count and display what record like this: Record 3 of 5 The above 3 of 5 means I searched for "1234". I'm not sure what loop I need and how to count the records, any help would be great! Here is what I'm thinking: $id_number = 74; $result = db_query("select * from table order by id_number ASC"); $num_rows = mysql_num_rows($result); //this will provide how many records are in the table $result = db_query("select * from table where id_number = '$id_number' order by id_number ASC"); for ($i = 1; $i == $num_rows; $i = $i + 1) { if ($result['id_number'] == $id_number) { This topic has been moved to MySQL Help. http://www.phpfreaks.com/forums/index.php?topic=312323.0 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 |