amitchhajer Posted April 10, 2009 Share Posted April 10, 2009 PLZ help me with this code...hav sum coding prblem m making a form 2 input values in a database..plz reply asap m a noob hi ur data is being processed and your account will be activated within 24hrs <?php $a=htmlspecialchars($_POST['name']); $b=htmlspecialchars($_POST['fname']); $c=htmlspecialchars($_POST['lname']); $d=htmlspecialchars($_POST['pass']); $e=htmlspecialchars($_POST['pass2']); $f=htmlspecialchars($_POST['sques']); $g=htmlspecialchars($_POST['sans']); $h=htmlspecialchars($_POST['smail']); $i=htmlspecialchars($_POST['location']); ?> Thanks for registering <?php $con = mysql_connect(); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("amit", $con); $sql="INSERT INTO LOGIN VALUES('$_POST[Choose LOGIN name]','$_POST[First name]','$_POST[Last name]','$_POST[Choose a Password]','$_POST[Re-enter Password]','$_POST[security Question]','$_POST[Answer]','$_POST[secondary email]','$_POST[Location]'); if (!mysql_query($sql,$con)) { die('Error: ' . mysql_error()); } echo "1 record added"; mysql_close($con) ?> Link to comment https://forums.phpfreaks.com/topic/153536-php_sql-coding-problem-in-wamp-server/ Share on other sites More sharing options...
jackpf Posted April 10, 2009 Share Posted April 10, 2009 Ok, you're not helping, you need to provide the necessary information. What error are you getting? How is it not working? Besides, you're not actually connectingto your database with any credentials. Link to comment https://forums.phpfreaks.com/topic/153536-php_sql-coding-problem-in-wamp-server/#findComment-806771 Share on other sites More sharing options...
amitchhajer Posted April 11, 2009 Author Share Posted April 11, 2009 I got this error in the program::: Parse error: parse error, expecting `']'' in C:\wamp\www\New Folder\actionlogin.php on line 27 i dont know wat is credential.. i made a form using form action in php and want to connect it to database links to both files:- http://www.mediafire.com/?sharekey=45cc7f380b7ea8cd1bee9a6e9edd9c76edd7e379ccbffa5cc95965eaa7bc68bc plz do reply Link to comment https://forums.phpfreaks.com/topic/153536-php_sql-coding-problem-in-wamp-server/#findComment-807253 Share on other sites More sharing options...
jackpf Posted April 11, 2009 Share Posted April 11, 2009 Try putting your post elements into variables. As in $username = $_POST['username']; And then insert into the database like this: VALUES ('$username' etc... Link to comment https://forums.phpfreaks.com/topic/153536-php_sql-coding-problem-in-wamp-server/#findComment-807259 Share on other sites More sharing options...
Andy-H Posted April 11, 2009 Share Posted April 11, 2009 When using the post array with strings you need to quote the string (key) in the array, also single quotation marks are for literal data. Example. $user = 'John Wayne'; echo 'Hello $user'; // Outputs Hello $user echo "Hello $user"; // Outputs Hello John Wayne Also I tend to break out of the string for echoing a variable and use mysql_real_escape_string() when inserting postdata into your database. Never insert raw postdata. // EDIT * Also please use code tags when posting code. [*code*][*/code*] Remove the asterix tho. Link to comment https://forums.phpfreaks.com/topic/153536-php_sql-coding-problem-in-wamp-server/#findComment-807271 Share on other sites More sharing options...
jackpf Posted April 11, 2009 Share Posted April 11, 2009 I don't believe quoting post arrays is a necessity, although it is faster. $_POST[whatever]; and $_POST['whatever']; both achieve the same results, though the latter is preferred. And yes, mysql data should be escaped; I was just wondering if it actually solved his problem first Link to comment https://forums.phpfreaks.com/topic/153536-php_sql-coding-problem-in-wamp-server/#findComment-807275 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.