Jump to content

Archived

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

SithLord2K

PHP Syntax Error.......

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.

Share this post


Link to post
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]

Share this post


Link to post
Share on other sites
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\"]')";

Share this post


Link to post
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......

Share this post


Link to post
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

Share this post


Link to post
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.  :(

Share this post


Link to post
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

Share this post


Link to post
Share on other sites
Still having the same issues......

[url=http://alphaomegawebdesign.ueuo.com/alphaomega/index.php?page=setname]http://alphaomegawebdesign.ueuo.com/alphaomega/index.php?page=setname[/url]

Please go here to see what I am talking about.

Share this post


Link to post
Share on other sites

×

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.