Jump to content

PHP Syntax Error.......


SithLord2K

Recommended Posts

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.
[code]
<?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);

}

?>[/code]


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.
Link to comment
https://forums.phpfreaks.com/topic/25509-php-syntax-error/
Share on other sites

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', [b]$_POST['name'][/b])";
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 [code=php:0]$user=$_POST['name']; [/code] to $user = mysql_real_escape_string($_POST['name']);[/code]
Link to comment
https://forums.phpfreaks.com/topic/25509-php-syntax-error/#findComment-116378
Share on other sites

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

[code]<?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);

}

?>[/code]

I have tested this but it still doesn't seem to work......
Link to comment
https://forums.phpfreaks.com/topic/25509-php-syntax-error/#findComment-116400
Share on other sites

[code]<?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);

}

?>[/code]


'users' should be users or `users`


:)

regards
Liam
Link to comment
https://forums.phpfreaks.com/topic/25509-php-syntax-error/#findComment-116402
Share on other sites

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.  :(
Link to comment
https://forums.phpfreaks.com/topic/25509-php-syntax-error/#findComment-116415
Share on other sites

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

[code]<?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';
        }
}

?>
[/code]

I beleave that should work :)

Liam
Link to comment
https://forums.phpfreaks.com/topic/25509-php-syntax-error/#findComment-116417
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.