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