Variables Combined With String In SQL Statements
I get this 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"
My sql statement is this:
mysql_query("INSERT INTO players (player_id, match_id, kills, deaths) VALUES ('$user_id', ".$_POST['match_id'].",".$_POST['kills$username'].", ".$_POST['deaths$username'].")") or die ('Error adding new player '.mysql_error());
I'm thinking it must be to do with me combining string and variables together.
So is ".$_POST['kills$username']." correct?
View Complete Forum Thread with Replies
Related Forum Messages:
Wordwrap() Not Working With Variable Combined String
I'm trying to get the wordwrap() function to work. It's not working properly. What I'm trying to do is combine five text strings into one variable string and then apply the wordwrap() function to the combined string. What it's doing is the wordwrap() function does not start working until it gets to the last variable in the combined string. Code:
View Replies !
Statements In Variables
possible to put if, if else and else statements in a variable: example: <?php $statement = 'if(1 = 1) {                    echo("1 does equal 1");                    }'; ?>
View Replies !
< ? Php $string ? > Within Html Statements?
I'm trying to reduce my code in html by calling a page.php file which blocks out the html for me. I was having a hell of a time since my html wouldn't parse the php code so in page.php I ended and started php and used regular html in between. my problem is that I'm trying to use a string to lable my blocks of html (you know .... a links menu < home > < go here > < go there > with the $ string lableling each header area. Everything is parsing except for the $ string name --- so I have lots of nested tables with everything filling except the title of the block, Code:
View Replies !
IF Statements And Empty Variables
I need to know how to do an IF Statement with a Empty Variable and how it to redirect to another page. I have tried this code but all it does to contiunes to reload. if (empty($section)) { header("Location: index.php?section=index"); exit; } So if you goto /index.php it would reload to /index.php?section=index
View Replies !
If(empty) Statements/session Variables
1. I have a 2 page form. When the user fills out the info on page form he is directed to the 2nd page of the form. A session variable has been created in the 2nd form to hold all the data from the 1st page. When the 2nd page is submitted all the data (stored from page 1 and new from page 2) are sent to the database. 2. Here is the problem. On page 1, I have several form fields (like combo boxes) that need to work together. For example: I have a text field (name=phylum) in which investigators add new phylum names which are eventually sent to database field "phylum" of the same name. Next to that is a select box (name=newphylum) that has all the names that the investigors have previously entered and that are dynamically retrieved from the database field "phylum". So when a researcher fills out page 1 of the form he/she can either add a new name or select an already existing name from the select box. But just one of these values can be sent to the database, not both. QUESTION 1: How can I say and where would I put something that basically says the following: if the phylum text field is left EMPTY (i.e. they don´t add a new name) and they select instead from the select box, that it is the value from the select box and not the text box that gets sent to the database. QUESTION 2: How do I pass the statement from question 1 into the session variable on page 2 of my form?
View Replies !
Problem Binding Variables To Oracle Statements
I'm experimenting with PHP5, ORacle 9i and ADODB and have run into problems trying to bind and output variable. I can make a successful connection to our database via the MSDAORA provider but the following simple statement will not work: $oCMD = new COM("ADODB.command"); $oCMD->ActiveConnection = $dbConn; /// $dbConn generated earlier ... $oCMD->Prepared = True; $oCMD->CommandText = "SELECT 12345 INTO :num FROM dual"; $oCMD->Parameters->Append($oCMD->CreateParameter("num",adInteger,adParamOutput,5)); $oCMD->Execute(); $ans = $oCMD->Parameters->Item("num")->Value; echo "answer: [$ans] <br />"; This generates the following : answer: [] I've tried binding via the '?' spaceholder as I've been told that can be used as well but it fails with the following: Fatal error: Uncaught exception 'com_exception' with message 'Source: Provider Description: Unspecified error' ....
View Replies !
Mysql Real Escape String() In Conditional Statements
I created the following bit of code that allows me to pass a MySQL conditional statement to a function. I am trying to figure out where and how would I go about incorporating the mysql_real_escape_string() function? Is there a way to call the mysql_real_escape_string() in the function itself? Code:
View Replies !
Collect Form Data, Use Variables, Concatenate Into String And Fopen String?
I currently have a PHP file that already includes variables such as 'username' and 'password' (for authentication), but I would like to collect the form data submitted, concatenate everything into one string, and then open up this string (which is essentially a url) I undrstand (with thanks to schme16) that I have to use $_POST['name_of_form input'] to retrieve the data, but after that I would like to put all of these into one string that looks like http://www.wbsite.com/something.php?username=$username&password=$password&msg=$message and then use fopen to load this url.
View Replies !
Php Combined With Html
I know that you can combine PHP with HTML and name the file with the php extension but what I was wondering, does it seem to cause alot of problems for people when doing this?? Why am I asking this you wonder? Well I have a website thats mainly HTML (all but the contact page) and I needed an image hosting script so I got one and combined it with my HTML template, renamed it .php and at first it worked but now its gone all wonky!! I cant seem to figure out what went wrong or if I had mistakingly changed something but I have been on this for hours and hours and now I have a headache and am fed up.. Code:
View Replies !
Combined Selections
I used session to pass the values along it working fine i can echo and see the values on difference pages but i cannt combine them i want to do is if you select something from page1 and then something else on page2 and 3 and so on at the end it will base on the combination of what have been selected on all the pages and will display output to the screen. select "a" from page1 and "b" from page 2 then "c" from page 3. on the last page i tried to combine the selection like this but it doesnt work PHP Code: if (($_POST['a'] == 'true') && ($_POST['a'] == 'true') || ($_POST['c'] == 'true')) { echo 'somthing here' }
View Replies !
Search By Firtst Name Or Last Name Or First And Last Combined?
Here is my query, it will search a user input name for first name or for last name but when a user types in First name SPACE Last name it returns nothing, how can I make it search this way? select * from friend_reg_user where 1=1 and (fname like '%$search%' AND lname like '%$search%') and status='Active' Like my guess is this part is fine for search for first or last name but in the user submitted name I need to search for a "jason+davis" the + and count the first word as a varibale and the 2nd word as a variable.
View Replies !
Creating A Combined Reference Number
I would like to create a simple reference number for example a customer and an order. currently i am using auto_increment ids to perform all dbase queries, which is fine for the dbase, however i also want a more meaningful representation of details for users. e.g. customer name = bob hoskins companyname = vcom dbase id = 78 = bovc78 so essentially i want a bit of each string to make one. i know how to use concatenate, however i dont know how to limit the number of chars used in each part of the string.
View Replies !
Multiple SELECT Queries Combined
I have several SELECT queries on a few of my webpages, and I have been told that the more query connections that are open the slower the server will run. So firstly, is it possible to merge/combine 2 SELECT queries into a single query? Code:
View Replies !
Looking For Windows Mysql/php/webserver Combined Package
A while ago I found a mysql/php/webserver bundle of software for windows that installed all three at once and made it easy to start developing sql/php web apps. Now I can't remember what it was or where to get it, and wondered if anyone here can suggest anything along those lines?
View Replies !
Database Query Function, Combined With IPN Script
I am using a IPN script I found after awhile of google searching, and it works perfectly, except I have one problem, I have a function that runs on success of a paypal payment, and it is suppose to run once the IPN script has confirmed the payment has been made. The function that runs on success of a paypal payment, updates information in a user table in my database. I had it working earlier, when I was testing this on paypal sandbox, but now for some reason it doesn't do the function, or atleast doesn't do the queries in the function. Code:
View Replies !
Comparing Values Of 2 Arrays Combined With Mysql Field Names
I am trying to create an edithistory table that has a text column into which I will put a string that can be read using strtok later to revert changes if necessary. I want to build this function so that it's dynamic enough to be applied to every table so that I don't have to write one for each table that might be updated. When a row is added to any table (a new entry), it retrieves the next available editid # from the edithistory table and assigns it to that item in the "edits" column for its row in its own table. Every edit made is a new entry in the edithistory table (entryid auto_increment primary key), and the editid is a reference back to the object being edited. Code:
View Replies !
2 Variables With The Same String
I've transfered a bunch of names from a txt file into an array. Now i need to compare it against a string i have. When the strings are the same, for some reason it returns 'false' when i compare it. any idea what's the problem? the names are the same but i don't know why's the result is false.
View Replies !
Modify String With Variables
i've built a multi-langual site. Languages are defined by a variable in the url -> 'l=en'. There can be more variables in the url: mydomain.com/site.php?l=en&item=5&name=foo, but l=en can also be the only variable. The requested url is saved in a session variable for various reasons. Now i wonder, if someone enters a language that doesn't match any language i provided, i want them to be redirected to a page which tells them the language doesn't exist. The links aren't allowed to lose any possible variables, i tried to use preg_replace by searching 'l=' and '&', but since i'm not sure there are multiple variables, there isn't always a '&' in the URL. Any clues?
View Replies !
Set URL String Data As Variables
I am trying to build a script that will read a list of strings from another webpage & break down the string to the info I need. Example string on the webpage: - 2104&The+title&This+is+where+the+description+goes so its basically ID&title&description with + as space . Can I use the $_GET command? or am I way off? All I want to do to use the same example.. is to get the output $id = 2104; $title = "The title"; $description = "This is where the description goes";
View Replies !
Splitting A String Into 2 Variables
I'm having trouble splitting a string into 2 variables in the following situation: an outside script from an affiliated site is going to post to my script using GET method, they will give me a numeric string and unfortunately, I cannot modify their script. The string will be posted using the get method and named 'sid' so for example, it may be ?sid= 1009102 Now here's what I want to do: I need to "grab" the first 4 digits, and pass them into one variable. There may be any number of digits after that, I'll need to pass those digits into a second variable. Code:
View Replies !
$_GET Variables From A Url String
im using a set of GET's form a url string that is generated from a search form. The problem is that none of the variables are showing up when echoed. The variables are obviously there because they are held in the url. The problem i think i may have broken it down to is that the string looks a little something like this: www.domain.com/search/?keywords=keywords..etc... do i need to include the file name in order for the $_GET to work? I did a test with this and worked better than without the file name but that may have been because it was a different file. Is there a way of doing this using $_GET variables? I flicked through the idea of sessions but i decided that i much prefer the idea of the url changing per search, this way the user can copy the search result url into an email etc...
View Replies !
Capture Variables In A String
I am trying to capture my query results in a string so that I can then pass that string to a javascript output display but am fairly new to PHP and am not sure which direction to head. Code:
View Replies !
Replace Variables In A String
Several years ago I came accross a Perl regular expression which found all variables in a string and replaced it with the correct value. I have $message stored in a database, and within $message is the text $name. My PHP code pulls a list of $name's from my database and needs to replace $name in $message. There are other variables to replace too, so the code needs to be a generic approach. I remember that the code searched for a '$' then [a-zA-Z0-9_]. It then replaced what it found with the contents of ${variable}. Does anyone have a similar solution available, as I aren't too good with regular expressions!
View Replies !
Passing Variables In A String To A Class
I have a class that handles establishing a connection to a mysql database, and outputting a mysql_query that can be acted upon to fetch results. I pass my sql query as a argument to the function in the class that handles the query. It's been working fine until I passed it a query that had a variable in it. PHP Code:
View Replies !
Include Variables In The Middle Of A String
I'm finding it hard to assign a variable at the beginning of a file and then throw the variable in the middle of an include string. For example: &var = "filename"; <?php include "http://www.mysite.com/".$filename;.".php";?> I've also tried it without the semi-colon after the filename. What am I doing wrong here?
View Replies !
Storing String In Database With Variables
I have a string I want to store in a text field in a database. This string has the variable $Name in it. When I pull it out of the database, I want that variable to be substituted with the value I define before I print the string. It doesn't seem to work. I tried looking into eval(), but that doesn't do what I want it to do. Has anyone who has done this before want to shed some light on how to do it?
View Replies !
Isolating Variables From Large String
Right now I'm faced with the problem of trying to isolate the variables. Let's say part of the source code looks like this: ... <td class="class" width="175" height="20" align="right" valign="top">Class: Calculus</td> <td>***</td> <td class="class" width="175" height="20" align="right" valign="top">Grade: A</td> <td>***</td> <td class="class" width="175" height="20" align="right" valign="top">Year: 1988</td> <td>***</td> ... What would be the best approach to isolate the values "Calculus", "A" and "1988"?
View Replies !
Smarty - 'explode' String Into An Array Or 2 Variables
I've a smarty var, like this: {$var} that is equal to: ttttttttttttt|zzzzzzzzzzzz It can be any size, the important is that they are separated by the '|' How do I 'explode' that into an array or 2 variables in the smarty template ? So I can just use: {$var[0]} = ttttttttttttt; {$var[0]} = zzzzzzzzzzzz;
View Replies !
Using Global Variables In The Database Connection String
I'm sure this has been asked a million times but I can't seem to formulate a google search that returns what i'm looking for. I've go a dev and live environment. Currently the DB connect string is hard coded into each php file which means i'm going to have to change every page - Arrgh!! If i put the DBonnect into a function and store it in an include file, it doesn't seem to work, Also the connetion works with inline PHP statements, but I have to repeat it in every function even if they are in the main php file??? which doesn't seem right to me.. I need to either :- Store the connection variables in an include file and retrieve them as global values OR Store the connection string in a function in an include file which can be accessed by all functions. also do I really have to call the dbconnect inside every function. Please note, if it makes any difference, I still havn't got my head round OO programming in PHP so it is still pretty much procedural. I am using PEAR but dont really understand (or care at the moment) about what it is doing.
View Replies !
Creating Incremental Variables From An Exploded String
I have searched and searched and can't seem to figure out exactly how to do this -- I think my syntax on some solutions may have been off, but I am not sure. I want to take a pipe-delimited string and cycle through the contents so I can mark associated check boxes as checked or not. Let's say I have a group of check boxes for a form. These check boxes are multiple selection named: performed[]. Code:
View Replies !
How To Parse Posted Variables To Do Preg_match And String Functions
I know how to parse posted variables to do preg_match and string functions. What I am wondering is if there is a way to parse global variables as a function. I am not too famialiar with functions per say, but I need to learn how to master them in order to finish my project. Here is a sample code php $name = $_POST["name"]; $favorite = $_POST["favorite"]; $time = $_POST["time"]; echo ?> What I am trying to do is striptags and preg_match the data to cleanse it. I know how to do that on a variable by variable basis, but I have a total of 31 variables that are user inputed. I hear that php5 has a cleanse function built in, but this is on php4..
View Replies !
For Statements
i have two values i wish to use in the one for(); Ill make an example below which will make it easier to understand what im trying to do. <?php $value1 = 100; $value2 = 100; for ($i=0;$i<???;$i++){ $value1 = $value1 - rand(0,10); $value2 = $value2 - rand(0,10); echo("Value1 is now $value1, And Value2 is now $value2"); if ($value1 < 0){ ???=1; } if ($value2 < 0){ ???=1; } } The question marks () is the section that im not sure how to do... As i have two values that are 100 but $value1 or $value2 will reach 0 first and i wish it to stop once either have become 0.
View Replies !
Statements
I'm trying to add some data to a MYSQL table UNLESS it sees a duplicate entry for what is entered in the textbox and submit is hit. However it just submits the data anyway despite it being a duplicate. Code:
View Replies !
If Statements With OR
I want to say something like this: PHP Code: <? if($row['status'] == Ƈ'Â Â Â ORÂ Â ƈ'Â Â Â Â ){ ?> Is there a way to simple state: if status is equal to 1 or 2, then.
View Replies !
If Statements
can i put an include in an if statement? this is my script: PHP Code: <?php if ( $user['close'] == 1 ) { header( 'location: closed.php' ); } else ( $user['close'] == 0 ) { header( 'location: index2.php' ); } ?> the error i get is:Parse error: syntax error, unexpected '{' in /home/twysted/public_html/game/index.php on line 5 how i would get this to work, i have scripters block at the moment.
View Replies !
IF ELSE Statements
I've search around and can't seem to find any references to it. Is there a way to make IF AND.. statements? Like - If (x=4 AND y=2) { } else if (x=2 AND y=4) { and so on... If not, what would be the best practice way to accomplish something like this?
View Replies !
If Ane Else Statements
Im trying to make it so that when someone goes to my website on the right there will be a login form if they arnt logged in, and if they are, I include a little welcome page. Code:
View Replies !
Else Statements
Normally I'd do something like this.<?php if (Something) { echo "Something..."; } else { echo ""; } ?> Would this work the same? <?php if (Something) { echo "Something..."; } else { } ?>
View Replies !
AND Statements
I have a tricky question. If there is a MySQL query that has Code: WHERE a=1 AND b=1 Will it still go to evaluate "b=1" if it finds "a is not equal to 1" first. If so, the order of WHERE statements can impact performance so I'm trying to find out.
View Replies !
|