Jump to content

A little syntax help, please.


shiloam

Recommended Posts

I really appreciate you guys.  Could you guys help me out with a little syntax trouble.

 

<?php


$id=$_POST['id'];

$db="prayers";

$link = mysql_connect('localhost', 'root' , '');
if (! $link) die(mysql_error());
mysql_select_db($db , $link) or die("Select Error: ".mysql_error());

$rt=mysql_query($query);
echo mysql_error(); 

while($nt=mysql_fetch_array($rt)){
$result=mysql_query(
$query = "SELECT howmanyprayed from prayerwall BY ". $id .""
$new_val = $row['howmanyprayed'] + 1;
"INSTERT $new_val into prayerwall (
howmanyprayed) VALUES (
'$new_val')") or die("Insert Error: ".mysql_error());
mysql_close($link);

?>

 

 

It's a button that's like the facebook "like" button.  It's submitting a form through a button, but I'm getting this error when I submit.

 

Parse error: syntax error, unexpected T_VARIABLE in /Applications/XAMPP/xamppfiles/htdocs/1/church@arkprayer/dafiles/prayedreceive.php on line 18

 

Here's the form submit button

 

<FORM METHOD=LINK ACTION=prayedreceive.php>
<INPUT TYPE=HIDDEN NAME=clickprayed value=$nt[id]>
<INPUT TYPE=submit VALUE=Prayed> #$nt[id]
</FORM></br></br>";  

 

I really appreciate any help.  :D

Link to comment
Share on other sites

This chunk of code is riddled with errors:

<?php

while($nt=mysql_fetch_array($rt)){
$result=mysql_query(
$query = "SELECT howmanyprayed from prayerwall BY ". $id .""
$new_val = $row['howmanyprayed'] + 1;
"INSTERT $new_val into prayerwall (
howmanyprayed) VALUES (
'$new_val')") or die("Insert Error: ".mysql_error());
mysql_close($link);
?>

 

Ken

Link to comment
Share on other sites

Yea I took a look at it I didn't see how bad it was.  I cleaned it up a bit... If it's too far off then tell me I'll mark solved.  Thank you.

 

<?php


$id=$_POST['id'];

$db="prayers";

$link = mysql_connect('localhost', 'root' , '');
if (! $link) die(mysql_error());
mysql_select_db($db , $link) or die("Select Error: ".mysql_error());
echo mysql_error(); 

$query = "SELECT * from prayerwall BY $id";
$rt=mysql_query($query);
echo mysql_error(); 

while($nt=mysql_fetch_array($rt)){

$new_val = $row['howmanyprayed'] + 1;
"INSERT $new_val into prayerwall (
howmanyprayed) VALUES (
'$new_val')" or die("Insert Error: ".mysql_error());
mysql_close($link);

}

?>

Link to comment
Share on other sites

It isn't throwing any php parse errors, but there are SQL syntax issues.

 

$query = "SELECT * from prayerwall BY $id"; // do WHAT by $id ? ? ?

// This query string is just out there in the middle of nowhere, not assigned to a variable or anything . . .
"INSERT $new_val into prayerwall (
howmanyprayed) VALUES (
'$new_val')" or die("Insert Error: ".mysql_error());

// The syntax is wrong too.
$example = "INSERT INTO `table` (`field1`, `field2`) VALUES ( 'string1', 'string2')";

Link to comment
Share on other sites

Maybe it would help if I explained a little..

 

There's a button on the other page that has the id of the post in it's form.  It's invisible, and in the button.  When they hit the "I prayed button".  It sends a form to prayedreceive.php.  Where it's selecting the one of the id.  And then the main function is to add one to the field "howmanyprayed".. so..

 

[----] #4 prayed!

 

 

They hit the button..

 

[----] #5 prayed!

 

<?php


$id=$_POST['id'];

$db="prayers";

$link = mysql_connect('localhost', 'root' , '');
if (! $link) die(mysql_error());
mysql_select_db($db , $link) or die("Select Error: ".mysql_error());
echo mysql_error(); 

$query = "SELECT howmanyprayed from prayerwall WHERE id = $id";

//This is what I was meaning to do haha.

$rt=mysql_query($query);
echo mysql_error(); 

while($nt=mysql_fetch_array($rt)){

$new_val = $row['howmanyprayed'] + 1;
$update = mysql_query(
"INSERT INTO 'prayerwall' ('howmanyprayed') VALUES ('$new_val')";


}

?>

 

Is this looking any better? I'm winging it here. Thank you I appreciate the help, also why do you hate everything?

Link to comment
Share on other sites

Ahh ok I'm getting it now.

 

I needed

$query = "SELECT howmanyprayed from prayerwall WHERE id = $id";

 

There's an auto-increment set on each prayer posted.  Each prayer has an unique number value for the howmanyprayed in mysql, due to how many people press the button. So it is selecting the $id equeal to the id that they pressed. 

Link to comment
Share on other sites

Yea that was part of it.  For some reason I'm getting this error.  Thanks for all the help man, I appreciate it.

 

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

Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in /Applications/XAMPP/xamppfiles/htdocs/1/church@arkprayer/dafiles/prayedreceive.php on line 18

 

<?php


$id=$_POST['id'];

$db="prayers";

$link = mysql_connect('localhost', 'root' , '');
if (! $link) die(mysql_error());
mysql_select_db($db , $link) or die("Select Error: ".mysql_error());
echo mysql_error(); 

$query = "SELECT howmanyprayed from prayerwall WHERE id = $id";

$rt=mysql_query($query);
echo mysql_error(); 

while($nt=mysql_fetch_array($rt)){

$new_val = $row['howmanyprayed'] + 1;
$update = "INSERT INTO prayerwall (howmanyprayed) VALUES ('$new_val')";

}

?>

 

Also you didn't answer the question of why you hate everything ha.

Link to comment
Share on other sites

Dude thanks so much, it's not updating, but it's also not giving me any errors.  I'm thinking it has to do with my form or something.  I'll mess around with it. 

 

Also there's hope bro.  I used to be atheist and doin drugs.  Religion sucks, but God is real.  He's straight up real dude, I dare you to try being real with Him and talking to Him.

 

Later  :shy:

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.