Jump to content


Photo

PHP Syntax Error.......


  • Please log in to reply
7 replies to this topic

#1 SithLord2K

SithLord2K
  • Members
  • PipPip
  • Member
  • 12 posts

Posted 29 October 2006 - 06:34 PM

I'm pretty sure there is a syntax error here somewhere but I'm not seeing it and I've been over it 100 times easily. But when I try to load this page it won't load. also anything that is supposed to load after it doesn't load either.
<?php

if (isset($_POST['submit']))
{
include('includes/db_conn.php');
	mysql_connect("$db.host", "$db.uname", "$db.pass"); 
	mysql_select_db("$db.name");


	$ip_address=$_SERVER['REMOTE_ADDR']; 
	$user=$_POST['name']; 

	$sql="INSERT INTO 'users' ('id', 'ip_address', 'name') VALUES (NULL '$ip_address', $_POST['name'])";
	$result=mysql_query($sql);

}

?>


below this is my form info. I have tried multiple times to try and get a separate file to do the php checking and data entry but they don't seem to work for me.

#2 wildteen88

wildteen88
  • Staff Alumni
  • Advanced Member
  • 10,482 posts
  • LocationUK, Bournemouth

Posted 29 October 2006 - 06:39 PM

The only error I got when running it through my IDE is the following error:
PHP Parse error:  parse error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in C:/Server/www/test.php on line 13

Which is to do with this:
$sql="INSERT INTO 'users' ('id', 'ip_address', 'name') VALUES (NULL '$ip_address', $_POST['name'])";
You need to use $user as you have already setup a variable which stores the value of $_POST['name'].

Also I suggest you use a function called mysql_real_escape_string on the $_POST['name'] variable to prevent SQL Injection attacks. So change
$user=$_POST['name'];
to $user = mysql_real_escape_string($_POST['name']);[/code]

#3 ponsho

ponsho
  • Members
  • PipPip
  • Member
  • 24 posts

Posted 29 October 2006 - 06:48 PM

i also noticed that you missed the comma between the NULL and the ip_adress

$sql="INSERT INTO 'users' ('id', 'ip_address', 'name') VALUES (NULL,'$ip_address', '$_POST[\"name\"]')";

#4 SithLord2K

SithLord2K
  • Members
  • PipPip
  • Member
  • 12 posts

Posted 29 October 2006 - 07:18 PM

Ok I've made the following changes.....

<?php

if (isset($_POST['submit']))
{
require('includes/db_conn.php') ; //Now contains the connect and database select strings
	


	$ip_address = $_SERVER['REMOTE_ADDR']; 
	$user = mysql_real_escape_string($_POST['name']); 

	$sql="INSERT INTO 'users' ('id', 'ip_address', 'name') VALUES (NULL, '$ip_address', '$user')";
	$result=mysql_query($sql);

}

?>

I have tested this but it still doesn't seem to work......

#5 shocker-z

shocker-z
  • Members
  • PipPipPip
  • Advanced Member
  • 864 posts
  • LocationNottingham

Posted 29 October 2006 - 07:21 PM

<?php

if (isset($_POST['submit']))
{
require('includes/db_conn.php') ; //Now contains the connect and database select strings
	


	$ip_address = $_SERVER['REMOTE_ADDR']; 
	$user = mysql_real_escape_string($_POST['name']); 

	$sql="INSERT INTO `users` ('id', 'ip_address', 'name') VALUES (NULL, '$ip_address', '$user')";
	$result=mysql_query($sql);

}

?>


'users' should be users or `users`


:)

regards
Liam
www: www.ukchat.ws | irc: irc.ukchat.ws chan: #blufudge

#6 SithLord2K

SithLord2K
  • Members
  • PipPip
  • Member
  • 12 posts

Posted 29 October 2006 - 07:32 PM

Thanks, I forgot about the `  instead of ' but for some reason it's still not working, all I get when I hit the submit button is a blank page and anything that's set to load after the script runs doesn't show up. I also checked the db and the info isn't entered.  :(

#7 shocker-z

shocker-z
  • Members
  • PipPipPip
  • Advanced Member
  • 864 posts
  • LocationNottingham

Posted 29 October 2006 - 07:37 PM

That's because your inserting.. a successful insert returns no data as it has simply inserted data and there is no return from that.. you can use this to echo a success tho

<?php

if (isset($_POST['submit']))
{
require('includes/db_conn.php') ; //Now contains the connect and database select strings
	


	$ip_address = $_SERVER['REMOTE_ADDR']; 
	$user = mysql_real_escape_string($_POST['name']); 

	$sql="INSERT INTO `users` ('id', 'ip_address', 'name') VALUES (NULL, '$ip_address', '$user')";
	$result=mysql_query($sql);
        $created=mysql_insert_id();
        if ($created !== '') {
         echo 'Successful';
        } else {
         echo 'ERROR';
        }
}

?>

I beleave that should work :)

Liam
www: www.ukchat.ws | irc: irc.ukchat.ws chan: #blufudge

#8 SithLord2K

SithLord2K
  • Members
  • PipPip
  • Member
  • 12 posts

Posted 30 October 2006 - 12:19 AM

Still having the same issues......

http://alphaomegaweb...hp?page=setname

Please go here to see what I am talking about.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users