What's wrong with this query? Syntax error [closed] - php

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
What's wrong with this? It returns "You have an error in your syntax... ...check if you have the right MySQL version to use near 'to, content, link) VALUES..."
$notito = $idoftheguy;
$contentofnoti = $username." just posted a comment on your update.";
$linkofnoti = "http://mywebsite.net/post.php?id=".$thepostid;
/* Now let's insert this */
$insertnoti = mysql_query("INSERT INTO newnotifications (to, content, link) VALUES ('$notito', '$contentofnoti', '$linkofnoti')");
All of the above things in the query are existent in the database. And here are the exact inputs that gave the error (haven't tried any other inputs):
$notito = 1;
$contentofnoti = "Schart just posted a comment on your update.";
$linkofnoti = "http://mywebsite.net/post.php?id=22";

As already mentioned. to is a reserverd word. Try this code:
$insertnoti = mysql_query("INSERT INTO newnotifications (`to`, `content`, `link`) VALUES ('$notito', '$contentofnoti', '$linkofnoti')");

Related

Assign empty string to php variable [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
Just need help fixing this php code
if ($cmtx_set_name_value == "anonymous")
{
$cmtx_set_name_value = ""
}
thanks
Try adding ; after the assignment.
$cmtx_set_name_value = "";
your code is work fine just put ; to end of line
if ($cmtx_set_name_value == "anonymous"){
$cmtx_set_name_value = "" ; }

Cannot show out results with SUM operator in PHP [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
may I ask for help? I cannot show out the result. If I run the code without the SUM operator, it works properly. Please help, thank you very much.
$sql1 ="SELECT SUM(SeatAmount) FROM reservation
WHERE RsvDate BETWEEN '07/01/2013' AND '07/31/2013'";
$result1 = $con->query($sql1);
printf('<td>');
printf('<b>Seat Amount</b><br/>');
while ($row1 = $result1->fetch_object())
{
printf('
%d<br/>',$row1->SeatAmount);
}
In order for that to work, you'd need an alias:
SELECT SUM(SeatAmount) AS SeatAmount
what is $row1's structure?
You can specify what the sum should be returned as like:
SELECT SUM(SeatAmount) AS SeatAmount
$sql1 ="SELECT SUM(SeatAmount) AS Total FROM reservation
WHERE RsvDate BETWEEN '07/01/2013' AND '07/31/2013'";
$result1 = $con->query($sql1);
printf('<td>');
printf('<b>Seat Amount</b><br/>');
while ($row1 = $result1->fetch_object())
{
printf('
%d<br/>',$row1->Total);
}

PHP "Notice: Array to string conversion" error when inserting to SQL [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I'm trying to insert some values to my table, but i keep getting the following Notice :
Notice: Array to string conversion in C:\Program Files\wamp\www\process_invitation.php on line 10
Line 10 is the insertion line in the following code :
if ((isset($_POST['inviter'], $_POST['opponent'])) && ($_POST['inviter'] != '' && $_POST['opponent'] != '' )) {
$inviter = $_POST['inviter'];
$opponent = $_POST['opponent'];
$now = time();
if ($mysqli->query("INSERT INTO invitations (inviter_user_id, invited_user_id, time) VALUES ('$inviter','$opponent','$now')")) {
return;
}
}
Have you tried var_dumping $inviter and $opponent to see what datatype they are? Try just casting them to (string) too. Also, it's a good idea to use parameterised queries with mysqli. As it stands, you're leaving yourself wide open to SQL injections.
Print the output of variables & you will know where the problem is:
print_r($inviter);
print_r($opponent);
Make sure to extract value from the array before mysql insertion.

how to find the count of letter 't' in the below paragraph mentioned using php [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
$a='Would you like to have responses to your questions sent to you via email'
for($a as $b=>c){
}
Kindly give me the solution
<?php echo substr_count($a, 't'); ?>
Here's a solution, though not necessarily the best
$letterCount = array_count_values(
str_split(strtolower($a))
);
$tCount = (isset($letterCount['t'])) ? $letterCount['t'] : 0;
$count = preg_match_all('/t/', $str);
check this one
<?php
$a = 'Would you like to have responses to your questions sent to you via email';
$t_explod = explode('t', strtolower($a));
echo count($t_explod) - 1;
?>

How to write a Loop for a Dummy? [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
this is probably an easy question, but I am not really a coder. I maintain a website for a group I belong to, and there are some php forms. I am trying to enhance a form, and I have added this php code, which works (see below). My question is, how can I put this code into a loop so that it repeats 10 times, for "01", "02", etc., "10" strings (code below is for "01" of the series)? Thanks for any help.
//Clean up the Photo Title & Maker Name to remove non-standard chars and replace spaces with underscores and generate a suggested fliename
$photo_01_clean = str_replace(" ","75357",$photo_01_name);
$photo_01_clean1 = str_replace("#","at",$photo_01_clean);
$photo_01_clean2 = preg_replace('/[^a-z0-9]/i', '', $photo_01_clean1);
$photo_01_clean3 = str_replace("75357","_",$photo_01_clean2);
$photo_01_maker_clean = str_replace(" ","75357",$photo_01_maker_name);
$photo_01_maker_clean1 = str_replace("#","at",$photo_01_maker_clean);
$photo_01_maker_clean2 = preg_replace('/[^a-z0-9]/i', '', $photo_01_maker_clean1);
$photo_01_maker_clean3 = str_replace("75357","_",$photo_01_maker_clean2);
$photo_01_filename_gen = $club_code."-01-".$photo_01_clean3."-".$photo_01_maker_clean3.".jpg";
You'd require a for loop control structure. You can find tons of resources that would teach you how to do it. example
Var i;
For (i =1; i<11; i++)
Execute Code here.

Categories