devwalt Posted April 1, 2008 Share Posted April 1, 2008 I have been working on the form to database for sometime now, ofcourse I am a student and things are not working as desired. However, I have made some progress. I have a form page that gathers member info Firstname, Lastname, State, Email, username, passoword and verfiy password. The page is account.php. That info is sent to login.php and gathers the info into variables, connects to server (localhost). To make sure the information is getting passed I echo the Firstname to the page and it prints fine, the problem is this, it does not insert info into the database. I also have the database echo the results to the page for now to see if the info is entering the database, which it is not. It does create the ID number (auto_increment) and the column names, but no member info. Before I wasn't even getting that, so I have made some improvement. Below is what I have to connect, gather and insert member info. Could you please review and advise why information is not inserting into the database. NOTE: Member names, state and email is set to one table and username, password and verfiy password to another. <?php $mysqli = mysqli_connect("localhost", "walter", "wv688802", "db_family_members"); if (mysqli_connect_errno()) { printf("Connect failed: %s\n", mysqli_connect_error()); exit(); } if ($mysqli) { $first = empty($_POST['FirstName']) ? die ("ERROR: Enter First Name") : mysqli_connect_error($_POST['FirstName']); $last = empty($_POST['LastName']) ? die ("ERROR: Enter Last Name") : mysqli_connect_error($_POST['LastName']); $state = empty($_POST['ST']) ? die ("ERROR: Enter your State") : mysqli_connect_error($_POST['ST']); $email = empty($_POST['EmailAdd']) ? die ("ERROR: Enter your State") : mysqli_connect_error($_POST['EmailAdd']); $query = "INSERT INTO tbl_member_info VALUES (NULL, '".$first."', '".$last."', '".$state."', '".$email."')"; mysqli_query($mysqli, $query); } if ($mysqli) { $user = empty($_POST['Username']) ? die ("ERROR: Enter Username") : mysqli_connect_error($_POST['Username']); $pass = empty($_POST['Password']) ? die ("ERROR: Enter Password") : mysqli_connect_error($_POST['Password']); $vpass = empty($_POST['VPassword']) ? die ("ERROR: Verify Password") : mysqli_connect_error($_POST['VPassword']); $query = "INSERT INTO tbl_users VALUES (NULL, '".$user."', '".$pass."', '".$vpass."')"; mysqli_query($mysqli, $query); } if ($mysqli) { $result = $mysqli->query("SELECT * FROM tbl_member_info"); while($row = $result->fetch_array()) { foreach($row as $key => $value){ echo "$key = $value<br />\n"; } } } $result->close(); $mysqli->close(); ?> Link to comment https://forums.phpfreaks.com/topic/99078-php-to-mysqli-in-php-5-help/ Share on other sites More sharing options...
roxki Posted April 2, 2008 Share Posted April 2, 2008 As far as I can see the problem is when you're adding data to your database you use multiple quotes (") which might ruin it all. <?php // Your code / Wrong code: $query = "INSERT INTO tbl_member_info VALUES (NULL, '".$first."', '".$last."', '".$state."', '".$email."')"; mysqli_query($mysqli, $query); // Right code / Working code: $query = "INSERT INTO tbl_member_info VALUES (NULL, '$first', '$last', '$state', '$email')"; mysqli_query($mysqli, $query); ?> You were simply stopping the variable quotes, so try change it and see if it solves your problem. And remember to change it on both of your $query variables. Link to comment https://forums.phpfreaks.com/topic/99078-php-to-mysqli-in-php-5-help/#findComment-507088 Share on other sites More sharing options...
devwalt Posted April 2, 2008 Author Share Posted April 2, 2008 Thanks for the reply roxki, That was my orginal syntax, however I tried it again and get the same results. Not sure, but I may have to rebuild the database and tables. Link to comment https://forums.phpfreaks.com/topic/99078-php-to-mysqli-in-php-5-help/#findComment-507127 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.