sandbudd Posted June 24, 2008 Share Posted June 24, 2008 here is the code and I cant get it to populate the database? <?php require_once('dbinfo.php'); function super_escape_string($in_string, $in_conn) { $str = $in_conn->real_escape_string($in_string); return ereg_replace('([%;])', '\\\1', $in_string); } // 1. // we will go light on data validation here a little bit in the // interest of not distracting much from our example. // // look at the normal data. $uname = isset($_POST['userName']) ? $_POST['userName'] : ''; $fname = isset($_POST['fullName']) ? $_POST['fullName'] : ''; $pw1 = isset($_POST['password1']) ? $_POST['password2'] : ''; $pw2 = isset($_POST['password2']) ? $_POST['password2'] : ''; $email = isset($_POST['email']) ? $_POST['email'] : ''; if ($pw1 != $pw2) throw new PasswordsDontMatchException(); // // did the upload succeed or fail? // if ($_FILES['avatarfile']['error'] == UPLOAD_ERR_OK) { $ext = strtolower(pathinfo($_FILES['avatarfile']['name'], PATHINFO_EXTENSION)); switch ($ext) { // 2. // we will need to know the file type later on to send the // image to the client browser. case 'jpg': case 'jpeg': $fileType = 'image/jpeg'; break; case 'gif': $fileType = 'image/gif'; break; case 'png': $fileType = 'image/png'; break; case 'bmp': $fileType = 'image/bmp'; break; default: throw new InvalidFileTypeException($ext); } // // to add binary data to a MySQL database, we need // to escape it using the addslashes function, as follows: // $f = @fopen($_FILES['avatarfile']['tmp_name'], 'r'); if ($f === NULL) throw new FileAccessException(); $fsize = @filesize($_FILES['avatarfile']['tmp_name']); $fileData = addslashes(fread($f, $fsize)); fclose($f); if (intval($_FILES['avatarfile']['size']) > 50000) throw new FileTooBigException(); } else throw new FileUploadExeption($_FILES['avatarfile']['error']); // 3. // now create a connection to the db and then make // the parameters safe for inserting. // $conn = @new mysqli(DB_HOST, DB_USR, DB_PW, DB_DB); if (mysqli_connect_errno() !== 0) throw new DatabaseErrorException(mysqli_connect_error()); $uname = super_escape_string($uname, $conn); $fname = super_escape_string($fname, $conn); $pw = md5($pw1); $email = super_escape_string($email, $conn); // 4. // now construct and execute the query: // $query = <<<EOQUERY INSERT INTO AvatarSample (user_name, full_name, password, email, avatar_image, file_type, file_size) VALUES('$uname', '$fname', '$pw', '$email', '$fileData', '$fileType', $fileSize) EOQUERY; $results = @$conn->query($query); if ($results === FALSE) { $msg = $conn->error; $conn->close(); throw new DatabaseErrorException($msg); } $userid = $conn->insert_id; $conn->close(); // // finally, give the user a way to browse the data. // echo <<<EOM <a href='view_user.php?uid=$userid'>View User Info</a> EOM; ?> Link to comment https://forums.phpfreaks.com/topic/111612-solved-php-mysql-does-not-populate-database/ Share on other sites More sharing options...
gijew Posted June 24, 2008 Share Posted June 24, 2008 Are you getting a mysql error? I see the line $msg = $conn->error; but is it telling you anything? Most of the time I find that if I didn't mistype the field name incorrectly I am putting the wrong data type into the field. See what the mysql error says. Link to comment https://forums.phpfreaks.com/topic/111612-solved-php-mysql-does-not-populate-database/#findComment-572900 Share on other sites More sharing options...
sandbudd Posted June 24, 2008 Author Share Posted June 24, 2008 I am getting no errors or anything just a blank page. It kinda funny because if I take all out except for the connect info and dont use password I get denied password but when I put it all back together and use wrong pass or correct pass I get a blank page? Link to comment https://forums.phpfreaks.com/topic/111612-solved-php-mysql-does-not-populate-database/#findComment-572902 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.