SithLord2K Posted October 29, 2006 Share Posted October 29, 2006 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]<?phpif (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 More sharing options...
wildteen88 Posted October 29, 2006 Share Posted October 29, 2006 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 13Which 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 More sharing options...
ponsho Posted October 29, 2006 Share Posted October 29, 2006 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\"]')"; Link to comment https://forums.phpfreaks.com/topic/25509-php-syntax-error/#findComment-116384 Share on other sites More sharing options...
SithLord2K Posted October 29, 2006 Author Share Posted October 29, 2006 Ok I've made the following changes..... [code]<?phpif (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 More sharing options...
shocker-z Posted October 29, 2006 Share Posted October 29, 2006 [code]<?phpif (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`:)regardsLiam Link to comment https://forums.phpfreaks.com/topic/25509-php-syntax-error/#findComment-116402 Share on other sites More sharing options...
SithLord2K Posted October 29, 2006 Author Share Posted October 29, 2006 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 More sharing options...
shocker-z Posted October 29, 2006 Share Posted October 29, 2006 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]<?phpif (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 More sharing options...
SithLord2K Posted October 30, 2006 Author Share Posted October 30, 2006 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. Link to comment https://forums.phpfreaks.com/topic/25509-php-syntax-error/#findComment-116510 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.